wxPython -- who's using?

Supporting 2.7 and 3.2+
GIS_Is_Me
Fresh meat
Posts: 3
Joined: Mon Jan 08, 2018 2:14 pm
Contact:

wxPython -- who's using?

Postby GIS_Is_Me » Mon Jan 22, 2018 3:27 pm

I'm new to Phidgets / robotics and am working on a learning project using some Phidgets and wxPython. The goal of the project is to create a test panel for:

  • HIN1100_0 thumbstick
  • HIN1000_0 thumbstick touchpad
  • HUB0000_0 VINT Hub

that's not too different from the Phidget Management Control Panel.

Does anyone have experience w wxPython to share? Particular widgets used to display data from the phidgets? Lessons' learned?

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

Re: wxPython -- who's using?

Postby DarkLight » Mon Aug 13, 2018 8:29 am

I've used the Humidity (HUM 1000_0) sensor and the differential pressure sensor (1136_0) connected to the VINT hub

for the humidity/temperature

Code: Select all

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

ct = TemperatureSensor()
ch = HumiditySensor()

try:
    ct.openWaitForAttachment(500)
    ch.openWaitForAttachment(500)

except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Press Enter to Exit...\n")
    readin = sys.stdin.read(1)
    exit(1)

app = wx.App()

temp = ct.getTemperature()
ct.close()
humd = ch.getHumidity()
ch.close()

# simple dialog
wx.MessageBox('Temperature:   %0.2fC \n==============\n Humidity:   %0.2f%%' % (temp, humd), 'Environment', wx.OK)

#print("Serial: %s Temperature: %0.2f°C" % (ct.getDeviceSerialNumber(), ct.getTemperature()))

#print("Serial: %s Humidity: %0.2f%%" % (ch.getDeviceSerialNumber(), ch.getHumidity()))





for the pressure (used to detect fan intaking or outaking airflow)

Code: Select all

from time import sleep
import sys
import wx
from Phidget22.Devices.VoltageRatioInput import *

minPress = 29
maxPress = 33

if len(sys.argv) > 1:
    if sys.argv[1] in ['?', 'help', 'Help', 'HELP', '/?', '/h', '/help']:
        print "1st argument is minimum pressure in PA to consider outake, " \
              "2nd is max for intake \n min default:29 \n max default 33"
        a = raw_input("any key to continue")
        sys.exit(0)
    minPress = sys.argv[1]
    maxPress = sys.argv[2]


PresArray = []

def VoltageRatioChangeHandler(e, voltageRatio):
    # print("VoltageRatio: %f" % voltageRatio)
    # print("SensorValue: %f" % cp.getSensorValue())

    pressure = 1000 * ((5 * cp.getSensorValue()) - 2.5)
    PresArray.append(pressure)
    # print ("Pressure in PA: %f" % pressure)


cp = VoltageRatioInput()
cp.setDeviceSerialNumber(-1)
cp.setHubPort(1)
cp.setIsHubPortDevice(1)
cp.setChannel(0)
cp.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
cp.openWaitForAttachment(5000)

sleep(2)

app = wx.App()

print ("Max PA: %f" % max(PresArray))
print ("Avg PA: %f" % (sum(PresArray)/len(PresArray)))
print ("Min PA: %f" % min(PresArray))

if max(PresArray) > maxPress:
    fanstat =  "Intake"
elif min(PresArray) < minPress:
    fanstat = "Outake"
else:
    fanstat = "NoFan"

print fanstat

wx.MessageBox('Max PA: %f \n Avg PA: %f \n Min PA: %f \n %s' % (max(PresArray), (sum(PresArray)/len(PresArray)), min(PresArray), fanstat), 'Pressure', wx.OK)


cp.close()


Lessons:
  • Some attributes can only be set after the attachment.
  • Some phidgets do not auto detect (like voltage[rational] Input) - must be hardcoded
  • Digital/analog inputs cannot be read once - you create an event and capture several readings.
  • Trap errors - don't neglect (it will bite you back...)
  • Remember to close the control panel while running code (you can get extream and detect the executable and kill it's task!)


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests