When I do this, I get a constant reading of 3 degC off the sensor (its much warmer than that in my room). If I look at the raw values that come off the sensor, the temperature part never changes.
I think my physical setup is correct as any other configuration doesn't return anything on the bus. Any idea what might be causing the problem? Let me know if I'm missing any important information.
out of Curiosity - have you tried to artificially modify the temp to see if the value changes? In example, apply an ice-cube to the sensor and watch the values? If it changes, then that will help you narrow down where the issue might be.
I'm using a combination of the OneWire code from the playground (Arduino Playground - OneWire) and the bit shifting from that forum post.
#include <OneWire.h>
// DS18S20 Temperature chip i/o
OneWire ds(12); // on pin 10
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();
int rawtemp = (data[1] << 8) + data[0];
double tempc, tempf;
tempc = (double)rawtemp / 16.0;
tempf = (tempc * 1.8) + 32.0;
Serial.print("T=");
Serial.println(tempf,DEC);
}
I think I see what's going wrong. The raw data seems reasonable, so I checked the DS18S20 data sheet and I think the value "rawdata" indicates temperature at 1/2 degree (celsius) chunks, and not 1/16 degree. If you change the one line to
tempc = (double)rawtemp / 2.0;
you get more plausible temperatures of 26.5C = 79.7F, 27.0C = 80.6F, and 21.5C = 70.7F.
For confirmation, look at "Table 1: Temperature/Data Relationship" in the datasheet.