DS18B20 with Multiple I/O Lines

Hi,

I'm new to C programming so please be kind to me - I can be quiet slow and dense at times!! :smiley:
( have done some Pic assembler).

I've got the Ds18b20 sensor up and running on the Uno in both single and multiple versions.

For my home project I would like to use a separate i/o line for each of three sensors rather than a daisy chain.

Have tried a couple of things to get the 'single' version to do separate channels but its doesn't like it - can it be done in its existing form ?

The reason I don't want to use the 'multiple' version is that if /when a sensor fails, its not a case of just plug in a new sensor, its address has to be read and added to the main program - too cumbersome. Also the chance of a failing sensor blocking out all the others on that line seems to increase the failure potential, which is not good for my purpose.

thanks

Install this library - MilesBurton.com

You should be able to create multiple instances of the objects needed:

Compiles but not tested as I have no sensors nearby.

#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
#define OWB2 3
 
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
OneWire OW2(OWB2); 

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DallasTemperature zenz(&OW2);
 
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
 
  // Start up the library
  sensors.begin();
  zenz.begin();
}
 
 
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
   
  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire  


  Serial.print("Requesting temperatures...");
  zenz.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
   
  Serial.print("Temperature for Device 1 is: ");
  Serial.print(zenz.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire  
}

Please let us know if it works.
Rob

Why do you anticipate sensors failing?

Why do you anticipate sensors failing?

Because he thinks and acts like a pro and has encountered failing hardware in his life before? :wink:

If I had spare I/O lines, I'd do the same as the OP, if only to avoid the nuisance of dealing with the chips' IDs. It will also allow a star topology, which 1-Wire doesn't like for multiple devices on one line... though in some circumstances, where a single run will work, multiple sensors on one line will of course save wire. Ah the joys of design!

However... I really write to address the question of the sensor chips failing. I've "worked" (as a hobbyist) with them for year, with some outdoors as well as indoors, and never had one fail. (yet!)

The temperature readings at my FarWatch page are done with Dallas chips...

http://mon7nc.dyndns.org/

See...

... for further on 1-Wire sensors.

robtillaart:
Please let us know if it works.
Rob

Hi Rob,

Indeed it does work well , many thanks! :smiley: :smiley:

I was using that library already and with a friends help had tried something similar but clearly wrong.

Yes, you are right about sensor failure, it being the weakest link in the design imho , not from the actual circuit design of the sensor but enviromental factors usually resulting from corrosion of the devices pins.

Either encapsulate the DS18B20 yourself with RTV/Silicone rubber in a small plastic tube, or for $5 buy one already built in Stainless steel like this:
http://arduino-direct.com/sunshop/index.php?l=product_detail&p=151

Disclaimer: That one is in my own shop....

Rob,

I am also new to Arduino and have a question about the code you posted for putting DS18B20 sensors on separate ports. I have tested your code and it does work, however, I would like for it to not only display in degrees C but if degrees F as well and have no idea how to do that. Can you help ?

Thanks

The Library usually used can give you results in either C or F.

See:
//Get DallasTemperature Library here: MilesBurton.com
#include <DallasTemperature.h>

Example code:
http://arduino-info.wikispaces.com/MultipleTemperatureSensorsToLCD

Converting Celsius to Fahrenheit is not trivial, especially in the integer domain.

See - Celsius to Fahrenheit revisited - integer averaging considered harmful - Libraries - Arduino Forum -