Hallo maverick1509,
meinst du so:
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ds(28); //pin für ds1820
//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x28, 0x36, 0x2F, 0x99, 0x4, 0x0, 0x0, 0x3A };
DeviceAddress sensor2 = { 0x28, 0xB1, 0xB7, 0xBD, 0x4, 0x0, 0x0, 0xA2 };
char sensor1Name[] = "Unterschrank: ";
char sensor2Name[] = "W.-Temp: ";
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 [color=orange]getTempC[/color](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 =getTempC(sensor1);
float temp2 =getTempC(sensor2);
Serial.print(sensor1Name);
Serial.print(temp1);
Serial.println(" Celsius");
Serial.print(sensor2Name);
Serial.print(temp2);
Serial.println(" Celsius");
Serial.println();
delay(1000);
}
zeigt aber leider immer noch die Temperatur in Fahrenheit an.
Gruß Jens