Read multiple humidity (HUM1000_0) sensors with python

Supporting 2.7 and 3.2+
DarkLight
Phidgetsian
Posts: 12
Joined: Wed Dec 27, 2017 6:59 am
Contact:

Read multiple humidity (HUM1000_0) sensors with python

Postby DarkLight » Wed Mar 21, 2018 5:01 am

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.

User avatar
mparadis
Site Admin
Posts: 609
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Postby mparadis » Wed Mar 21, 2018 7:56 am

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.

jdecoux
Labview Developer
Posts: 74
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Postby jdecoux » Wed Mar 21, 2018 12:34 pm

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.

DarkLight
Phidgetsian
Posts: 12
Joined: Wed Dec 27, 2017 6:59 am
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Postby DarkLight » Thu Mar 22, 2018 12:20 am

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.

DarkLight
Phidgetsian
Posts: 12
Joined: Wed Dec 27, 2017 6:59 am
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Postby DarkLight » Thu Mar 22, 2018 2:30 am

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


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests