VINT Hub Phidget + PhidgetAnalog 4-Output

General PhidgetSBC Discussion.
Post Reply
Megametrope
Phidgetsian
Posts: 7
Joined: Fri Sep 11, 2020 8:45 am
Contact:

VINT Hub Phidget + PhidgetAnalog 4-Output

Post by Megametrope »

Hi there,

Is it possible to run, at the same time, on the same PC, a VINT Hub Phidget (HUB0000_0) with sensors + a PhidgetAnalog 4-Output (1002_0B) ?
If it's possible How can I adress each one?

Thanks for your answer.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: VINT Hub Phidget + PhidgetAnalog 4-Output

Post by mparadis »

Yes, you can connect any number of Phidgets to the same computer (until you run out of USB ports- then you need a USB hub).

You can simply open the objects on your HUB0000 and 1002_0B in the same program. For example, if you had three DST1002 sensors connected to the HUB0000, and you wanted to use one LED on VINT port 3 and two channels of the 1002_0B, you could open them all like this in Python:

Code: Select all

from Phidget22.Phidget import *
from Phidget22.Devices.DistanceSensor import *
from Phidget22.Devices.VoltageOutput import *
from Phidget22.Devices.DigitalOutput import *
import time

def onDistanceChange(self, distance):
	print("Distance: " + str(distance))

def main():
	sensor0 = DistanceSensor()
        sensor1 = DistanceSensor()
        sensor2 = DistanceSensor()
        voltageOut0 = VoltageOutput()
        voltageOut1 = VoltageOutput()
        led0 = DigitalOutput()
         
        sensor0.setHubPort(0)
        sensor1.setHubPort(1)
        sensor2.setHubPort(2)
        voltageOut0.setChannel(0)
        voltageOut1.setChannel(1)
        led0.setHubPort(3)
        led0.setIsHubPortDevice(True)
        
	sensor0.setOnDistanceChangeHandler(onDistanceChange)
	sensor1.setOnDistanceChangeHandler(onDistanceChange)
	sensor2.setOnDistanceChangeHandler(onDistanceChange)

	sensor0.openWaitForAttachment(5000)
	sensor1.openWaitForAttachment(5000)
	sensor2.openWaitForAttachment(5000)
	voltageOut0.openWaitForAttachment(5000)
	voltageOut1.openWaitForAttachment(5000)
	led0.openWaitForAttachment(5000)

	try:
		input("Press Enter to Stop\n")
	except (Exception, KeyboardInterrupt):
		pass

	sensor0.close()
	sensor1.close()
	sensor2.close()
	voltageOut0.close()
	voltageOut1.close()
	led0.close()

main()
- The first block in the main function declares all of the different channels.

- The second block sets all of the addressing parameters. You can read about all of the possible addressing options on this page.

- The third block sets the data handler function for the distance sensors. In this example, they all use the same one but you could instead specify different functions for each sensor, or you could use the "self" variable inside the event to determine which distance sensor is sending the event (for more info about this including how to do it in other programming languages, see the "Distinguishing Events" section of this page).

- The fourth block is where each channel is opened.

- The last part at the end is where each channel is closed.
Megametrope
Phidgetsian
Posts: 7
Joined: Fri Sep 11, 2020 8:45 am
Contact:

Re: VINT Hub Phidget + PhidgetAnalog 4-Output

Post by Megametrope »

Thanks! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests