Hallo,
ich versuche die Temperatur aus einem DS18S20+ auszulesen, bekomme aber eine etwas zu hohe Temperatur heraus (~26 statt 21 °C):
int temperatur(void) {
byte i;
byte present = 0;
byte data[12];
int Tc_100 = 0;
int HighByte, LowByte, TReading, SignBit;
byte addr[8]={16,98,181,116,2,8,0,84}; // Adresse meines Sensors
if ( OneWire::crc8( addr, 7) != addr[7]) {
//Serial.print("CRC is not valid!\n");
return -2000;
}
if ( addr[0] != 0x10) {
//Serial.print("Device is not a DS18S20 family device.\n");
return -2000;
}
// The DallasTemperature library can do all this work for you!
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
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
// Temeperatur bestimmen
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
return Tc_100;
}
Ist der Umrechnungsfaktor möglicherweise falsch?
Danke
Gruß
Mebus