In case some of you develop a similar project, this is the final sketch @ric has helped to create last weekend:
#include <OneWire.h>
const int oneWirePin = D3;
OneWire ds = OneWire(oneWirePin);
byte addrs0[6][8] = {{0x28,0xFF,0x0D,0x4C,0x05,0x16,0x03,0xC7}, {0x28,0xFF,0x25,0x1A,0x01,0x16,0x04,0xCD}, {0x28,0xFF,0x89,0x19,0x01,0x16,0x04,0x57}, {0x28,0xFF,0x21,0x9F,0x61,0x15,0x03,0xF9}, {0x28,0xFF,0x16,0x6B,0x00,0x16,0x03,0x08}, {0x28,0xFF,0x90,0xA2,0x00,0x16,0x04,0x76}};
byte addrs1[3][8] = {{0x10,0xE9,0x6B,0x0A,0x03,0x08,0x00,0xAC}, {0x10,0x44,0x4E,0x0B,0x03,0x08,0x00,0x1F}};
double TopH, TopL, MidH, MidL, BotH, BotL;
double* temps[] = {&TopH, &TopL, &MidH, &MidL, &BotH, &BotL};
double celsius;
double Tmin = 35;
double Av1, Av2, Av3, Av4, Av5;
double Q1, Q2, Q3, Q4, Q5, Qtot;
void setup()
{
Particle.variable("TopH", TopH);
Particle.variable("TopL", TopL);
Particle.variable("MidH", MidH);
Particle.variable("MidL", MidL);
Particle.variable("BotH", BotH);
Particle.variable("BotL", BotL);
Particle.variable("ECO-Qtot", Qtot);
}
void loop()
{
getTemperatures(0);
Av1 = (TopH + TopL)/2;
Av2 = (TopL + MidH)/2;
Av3 = (MidH + MidL)/2;
Av4 = (MidL + BotH)/2;
Av5 = (BotH + BotL)/2;
Q1 = (Av1-Tmin)*110*1.163/1000;
Q2 = (Av2-Tmin)*90*1.163/1000;
Q3 = (Av3-Tmin)*90*1.163/1000;
Q4 = (Av4-Tmin)*90*1.163/1000;
Q5 = (Av5-Tmin)*110*1.163/1000;
Qtot = Q1+Q2+Q3+Q4+Q5;
delay(5000);
}
void getTemperatures(int select)
{
ds.reset();
ds.skip();
ds.write(0x44, 0);
delay(1000);
ds.reset();
for (int i=0; i< sizeof(temps)/sizeof(temps[0]); i++)
{
switch (select)
{
case 0:
ds.select(addrs0[i]);
break;
case 1:
ds.select(addrs1[i]);
break;
}
ds.write(0xBE,0);
byte data0 = ds.read();
byte data1 = ds.read();
ds.reset();
if (select == 0)
{
int16_t raw = (data1 << 8) | data0;
celsius = (double)raw * 0.0625;
}
else if (select == 1)
{
int16_t raw = data0;
celsius = (double)raw * 0.5;
}
*temps[i] = celsius;
}
}
It is in my opinion simplified as much as possible and it works really perfectly, thanks @ric!
I could not have developed this myself…