Read multiple humidity (HUM1000_0) sensors with python

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

Read multiple humidity (HUM1000_0) sensors with python

Post 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.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Post 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.
jdecoux
Labview Developer
Posts: 161
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Post 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.
DarkLight
Phidgetsian
Posts: 12
Joined: Wed Dec 27, 2017 6:59 am
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Post 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.
DarkLight
Phidgetsian
Posts: 12
Joined: Wed Dec 27, 2017 6:59 am
Contact:

Re: Read multiple humidity (HUM1000_0) sensors with python

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests