getSensorValue - Phidget21 vs Phidget22

Supporting 2.7 and 3.2+
Post Reply
headcrash
Phidgetsian
Posts: 8
Joined: Fri Aug 11, 2017 10:46 am
Contact:

getSensorValue - Phidget21 vs Phidget22

Post by headcrash »

I have a Python program I've been using for years to monitor my home heating system. At one time or another I've used it under both Linux and Windows. The Phidget hardware consists of a 1018-1 interface board and (6) 1124 temperature sensors.

At the heart of the program it polls all the temperature sensors when the furnace burners turns on/off (event driven from a digital input).

At present I'm trying to move the program from Phidget21 to Phidget22 and have run into an issue with getSensorValue.

Under Phidget21 I would open the InterfaceKit object and leave it open day after day. I could do a getSensorValue from any analog or digital channel and get live data.

However, under Phidget22 doing a getSensorValue while the VoltageRatioInput object is open returns a fixed reading that never changes unless I close and reopen the VoltageRatioInput object.

The documentation for getSensorValue under Phidget22/Python says it returns "The most recent sensor value that the channel has reported." That sounds like I should get live data not a stored value, but apparently it apparently doesn't work that way. Maybe a bug?

I can certainly close and reopen all (6) VoltageRatioInput objects everytime I need to get readings, but that will result in a lot of coding overhead.

I have experimented with getting readings from the temperature sensors using event driven programming and found I can get live readings without closing and reopening the objects. But I don't see how I can do that in my program because it's the furnace burner (digital input) that triggers the event for me, not the temperature sensors.

Looking forward to feedback and suggestions!
headcrash
Phidgetsian
Posts: 8
Joined: Fri Aug 11, 2017 10:46 am
Contact:

Re: getSensorValue - Phidget21 vs Phidget22

Post by headcrash »

Here's a simple test program that illustrates my issue. For this test, I'm using an 1109 Rotation Sensor (pot) instead of a temp sensor.

As I rotate the pot, the VoltageRatio changes while the SensorValue remains the same as its initial reading.

Code: Select all

from time import sleep
from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *
  
def VoltageRatioChangeHandler(e, voltageRatio):
    print("VoltageRatio: %f" % voltageRatio)
    print("SensorValue: %f" % vri3.getSensorValue())
    print
    
vri3 = VoltageRatioInput()
vri3.setDeviceSerialNumber(97505)
vri3.setChannel(3)
vri3.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
vri3.openWaitForAttachment(5000)
print('Reporting voltage ratio input channel 3 changes for 60 seconds')
sleep(60)
vri3.close()
Output:

Code: Select all

VoltageRatio: 0.306200
SensorValue: 0.413400

VoltageRatio: 0.265000
SensorValue: 0.413400

VoltageRatio: 0.237800
SensorValue: 0.413400

VoltageRatio: 0.210900
SensorValue: 0.413400

VoltageRatio: 0.238900
SensorValue: 0.413400

VoltageRatio: 0.304500
SensorValue: 0.413400

VoltageRatio: 0.355300
SensorValue: 0.413400
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: getSensorValue - Phidget21 vs Phidget22

Post by Patrick »

This isn't well documented yet, but SensorValue and VoltageRatio properties are meant to be mutually exclusive. If you want to use the SensorValue property and/or event, you need to set the SensorType to something other then SENSOR_TYPE_VOLTAGERATIO - you probably want to set it to SENSOR_TYPE_1124. The SensorValue property will now return degrees celcius. If you want to apply the formula yourself, you can use the VoltageRatio property, which returns a value between 0 and 1.

I will need to fix this bug in the library so that the SensorValue property doesn't return bogus data.

-Patrick
headcrash
Phidgetsian
Posts: 8
Joined: Fri Aug 11, 2017 10:46 am
Contact:

Re: getSensorValue - Phidget21 vs Phidget22

Post by headcrash »

Thanks, I think I got it. I shouldn't use getSensorValue without first setting the sensor type to 0x2be8 (11240) in the case of my 1124 temp sensors. I tried that and do indeed get back the temp in degrees Celsius.

I also tried applying a formula to the VoltageRatio itself by working backward from what the Phidget Control Panel reports in Windows. For example, a .373400 Voltage Ratio equals a sensor value of 21.858 degrees Celsius. So, my formula becomes 21.858 = (.373400 * 222.199) - 61.111 or c = (voltageRatio * 222.199) - 61.111 in my program.

The 1124 doc only shows a general formula based on Voltage not VoltageRatio, which is understandable since the reference voltage could be different.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests