ds18b20 help please

I am new to all this and know very little about electronics but I'm learning. I know nothing about programming and I think that is where my problem lies. I have 2 dallas ds18b20 temp sensors on my bread board and I can call up their addresses and see the temperature of each but once I down load the next code from Beginning Arduino Project 37 (Part 2) I get a temperture but it won't change for either sensor. I used to get the 85 degree error and I when through the wires and found the short but now I am stuck. Any help would be great. I am about to tear my hair out. :0 Thanks

code from Beginning Arduino Project 37 (Part 2)

do you have a link to this?

Sounds like Mike Mc's book.

There are .pde files available for download from Apress.

// Project 37 - Part 2                                                                                                                                    

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3                           
#define TEMPERATURE_PRECISION 12                 

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas?
 temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses – replace with your sensors addresses
DeviceAddress insideThermometer = { 0x28, 0xCA, 0x90, 0xC2, 0x2, 0x00, 0x00, 0x88 };
DeviceAddress outsideThermometer = { 0x28, 0x3B, 0x40, 0xC2, 0x02, 0x00, 0x00, 0x93 };

void setup()
{
  // start serial port
  Serial.begin(9600);

  // Start up the library
  sensors.begin();

  Serial.println("Initialising...");
  Serial.println();

// set the resolution
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(" Temp C: ");
  Serial.print(tempC);
  Serial.print("  Temp F: ");
  Serial.println(DallasTemperature::toFahrenheit(tempC));
}

void loop()
{
  // print the temperatures
  Serial.print("Inside Temp:");
  printTemperature(insideThermometer);
  Serial.print("Outside Temp:");
  printTemperature(outsideThermometer);
  Serial.println();
  delay(3000);
}

dustyclc, did you change the sensor addresses before running the sketch?

dustyclc,

I know the DallasTemperature library should make it easier to read the sensors, but I don't understand why they require you to hard code the sensor addresses in the sketch.

You can try read the sensors directly with the OneWire V2 Library from PJRC using the example code on the same page as the library at OneWire Arduino Library, connecting 1-wire devices (DS18S20, etc) to Teensy. This code will find all of the sensors on your 1-Wire bus and the output should let you know if you are communicating correctly.

You can also see the example in the Arduino Playground to convert the HEX data returned in the example above to temperature in Celsius. See "Converting HEX to something meaningful (Temperature)" at Arduino Playground - OneWire

willnue

Thank guys for responding. I will try the other library suggested by willnue. Sorry for the confusion about the tutorial I was using it was Mike Mc's book I found online.

Justjed I did change the addresses as instructed but the temp would not change it would stay stuck at 23 degrees and not change period.

Which I thought was weird because the first sketch from the book returned the addresses for each ds1820 and displayed the temp for each also. So I know I was doing something right.

Well I will go give this a try and report back to you all later, Thanks again.

willnue:
I know the DallasTemperature library should make it easier to read the sensors, but I don't understand why they require you to hard code the sensor addresses in the sketch.

I assume that's just for keeping things very very simple (though I agree it's arguable whether declaring an array of hex-quoted uint8_t type is simpler than just storing the addresses in an array for later use). The 'Multi' example in the Dallas library assigns addresses using the search function. (In Multiple.pde, the search usage is commented out, but it's provided for example.)

 [content snipped]

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

 [content snipped]

  // Must be called before search()
  oneWire.reset_search();
  // assigns the first address found to insideThermometer
  if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
  // assigns the seconds address found to outsideThermometer
  if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");

 [content snipped]

The 'Multi' example in the Dallas library assigns addresses using the search function. (In Multiple.pde, the search usage is commented out, but it's provided for example.)

I have seen that before, but since the way the Multiple.pde example is written to still require the use of a statically assigned DeviceAddress variable and corresponding output functions etc... for each sensor even when using the search function makes it cumbersome for a beginner to figure out and get working with their particular setup. It also pretty much defeats the purpose of the search function ie. I need to know the number of sensors and write code to support each of them prior to using it or the index method, the only difference between search and index being whether or not I add the hard coded address to my already existing hard coded DeviceAddress variable.

I think most beginners are looking for more plug and play code, which I think the code on the Arduino Playground 1-Wire is better suited to.

willnue

Hey guys I finally looked at the code from the first part of the tutorial and this is what comes out of the serial monitor.
Requesting temperatures...DONE
Device Address: 28B2DFDF02000092 Temp C: 23.12 Temp F: 73.62
Device Address: 2889C0DF02000094 Temp C: 23.12 Temp F: 73.62

So I am getting the temp and the address so I guess I don't need the second part of the tutorial.

Well I will have to study up on the code some more so I can adapt this to the arduino controlled incubator I want to automate.
Thanks for all you suggestions I just need to read a little more slowly and not drink so much coffee.

I will post my results as I get them. Thanks