Hi,
I changed your code to avoid the 2-dimensional array. That makes the code not really beautiful but it works...
I can confirm that it runs with two sensors on my ZUNO and that I receive the temperature for both sensors in my system (I am using fhem...). However, I had to set up multi-channel assoziation to receive the values for sensor 2 to sensor 5, but this might be different for the Vera system you are running.
I think you can understand the small changes I have made to the handling of the sensor_addresses. If not feel free to ask.
I have also casted the temperature in the Serial.print to (float) to get some decimals.
For my needs I just changed the pin from 9 to 11 and exchanged the first two sensor addresses with the adresses of my sensors.
Just test this sketch and see if it is running.
Best regards,
Andreas.
Code: Select all
// Multiple temperature sensors
#include <ZUNO_DS18B20.h>
// DS18B20 pin connections
#define PIN_OW 9 // this is s_pin number and it have to be in range[9;16]
// We can connect a lot of 1-wire devices to 1-pin
// Because 1-wire is BUS with addresses
OneWire ow(PIN_OW);
// We need only one sensor in one moment of time to read it, so just
// create one object of it
DS18B20Sensor sen18b20(&ow);
// Currrently uCxx (v 0.810) doesn't support an array of constructed object
// But you can use an array of pointers to object
// For example in terms of 18b20:
// DS18B20Sensor sen1(&ow);
// DS18B20Sensor sen2(&ow);
// DS18B20Sensor * sensors[] = {&sen1, &sen2};
// Anyway you don't need it ^ here :)
// Instead of it we have to know adresses of all sensors that you connect to your 1-Wire bus.
// You can detect it if you connect it alone to the BUS one by one and record them addresses
// use scanAloneSensor() it returns 8-byte unique address of sensor connected to the BUS and fill sensor_addresses. This addresses is unique for any 1-wire device.
#define NUMBER_OF_SENSORS 5
#define ADDR_SIZE 8
byte sensor_addresses[NUMBER_OF_SENSORS*ADDR_SIZE] =
{
0x28, 0x34, 0x32, 0x3B, 0x05, 0x00, 0x00, 0xC1,
0x28, 0x13, 0xB7, 0x3B, 0x05, 0x00, 0x00, 0xEB,
0x28, 0x1E, 0xFF, 0x42, 0x05, 0x00, 0x00, 0x4D,
0x28, 0x43, 0x9C, 0x3B, 0x05, 0x00, 0x00, 0x4D,
0x28, 0x1E, 0x78, 0x3B, 0x05, 0x00, 0x00, 0xEC
};
int temp[NUMBER_OF_SENSORS];
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp2),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp3),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp4)
);
void setup() {
Serial.begin(9600);
Serial.println("start");
}
void loop()
{
byte address[ADDR_SIZE];
// use byte instead of int to reduce code size
for (byte i=0; i<NUMBER_OF_SENSORS; i++)
{
// Use fixed point math
// get temperature of sensor i from sensor_addresses
Serial.print("Sensor ");
Serial.print(i);
Serial.print(" address is: ");
for (byte j=0; j < ADDR_SIZE; j++)
{
address[j] = sensor_addresses[i*ADDR_SIZE+j];
Serial.print(address[j], HEX);
Serial.print(" ");
}
temp[i] = sen18b20.getTempC100(address);
Serial.println();
Serial.print("Temperature: ");
Serial.println((float)temp[i]/100.0);
Serial.println();
// Sending report to the right channel
zunoSendReport(1 + i);
}
delay(30000);
}
word getterTemp0()
{
return temp[0];
}
word getterTemp1()
{
return temp[1];
}
word getterTemp2()
{
return temp[2];
}
word getterTemp3()
{
return temp[3];
}
word getterTemp4()
{
return temp[4];
}