Before calling it a day, I have integrated @Ric 's full library (with 2 buses of sensors) into my revised sketch, so that I can also compile in the Web-IDE.
Here it is:
// Buffer-TEST.ino = Sketch to read hardcoded DS18B20 sensors by their HEX sensor code and call them from the loop() by their names...
// Choose one of 2 possibilities:
// 1) For use in the IDE:
//#include "OneWire/OneWire.h"
// 2) For use with Particle Dev:
#include "OneWire.h"
double celsius;
// Group sensors in their bus (on one I/O pin) ; [6][8] means: 6 sensor codes with 8 bytes.
// Attention: If the 2 types of sensors are mixed, you must group DS18S20 sensors in one bus and DS18B20 in another bus. You must adapt below code (if(select == 0 or 1)) to the sensor type...
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}};
// Unused sensors: {0x28,0x3A,0xBC,0x07,0x00,0x00,0x80,0x58}, {0x28,0x72,0x03,0x04,0x00,0x00,0x80,0x24}, {0x28,0xD4,0xE7,0x03,0x00,0x00,0x80,0x89}, {0x28,0x78,0xF9,0x03,0x00,0x00,0x80,0x76}, {0x28,0x70,0xAD,0x07,0x00,0x00,0x80,0x53}, {0x28,0x40,0xE1,0x03,0x00,0x00,0x80,0x78}}; // 12x DS18B20 Waterproof wired sensors
byte addrs1[3][8] = {{0x10,0xE9,0x6B,0x0A,0x03,0x08,0x00,0xAC}, {0x10,0x44,0x4E,0x0B,0x03,0x08,0x00,0x1F}, {0x28, 0xD, 0xD3, 0xE2, 0x3, 0x0, 0x0, 0xEE}};// 2x DS18S20 TO92 sensors (Third code is from Ric, not on the bus: Test error handling!)
double Tmin = 25; // Minimum ECO boiler temperature
float TopH, TopL, MidH, MidL, BotH, BotL; // The names you want to call the sensors, created in the array(s) in Dallas.cpp
float* temps1[] = {&TopH, &TopL, &MidH, &MidL, &BotH, &BotL}; // Group1: 6 waterproof sensors
double Av1, Av2, Av3, Av4, Av5; // To store average temperatures
double Q1, Q2, Q3, Q4, Q5, Qtot; // To store energy
void setup()
{
Serial.begin(9600);
delay(3000);
// Particle.variable does not work with 'float' variables. OK with 'double'... (But then I get weird errors...)
Particle.variable("ECO_Av1", Av1);
Particle.variable("ECO_Av2", Av2);
Particle.variable("ECO_Av3", Av3);
Particle.variable("ECO_Av4", Av4);
Particle.variable("ECO_Av5", Av5);
Particle.variable("ECO-Qtot", Qtot);
}
void loop()
{
// Read sensor values! Argument 1: N° of sensors, Argument 2: Particle I/O pin , Argument 3: Select array of addresses (addrs0, addrs1 ...) in Dallas.cpp
getTemperatures(*temps1, 6, D3, 0); // From now you can use the chosen sensor names as if it were ordinary floating type variables...
// Serial output:
Serial.printf("TopH = %.1f TopL = %.1f MidH = %.1f MidL = %.1f BotH = %.1f BotL = %.1f", TopH, TopL, MidH, MidL, BotH, BotL); Serial.println();
// Calculate the average temperature in each of the 5 zones:
Av1 = (TopH + TopL)/2;
Av2 = (TopL + MidH)/2;
Av3 = (MidH + MidL)/2;
Av4 = (MidL + BotH)/2;
Av5 = (BotH + BotL)/2;
// Calculate the energy in each of the 5 zones:
Q1 = (Av1-Tmin)*110*1.163/1000; // Energy in top zone (kWh)
Q2 = (Av2-Tmin)*90*1.163/1000; // Energy in top/mid zone (kWh)
Q3 = (Av3-Tmin)*90*1.163/1000; // Energy in middle zone (kWh)
Q4 = (Av4-Tmin)*90*1.163/1000; // Energy in mid/bottom zone (kWh)
Q5 = (Av5-Tmin)*110*1.163/1000; // Energy in bottom zone (kWh)
Qtot = Q1+Q2+Q3+Q4+Q5; // Total energy content in Buffer
delay(5000); // Minimum 1000 !!!
}
void getTemperatures(float temps[], int tempsCount, int pin, int select)
{
OneWire ds = OneWire(pin);
ds.reset();
ds.skip(); // Make all devices start the temperature conversion
ds.write(0x44, 0); // Tell it to start a conversion (second argument: 1 = parasite power, 0 = powered mode)
delay(1000); // Wait 1 sec for conversion
ds.reset();
for (int i=0; i<tempsCount; 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 you mix both types of sensors, you need this branching:
if (select == 0)
{
int16_t raw = (data1 << 8) | data0;
celsius = (float)raw * 0.0625; // DS18B20 sensor = 12 bit resolution device
}
else if (select == 1)
{
int16_t raw = data0;
celsius = (float)raw * 0.5; // DS18S20 sensor = 9 bit resolution device
}
/*
// If you use only DS18B20 sensors, you can keep it simpler:
int16_t raw = (data1 << 8) | data0;
celsius = (float)raw * 0.0625; // For DS18B20 sensors
*/
temps[i] = celsius;
}
}
The results I get from the Particle variables are still not what I expect:
(Temperatures between 20 - 80°C)

The last variable should be around 20…
I would be very glad to get some tips to find a way to reading the correct data…
Thanks on beforehand!
