I've been through all the tutorials I have parts for.
Now I've got my hands on a couple DS18B20 temp sensors. I'm seeing the thing at the ardu playground, it all makes sense except for the library stuff. I don't know how/where to put the files (they link http://homepage.mac.com/wtpollard/Software/FileSharing7.html for library) and I have downloaded that. Now I'm stuck on what to do!
Help please.
Found it. was a loose nut between the keyboard and chair :o. So now I've got some intelligable results, but still a problem.
Output from serial:
R=28 C9 C2 1 2 0 0 76 P=1 A0 1 4B 46 7F FF 10 10 6E CRC=6E (I do notice that the CRC value does change from set to set)
The 26.00 should be the temperature, in Celsius, as given from the
two hex numbers just after P=1.
That CRC value should change, if there's a change in the scratchpad
registers, those 9 values after P=1.
Suggestions? In terms of what?
It looks like it's working to me unless you've got more than one
temperature sensor on your OneWire pin.
The output looks a little odd unless the OneWire sample program has
been altered, which it must have been if the temperature is displayed
and the DS18B20 are accepted since the sample program I have looks
for temperature sensors with family code 0x10, the 18B20 is 0x28.
If the output ended after the second R=28 C9... then there's a problem
in your program or maybe a loose wire in your circuit causing your
program to hang/crash.
Well, that is certainly progress. Now how do I make use of or get rid of all that other stuff? I'm really just interested in the temperature alone.
Also, any idea if I should expect this sensor to have any drift over time?
Please let me know if I have mistakes, as I am as new to coding as I am to the Arduino. I have pasted the code I use below:
#include <OneWire.h>
// DS18b20 Temperature chip i/o
OneWire ds(10); // on pin 10
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
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] != 0x28) {
Serial.print("Device is not a DS18B20 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();
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
if (SignBit) // If its negative
{
Serial.print("-");
}
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
{
Serial.print("0");
}
Serial.print(Fract);
Serial.print("\n");
}
Ok, I've got it working pretty slick now. I've seen a couple folks who have done conversions from °C to °F, and I've tried to adapt pieces of what they did, or even make it from scratch...and all i get is scratching my head.