Hallo,
um zwei DS18s20 auszulesen benutze ich folgenden Sketch von FLUXX:
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ds(2); //pin für ds1820
//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x10, 0xDE, 0x29, 0x95, 0x2, 0x8, 0x0, 0x7E };
DeviceAddress sensor2 = { 0x10, 0x3, 0xCF, 0x95, 0x2, 0x8, 0x0, 0xB6 };
//DeviceAddress sensor3 = { 0x10, 0x11, 0x40, 0xC0, 0x1, 0x8, 0x0, 0x9A };
//DeviceAddress sensor4 = { 0x10, 0x77, 0x38, 0x57, 0x2, 0x8, 0x0, 0x3B };
char sensor1Name[] = "Aussen : ";
char sensor2Name[] = "Waermetauscher: ";
//char sensor3Name[] = "Heizkeller: ";
//char sensor4Name[] = "Aquarium: ";
void setup(void)
{
Serial.begin(9600);
}
void writeTimeToScratchpad(byte* address)
{
//reset the bus
ds.reset();
//select our sensor
ds.select(address);
//CONVERT T function call (44h) which puts the temperature into the scratchpad
ds.write(0x44,1);
//sleep a second for the write to take place
delay(1000);
}
void readTimeFromScratchpad(byte* address, byte* data)
{
//reset the bus
ds.reset();
//select our sensor
ds.select(address);
//read the scratchpad (BEh)
ds.write(0xBE);
for (byte i=0;i<9;i++){
data[i] = ds.read();
}
}
float getTemperature(byte* address)
{
int tr;
byte data[12];
writeTimeToScratchpad(address);
readTimeFromScratchpad(address,data);
//put in temp all the 8 bits of LSB (least significant byte)
tr = data[0];
//check for negative temperature
if (data[1] > 0x80)
{
tr = !tr + 1; //two's complement adjustment
tr = tr * -1; //flip value negative.
}
//COUNT PER Celsius degree (10h)
int cpc = data[7];
//COUNT REMAIN (0Ch)
int cr = data[6];
//drop bit 0
tr = tr >> 1;
return tr - (float)0.25 + (cpc - cr)/(float)cpc;
}
void loop(void)
{
float temp1 = getTemperature(sensor1);
float temp2 = getTemperature(sensor2);
//float temp3 = getTemperature(sensor3);
//float temp4 = getTemperature(sensor4);
Serial.print(sensor1Name);
Serial.print(temp1);
Serial.println(" Celsius");
Serial.print(sensor2Name);
Serial.print(temp2);
Serial.println(" Celsius");
//Serial.print(sensor3Name);
//Serial.print(temp3);
//Serial.println(" Celsius");
//Serial.print(sensor4Name);
//Serial.print(temp4);
//Serial.println(" Celsius");
Serial.println();
//delay(1000);
}
Dies funktioniert auch.
Nur gibt es in der Funktion " writeTimeToScratchpad" ein delay von 1000 !!!
Dieser bremst mir doch meinn gesamten Sketch aus ... oder etwa nicht.
Wenn ich dies delay rausnehme habe ich bei einem von beiden DS eine Temperatur von konstant 85 Grad (Fehler vom DS...wie auch bei anderen Sketches welche ich getestet habe).
Hat jemand eine Lösung parat ????
Danke erstmal