Help with DS18S20 Temp Sensors

Hi All,

I've setup my new Arduino Duemilanove with the DS18S20 Parasite temp sensors with the code located in the Arduino playground.

#include <OneWire.h>

// DS18S20 Temperature chip i/o

OneWire ds(8);  // on pin 8

void setup(void) {
  // initialize inputs/outputs
  // start serial port
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }

  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] != 0x10) {
      Serial.print("Device is not a DS18S20 family device.\n");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("P=");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();
}

But for what ever reason the code is not recognizing the sensor as valid.

R=0 0 0 0 0 0 0 0 Device is not a DS18S20 family device.
R=0 0 0 0 0 0 0 80 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!

I've got pin 8 wired to pin 2 on the sensor. A 4.7k Ohm resistor from 5V power on the Arduino also to pin 2 on the sensor. And finally pin 1 on the sensor to GND on the Arduino.

I've tried a couple different pins on Arduino, different sensors, and different resistors but none have made any difference.

Any help would be great.

thanks

Is at an S and not a B ?

Try 0x28 as the crc code instead of 0x10

I am having similar difficulty as well. I get the message "No more addresses" over and over. If I change the pin number in the code (without actually changing the wire) I then get the invalid message you are recieving. My sensors are DS18S20+. Not sure if different code is required for the +. I got mine as free samples from the manufacturer. Has anyone got code that will work with these things. The stuff on playground doesn't seem to work?

Mike, Yeah, its definitely a DS18S20P. I did however try changing the 0x10 to 0x28 for the DS18B20 and 0x22 for the DS1822.

Woodnotoil, FYI I'm trying to do the essentially the same thing as you with a control system for my Tarm boiler and storage tank based on a post you made over in the Boiler room. Thanks. I'll be happy to share my code with you if you're interested and I ever get it working.

Woodnotoil, FYI I'm trying to do the essentially the same thing as you with a control system for my Tarm boiler and storage tank based on a post you made over in the Boiler room. Thanks. I'll be happy to share my code with you if you're interested and I ever get it working.

That would be ideal. I am a little out of my comfort zone, but enjoying myself in the electronics world. If you get something working, send me the code and some pictures. You can PM me in either forum. Thanks for the help.

Bump.

Does anyone have experience with the DS18S20 that could help us get this working? Thanks

I haven't used OneWire but looking at the code, I would think you should see the 'no more addresses' printed – it appears that no device has been found by the ds.search routine.
I note that the code was last tested with version 0010, I wonder if anyone has successfully used it with version 0011 or 0012?

mem, you are certainly right it would indicate there are no devices but there is a device connected. I did consider that the newer version of the IDE might cause an issue so I downloaded and tried 0010 but unfortunately it still gives the same results.

thanks

Have you connected both pin 1 AND pin 3 of the sensor to ground (if you are using the parasite power mode)?

I haven't but will try, thanks. As I understand it though the model I'm using is the parasite model DS18S20P and there is no internal connection on pin 3.

My problem was that I had a 4.7 ohm instead of a 4.7 kohm resistor on it. With the correct resistance I get the id and temp for both of my sensors with the sample code. I get a temp reading of 637. Does anyone have a good equation for converting the 637 reading into Fahrenheit?

a google search found this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208206686

Thanks mem. After reviewing the code I realized it was already giving me Fahren just multiplied by 10.

Now my question is what do you have to do to modify the original code to actually see the temp of another sensor. I seem to only get the temp of the one marked inside in the original code even though I now have the ids for both of my sensors.

Woodnotoil, if you're using the code from fungizmos adding these lines should get you data from your other sensors.

       temp = get_temp(outside);
       
       Serial.print("Temp = ");
       Serial.println(temp*10, DEC); //cant print floats so multiply by 10. ie: 72.1 now = 721 for display purposes

       temp = get_temp(attic);
       
       Serial.print("Temp = ");
       Serial.println(temp*10, DEC);

I unfortunately am still stuck. On the chance that maybe my resistors were the wrong size I went to Radio Shack and grabbed some more 4.7K resistors. I still have the same problem as before though.

Does anyone know if I originally used the 0012 version of the IDE does that permanently become part of the memory of the device? Maybe there is some incompatibility with the latest version of the IDE and the OneWire code so even though I tried using the 0010 version the newer version is stuck on the device.

thanks

thephantomlord

I am using 12 and got it to work so I don't think it is a compatability thing. You probably already did, but try turning the sensor around to make sure you are connecting to the correct pin for ground. I initially had mine backwards as well and didn't realize it until I saw the picture in the 5 post here http://forums.fungizmos.com/viewtopic.php?f=6&t=2&st=0&sk=t&sd=a&sid=b36bb8c9197fc9ca820cab851de66b21 . I am not sure what the difference is between the sensors we bought, but they are so cheap you may want to order some of the ones I got and try those instead. I got the DS18S20+ free samples they offer here Mixed-signal and digital signal processing ICs | Analog Devices . I am not sure why they offer the PAR version since mine are running in parasite mode only. Keep at it you'll get it.

You were right on with the code. I now get the temp of both sensors. I changed the

Serial.print("Temp = ");

to read Temp Inside = and Temp Outside = for each just to make sure I was getting two different readings.

Edit: Also, did you load the onewire.h library thing correctly?

Not meaning to hijack this thread, but has anyone had any luck running that fungizmos.com code (with the exact parts outlined - DS18S20-PAR, 4.7 kohm resistor, arduino, etc...) in sub-freezing temperatures (i.e., <32F)? Once any of my sensors drop below ~32F, the reading switches to something like -190 (I'm not in front of my setup). I'll admit that I need to spend a little more time deep in the code (or am I missing something), but I figured it wouldn't hurt to ask? It's either that or run a line to the freezer and debug!

I did find this -> http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1161557194/58#58
But it really wasn't that helpful...

Thanks in advance for any help you may provide.

Woodnotoil, any chance you could post a picture of your Arduino and wiring? I saw that picture too but as soon as I flip the sensor around I get the no more addresses error. If it's flipped the other way I get the errors about it not being a dS18S20 family device and a CRC error.

I was originally was going to order the sensors you have directly from Maxim but there were closed for the holiday break and I wanted to work on this project ASAP. If I don't get this going with the current sensors though I guess I'll have to order some from them anyway.

thanks

I couldn't figure out how to post the pictures on this forum so I put them in a post on the other one we were following.

http://forums.fungizmos.com/viewtopic.php?f=6&t=2&p=36&sid=9fa3f5eb05dbbe84f6f41dbe58437bb6#p36

Now for a code question. I now need to turn a relay on and off based on an if statement. That if statement will include the temp of the boiler output, the storage tank temp, a setpoint temperature and a differential. I will add the following to the top of the code to initialize the relay pin and to set the last two variables:

    byte boiler[8]  = {0x10, 0xCE, 0xE3, 0x0F, 0x01, 0x08, 0x00, 0xA4};
    byte storage[8] = {0x10, 0xC0, 0x08, 0x64, 0x00, 0x08, 0x00, 0xB2};
    int relayPin = 12;      // Relay connected to digital pin 12
    int setpoint = 175;     // Set the desired storage maximum temp in Fahrenheit here
    int differential = 10;   // Set the differential between source temp and storage temp in Fahrenheit here

Then I need to add the if statement to the loop at the end of the code. My problem is that I am not sure what each temp that has been floated is being called to use in the statement. They appear to both be called temp and printed to serial. I need to use those temps. This is what I have worked out so far and have simply called them (boiler) and (storage) for now. Anyone know how to do this?

    // ########### L O O P ###########
    void loop(void) {

       //search_devices(); //enable this line to get sensor device id. comment out when finished
       
       float temp;
       temp = get_temp(boiler);
       
       Serial.print("Temp = ");
       Serial.println(temp, DEC); 
  
       temp = get_temp(storage);
       
       Serial.print("Temp = ");
       Serial.println(temp, DEC); 


     //Turn Relay on/off routine

     if ((boiler) > (storage) + (differential))     //check source temp for differential
                         {
       digitalWrite (relayPin, HIGH);            //if temp is above x degrees turn pin "ON"
                           }
       else if ((storage) > (setpoint))                  //check storage temp against setpoint
                         {
       digitalWrite (relayPin, LOW);            //if temp is below x degree turn pin "OFF"
                         }
       else
                               {
       digitalWrite (relayPin, LOW);            //if temp is below x degree turn pin "OFF"
                               }

     delay(1000*60);  //1 minute loop
    }

Sorry about that, my quick code/mangle/snippit on the FunGizmos forum left off the twos complement adjustment for temps below freezing.

Where it checks to see if the sign bit is set it you need to do a two's compliment flip as well as making the temp negative. You can replace the if statement to read as follows:

  • if (data[1] > 0x80){ // sign bit set, temp is negative*
  • temp = !temp + 1; //two's complement adjustment*
    _ temp = temp * -1; //flip value negative._
  • }*

That was mentioned in the datasheet, but didn't get tested here until a few weeks ago when our outside temp dropped down to 8 degrees or so..

Not meaning to hijack this thread, but has anyone had any luck running that fungizmos.com code (with the exact parts outlined - DS18S20-PAR, 4.7 kohm resistor, arduino, etc...) in sub-freezing temperatures (i.e., <32F)? Once any of my sensors drop below ~32F, the reading switches to something like -190 (I'm not in front of my setup). I'll admit that I need to spend a little more time deep in the code (or am I missing something), but I figured it wouldn't hurt to ask? It's either that or run a line to the freezer and debug!