robtillaart:
A big question at the moment is how to handle the 1Wire Sensor Adresses and assign them to the right Terrarium.
your idea looks good but I see no code you have tried sofar ...
Yes it is still pre Alpha
But here is something:
I created the following Object
/*
Represents a Terrarium Object
*/
typedef struct
{
String Name;
byte* Sensor;
}Terrarium;
Created an Array of it
const int NumTerrariums = 2;
byte sensor1[8] = { 0x10, 0xB2, 0xA0, 0x54, 0x2, 0x8, 0x0, 0x4E };
byte sensor2[8] = { 0x10, 0x3F, 0x7D, 0x54, 0x2, 0x8, 0x0, 0x5C };
Terrarium Terrariums[NumTerrariums];
Add initialize it with the following Data:
void updateTerrariums {
Terrariums[0].Name = "Terrarium1";
Terrariums[0].Sensor =&sensor1[0];
Terrariums[1].Name = "Terrarium2";
Terrariums[1].Sensor = &sensor2[0];
}
I use the sensor first in the following DS1820 libfunction:
float GetTemperature(byte sensor[8])
{
//CRC Check
if (OneWire::crc8(sensor, 7) != sensor[7]) {
Serial.println("CRC is not valid!");
return 0;
}
// the first ROM byte indicates which chip
switch (sensor[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 is not a DS18x20 family device.");
return 0;
}
ds.reset();
ds.select(sensor);
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(sensor);
ds.write(0xBE); // Read Scratchpad
//Serial.print(" Data = ");
//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(" ");
}
// convert the data to actual temperature
unsigned int 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);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
return celsius;
}
But i think i missed something with the pointers... I come from the c# world so i dont know the point(er)...
BTW: Look what i received from China And so nicely wrapped