Page 1 of 1

Read multiple humidity (HUM1000_0) sensors with python

Posted: Wed Mar 21, 2018 5:01 am
by DarkLight
Hi All,

I need to get the Humidity and Temperature readouts from multiple (~15) humidity (HUM1000_0) sensors - each one connected to it's own hub (HUB0000_0).
The Python example I have, reads only one sensor.

Is there a way to get all sensors at once? (Please note - each sensor has it's own hub...)

Regards,
S.C.

Re: Read multiple humidity (HUM1000_0) sensors with python

Posted: Wed Mar 21, 2018 7:56 am
by mparadis
In order to read multiple humidity sensors, you need to create and open multiple humidity objects. Before opening, you can specify things like channel and device serial number to make sure you know which humidity sensor is being addressed by which variable.

We have a video that explains how this is done here.

And this video explains how to address each channel specifically.

Re: Read multiple humidity (HUM1000_0) sensors with python

Posted: Wed Mar 21, 2018 12:34 pm
by jdecoux
You may also find this article useful for dealing with all those similar sensors. Just be sure to change the serial number from -1 for each hub.

Re: Read multiple humidity (HUM1000_0) sensors with python

Posted: Thu Mar 22, 2018 12:20 am
by DarkLight
mparadis wrote:In order to read multiple humidity sensors, you need to create and open multiple humidity objects. Before opening, you can specify things like channel and device serial number to make sure you know which humidity sensor is being addressed by which variable.

We have a video that explains how this is done here.

And this video explains how to address each channel specifically.
Thank you! worked like a charm...
I'll post the entire solution once I'll perfect it.

Re: Read multiple humidity (HUM1000_0) sensors with python

Posted: Thu Mar 22, 2018 2:30 am
by DarkLight
Hi all,

this is quick and dirty, and does not handle exceptions as well as the demo code. but for "fresh meats" with little code experience it's a datum from which to grow...

Code: Select all

# -*- coding: utf-8 -*-
from Phidget22.Devices.TemperatureSensor import *
from Phidget22.Devices.HumiditySensor import *
from Phidget22.Net import *

TempArray = []
HumdArray = []

i = 0

while 1:
    i += 1
    ct = TemperatureSensor()
    ch = HumiditySensor()
    try:
        ct.openWaitForAttachment(5000)
        ch.openWaitForAttachment(5000)
    except PhidgetException as e:
        break
    TempArray.append(ct)
    HumdArray.append(ch)

for i in TempArray:
    print("Serial: %s Temperature: %0.2f°C" % (i.getDeviceSerialNumber(), i.getTemperature()))
    i.close()
print "================="
for i in HumdArray:
    print("Serial: %s Humidity: %0.2f%%" % (i.getDeviceSerialNumber(), i.getHumidity()))
    i.close()
the output looks like:
Serial: 497393 Temperature: 22.62°C
Serial: 496522 Temperature: 23.29°C
=================
Serial: 497393 Humidity: 31.24%
Serial: 496522 Humidity: 31.74%

Process finished with exit code 0