Since I am the only one in my office who program in python, they asked me to program a device that turns on and off a fan for cooling the Peltier cells.
The components at my disposal are:
1 PhidgetSBC4 ID: SBC3003_0;
1VINT Hub Phidget ID: HUB0000_0
1 Humidity Phidget ID: HUM1001_0
1 12V battery pack
Peltier cells
1 Brush Motor Control CC 1000_0
1 12V fan
The connection should thus be SBC 3003_0 powered by the 15V battery pack, it receives as input from the HUB 0000_0 the temperature and humidity data which it receives in turn from the HUM 1001_0.
Depending on the temperature and humidity detected, the Brush Motor Control Fan CC 1000_0 must turn on.
The code I wrote (copied from your site) is:
Code: Select all
from Phidget22.Phidget import *
from Phidget22.Devices.DigitalInput import *
from Phidget22.Devices.DigitalOutput import *
from Phidget22.Devices.HumiditySensor import *
from Phidget22.Devices.TemperatureSensor import *
import time
#Declare any event handlers here. These will be called every time the associated event occurs.
def onStateChange(self, state):
print("State: " + str(state))
def main():
#Create your Phidget channels
digitalInput0 = DigitalInput()
digitalOutput4 = DigitalOutput()
digitalOutput5 = DigitalOutput()
#Set addressing parameters to specify which channel to open (if
#any)
digitalInput0.setIsHubPortDevice(True)
digitalInput0.setHubPort(0)
digitalInput0.setDeviceSerialNumber(1000)
digitalOutput4.setIsHubPortDevice(True)
digitalOutput4.setHubPort(4)
digitalOutput4.setDeviceSerialNumber(1000)
digitalOutput5.setIsHubPortDevice(True)
digitalOutput5.setHubPort(5)
digitalOutput5.setDeviceSerialNumber(1000)
#Assign any event handlers you need before calling open so that no
#events are missed.
digitalInput0.setOnStateChangeHandler(onStateChange)
#Open your Phidgets and wait for attachment
digitalInput0.openWaitForAttachment(5000)
digitalOutput4.openWaitForAttachment(5000)
digitalOutput5.openWaitForAttachment(5000)
#Do stuff with your Phidgets here or in your event handlers.
humiditySensor0 = HumiditySensor()[/b]
temperatureSensor0 = TemperatureSensor()
if digitalInput0_temperature > """write the temperature max""" or
digitalInput0_humidity > """write the humidity max""":
digitalOutput4.setDutyCycle(1)
digitalOutput5.setDutyCycle(1)
time.sleep(5)
#Close your Phidgets once the program is done.
digitalInput0.close()
digitalOutput4.close()
digitalOutput5.close()
main()
I use Python 3.7 and Spyder as a compiler.
humiditySensor0 is considered an error by Spyder.
But my question is how do I import the temperature and humidity from digitalInput0?
The digitalOutput4 and digitalOutput5 ports are set to True is this correct, or should they be set to false and then in the if set to True when the temperature or humidity reaches a certain threshold?
If the loop has to repeat itself "infinite" times do I have to write digitalInput0.close ()?
I thank you in advance. Sorry for my silly questions, but I just don't know how.
Regards
Nicola