Please share example .ino with multiple DS18B20?

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Please share example .ino with multiple DS18B20?

Post by n0ir »

Could someone please share a working example of a sketch with multiple DS18B20 sensors using the Z-Uno libraries so I can understand what I am doing wrong?

I'm having trouble editing the sketch from https://z-uno.z-wave.me/examples/1-wire ... re-sensor/ and the other Arduino sketches for this I have found use the OneWire and DallasTemperature libraries (and if I udnerstand correct I can only use the libraries in user\AppData\Roaming\Arduino15\packages\Z-Uno\hardware\zw8051\2.0.6\libraries, i.e. ZUNO_DS18B20.h not OneWire.h or DallasTemperature.h).

More examples like the one already published on the site (and in the IDE Z-Uno package) would really be welcomed!

I am a user that (obviously) don't have any experience with Arduino, but I would love to be able to use the device for my smart home system.

A wider number of examples to download would go a long way, because then dullards like me can use the available .ino-files as "plugins" without needing to understand Arduino and the programming part.

I read you might plan a Z-Uno starter set with some components. Maybe that will contain more pre-written sketches? :)
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Re: Please share example .ino with multiple DS18B20?

Post by n0ir »

No-one who have a working sketch for multiple DS18B20 sensors using the Z-Uno?

I am sure it is very easy modifying the https://z-uno.z-wave.me/examples/1-wire ... re-sensor/ example sketch to include multiple sensors, but I really don't understand how and all the tutorials from other sites using other Arduino boards are not working.

This is the original example sketch for 1 sensor:

Code: Select all

// demo sketch for connecting OneWire temperature sensor DS18B20 to Z-Uno

// add library ds18b20
#include "ZUNO_DS18B20.h"

// pin connection ds18b20
#define PIN_DS18B20 11

OneWire ow(PIN_DS18B20);

// onewire connection temperature sensors
DS18B20Sensor ds1820(&ow); 

byte addr1[8];
int temp; // here we will store the temperature

// set up channel
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,
                          getterTemp)
);

void setup() {
    Serial.begin();
    Serial.println("start"); 

    
     
}

void loop() {
    ds1820.scanAloneSensor(addr1);
    // obtaining readings from the sensor ds18b20
    float temerature = ds1820.getTemperature(addr1);
    // make scaled word value for report
    temp=int(temerature*100);
    Serial.print("Your sensor address is: ");
    for(int i = 0; i < 8; i++) {
            // print OneWire code
            Serial.print(addr1[i], HEX);
            Serial.print(" ");
    }
    Serial.println();
    
    Serial.print("Temperature: ");
    Serial.println(temerature);
    
    // send data to channel
    zunoSendReport(1);     
    // send every 30 second
    delay(30000);
}

word getterTemp() {
    return temp;
}
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Please share example .ino with multiple DS18B20?

Post by p0lyg0n1 »

You are not alone. Look here: https://forum.z-wave.me/viewtopic.php?f ... 473#p65473
In short words: Z-Uno can work with miltiple sensors, but you have to know them ONEWIRE addresses. We haven't implement the complete ONEWIRE-scan procedure yet. I hope we will do it in 2.0.8.
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Re: Please share example .ino with multiple DS18B20?

Post by n0ir »

Thank you for your help.

I have now used the instructions here https://www.hacktronics.com/Tutorials/a ... inder.html with my Uno to find my DS18B20 unique addresses.

I have hooked up and tested the DS18B20 sensors using the addresses with this sketch for Uno https://www.hacktronics.com/Tutorials/a ... orial.html. The sketch seems to work and I get temperature readings for all sensors in the Serial Monitor:
2016-12-04 (1).png
2016-12-04 (1).png (7.65 KiB) Viewed 11390 times
I have then modified the Z-Uno sketch using the specific addresses:

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() 
{
// 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 with address sensor_addresses[i] 
temp[i] = sen18b20.getTempC100(sensor_addresses[i]);

Serial.print("Sensor ");
Serial.print(i);
Serial.print(" address is: ");
for (byte j = 0; j < ADDR_SIZE; j++)
{
Serial.print(sensor_addresses[i][j], HEX);
Serial.print(" ");
}

Serial.println();
Serial.print("Temperature: ");
Serial.println(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];
}
However, the DS18B20 sensors do not report a temperature value when using the Z-Uno sketch! This is the output in the Serial Monitor:
2016-12-04 (3).png
2016-12-04 (3).png (21.39 KiB) Viewed 11390 times
What could be the issue? The sensors obviously work because they report a temperature value using the sketch for Uno. Why is all values 0 when using the Z-Uno sketch above?
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Re: Please share example .ino with multiple DS18B20?

Post by n0ir »

This is what is shown in my Vera Edge running UI7:
2016-12-04 (4).png
2016-12-04 (4).png (50.84 KiB) Viewed 11390 times
Obviously something with the Z-Uno is not working properly, but what? Is it the sketch? The device itself?
A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: Please share example .ino with multiple DS18B20?

Post by A.Harrenberg »

Hi,

I think the multi-dimension array:

Code: Select all

byte sensor_addresses[NUMBER_OF_SENSORS][ADDR_SIZE] = 
is not supported by the current compiler. There was another example in the forum where it didn't work, but I can't find it right now.

Just try to make seperate arrays for each sensor or convert it to one-dimensional.

Regards,
Andreas.
fhem.de - ZWave development support
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Re: Please share example .ino with multiple DS18B20?

Post by n0ir »

I'm just starting with Arduino and my skill set right now is just copy existing sketches and maybe making some easy adjustments. Could you please explain what you mean with "make seperate arrays for each sensor or convert it to one-dimensional"?

I'm REALLY getting frustrated by the Z-Uno. :S I understand it is 99% my lack of knowledge of Arduino, but if Fibaro had a Z-Wave+ enabled universal sensor I had sold my Z-Uno in a heartbeat. The only thing I want is a Z-Wave+ enabled temperature sensor for 5 DSB1920 and maybe a relay status sensor. I have spent almost 2-3 weeks trying to get this to work and still no success.
A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: Please share example .ino with multiple DS18B20?

Post by A.Harrenberg »

Hi,

learn how to programm takes time... Don't be taken back by the time it takes to learn.

I have to cook now, I will have a deeper look at your sketch and will try to test it here on my system. So be a little patient, with any luck I can answer you later today.

Regards,
Andreas.
fhem.de - ZWave development support
A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: Please share example .ino with multiple DS18B20?

Post by A.Harrenberg »

Hi,

I changed your code to avoid the 2-dimensional array. That makes the code not really beautiful but it works... :P

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];
}
fhem.de - ZWave development support
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Re: Please share example .ino with multiple DS18B20?

Post by n0ir »

HI Andreas!

Thank you! The sketch you uploaded seems to work! :) I'm really thankful for your help. Maybe your sketch could be featured in the https://z-uno.z-wave.me/examples/ to help other users? I assume there must be several other users who want to use the Z-Uno with multiple temperature sensors?

For future references, when included in my Vera the Z-Uno (my have 5 DS18B20 sensors attached) is added as 1 parent device, 1 "_Temperature Sensor" and 5 "_Generic IO" devices.

The "_Generic IO" devices need to have the "device_file" and "device_json" under Settings -> Advanced changed to "D_TemperatureSensor1.xml" and "D_TemperatureSensor1.json" respectively.
2016-12-07 (1).png
2016-12-07 (1).png (59.04 KiB) Viewed 11358 times
After a reload the temperature readings seems to work!
2016-12-07.png
2016-12-07.png (32.39 KiB) Viewed 11358 times
The only weird thing is I have 6 temperature sensors (the one temperature sensor that was automatically added when the Z-Uno was included and 5 _Generic IO devices that was manually converted to temperature sensors). Two of these are obviously duplicates.

I have tried to log the sensors using the Vera plugin dataMine and it SEEMS like the "_Generic IO" and "_Generic IO 3" report the exact same values over time. I assume this could differ between systems, but adding the line

Code: Select all

luup.attr_set("invisible","1",[DEVICEID])
in Startup Lua you can easily hide this duplicate device. I will probably also hide the parent device ("Z-Uno" in the image above).

Next step will be to try and include a relay function in the same sketch, to report changes from NC or NO. If this could be integrated in the sketch the Z-Uno will have the functionality from my old Fibaro Universal Sensor (but better because of Z-Wave+).

If I also could include a HC-SR04 Ultrasonic Distance Sensor using the instructions in https://z-uno.z-wave.me/examples/hc-sr0 ... ce-sensor/ the Z-Uno will have more features.
Post Reply