How to: two chains of DS18B20 by code? (SOLVED)


hi,

i have problem reading temperature data 2 chains of ds18b20 soldered in parasite mode each 1 of them, , connected 2 different digital pins in arduino 2009.

i had 1 of chains running measuring temperature of air @ different altitudes ground. added new chain in order measure temperature of ground @ different deeps.

each chain runs independenty, , writed next example code in order have both of them connected arduino 2009:

code: [select]
#include <dallastemperature.h>
#include <onewire.h>

#define tempair 2
#define tempground 4
onewire onewire(tempair);
dallastemperature sensors(&onewire);
onewire onewire2(tempground);
dallastemperature sensors2(&onewire);

float temperature=0;
float temperature2=0;
int i;

void setup(){
 sensors.begin();
 serial.begin(9600);
}

void loop(){
 serial.println("air temperature...");
 for (i=0; i<5; i++){
   sensors.requesttemperatures();
   temperature=sensors.gettempcbyindex(i);
   serial.print("sensor ");
   serial.print(i);
   serial.print(": ");
   serial.print(temperature);
   serial.println(" (celsius)");
 }
 serial.println();
 serial.println("ground temperature...");
 for (i=0; i<5; i++){
   sensors2.requesttemperatures();
   temperature2=sensors2.gettempcbyindex(i);
   serial.print("sensor ");
   serial.print(i);
   serial.print(": ");
   serial.print(temperature2);
   serial.println(" (celsius)");
 }
 delay(2000);
}


however, data not correct second chain (ground temperature), connected digital pin 4. returned values -127...

any idea how solve it? see wrong in code?

by way, can not change hardware connect sensors in 1 chain.

thanks!!

did leave out sensors2.begin() call in setup()?


Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > How to: two chains of DS18B20 by code? (SOLVED)


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums