### Install Phidget Python libraries Source: https://www.phidgets.com/docs/OS_-_Phidget_SBC Run the setup script to install the Phidget Python libraries. ```bash python setup.py install ``` -------------------------------- ### Install C compiler and builder Source: https://www.phidgets.com/docs/MOT2002_User_Guide Installs the C compiler (gcc) and make build tool, needed to compile Phidgets examples. ```bash apt-get install gcc ``` ```bash apt-get install make ``` -------------------------------- ### Configure and open TemperatureSensor channel (Java) Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=Phidget_Programming_Basics Sets the hub port and channel for a TemperatureSensor object, then opens it with a 5000 ms timeout. The commented '//Open' indicates the open call. This snippet is part of a larger example that may require additional setup. ```java tc.setHubPort(2); tc.setChannel(0); tc.open(5000); //Open ``` -------------------------------- ### Install Python on Phidget SBC Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=OS_-_Phidget_SBC Run these commands to update the package list and install Python on the Phidget SBC. ```bash apt-get update apt-get install python ``` -------------------------------- ### Configure Debian wheezy repository and install Python Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=OS_-_Phidget_SBC Configure the Debian wheezy repository in sources.list, then update and install Python. The first block is the content to place in the sources.list file, and the second block contains the commands to run afterward. ```bash # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN deb http://archive.debian.org/debian wheezy main contrib non-free ``` ```bash apt-get update apt-get install python ``` -------------------------------- ### Configure and open TemperatureSensor channel (Python) Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=Phidget_Programming_Basics Sets the hub port and channel for a TemperatureSensor object, then opens it with a 5000 ms timeout. This is the Python equivalent of the Java example. ```python tc.setHubPort(2) tc.setChannel(0) ``` -------------------------------- ### Install Python on Phidget SBC Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=OS_-_Phidget_SBC Install Python on the Phidget SBC. For SBC3 or older, first update /etc/apt/sources.list.d/multistrap-debian.list because Debian 7 has been archived. On SBC4, this command works without modifying the apt file. ```bash apt-get install python ``` -------------------------------- ### Install Phidget22 on Windows with pip Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=Language_-_Python Run this command in the VS Code terminal to install the Phidget22 Python package on Windows. Use the Command Palette (Ctrl + Shift + P) and select 'Terminal: Create New Terminal' first. ```bash #Windows py -m pip install phidget22 ``` -------------------------------- ### Update apt sources for Debian 7 archive Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=OS_-_Phidget_SBC Add these lines to /etc/apt/sources.list.d/multistrap-debian.list to update the apt file, since Debian 7 has been archived, before installing Python. ```bash # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN deb http://archive.debian.org/debian wheezy main contrib non-free ``` -------------------------------- ### Install phidget22 on macOS Source: https://www.phidgets.com/docs/index.php?action=history&feed=atom&title=Language_-_Python Use this command to install the Phidget Python package on macOS via pip. It requires Python 3 and pip to be available. ```bash python3 -m pip install phidget22 ``` -------------------------------- ### Download HelloWorld Example on SBC Source: https://www.phidgets.com/docs/OS_-_Phidget_SBC Downloads the Phidget Java HelloWorld example archive to the SBC using wget. Replace the placeholder URL with the actual link. ```bash wget http://examples_link ``` -------------------------------- ### Compile and run HelloWorld C example Source: https://www.phidgets.com/docs/MOT2002_User_Guide Compile the HelloWorld.c example with the Phidget22 library and run it with sudo to access USB devices. The output should show a 'Hello' line for each discovered Phidget channel. ```bash gcc HelloWorld.c -o HelloWorld -lphidget22 ``` ```bash sudo ./HelloWorld ``` -------------------------------- ### Install Phidget libraries on Raspberry Pi (with sudo) Source: https://www.phidgets.com/docs/Raspberry_Pi_and_Python Alternative terminal command to install Phidget libraries using sudo for both the setup script and the apt-get install. Suitable when elevated privileges are required. ```bash curl -fsSL https://www.phidgets.com/downloads/setup_linux | sudo -E bash - &&\ sudo apt-get install -y libphidget22 ``` -------------------------------- ### Compile and run HelloWorld example with Mono Source: https://www.phidgets.com/docs/Language_-_Visual_Basic_.NET_Windows_Visual_Studio Commands to compile and run the HelloWorld example using vbnc and mono. Requires Phidget22.NET.dll in the same folder as Module1.vb. ```bash vbnc /r:Phidget22.NET.dll Module1.vb ``` ```bash mono Module1.exe ``` -------------------------------- ### Enable ChannelPersistence on a VINT Hub DigitalOutput Source: https://www.phidgets.com/docs/Channel_Persistence_Guide A VINT Hub digital output example that enables channel persistence before opening the channel. On first run the output starts off and turns on after 500ms; on subsequent runs it starts in the on state. The same example is shown in C#, Python, JavaScript, Java, and C. ```C# using System; using Phidget22; namespace ConsoleApplication { class Program { static void Main(string[] args) { DigitalOutput digitalOutput0 = new DigitalOutput(); digitalOutput0.IsHubPortDevice = true; digitalOutput0.HubPort = 0; digitalOutput0.ChannelPersistence = true; digitalOutput0.Open(5000); Thread.Sleep(500); digitalOutput0.DutyCycle = 1; digitalOutput0.Close(); } } } ``` ```Python from Phidget22.Phidget import * from Phidget22.Devices.DigitalOutput import * import time def main(): digitalOutput0 = DigitalOutput() digitalOutput0.setIsHubPortDevice(True) digitalOutput0.setHubPort(0) digitalOutput0.setChannelPersistence(True) digitalOutput0.openWaitForAttachment(5000) time.sleep(1) digitalOutput0.setDutyCycle(1) try: input("Press Enter to Stop\n") except (Exception, KeyboardInterrupt): pass digitalOutput0.close() main() ``` ```JavaScript import * as phidget22 from 'phidget22'; const conn = new phidget22.NetworkConnection(5661, 'localhost'); await conn.connect(); const digitalOutput0 = new phidget22.DigitalOutput(); digitalOutput0.setIsHubPortDevice(true); digitalOutput0.setHubPort(0); digitalOutput0.channelPersistence = 1; await digitalOutput0.open(5000); await digitalOutput0.setDutyCycle(1); setTimeout(async () => { await digitalOutput0.close(); conn.close(); conn.delete(); process.exit(); }, 5000); ``` ```Java import com.phidget22.*; import java.util.Scanner; //Required for Text Input import java.io.IOException; public class Java_Example { public static void main(String[] args) throws Exception { DigitalOutput digitalOutput0 = new DigitalOutput(); digitalOutput0.setIsHubPortDevice(true); digitalOutput0.setHubPort(0); digitalOutput0.setChannelPersistence(true); digitalOutput0.open(5000); Thread.sleep(500); digitalOutput0.setDutyCycle(1); //Wait until Enter has been pressed before exiting System.in.read(); digitalOutput0.close(); } } ``` ```C #include #include #include int main() { PhidgetDigitalOutputHandle digitalOutput0; PhidgetDigitalOutput_create(&digitalOutput0); Phidget_setIsHubPortDevice((PhidgetHandle)digitalOutput0, 1); Phidget_setHubPort((PhidgetHandle)digitalOutput0, 0); Phidget_setChannelPersistence((PhidgetHandle)digitalOutput0, 1); Phidget_openWaitForAttachment((PhidgetHandle)digitalOutput0, 5000); sleep(1); PhidgetDigitalOutput_setDutyCycle(digitalOutput0, 1); //Wait until Enter has been pressed before exiting getchar(); Phidget_close((PhidgetHandle)digitalOutput0); PhidgetDigitalOutput_delete(&digitalOutput0); } ``` -------------------------------- ### Compile HelloWorld on SBC Source: https://www.phidgets.com/docs/OS_-_Phidget_SBC Compiles HelloWorldExample.java on the SBC, using the system-installed phidget22.jar located in /usr/share/java. ```bash javac -classpath .:/usr/share/java/phidget22.jar HelloWorldExample.java ```