Default DS18S20 example returns perplexing results
greetings,
i beginning play dallas semiconductor ds18s20 , onewire library , out of gate seeing strange results.
i using default temperature sensor example. i'm connecting single ds18s10 pin 10 of leonardo 4.7k pullup resistor, not using parasitic power. sketch compiles, uploads, , runs fine either arduino 1.0.5 or 1.5.7 on mac os x mavericks. seems see ds18s20 , extract serial number, seems pass crc check. temperatures negative territory. respond temperature changes, it's clear data being read, not interpreted correctly.
at first blush i'd guess there byte order problem or byte misalignment or of type, without proper debugger i'm stabbing in dark. there peculiar arduino on mac perhaps missed when library made? best googling skills not helping.
here's output few runs sensor between fingers raise temperature.
the example code:
i beginning play dallas semiconductor ds18s20 , onewire library , out of gate seeing strange results.
i using default temperature sensor example. i'm connecting single ds18s10 pin 10 of leonardo 4.7k pullup resistor, not using parasitic power. sketch compiles, uploads, , runs fine either arduino 1.0.5 or 1.5.7 on mac os x mavericks. seems see ds18s20 , extract serial number, seems pass crc check. temperatures negative territory. respond temperature changes, it's clear data being read, not interpreted correctly.
at first blush i'd guess there byte order problem or byte misalignment or of type, without proper debugger i'm stabbing in dark. there peculiar arduino on mac perhaps missed when library made? best googling skills not helping.
here's output few runs sensor between fingers raise temperature.
code: [select]
rom = 10 3d ae 62 0 8 0 2c
chip = ds18s20
data = 1 ff 0 0 ff ff c 10 38 crc=38
temperature = -33.00 celsius, -27.40 fahrenheit
no more addresses.
rom = 10 3d ae 62 0 8 0 2c
chip = ds18s20
data = 1 c0 ff 0 0 ff ff f 10 61 crc=61
temperature = -32.19 celsius, -25.94 fahrenheit
no more addresses.
rom = 10 3d ae 62 0 8 0 2c
chip = ds18s20
data = 1 c1 ff 0 0 ff ff 1 10 fe crc=fe
temperature = -31.31 celsius, -24.36 fahrenheit
no more addresses.
rom = 10 3d ae 62 0 8 0 2c
chip = ds18s20
data = 1 c3 ff 0 0 ff ff 7 10 d2 crc=d2
temperature = -30.69 celsius, -23.24 fahrenheit
no more addresses.
rom = 10 3d ae 62 0 8 0 2c
chip = ds18s20
data = 1 c4 ff 0 0 ff ff f 10 74 crc=74
temperature = -30.19 celsius, -22.34 fahrenheit
no more addresses.
rom = 10 3d ae 62 0 8 0 2c
chip = ds18s20
data = 1 c4 ff 0 0 ff ff 10 8b crc=8b
temperature = -29.87 celsius, -21.77 fahrenheit
no more addresses.
the example code:
code: [select]
#include <onewire.h>
// onewire ds18s20, ds18b20, ds1822 temperature example
//
// http://www.pjrc.com/teensy/td_libs_onewire.html
//
// dallastemperature library can work you!
// http://milesburton.com/dallas_temperature_control_library
onewire ds(10); // on pin 10 (a 4.7k resistor necessary)
void setup(void) {
serial.begin(9600);
}
void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
serial.println("no more addresses.");
serial.println();
ds.reset_search();
delay(250);
return;
}
serial.print("rom =");
for( = 0; < 8; i++) {
serial.write(' ');
serial.print(addr[i], hex);
}
if (onewire::crc8(addr, 7) != addr[7]) {
serial.println("crc not valid!");
return;
}
serial.println();
// first rom byte indicates chip
switch (addr[0]) {
case 0x10:
serial.println(" chip = ds18s20"); // or old ds1820
type_s = 1;
break;
case 0x28:
serial.println(" chip = ds18b20");
type_s = 0;
break;
case 0x22:
serial.println(" chip = ds1822");
type_s = 0;
break;
default:
serial.println("device not ds18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, parasite power on @ end
delay(1000); // maybe 750ms enough, maybe not
// might ds.depower() here, reset take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xbe); // read scratchpad
serial.print(" data = ");
serial.print(present, hex);
serial.print(" ");
( = 0; < 9; i++) { // 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();
// convert data actual temperature
// because result 16 bit signed integer, should
// stored "int16_t" type, 16 bits
// when compiled on 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xfff0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// @ lower res, low bits undefined, let's 0 them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
serial.print(" temperature = ");
serial.print(celsius);
serial.print(" celsius, ");
serial.print(fahrenheit);
serial.println(" fahrenheit");
}
please post code, using code tags ("#" button).
Arduino Forum > Using Arduino > Sensors > Default DS18S20 example returns perplexing results
arduino
Comments
Post a Comment