<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.phidgets.com/docs/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mparadis</id>
	<title>Phidgets Support - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.phidgets.com/docs/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mparadis"/>
	<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/Special:Contributions/Mparadis"/>
	<updated>2026-06-16T03:04:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Using_XLights_with_Phidgets&amp;diff=35680</id>
		<title>Using XLights with Phidgets</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Using_XLights_with_Phidgets&amp;diff=35680"/>
		<updated>2026-06-10T22:23:16Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: Mparadis moved page Using XLights with Phidgets to Using xLights with Phidgets&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Using xLights with Phidgets]]&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Using_xLights_with_Phidgets&amp;diff=35679</id>
		<title>Using xLights with Phidgets</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Using_xLights_with_Phidgets&amp;diff=35679"/>
		<updated>2026-06-10T22:23:15Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: Mparadis moved page Using XLights with Phidgets to Using xLights with Phidgets&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Project]]&lt;br /&gt;
{{TOC limit|3}}&lt;br /&gt;
{{#seo:|keywords=xLights, ws2812, christmas lights}}&lt;br /&gt;
{{#seo:|description=Learn how to use a Phidgets addressable LED controller with xLights software.}}&lt;br /&gt;
==Introduction==&lt;br /&gt;
[[Image:xLights.png|400px|thumb|link=]]&lt;br /&gt;
xLights is a free and open-source comprehensive light control platform that helps create small or large light displays quickly, without the need for coding. This guide will walk you through how to add the Addressable LED Phidget as a controller in xLights. &lt;br /&gt;
&lt;br /&gt;
== Demonstration ==&lt;br /&gt;
&amp;lt;center&amp;gt;{{#ev:youtube|G6JIiXuTe18|rel=0}}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hardware==&lt;br /&gt;
This project uses the following parts:&lt;br /&gt;
* [{{SERVER}}/?prodid=969 PhidgetSBC4 (SBC3003_0)]&lt;br /&gt;
* [{{SERVER}}/?prodid=1368 Addressable LED Phidget (LED0100_0)]&lt;br /&gt;
* [{{SERVER}}/?tier=2&amp;amp;catid=28&amp;amp;pcid=24 USB Cable]&lt;br /&gt;
* [{{SERVER}}/?tier=1&amp;amp;catid=61&amp;amp;pcid=54 12V Power Supply for PhidgetSBC]&lt;br /&gt;
* [{{SERVER}}/?prodid=1011&amp;amp;pcid=77 Ethernet cable]&lt;br /&gt;
* 16x16 Addressable LED Array&lt;br /&gt;
* 5V 3.5A Power Supply for LEDs&lt;br /&gt;
* Windows, macOS or Linux computer&lt;br /&gt;
&lt;br /&gt;
==Assembly==&lt;br /&gt;
[[Image:xL_setup.png|link=|700px]]&lt;br /&gt;
&lt;br /&gt;
Assemble the system following these steps:&lt;br /&gt;
* Connect your LED array to the Addressable LED Phidget&lt;br /&gt;
* Connect the Addressable LED Phidget to the PhidgetSBC4 using a USB cable&lt;br /&gt;
* Connect the PhidgetSBC4 to your network router or switch with an ethernet cable&lt;br /&gt;
* Connect the 12V power supply to the PhidgetSBC&lt;br /&gt;
* Connect the LED power supply to the Addressable LED Phidget. Here, our LED array requires 5V.&lt;br /&gt;
&lt;br /&gt;
== Server Setup ==&lt;br /&gt;
&lt;br /&gt;
=== SBC Web Configuration ===&lt;br /&gt;
In this project, we&#039;ll be using a client (our desktop computer) and a server (the PhidgetSBC4). &lt;br /&gt;
&lt;br /&gt;
To start, we need prepare the PhidgetSBC4 with the required packages and configurations. Log into the SBC&#039;s web interface by double clicking on its control panel entry:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_controlpanel.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Next, follow these steps:&lt;br /&gt;
#Log in and navigate to &#039;&#039;&#039;System -&amp;gt; Packages&#039;&#039;&#039;. &lt;br /&gt;
#Install the &#039;&#039;&#039;C/C++ Development Tools/Headers&#039;&#039;&#039;. &lt;br /&gt;
#&#039;&#039;&#039;Refresh Available Packages&#039;&#039;&#039; and &#039;&#039;&#039;Upgrade All Packages&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_packages.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, go to &#039;&#039;&#039;Network -&amp;gt; Settings&#039;&#039;&#039; and enable the SSH server if it isn&#039;t already enabled.&lt;br /&gt;
&lt;br /&gt;
=== Installing the Server ===&lt;br /&gt;
&lt;br /&gt;
Now that SSH is enabled, we can remote in with SSH software (we recommend  [https://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY]). Or, you can plug a monitor and keyboard into the SBC4 and complete the rest of this section in the terminal directly.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t already have &#039;&#039;&#039;git&#039;&#039;&#039; installed, you can get it with the following commands:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt update&lt;br /&gt;
apt install git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t already have the &#039;&#039;&#039;make&#039;&#039;&#039; command installed, you can get it with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigate to &#039;&#039;&#039;/usr/userapps/&#039;&#039;&#039; (you&#039;ll have to create the userapps directory if this is the first project on this SBC) and use the following command to download the server project files:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
git clone https://github.com/PhidgetsInc/openpixelcontrol-ph22.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All of the files and folders for the server code will be added in a folder named &#039;&#039;&#039;openpixelcontrol-ph22&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not experienced with the terminal, we recommend switching back to the SBC web interface at this point. Go to the &#039;&#039;&#039;Projects&#039;&#039;&#039; tab and you should see the project folder. Click on the folder to open it.&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_project1.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Scroll down and click the &#039;&#039;&#039;make&#039;&#039;&#039; button to build the project.&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_make.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Once it&#039;s done building you can test the server by returning to your SSH terminal and typing &#039;&#039;&#039;./bin/Phidget_server&#039;&#039;&#039; from the project folder. If it&#039;s successful, you should see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_serverRunning.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Once the server is running, we can configure our client.&lt;br /&gt;
&lt;br /&gt;
== Client Setup ==&lt;br /&gt;
&lt;br /&gt;
To begin, install [https://xlights.org/ xLights] on your client computer.&lt;br /&gt;
&lt;br /&gt;
=== Controller Configuration ===&lt;br /&gt;
&lt;br /&gt;
Open xLights and add a new ethernet controller under the controllers tab:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_controller.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Protocol&#039;&#039;&#039; should be set to &#039;OPC&#039;.&lt;br /&gt;
* The &#039;&#039;&#039;Message Data Size&#039;&#039;&#039; should be equal to the number of LEDs in your display multiplied by the number of color channels. This project uses a 16x16 grid of RGB lights, so the data size is 768. For a strand of 100 RGBW lights, the data size would be 400.&lt;br /&gt;
* The &#039;&#039;&#039;IP address&#039;&#039;&#039; needs to be set to the SBC&#039;s IP, which you can find in the Phidget Control Panel:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_IP.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
=== Layout Configuration ===&lt;br /&gt;
&lt;br /&gt;
The layout lets you accurately model your lights in xLights. For a simple LED strip click on &amp;quot;Single Line&amp;quot;, and for a grid, use &amp;quot;Matrix&amp;quot;. Then click and drag in the black space to create the model.&lt;br /&gt;
[[Image:xL_layout.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Once it&#039;s created, click on your model to access the options.&lt;br /&gt;
[[Image:xL_layoutOptions.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
We won&#039;t be going in depth on all the layout options in this article, but you can find more information in xLights&#039; official documentation. For now, the important thing is to select &#039;&#039;&#039;Use Start Channel&#039;&#039;&#039; for the controller. Next, click on start channel and click on the &#039;...&#039; that appears. For &#039;&#039;&#039;Universe number&#039;&#039;&#039; select the IP address of the SBC. &lt;br /&gt;
[[Image:xL_universe.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
In order to have our 16x16 grid display properly, the Strings, Nodes/String, and Strands/String must be set to 4, 64, and 4. This is because the LEDs are laid out in a zig-zag pattern. If you&#039;re using a strip, you can just set it to 1, N, 1, where N is the number of lights in your strip.&lt;br /&gt;
&lt;br /&gt;
=== Sequencer ===&lt;br /&gt;
&lt;br /&gt;
Once your controller and layout are set up, you can move to the sequencer tab and do &#039;&#039;&#039;File -&amp;gt; New Sequence&#039;&#039;&#039;. Select &#039;Animation&#039;, &#039;40fps&#039;, and &#039;Quick Start&#039;. &lt;br /&gt;
&lt;br /&gt;
Now you can choose one of the effects from the effects bar and drag it into the row in the timeline corresponding to the layout you created. Drag it out so it lasts longer than a few seconds. Click on the play button, and you should see the effect play out on the preview in the bottom left. You can play with the Effect Settings and Colors windows to customize the effect.&lt;br /&gt;
[[Image:xL_timeline.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Further details on creating sequences fall outside of the scope of this article, but you can see the official xLights documentation for more information. &lt;br /&gt;
&lt;br /&gt;
Now that your sequence is set up, you can click the lightbulb icon to attempt to connect to the SBC&#039;s server.&lt;br /&gt;
[[Image:xL_bulb.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
If it&#039;s successful, you&#039;ll see the IP address of your client appear in your SSH terminal:&lt;br /&gt;
[[Image:xL_sshConnect.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
When you hit play, you should see your lights activate.&lt;br /&gt;
&lt;br /&gt;
[[Image:animation.gif|link=|center]]&lt;br /&gt;
&lt;br /&gt;
== Running the Project on Boot ==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve confirmed the server and client work using SSH or a local terminal, we can set the program to launch on boot as a daemon.&lt;br /&gt;
&lt;br /&gt;
Open the SBC web interface again and navigate to your project. Scroll down to &#039;&#039;&#039;Startup Settings&#039;&#039;&#039; and enable it, selecting &#039;&#039;&#039;bin/Phidget_server&#039;&#039;&#039; as the executable and clicking the save button below.&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_startup.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
The next time you power cycle the SBC, the server will run and you should be able to connect with your xLights client.&lt;br /&gt;
&lt;br /&gt;
== Running Autonomously on the SBC ==&lt;br /&gt;
&lt;br /&gt;
You may find that having a second computer running the xLights app 24/7 is a bit overkill for the size and scope of your project. If you just want the SBC to run a few patterns on a loop all by itself, but you still want to use xLights to design the pattern, you can have the SBC act as both client and server for the OPC stream.&lt;br /&gt;
&lt;br /&gt;
Open an SSH connection and go back to the /userapps/ directory on your SBC. Run the following command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
git clone https://github.com/PhidgetsInc/opcdecode-ph22.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This project requires &#039;&#039;&#039;libzstd&#039;&#039;&#039; to run. Install it with the following command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt install libzstd-dev&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should now have a second project visible in the SBC web interface:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_project2.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Click on openpixelcontrol-ph22 and start the project:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_startProj.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Then go back and do the same for opcdecode-ph22. You should see your lights turn on and display the default pattern.&lt;br /&gt;
&lt;br /&gt;
You can now configure both projects to run on boot as we did in the previous section, which will cause the pattern to display autonomously on boot, even if the SBC isn&#039;t connected to any network. You can design and save your own sequence in xLights and copy the .fseq file to the SBC to customize the pattern.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Using_xLights_with_Phidgets&amp;diff=35678</id>
		<title>Using xLights with Phidgets</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Using_xLights_with_Phidgets&amp;diff=35678"/>
		<updated>2026-06-10T22:11:43Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: Created page with &amp;quot;Category: Project {{TOC limit|3}} {{#seo:|keywords=xLights, ws2812, christmas lights}} {{#seo:|description=Learn how to use a Phidgets addressable LED controller with xLights software.}} ==Introduction== link= xLights is a free and open-source comprehensive light control platform that helps create small or large light displays quickly, without the need for coding. This guide will walk you through how to add the Addressable LED Phidge...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Project]]&lt;br /&gt;
{{TOC limit|3}}&lt;br /&gt;
{{#seo:|keywords=xLights, ws2812, christmas lights}}&lt;br /&gt;
{{#seo:|description=Learn how to use a Phidgets addressable LED controller with xLights software.}}&lt;br /&gt;
==Introduction==&lt;br /&gt;
[[Image:xLights.png|400px|thumb|link=]]&lt;br /&gt;
xLights is a free and open-source comprehensive light control platform that helps create small or large light displays quickly, without the need for coding. This guide will walk you through how to add the Addressable LED Phidget as a controller in xLights. &lt;br /&gt;
&lt;br /&gt;
== Demonstration ==&lt;br /&gt;
&amp;lt;center&amp;gt;{{#ev:youtube|G6JIiXuTe18|rel=0}}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hardware==&lt;br /&gt;
This project uses the following parts:&lt;br /&gt;
* [{{SERVER}}/?prodid=969 PhidgetSBC4 (SBC3003_0)]&lt;br /&gt;
* [{{SERVER}}/?prodid=1368 Addressable LED Phidget (LED0100_0)]&lt;br /&gt;
* [{{SERVER}}/?tier=2&amp;amp;catid=28&amp;amp;pcid=24 USB Cable]&lt;br /&gt;
* [{{SERVER}}/?tier=1&amp;amp;catid=61&amp;amp;pcid=54 12V Power Supply for PhidgetSBC]&lt;br /&gt;
* [{{SERVER}}/?prodid=1011&amp;amp;pcid=77 Ethernet cable]&lt;br /&gt;
* 16x16 Addressable LED Array&lt;br /&gt;
* 5V 3.5A Power Supply for LEDs&lt;br /&gt;
* Windows, macOS or Linux computer&lt;br /&gt;
&lt;br /&gt;
==Assembly==&lt;br /&gt;
[[Image:xL_setup.png|link=|700px]]&lt;br /&gt;
&lt;br /&gt;
Assemble the system following these steps:&lt;br /&gt;
* Connect your LED array to the Addressable LED Phidget&lt;br /&gt;
* Connect the Addressable LED Phidget to the PhidgetSBC4 using a USB cable&lt;br /&gt;
* Connect the PhidgetSBC4 to your network router or switch with an ethernet cable&lt;br /&gt;
* Connect the 12V power supply to the PhidgetSBC&lt;br /&gt;
* Connect the LED power supply to the Addressable LED Phidget. Here, our LED array requires 5V.&lt;br /&gt;
&lt;br /&gt;
== Server Setup ==&lt;br /&gt;
&lt;br /&gt;
=== SBC Web Configuration ===&lt;br /&gt;
In this project, we&#039;ll be using a client (our desktop computer) and a server (the PhidgetSBC4). &lt;br /&gt;
&lt;br /&gt;
To start, we need prepare the PhidgetSBC4 with the required packages and configurations. Log into the SBC&#039;s web interface by double clicking on its control panel entry:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_controlpanel.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Next, follow these steps:&lt;br /&gt;
#Log in and navigate to &#039;&#039;&#039;System -&amp;gt; Packages&#039;&#039;&#039;. &lt;br /&gt;
#Install the &#039;&#039;&#039;C/C++ Development Tools/Headers&#039;&#039;&#039;. &lt;br /&gt;
#&#039;&#039;&#039;Refresh Available Packages&#039;&#039;&#039; and &#039;&#039;&#039;Upgrade All Packages&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_packages.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, go to &#039;&#039;&#039;Network -&amp;gt; Settings&#039;&#039;&#039; and enable the SSH server if it isn&#039;t already enabled.&lt;br /&gt;
&lt;br /&gt;
=== Installing the Server ===&lt;br /&gt;
&lt;br /&gt;
Now that SSH is enabled, we can remote in with SSH software (we recommend  [https://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY]). Or, you can plug a monitor and keyboard into the SBC4 and complete the rest of this section in the terminal directly.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t already have &#039;&#039;&#039;git&#039;&#039;&#039; installed, you can get it with the following commands:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt update&lt;br /&gt;
apt install git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t already have the &#039;&#039;&#039;make&#039;&#039;&#039; command installed, you can get it with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigate to &#039;&#039;&#039;/usr/userapps/&#039;&#039;&#039; (you&#039;ll have to create the userapps directory if this is the first project on this SBC) and use the following command to download the server project files:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
git clone https://github.com/PhidgetsInc/openpixelcontrol-ph22.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All of the files and folders for the server code will be added in a folder named &#039;&#039;&#039;openpixelcontrol-ph22&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not experienced with the terminal, we recommend switching back to the SBC web interface at this point. Go to the &#039;&#039;&#039;Projects&#039;&#039;&#039; tab and you should see the project folder. Click on the folder to open it.&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_project1.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Scroll down and click the &#039;&#039;&#039;make&#039;&#039;&#039; button to build the project.&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_make.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Once it&#039;s done building you can test the server by returning to your SSH terminal and typing &#039;&#039;&#039;./bin/Phidget_server&#039;&#039;&#039; from the project folder. If it&#039;s successful, you should see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_serverRunning.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Once the server is running, we can configure our client.&lt;br /&gt;
&lt;br /&gt;
== Client Setup ==&lt;br /&gt;
&lt;br /&gt;
To begin, install [https://xlights.org/ xLights] on your client computer.&lt;br /&gt;
&lt;br /&gt;
=== Controller Configuration ===&lt;br /&gt;
&lt;br /&gt;
Open xLights and add a new ethernet controller under the controllers tab:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_controller.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Protocol&#039;&#039;&#039; should be set to &#039;OPC&#039;.&lt;br /&gt;
* The &#039;&#039;&#039;Message Data Size&#039;&#039;&#039; should be equal to the number of LEDs in your display multiplied by the number of color channels. This project uses a 16x16 grid of RGB lights, so the data size is 768. For a strand of 100 RGBW lights, the data size would be 400.&lt;br /&gt;
* The &#039;&#039;&#039;IP address&#039;&#039;&#039; needs to be set to the SBC&#039;s IP, which you can find in the Phidget Control Panel:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_IP.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
=== Layout Configuration ===&lt;br /&gt;
&lt;br /&gt;
The layout lets you accurately model your lights in xLights. For a simple LED strip click on &amp;quot;Single Line&amp;quot;, and for a grid, use &amp;quot;Matrix&amp;quot;. Then click and drag in the black space to create the model.&lt;br /&gt;
[[Image:xL_layout.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Once it&#039;s created, click on your model to access the options.&lt;br /&gt;
[[Image:xL_layoutOptions.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
We won&#039;t be going in depth on all the layout options in this article, but you can find more information in xLights&#039; official documentation. For now, the important thing is to select &#039;&#039;&#039;Use Start Channel&#039;&#039;&#039; for the controller. Next, click on start channel and click on the &#039;...&#039; that appears. For &#039;&#039;&#039;Universe number&#039;&#039;&#039; select the IP address of the SBC. &lt;br /&gt;
[[Image:xL_universe.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
In order to have our 16x16 grid display properly, the Strings, Nodes/String, and Strands/String must be set to 4, 64, and 4. This is because the LEDs are laid out in a zig-zag pattern. If you&#039;re using a strip, you can just set it to 1, N, 1, where N is the number of lights in your strip.&lt;br /&gt;
&lt;br /&gt;
=== Sequencer ===&lt;br /&gt;
&lt;br /&gt;
Once your controller and layout are set up, you can move to the sequencer tab and do &#039;&#039;&#039;File -&amp;gt; New Sequence&#039;&#039;&#039;. Select &#039;Animation&#039;, &#039;40fps&#039;, and &#039;Quick Start&#039;. &lt;br /&gt;
&lt;br /&gt;
Now you can choose one of the effects from the effects bar and drag it into the row in the timeline corresponding to the layout you created. Drag it out so it lasts longer than a few seconds. Click on the play button, and you should see the effect play out on the preview in the bottom left. You can play with the Effect Settings and Colors windows to customize the effect.&lt;br /&gt;
[[Image:xL_timeline.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Further details on creating sequences fall outside of the scope of this article, but you can see the official xLights documentation for more information. &lt;br /&gt;
&lt;br /&gt;
Now that your sequence is set up, you can click the lightbulb icon to attempt to connect to the SBC&#039;s server.&lt;br /&gt;
[[Image:xL_bulb.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
If it&#039;s successful, you&#039;ll see the IP address of your client appear in your SSH terminal:&lt;br /&gt;
[[Image:xL_sshConnect.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
When you hit play, you should see your lights activate.&lt;br /&gt;
&lt;br /&gt;
[[Image:animation.gif|link=|center]]&lt;br /&gt;
&lt;br /&gt;
== Running the Project on Boot ==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve confirmed the server and client work using SSH or a local terminal, we can set the program to launch on boot as a daemon.&lt;br /&gt;
&lt;br /&gt;
Open the SBC web interface again and navigate to your project. Scroll down to &#039;&#039;&#039;Startup Settings&#039;&#039;&#039; and enable it, selecting &#039;&#039;&#039;bin/Phidget_server&#039;&#039;&#039; as the executable and clicking the save button below.&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_startup.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
The next time you power cycle the SBC, the server will run and you should be able to connect with your xLights client.&lt;br /&gt;
&lt;br /&gt;
== Running Autonomously on the SBC ==&lt;br /&gt;
&lt;br /&gt;
You may find that having a second computer running the xLights app 24/7 is a bit overkill for the size and scope of your project. If you just want the SBC to run a few patterns on a loop all by itself, but you still want to use xLights to design the pattern, you can have the SBC act as both client and server for the OPC stream.&lt;br /&gt;
&lt;br /&gt;
Open an SSH connection and go back to the /userapps/ directory on your SBC. Run the following command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
git clone https://github.com/PhidgetsInc/opcdecode-ph22.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This project requires &#039;&#039;&#039;libzstd&#039;&#039;&#039; to run. Install it with the following command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt install libzstd-dev&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should now have a second project visible in the SBC web interface:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_project2.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Click on openpixelcontrol-ph22 and start the project:&lt;br /&gt;
&lt;br /&gt;
[[Image:xL_startProj.png|link=|center]]&lt;br /&gt;
&lt;br /&gt;
Then go back and do the same for opcdecode-ph22. You should see your lights turn on and display the default pattern.&lt;br /&gt;
&lt;br /&gt;
You can now configure both projects to run on boot as we did in the previous section, which will cause the pattern to display autonomously on boot, even if the SBC isn&#039;t connected to any network. You can design and save your own sequence in xLights and copy the .fseq file to the SBC to customize the pattern.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_startProj.png&amp;diff=35677</id>
		<title>File:XL startProj.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_startProj.png&amp;diff=35677"/>
		<updated>2026-06-10T22:11:03Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_project2.png&amp;diff=35676</id>
		<title>File:XL project2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_project2.png&amp;diff=35676"/>
		<updated>2026-06-10T22:10:48Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_startup.png&amp;diff=35675</id>
		<title>File:XL startup.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_startup.png&amp;diff=35675"/>
		<updated>2026-06-10T22:10:36Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Animation.gif&amp;diff=35674</id>
		<title>File:Animation.gif</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Animation.gif&amp;diff=35674"/>
		<updated>2026-06-10T22:10:25Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_sshConnect.png&amp;diff=35673</id>
		<title>File:XL sshConnect.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_sshConnect.png&amp;diff=35673"/>
		<updated>2026-06-10T22:10:17Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_bulb.png&amp;diff=35672</id>
		<title>File:XL bulb.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_bulb.png&amp;diff=35672"/>
		<updated>2026-06-10T22:10:06Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_timeline.png&amp;diff=35671</id>
		<title>File:XL timeline.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_timeline.png&amp;diff=35671"/>
		<updated>2026-06-10T22:09:56Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_universe.png&amp;diff=35670</id>
		<title>File:XL universe.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_universe.png&amp;diff=35670"/>
		<updated>2026-06-10T22:09:46Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_layoutOptions.png&amp;diff=35669</id>
		<title>File:XL layoutOptions.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_layoutOptions.png&amp;diff=35669"/>
		<updated>2026-06-10T22:09:38Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_layout.png&amp;diff=35668</id>
		<title>File:XL layout.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_layout.png&amp;diff=35668"/>
		<updated>2026-06-10T22:09:25Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_IP.png&amp;diff=35667</id>
		<title>File:XL IP.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_IP.png&amp;diff=35667"/>
		<updated>2026-06-10T22:09:17Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_controller.png&amp;diff=35666</id>
		<title>File:XL controller.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_controller.png&amp;diff=35666"/>
		<updated>2026-06-10T22:08:28Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_serverRunning.png&amp;diff=35665</id>
		<title>File:XL serverRunning.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_serverRunning.png&amp;diff=35665"/>
		<updated>2026-06-10T22:08:16Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_make.png&amp;diff=35664</id>
		<title>File:XL make.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_make.png&amp;diff=35664"/>
		<updated>2026-06-10T22:08:07Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_project1.png&amp;diff=35663</id>
		<title>File:XL project1.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_project1.png&amp;diff=35663"/>
		<updated>2026-06-10T22:07:52Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_packages.png&amp;diff=35662</id>
		<title>File:XL packages.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_packages.png&amp;diff=35662"/>
		<updated>2026-06-10T22:07:41Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_controlpanel.png&amp;diff=35661</id>
		<title>File:XL controlpanel.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_controlpanel.png&amp;diff=35661"/>
		<updated>2026-06-10T22:07:20Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XL_setup.png&amp;diff=35660</id>
		<title>File:XL setup.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XL_setup.png&amp;diff=35660"/>
		<updated>2026-06-10T22:07:11Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:XLights.png&amp;diff=35659</id>
		<title>File:XLights.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:XLights.png&amp;diff=35659"/>
		<updated>2026-06-10T22:06:46Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=35653</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=35653"/>
		<updated>2026-05-27T19:58:04Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* GCC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Learn how to use Phidget USB devices with C and C++.}}&lt;br /&gt;
[[Category:Language]]&lt;br /&gt;
&lt;br /&gt;
== Get Started ==&lt;br /&gt;
With the Phidget22 library, it&#039;s easy to create C or C++ applications that work with Phidget devices.&lt;br /&gt;
&lt;br /&gt;
== C Libraries ==&lt;br /&gt;
If you&#039;ve installed the Phidget drivers for [[OS - Windows|Windows]], [[OS - macOS|MacOS]], or [[OS - Linux|Linux]], then you already have the files you need for your C project. &lt;br /&gt;
&lt;br /&gt;
==== Windows Considerations ====&lt;br /&gt;
When adding directories for your project dependencies, add&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:/Program Files/Phidgets/Phidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
And for the linker, you can add&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:/Program Files/Phidgets/Phidget22/phidget22.lib}}     #(for 64-bit systems)&lt;br /&gt;
C:/Program Files/Phidgets/Phidget22/x86/phidget22.lib}} #(for 32-bit systems)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====macOS Considerations====&lt;br /&gt;
Legacy Phidgets running a HID USB stack require a driver extension (macOS 10.15 and newer) or a kernel extension (macOS 10.14 and earlier). During development, we recommend downloading the appropriate [https://www.phidgets.com/docs/OS_-_macOS#Quick_Downloads package] which will install the extension. When deploying applications, review the README in the [https://cdn.phidgets.com/downloads/phidget22/libraries/macos/Phidget22_macosdevel.zip macOS Development Files] for information about bundling the extension with your application.&lt;br /&gt;
&lt;br /&gt;
=====Determining USB Stack=====&lt;br /&gt;
To determine which USB stack your device is running, navigate to the product page and then to the specification tab, and look for the &#039;&#039;USB Stack&#039;&#039; specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.&lt;br /&gt;
&lt;br /&gt;
[[Image:Javascript_networkserver_webusb_spec.png|center|600px|link=https://cdn.phidgets.com/docs/images/8/80/Javascript_networkserver_webusb_spec.png]]&lt;br /&gt;
&lt;br /&gt;
====Linux Considerations====&lt;br /&gt;
Linux restricts access to USB devices to the root user. &lt;br /&gt;
&lt;br /&gt;
To run your C application as a regular user, you&#039;ll need to [{{SERVER}}/docs/OS_-_Linux#Setting_udev_Rules set up udev rules] on your system.&lt;br /&gt;
&lt;br /&gt;
=== Library Files ===&lt;br /&gt;
If you would like to manually manage the Phidget22 library files, you can download them [https://cdn.phidgets.com/downloads/phidget22/libraries/windows/Phidget22-windevel.zip here].&lt;br /&gt;
&lt;br /&gt;
== Development Environment Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== GCC === &lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| &lt;br /&gt;
The most common tool for C development is GCC, whether used in the command line or through an IDE. GCC is packaged with many other IDEs and packages, so you may already have it installed.&lt;br /&gt;
&lt;br /&gt;
{{hiddenh4|Windows}}&lt;br /&gt;
We recommend installing [https://www.cygwin.com/ Cygwin] or [https://sourceforge.net/projects/mingw/ MinGW], ensuring you select all gcc packages when prompted by the installer.  &lt;br /&gt;
&lt;br /&gt;
To compile your code, go to the folder where your code is and open the command prompt by typing &#039;cmd&#039; in the address bar.&lt;br /&gt;
&lt;br /&gt;
The specific command you will use depends on your compiler of choice:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#Cygwin x86:&lt;br /&gt;
gcc example.c -o example -I&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22&amp;quot;-L&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22/x86&amp;quot; -lphidget22&lt;br /&gt;
&lt;br /&gt;
#Cygwin x64:&lt;br /&gt;
gcc example.c -o example -I&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22&amp;quot; -lphidget22&lt;br /&gt;
&lt;br /&gt;
#MinGW:&lt;br /&gt;
gcc example.c -o example -I&amp;quot;C:/Program Files/Phidgets/Phidget22&amp;quot; -L&amp;quot;C:/Program Files/Phidgets/Phidget22/x86&amp;quot; -lphidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After running the commands above for either Cygwin or MinGW, an executable file called example.exe will be created. Enter the following command to run the program:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{hiddenh4|MacOS}}&lt;br /&gt;
If you don&#039;t already have gcc installed, you can get it by installing [https://developer.apple.com/xcode/ Xcode].&lt;br /&gt;
&lt;br /&gt;
To compile the program, enter the following command in the terminal, substituting &amp;quot;example&amp;quot; for the name of your C file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gcc example.c -o example -F /Library/Frameworks -framework Phidget22 -I /Library/Frameworks/Phidget22.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Finally, run the program by entering the following command in the terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Success! The project is now running with Phidgets.&lt;br /&gt;
&lt;br /&gt;
{{hiddenh4|Linux}}&lt;br /&gt;
On Linux, gcc is installed through the package manager:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install gcc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To compile the program, enter the following command in the terminal, substituting &amp;quot;example&amp;quot; for the name of your C file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gcc example.c -o example -lphidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After compiling, you can run the program by entering the following command in the terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Success! The project is now running with Phidgets.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Visual Studio === &lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| If you want to jump right into a pre-configured project, you can download one on our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=C Code Sample Generator] page. || [[Image:Language_C_VSProject.jpg|center|link=https://cdn.phidgets.com/docs/images/f/f1/Language_C_VSProject.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| To configure a new project, follow these steps. ||&lt;br /&gt;
|-&lt;br /&gt;
| First, create a new Win32 Console Application: || [[Image:Language_C_VS_step1.jpg|center|link=https://cdn.phidgets.com/docs/images/a/a1/Language_C_VS_step1.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| If you are using a 64-bit machine, select x64, otherwise, select x86: || [[Image:Language_C_VS_step2.jpg|center|link=https://cdn.phidgets.com/docs/images/6/6b/Language_C_VS_step2.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Next, right click on the source folder and click New Item: || [[Image:Language_C_VS_step3.jpg|center|link=https://cdn.phidgets.com/docs/images/e/e1/Language_C_VS_step3.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Give the source file a name and click Add: || [[Image:Language_C_VS_step4.jpg|center|link=https://cdn.phidgets.com/docs/images/e/e5/Language_C_VS_step4.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Right click your project and access its properties: || [[Image:Language_C_VS_step5.jpg|center|link=https://cdn.phidgets.com/docs/images/1/1e/Language_C_VS_step5.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Go to Configuration Properties -&amp;gt; C/C++ -&amp;gt; General and add this to the additional include directories:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:\Program Files\Phidgets\Phidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|| [[Image:Language_C_VS_step6.jpg|center|link=https://cdn.phidgets.com/docs/images/d/d3/Language_C_VS_step6.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Go to Configuration Properties -&amp;gt; Linker -&amp;gt; Input and add the appropriate line to additional dependencies:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:\Program Files\Phidgets\Phidget22\phidget22.lib #(for 64-bit systems)&lt;br /&gt;
C:\Program Files\Phidgets\Phidget22\x86\phidget22.lib #(for 32-bit systems)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|| [[Image:Language_C_VS_step7.jpg|center|link=https://cdn.phidgets.com/docs/images/0/09/Language_C_VS_step7.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Lastly, include the Phidget library at the beginning of your program:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#include &amp;lt; phidget22.h &amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
||&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== PhidgetSBC Web Interface ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+&#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;center&amp;gt;{{#ev:youtube|2hTlVexctqY|rel=0}}&amp;lt;/center&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Example Code ==&lt;br /&gt;
Navigate to our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=C Code Sample Generator] to view and download code samples that are tailored to your specific device.&lt;br /&gt;
&lt;br /&gt;
[[Image:Language_c_codesample2.png|center|600px|link=]]&lt;br /&gt;
&lt;br /&gt;
===Phidget Programming Basics===&lt;br /&gt;
{{PhidgetProgrammingBasicsLink}}&lt;br /&gt;
&lt;br /&gt;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=C Phidget22 API]&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Template:DCMotor_ESTOP&amp;diff=35652</id>
		<title>Template:DCMotor ESTOP</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Template:DCMotor_ESTOP&amp;diff=35652"/>
		<updated>2026-05-26T21:45:15Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#switch: {{{1}}}&lt;br /&gt;
 | bldc= New BLDC Motor Phidgets include an E-Stop circuit that can be used to trigger a Failsafe state.&lt;br /&gt;
 | dc = New DC Motor Phidgets include an E-Stop circuit that can be used to trigger a Failsafe state.&lt;br /&gt;
 | #default = New Phidget motor controllers include an E-Stop circuit that can be used to trigger a Failsafe state.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin:auto;width:75%;text-align:center&amp;quot;&lt;br /&gt;
! style=&amp;quot;text-align: center;&amp;quot; | E-Stop Input Terminals&lt;br /&gt;
! style=&amp;quot;text-align: center;&amp;quot; | Result&lt;br /&gt;
|-&lt;br /&gt;
| Shorted || Normal operation&lt;br /&gt;
|-&lt;br /&gt;
| Open || Failsafe state activated&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The E-Stop input is shorted with a jumper wire by default. If you would like to implement an E-Stop system, we recommend connecting a normally-closed (NC) switch to the E-Stop input.&lt;br /&gt;
&lt;br /&gt;
[[Image:Multi_estop.png|link=|thumb|A 3PST E-stop switch|100px]]&lt;br /&gt;
====Multiple Motor Controllers====&lt;br /&gt;
&lt;br /&gt;
If your project uses multiple motor controllers with E-Stops, we recommend wiring them separately because wiring them together can cause ground loops that introduce instability. The best solution is to buy a multi-throw E-Stop switch that provides a separate circuit for each controller. &lt;br /&gt;
&lt;br /&gt;
You can search for on an electronics retailer like Digikey for a DPST-NC switch for two controllers, or 3PST/4PST for three or four.&lt;br /&gt;
&lt;br /&gt;
====Other Considerations====&lt;br /&gt;
The E-Stop circuit does not physically interact with the supply voltage or the motor connection. You should not wire your motor, or your supply voltage to this circuit.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Multi_estop.png&amp;diff=35651</id>
		<title>File:Multi estop.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Multi_estop.png&amp;diff=35651"/>
		<updated>2026-05-26T21:42:37Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=BLDCMotor_API_Guide&amp;diff=35650</id>
		<title>BLDCMotor API Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=BLDCMotor_API_Guide&amp;diff=35650"/>
		<updated>2026-05-26T19:37:17Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Get started with your Brushless DC Motor Phidget}}&lt;br /&gt;
[[Category:IntroGuide]]&lt;br /&gt;
&amp;lt;div class=&amp;quot;nonumtoc&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-4&amp;quot;&amp;gt;&lt;br /&gt;
=Introduction=&lt;br /&gt;
[[Image:DCC1120_0.png|thumb|link=https://cdn.phidgets.com/docs/images/3/38/DCC1120_0.png|&amp;lt;center&amp;gt;30V 50A Brushless DC Motor Phidget (DCC1120_0)&amp;lt;/center&amp;gt;]]&lt;br /&gt;
This guide will provide information about the Brushless DC Motor (BLDC) API to get you up and running with your new BLDC Motor Phidget.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before starting this guide, visit the Quick Start Guide on your BLDC Motor Phidget&#039;s product page for information about wiring and power.&lt;br /&gt;
&lt;br /&gt;
==Guide Compatibility==&lt;br /&gt;
&amp;lt;tabber&amp;gt;&lt;br /&gt;
Info=&lt;br /&gt;
&#039;&#039;Select your controller for compatibility information relating to this guide.&#039;&#039;&lt;br /&gt;
|-|&lt;br /&gt;
DCC1120=&lt;br /&gt;
[[Image:DCC1120_0.png|link=https://cdn.phidgets.com/docs/images/3/38/DCC1120_0.png|thumb|200px|[{{SERVER}}/?prodid=1334 30V 50A Brushless DC Motor Phidget (DCC1120_0)]]]&lt;br /&gt;
The [{{SERVER}}/?prodid=1334 30V 50A Brushless DC Motor Phidget (DCC1120_0)] is fully compatible with this guide.&lt;br /&gt;
|-|&lt;br /&gt;
DCC1100=&lt;br /&gt;
[[Image:DCC1100_0.jpg|link=https://cdn.phidgets.com/docs/images/8/87/DCC1100_0.jpg|thumb|200px|[https://www.phidgets.com/?prodid=1391 Brushless DC Motor Phidget (DCC1100_1)]]]&lt;br /&gt;
[https://www.phidgets.com/?prodid=1391 Brushless DC Motor Phidget (DCC1100_1)] considerations:&lt;br /&gt;
* Stall Velocity is not covered in this guide. Information on this topic is available in the device API.&lt;br /&gt;
|-|&lt;br /&gt;
&amp;lt;/tabber&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=BLDCMotor API Overview=&lt;br /&gt;
==Phidget Control Panel==&lt;br /&gt;
After wiring your BLDC Motor Phidget, we recommend opening the [https://www.phidgets.com/docs/Phidget_Control_Panel Phidget Control Panel] on a Windows computer to experiment with key features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DCC1120_0_Panel.png|center|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When the BLDC Motor Phidget is powered, it will appear up on the Phidget Control Panel device list as shown above. Double-click on the &#039;&#039;BLDC Motor Controller&#039;&#039; entry to view the program.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DCC1120_0_BLDC.png|800px|center|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After opening the program, you will see the screen shown above. The program is split into multiple sections to help you get familiar with your motor controller.&lt;br /&gt;
#Phidget Info&lt;br /&gt;
#Motor Status&lt;br /&gt;
#Controls&lt;br /&gt;
#Configuration&lt;br /&gt;
&lt;br /&gt;
In this guide, we will focus on the areas that contain important information about controlling your Brushless DC motor. For information about the Phidget Info section, and the Phidget Control Panel in general, visit our [https://www.phidgets.com/docs/Phidget_Control_Panel Phidget Control Panel] Page.&lt;br /&gt;
&lt;br /&gt;
==Controls==&lt;br /&gt;
{{DCBLDCMotor_Controls}}&lt;br /&gt;
&lt;br /&gt;
==Configuration==&lt;br /&gt;
This area of the program allows you to try out different configurations with your BLDC Motor Phidget to determine the best fit for your application.&lt;br /&gt;
&lt;br /&gt;
===Drive Mode===&lt;br /&gt;
{{DCBLDCMotor_DriveMode|bldc}}&lt;br /&gt;
&lt;br /&gt;
===Rescale Factor===&lt;br /&gt;
&amp;lt;center&amp;gt;{{#ev:youtube|SbO3hAuYsAE|rel=0}}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Rescale Factor allows you to change the units of the following properties:&lt;br /&gt;
* [[#Position|Position]]&lt;br /&gt;
&lt;br /&gt;
By default, the units will be in commutations which is dictated by the number of poles/phases your motor and are often non-intuitive. We recommend utilizing the Rescale Factor so your software is easier to understand.&lt;br /&gt;
&lt;br /&gt;
====Example Calculations====&lt;br /&gt;
Generally, most users will prefer units of degrees or rotations. To determine an appropriate Rescale Factor, you will need to know the following values:&lt;br /&gt;
*Commutations per revolution, equivalent to the number of poles multiplied by the number of phases&lt;br /&gt;
*Gearbox ratio (if applicable)&lt;br /&gt;
&lt;br /&gt;
These values will be available from manufacturer data sheets, or directly on the motor.&lt;br /&gt;
&lt;br /&gt;
=====Converting to Degrees=====&lt;br /&gt;
Specifications of system:&lt;br /&gt;
* Motor gear ratio: 10:1&lt;br /&gt;
* Motor poles: 2&lt;br /&gt;
* Motor phases: 3&lt;br /&gt;
&lt;br /&gt;
Rescale Factor = 360 / (10&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;2&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;3) = &#039;&#039;&#039;6.0&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=====Converting to Rotations=====&lt;br /&gt;
Specifications of system:&lt;br /&gt;
* Motor gear ratio: 10:1&lt;br /&gt;
* Motor poles: 2&lt;br /&gt;
* Motor phases: 3&lt;br /&gt;
&lt;br /&gt;
Rescale Factor = 1 / (10&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;2&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;3) = &#039;&#039;&#039;0.016666667&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Braking Enabled===&lt;br /&gt;
{{DCBLDCMotor_BrakingEnabled}}&lt;br /&gt;
&lt;br /&gt;
===Surge Current Limit===&lt;br /&gt;
{{DCBLDCMotor_SurgeCurrentLimit}}&lt;br /&gt;
&lt;br /&gt;
===Acceleration===&lt;br /&gt;
{{DCBLDCMotor_Acceleration}}&lt;br /&gt;
&lt;br /&gt;
===Data Interval===&lt;br /&gt;
{{DCBLDCMotor_DataInterval}}&lt;br /&gt;
&lt;br /&gt;
==Motor Status==&lt;br /&gt;
This area of the program shows information that has been sent back from the BLDC Motor Phidget.&lt;br /&gt;
===Velocity===&lt;br /&gt;
{{DCMotor_VelocityStatus}}&lt;br /&gt;
&lt;br /&gt;
===Braking Strength===&lt;br /&gt;
{{DCMotor_BrakingStrength}}&lt;br /&gt;
&lt;br /&gt;
===Position===&lt;br /&gt;
The most recent Position value reported by the controller. The Position is calculated using Hall Effect sensors mounted inside the motor, therefore, the resolution of the position depends on the motor you are using.&lt;br /&gt;
&lt;br /&gt;
====Other Considerations====&lt;br /&gt;
* {{DCMotor_RescaleFactorNote}}&lt;br /&gt;
* Consider using an encoder for more accurate position information.&lt;br /&gt;
&lt;br /&gt;
===Active Current Limit===&lt;br /&gt;
{{DCMotor_ActiveCurrentLimit}}&lt;br /&gt;
&lt;br /&gt;
===Motor Inductance===&lt;br /&gt;
{{DCMotor_MotorInductance}}&lt;br /&gt;
&lt;br /&gt;
==Failsafe==&lt;br /&gt;
{{DCMotor_Failsafe}}&lt;br /&gt;
&lt;br /&gt;
===E-Stop===&lt;br /&gt;
{{DCMotor_ESTOP|bldc}}&lt;br /&gt;
&lt;br /&gt;
==Errors==&lt;br /&gt;
{{DCMotor_Errors|bldc}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Android&amp;diff=35649</id>
		<title>OS - Android</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Android&amp;diff=35649"/>
		<updated>2026-05-25T21:52:16Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Direct USB Connection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;metadesc&amp;gt;Communicate over USB with sensors, controllers and relays with Phidgets! Program in Android using Android Java.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
[[Category:OS]]&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;vertical-align:middle; width: 60%;&amp;quot;|&lt;br /&gt;
==Getting Started with Android==&lt;br /&gt;
Welcome to using Phidgets with Android! &lt;br /&gt;
&lt;br /&gt;
If this is your first Phidget, we highly recommend working through the Getting Started guide for your specific Phidget device, which may be found in its [[:Category:UserGuide|user guide]]. If you are ready to go, the first step to creating an Android application with Phidgets is downloading the Phidget libraries on your development machine!&lt;br /&gt;
|{{TOC limit|2}}&lt;br /&gt;
|}&lt;br /&gt;
==Download==&lt;br /&gt;
The Phidget libraries for Android development are available here:&lt;br /&gt;
*[https://cdn.phidgets.com/downloads/phidget22/libraries/android/phidget22-android.zip Android Java Libraries]&lt;br /&gt;
&lt;br /&gt;
Download and unpack the libraries. You will need to reference these files from your project in order to use Phidgets. This step is covered in detail in the [[Language - Android Java | Android Java page]]. If you need to access older versions of the libraries, [https://www.phidgets.com/downloads/phidget22/libraries/android/ click here].&lt;br /&gt;
&lt;br /&gt;
==Direct USB Connection==&lt;br /&gt;
For directly controlling a Phidget with your Android device (i.e. plugging a Phidget directly into your device), you will need to ensure the device is capable of being a USB host. Just having a port that the USB cable can fit into does not necessarily indicate that the port can host a USB device. On the other hand, some phones can use an OTG (on-the-go) cable to allow plugging USB devices into their charging port. Some tablets (like the Samsung Galaxy Tab, for example) have the large 30-pin connectors that can be changed into a USB host using an adapter.  &lt;br /&gt;
&lt;br /&gt;
The best way to know before getting your hands on a device is to check its specifications for whether it can serve as a USB host. Alternately, a quick way to figure out if your device can serve as a USB host is to try plugging other devices (such as a mouse, or USB memory stick) into your Android device.&lt;br /&gt;
&lt;br /&gt;
To allow the use of the network and/or USB connections, the following lines must be added to your AndroidManifest.xml file:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;!-- Required for network access --&amp;gt;&lt;br /&gt;
&amp;lt;uses-permission android:name=&amp;quot;android.permission.INTERNET&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Required for USB access --&amp;gt;&lt;br /&gt;
&amp;lt;uses-feature android:name=&amp;quot;android.hardware.usb.host&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll need to initialize the method that the Android device can use to communicate with the Phidget. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
//Allow direct USB connection of Phidgets&lt;br /&gt;
com.phidget22.usb.Manager.Initialize(this);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the device is closed, to completely clean up after using Phidgets, you must uninitialize the USB connection as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
//Disable USB connection to Phidgets&lt;br /&gt;
com.phidget22.usb.Manager.Uninitialize();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Network Server==&lt;br /&gt;
In applications where you aren&#039;t plugging Phidgets into your Android device directly, you must have a host computer that is running the Phidget Network Server. &lt;br /&gt;
&lt;br /&gt;
[[Image:android-connection.jpg|link=|center]]&lt;br /&gt;
&lt;br /&gt;
*Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.&lt;br /&gt;
*Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer. When developing for Android, your Android device acts as the client.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, you will need to install the Phidget libraries on your host computer, and get the Phidget Network Server up and running. Follow the &#039;&#039;Getting Started&#039;&#039; guide, and continue with the &#039;&#039;Network Server&#039;&#039; guide for your operating system. When you are done, come back and finish this guide!&lt;br /&gt;
*[[OS - Windows| Windows]]&lt;br /&gt;
*[[OS - macOS| macOS]]&lt;br /&gt;
*[[OS - Linux| Linux]]&lt;br /&gt;
*[[OS - Phidget SBC| Phidget Single Board Computer]]&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basics set up, check out the [[Language - Android Java|Android Java]] page for information on how to write code for Phidgets to run on your Android device.&lt;br /&gt;
&lt;br /&gt;
Note that Android Java is NOT the same as mainstream Java.  Any Java programs you have will probably need significant modification before they run on Android, including our [[Language - Java|mainstream Java]] Phidget Examples.&lt;br /&gt;
&lt;br /&gt;
==Software License==&lt;br /&gt;
By downloading the Android library you agree to adhere to the terms of the [{{SERVER}}/documentation/Licenses/Phidgets_EULA.pdf Phidgets End User License Agreement]. The C API section of Phidget22 is covered by the [https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License]. The source code of C API can be found [{{SERVER}}/downloads/phidget22/libraries/linux/libphidget22.tar.gz here].&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35648</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35648"/>
		<updated>2026-05-25T21:33:45Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Learn how to use Phidget USB devices with Java.}}&lt;br /&gt;
[[Category:Language]]&lt;br /&gt;
&lt;br /&gt;
==Get Started==&lt;br /&gt;
With the Phidget22 library, it&#039;s easy to create Java applications that work with Phidget devices.&lt;br /&gt;
&lt;br /&gt;
==Java Libraries==&lt;br /&gt;
During development, we recommend downloading the appropriate installer or package for your [https://www.phidgets.com/docs/Operating_System_Support operating system]. This will place the required Phidget library files in standard locations where Java will look for them. When [[#Deploying Applications|deploying applications]], you can instead include these files manually as part of your application. &lt;br /&gt;
&lt;br /&gt;
====macOS Considerations====&lt;br /&gt;
Legacy Phidgets running a HID USB stack require a driver extension (macOS 10.15 and newer) or a kernel extension (macOS 10.14 and earlier). During development, we recommend downloading the appropriate [https://www.phidgets.com/docs/OS_-_macOS#Quick_Downloads package] which will install the extension. When deploying applications, review the README in the [https://cdn.phidgets.com/downloads/phidget22/libraries/macos/Phidget22_macosdevel.zip macOS Development Files] for information about bundling the extension with your application.&lt;br /&gt;
&lt;br /&gt;
=====Determining USB Stack=====&lt;br /&gt;
To determine which USB stack your device is running, navigate to the product page and then to the specification tab, and look for the &#039;&#039;USB Stack&#039;&#039; specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.&lt;br /&gt;
&lt;br /&gt;
[[Image:Javascript_networkserver_webusb_spec.png|center|600px|link=https://cdn.phidgets.com/docs/images/8/80/Javascript_networkserver_webusb_spec.png]]&lt;br /&gt;
&lt;br /&gt;
====Linux Considerations====&lt;br /&gt;
Linux restricts access to USB devices to the root user. To run your Python application as a regular user, you&#039;ll need to [{{SERVER}}/docs/OS_-_Linux#Setting_Udev_Rules set up udev rules] on your system.&lt;br /&gt;
&lt;br /&gt;
==Development Environment Configuration==&lt;br /&gt;
&lt;br /&gt;
Before choosing a development environment, make sure you have the [http://www.oracle.com/technetwork/java/index.html Java Development Kit] installed. &lt;br /&gt;
&lt;br /&gt;
===Visual Studio Code===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| To start developing with Java in VSCode, open it up and install the &#039;&#039;&#039;Extension Pack for Java&#039;&#039;&#039;.||[[Image:Language_java_vscode_extension2.png|center|350px|link=https://cdn.phidgets.com/docs/images/b/b4/Language_java_vscode_extension2.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Next, press &#039;&#039;&#039;Ctrl+Shift+P&#039;&#039;&#039; to open the command palette, type &amp;quot;java&amp;quot; and select &#039;&#039;&#039;Java: Create Java Project&#039;&#039;&#039;.  || [[Image:Language_java_vscode_createproj.png|center|360px|link=https://cdn.phidgets.com/docs/images/7/78/Language_java_vscode_createproj.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Select &amp;quot;No Build Tools&amp;quot; and select a directory for the new project. You&#039;ll be asked for a project name, and  VSCode will create the directory structure. || [[Image:Language_java_vscode_emptyproj.png|center|350px|link=https://cdn.phidgets.com/docs/images/c/c1/Language_java_vscode_emptyproj.png]]&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;|You&#039;ll need to get a copy of &#039;&#039;&#039;phidget22.jar&#039;&#039;&#039; to put inside the &amp;quot;lib&amp;quot; folder. [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip You can download phidget22.jar here]. &lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| You can now begin writing code in the newly created &amp;quot;App.java&amp;quot; file, or you can download a [[#Example_Code|sample program]] for your device and place it in the &amp;quot;src&amp;quot; folder.&lt;br /&gt;
|-&lt;br /&gt;
| Compile and run by pressing &#039;&#039;&#039;F5&#039;&#039;&#039; or by clicking the play button in the top right. || [[Image:Language_java_vscode_run.png|center|350px|link=https://cdn.phidgets.com/docs/images/e/ea/Language_java_vscode_run.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Once you&#039;re ready to compile your project into a .jar executable, click on the &#039;&#039;&#039;Java Projects&#039;&#039;&#039; section in the explorer. || [[Image:Language_java_vscode_jar.png|center|350px|link=https://cdn.phidgets.com/docs/images/6/65/Language_java_vscode_jar.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Click on the export icon, and then select your main class and click OK. || [[Image:Language_java_vscode_jar2.png|center|350px|link=https://cdn.phidgets.com/docs/images/7/74/Language_java_vscode_jar2.png]]&lt;br /&gt;
|- &lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| Now you can run your new .jar file with the following command:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
java -jar Example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Javac===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|The easiest way to allow Java to access the Phidgets Java library is to place a copy of &#039;&#039;&#039;phidget22.jar&#039;&#039;&#039; in the same folder as your .java program.  ||[[Image:Language_java_javac_folder.png|center|350px|link=https://cdn.phidgets.com/docs/images/8/89/Language_java_javac_folder.png]]&lt;br /&gt;
|-&lt;br /&gt;
|[https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip You can download phidget22.jar here].|| &lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|To run your program, enter the following command in the command prompt or terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
javac -classpath .;phidget22.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then, enter the following command to run the program:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
java -classpath .;phidget22.jar example &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| Once you&#039;re ready to compile your project into a .jar executable, create a &#039;&#039;&#039;manifest.mf&#039;&#039;&#039; file with the following contents:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Main-Class: example&lt;br /&gt;
Class-Path: phidget22.jar&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Make sure there&#039;s an empty newline at the bottom of the three lines and a space after each colon.&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| Next, create the .jar file with this command:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
jar cfm example.jar manifest.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Once the .jar is created, you can execute it with&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Netbeans===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|The easiest way to allow Java to access the Phidgets Java library is to place a copy of &#039;&#039;&#039;phidget22.jar&#039;&#039;&#039; in the same folder as your .java program.  ||[[Image:Language_java_javac_folder.png|center|350px|link=https://cdn.phidgets.com/docs/images/8/89/Language_java_javac_folder.png]]&lt;br /&gt;
|-&lt;br /&gt;
|[https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip You can download phidget22.jar here].|| &lt;br /&gt;
|-&lt;br /&gt;
| To start, open NetBeans and create a new project. Select Java Application and follow the steps as directed by Netbeans.|| [[Image:Windows_netbeans1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/c/c9/Windows_netbeans1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Next, add a reference to phidget22.jar by right-clicking on the libraries folder. || [[Image:Windows_netbeans2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/2/2b/Windows_netbeans2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Navigate to the folder where you downloaded phidget22.jar, and select it. || [[Image:Windows_netbeans3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/7/76/Windows_netbeans3.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| The project now has access to Phidgets. By default, Netbeans should create an executable .jar file in the &#039;&#039;&#039;dist&#039;&#039;&#039; folder of the project directory when it&#039;s built. If it didn&#039;t, go to &#039;&#039;&#039;Build -&amp;gt; Packaging&#039;&#039;&#039; in the project properties and make sure &amp;quot;Build JAR after compiling&amp;quot; is checked.|| [[Image:Windows_netbeans4.png|center|350px|link=https://cdn.phidgets.com/docs/images/7/78/Windows_netbeans4.png]]&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| You can now run the .jar file from the command prompt with:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
java -jar phidgetTest.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| To start, open Eclipse and create a new Java project. Name the project and uncheck the &#039;&#039;&#039;create module-info.java file&#039;&#039;&#039; box.|| [[Image:java_eclipse_newproj.png|center|350px|link=https://cdn.phidgets.com/docs/images/9/97/Java_eclipse_newproj.png]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar].  to your project as an external jar. Be sure it&#039;s being added to the &#039;&#039;&#039;Classpath&#039;&#039;&#039; and not the module path. || [[Image:java_eclipse_library.png|center|350px|link=https://cdn.phidgets.com/docs/images/1/1b/Java_eclipse_library.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:java_eclipse_newclass.png|center|350px|link=https://cdn.phidgets.com/docs/images/0/02/Java_eclipse_newclass.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Name the class, and be sure to check the &#039;&#039;&#039;public static void main&#039;&#039;&#039; box. Eclipse may require that you add a package name. || [[Image:java_eclipse_newclass2.png|center|350px|link=https://cdn.phidgets.com/docs/images/c/ca/Java_eclipse_newclass2.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&lt;br /&gt;
|-&lt;br /&gt;
| Once you&#039;re ready to compile your project into a .jar executable, right click on the project in the package explorer and choose &#039;&#039;&#039;Export&#039;&#039;&#039;. Select &#039;&#039;&#039;Runnable JAR file&#039;&#039;&#039;. || [[Image:java_eclipse_export.png|center|350px|link=https://cdn.phidgets.com/docs/images/8/8c/Java_eclipse_export.png]]&lt;br /&gt;
|-&lt;br /&gt;
| Choose the main class and a destination for the .jar file and click finish. || [[Image:java_eclipse_export2.png|center|350px|link=https://cdn.phidgets.com/docs/images/8/8d/Java_eclipse_export2.png]]&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| You can now run the .jar file from the command prompt with:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
java -jar phidgetTest.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Android Studio===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| To start, create a new project in Android Studio.|| [[Image:java_as_newproj.png|center|350px|link=]]&lt;br /&gt;
|-&lt;br /&gt;
| Once you have a new project, be sure to switch the side bar to Project view. || [[Image:java_as_view.png|center|350px|link=]]&lt;br /&gt;
|-&lt;br /&gt;
| Next, download the [https://cdn.phidgets.com/downloads/phidget22/libraries/android/phidget22-android.zipPhidget22 Android Java libraries], extract the contents, and open the resulting folder. || [[Image:java_as_extract.png|center|350px|link=]]&lt;br /&gt;
|-&lt;br /&gt;
| Copy the .jar files into the &#039;&#039;&#039;app/libs/&#039;&#039;&#039; folder of your project. If you are only going to use network Phidgets in your app, then you don&#039;t need to copy Phidget22usb.jar into your project.&lt;br /&gt;
&lt;br /&gt;
Right click the jar files you just copied and select &#039;&#039;&#039;Add As Library.&#039;&#039;&#039;&lt;br /&gt;
|[[Image:java_as_jnilibs.png|center|350px|link=]]&lt;br /&gt;
|-&lt;br /&gt;
|Create a directory called &#039;&#039;&#039;jnilibs&#039;&#039;&#039; under &#039;&#039;&#039;app/src/main&#039;&#039;&#039; || [[Image:java_as_jnilibs2.png|center|350px|link=]]&lt;br /&gt;
|-&lt;br /&gt;
| Copy the remaining folders from the Phidget22 library (containing versions of libphidget22java.so) into the directory you just created. || [[Image:java_as_jnilibs3.png|center|350px|link=]]&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;|  To allow the use of the network and/or USB connections, the following lines must be added to your AndroidManifest.xml file:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;!-- Required for network access --&amp;gt;&lt;br /&gt;
&amp;lt;uses-permission android:name=&amp;quot;android.permission.INTERNET&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Required for USB access --&amp;gt;&lt;br /&gt;
&amp;lt;uses-feature android:name=&amp;quot;android.hardware.usb.host&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Finally, to import the Phidget22 library into your code, add the following line to the rest of your imports:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
import com.phidget22.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to Phidgets. Next, we&#039;ll walk through the steps for writing your own code. ||&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot;| &lt;br /&gt;
By following the instructions for your operating system and compiler above, you now have working examples and a project that is configured. This teaching section will help you understand how the examples were written so you can start writing your own code.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Android Java code will be:&lt;br /&gt;
&lt;br /&gt;
* The [https://www.phidgets.com/?view=api Phidget22 API]&lt;br /&gt;
* The [https://www.phidgets.com/?view=code_samples&amp;amp;lang=Java Java example code]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step One: Initialize and Open&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You will need to declare your Phidget object in your code. For example, we can declare a digital input object like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
DigitalInput device;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we need to initialize the method(s) that the Android device can communicate with the Phidget. This is done either by enabling Network Server Discovery, and/or allowing direct USB connections as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
//Enable server discovery to list remote Phidgets&lt;br /&gt;
this.getSystemService(Context.NSD_SERVICE);&lt;br /&gt;
Net.enableServerDiscovery(ServerType.DEVICE_REMOTE);&lt;br /&gt;
&lt;br /&gt;
//Allow direct USB connection of Phidgets&lt;br /&gt;
com.phidget22.usb.Manager.Initialize(this);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To support remote (network) Phidgets on Android API versions earlier than API version 16, or to connect to Phidget Network Servers with passwords, you will need to add the specific server to your program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
//Add a specific network server to communicate with Phidgets remotely&lt;br /&gt;
Net.addServer(&amp;quot;ServerName&amp;quot;, &amp;quot;192.168.1.105&amp;quot;, 5661, &amp;quot;password&amp;quot;, 0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the connection methods are established, the Phidget object needs to be initialized and opened:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
device = new DigitalInput();&lt;br /&gt;
device.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although we are not including it on this page, you should include error handling for all Phidget functions. Here is an example of the previous code with error handling:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
try{&lt;br /&gt;
    device = new DigitalInput();&lt;br /&gt;
    device.open();&lt;br /&gt;
}catch (PhidgetException e) {&lt;br /&gt;
    e.printStackTrace();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information on error handling with Phidgets, see [[Handling Errors and Logging|this page]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step Two: Wait for Attachment (plugging in) of the Phidget&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Simply calling open does not guarantee you can use the Phidget immediately. To use a Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the attach events. Alternatively, we can modify our code so we wait for an attachment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
ch = new DigitalInput();&lt;br /&gt;
ch.open(5000); //wait for attach for 5 seconds, if not time out&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Waiting for attachment will block indefinitely until a connection is made, or until the timeout value is exceeded.&lt;br /&gt;
&lt;br /&gt;
To use events, we have to modify our code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
ch = new DigitalInput();&lt;br /&gt;
device.addAttachListener(new AttachListener() {&lt;br /&gt;
    public void onAttach(final AttachEvent attachEvent) {&lt;br /&gt;
        AttachEventHandler handler = new AttachEventHandler(device);&lt;br /&gt;
        synchronized(handler)&lt;br /&gt;
        {&lt;br /&gt;
            runOnUiThread(handler);&lt;br /&gt;
            try {&lt;br /&gt;
                handler.wait();&lt;br /&gt;
            } catch (InterruptedException e) {&lt;br /&gt;
                e.printStackTrace();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
ch.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we have to declare the function that will be called when an attach event is fired - in this case the function AttachEventHandler will be called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class AttachEventHandler implements Runnable { &lt;br /&gt;
    Phidget device;&lt;br /&gt;
&lt;br /&gt;
    public AttachEventHandler(Phidget device) {&lt;br /&gt;
        this.device = device;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void run() {&lt;br /&gt;
        TextView attachedTxt = (TextView) findViewById(R.id.attachedTxt);&lt;br /&gt;
        attachedTxt.setText(&amp;quot;Attached&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        //notify that we&#039;re done&lt;br /&gt;
        synchronized(this)&lt;br /&gt;
        {&lt;br /&gt;
	    this.notify();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step Three: Do Things with the Phidget&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. In a similar way to handling an attach event as described above, we can also add an event handler for a state change event:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
ch = new DigitalInput();&lt;br /&gt;
device.addStateChangeListener(new DigitalInputStateChangeListener() {&lt;br /&gt;
	public void onStateChange(DigitalInputStateChangeEvent stateChangeEvent) {&lt;br /&gt;
        DigitalInputStateChangeEventHandler handler = &lt;br /&gt;
            new DigitalInputStateChangeEventHandler(device, stateChangeEvent);&lt;br /&gt;
	runOnUiThread(handler);&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
ch.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code will connect a function and an event. In this case, the &#039;&#039;&#039;DigitalInputStateChangeEventHandler&#039;&#039;&#039; function will be called when there has been a change to the devices input.&lt;br /&gt;
&lt;br /&gt;
Next, we need to create the &#039;&#039;&#039;DigitalInputStateChangeEventHandler&#039;&#039;&#039; function itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class DigitalInputStateChangeEventHandler implements Runnable {&lt;br /&gt;
    Phidget device;&lt;br /&gt;
    DigitalInputStateChangeEvent stateChangeEvent;&lt;br /&gt;
&lt;br /&gt;
    public DigitalInputStateChangeEventHandler(Phidget device,&lt;br /&gt;
       DigitalInputStateChangeEvent stateChangeEvent)&lt;br /&gt;
    {&lt;br /&gt;
        this.device = device;&lt;br /&gt;
        this.stateChangeEvent = stateChangeEvent;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void run() {&lt;br /&gt;
        CheckBox stateBox = (CheckBox) findViewById(R.id.stateBox);&lt;br /&gt;
        stateBox.setChecked(stateChangeEvent.getState());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If events do not suit your needs, you can also poll the device directly for data using code like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
boolean state = ch.getState();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step Four: Close and Delete&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
At the end of your program, be sure to close your device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
ch.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the device is closed, to completely clean up after using Phidgets, you must uninitialize the USB connection as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
//Disable USB connection to Phidgets&lt;br /&gt;
com.phidget22.usb.Manager.Uninitialize();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve set up Phidgets in your programming environment, you should read our guide on [[Phidget Programming Basics]] to learn the fundamentals of programming with Phidgets.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== PhidgetSBC Web Interface ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+&#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;center&amp;gt;{{#ev:youtube|gZmWvWXICIA|rel=0}}&amp;lt;/center&amp;gt; &lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Debian Linux may not have support for the newest JDK by default, so if you&#039;re developing your code on another machine, you may have to target an older version of Java in order to run it on the PhidgetSBC.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example Code==&lt;br /&gt;
Navigate to our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=Java Code Sample Generator] to view and download code samples that are tailored to your specific device.&lt;br /&gt;
&lt;br /&gt;
[[Image:Language_java_codesample.png|center|600px|link=https://cdn.phidgets.com/docs/images/a/af/Language_java_codesample.png]]&lt;br /&gt;
&lt;br /&gt;
===Phidget Programming Basics===&lt;br /&gt;
{{PhidgetProgrammingBasicsLink}}&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
The following files are required for your Java application:&lt;br /&gt;
* phidget22.jar &lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
The files can be found in the [https://cdn.phidgets.com/downloads/phidget22/libraries/windows/Phidget22-windevel.zip Development Files]. The .jar file is in lib/java, and the dll files are in lib/c/x64. &lt;br /&gt;
&lt;br /&gt;
Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;br /&gt;
&lt;br /&gt;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_as_jnilibs3.png&amp;diff=35647</id>
		<title>File:Java as jnilibs3.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_as_jnilibs3.png&amp;diff=35647"/>
		<updated>2026-05-25T21:31:00Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_as_jnilibs2.png&amp;diff=35646</id>
		<title>File:Java as jnilibs2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_as_jnilibs2.png&amp;diff=35646"/>
		<updated>2026-05-25T21:28:20Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_as_jnilibs.png&amp;diff=35645</id>
		<title>File:Java as jnilibs.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_as_jnilibs.png&amp;diff=35645"/>
		<updated>2026-05-25T21:28:04Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_as_extract.png&amp;diff=35644</id>
		<title>File:Java as extract.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_as_extract.png&amp;diff=35644"/>
		<updated>2026-05-25T21:27:52Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_as_view.png&amp;diff=35643</id>
		<title>File:Java as view.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_as_view.png&amp;diff=35643"/>
		<updated>2026-05-25T21:27:24Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_as_newproj.png&amp;diff=35642</id>
		<title>File:Java as newproj.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_as_newproj.png&amp;diff=35642"/>
		<updated>2026-05-25T21:27:06Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=REL2103_User_Guide&amp;diff=35640</id>
		<title>REL2103 User Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=REL2103_User_Guide&amp;diff=35640"/>
		<updated>2026-05-08T19:15:08Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Part 4: Advanced Topics and Troubleshooting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOINDEX__&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&amp;lt;metadesc&amp;gt;Use a VINT port with the Solid State Relay Phidget to switch power to a circuit running at up to 30 volts and 10 amps, AC or DC.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
[[Category:UserGuide]]&lt;br /&gt;
==Part 1: Setup==&lt;br /&gt;
{{PT1 Deck Sequence}}&lt;br /&gt;
&lt;br /&gt;
==Part 2: Using Your Phidget==&lt;br /&gt;
===About===&lt;br /&gt;
The REL2103 is a solid-state relay capable of switching up to 10 amps or controlling power up to 30V. You interact with the REL2103 through the Digital Output Channel Class to turn on or off the power to a circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2103_About.jpg|link=|center]]&lt;br /&gt;
&lt;br /&gt;
===Explore your Phidget Channels Using the Control Panel===&lt;br /&gt;
Double click on the Digital Output channel class under the port your REL2103 is connected to.&lt;br /&gt;
[[Image:REL2103_0_Panel_Example.jpg|link=]]&lt;br /&gt;
&lt;br /&gt;
{{UG-Part3}}&lt;br /&gt;
&lt;br /&gt;
==Part 4: Advanced Topics and Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
{{UGC-Start}}&lt;br /&gt;
{{UGC-Addressing}}&lt;br /&gt;
{{UGC-Entry|Solid State Relays|&lt;br /&gt;
|&lt;br /&gt;
A solid-state relay is an electrically-controlled switch. For more information about how SSRs work and how to use them, visit the [[Solid State Relay Guide]].}}&lt;br /&gt;
{{UGC-Entry|Using the SRC Terminals|&lt;br /&gt;
|&lt;br /&gt;
The two middle pins on the REL2103, labeled &amp;quot;SRC&amp;quot; give you access to the source of the MOSFETs used to switch your circuit. &lt;br /&gt;
If you are switching a DC load, the setup will be advantageous as you can double the maximum current handled by this Phidget (10A to 20A).&lt;br /&gt;
 &lt;br /&gt;
[[Image:REL2103-src.jpg|link=|600px]]&lt;br /&gt;
&lt;br /&gt;
The white schematic on the left shows a simplified version of the REL2103&#039;s circuitry: An optocoupler that activates two MOSFETs. The black schematic on the right shows how you would hook up a DC circuit to take advantage of the increased maximum current.}}&lt;br /&gt;
{{UGC-Entry|Can I use this relay without a VINT Hub?|&lt;br /&gt;
|&lt;br /&gt;
Unlike most VINT devices that communicate to the VINT Hub by sending packets on the data line, the REL2103 is simply controlled with the port in digital output mode. This means that you can control it with other digital output devices. For example, you can control it with a Phidget 1018 like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2XXX_1018.png|link=|500px]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a simplified diagram to clarify how the input side of REL2103 works:&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2103_circuit.png|link=|650px]]&lt;br /&gt;
&lt;br /&gt;
The red wire requires 5V to power the opto-isolator diode, and the white wire requires at least 3.3V to switch the MOSFET. &lt;br /&gt;
}}&lt;br /&gt;
{{UGC-End}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:REL2103_circuit.png&amp;diff=35639</id>
		<title>File:REL2103 circuit.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:REL2103_circuit.png&amp;diff=35639"/>
		<updated>2026-05-08T19:14:37Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=REL2002_User_Guide&amp;diff=35638</id>
		<title>REL2002 User Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=REL2002_User_Guide&amp;diff=35638"/>
		<updated>2026-05-08T15:33:10Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Part 4: Advanced Topics and Troubleshooting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOINDEX__&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&amp;lt;metadesc&amp;gt;Switch a small digital signal with the Signal Relay Phidget. Switches up to 60W of DC power or 125 VA of AC power.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
[[Category:UserGuide]]&lt;br /&gt;
==Part 1: Setup==&lt;br /&gt;
{{PT1 Deck Sequence}}&lt;br /&gt;
&lt;br /&gt;
== Part 2: Using Your Phidget ==&lt;br /&gt;
&lt;br /&gt;
===About===&lt;br /&gt;
[[File:1017_1_Relay_Diagram.jpg|200px|right|link=]]&lt;br /&gt;
&lt;br /&gt;
The REL2002 is a mechanical relay suitable for both AC and DC applications. It is a double-pole double-throw style relay meaning it will switch two circuits at once. You interact with the REL2002 through the Digital Output Channel Class to turn power to your circuit or device on and off . &lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
===Explore Your Phidget Channels Using The Control Panel===&lt;br /&gt;
&lt;br /&gt;
Double click on the Digital Output channel class under the port your REL2002 is connected to.&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2002_Panel_Example.jpg|link=|center]]&lt;br /&gt;
&lt;br /&gt;
{{UG-Part3}}&lt;br /&gt;
&lt;br /&gt;
== Part 4: Advanced Topics and Troubleshooting ==&lt;br /&gt;
{{UGC-Start}}&lt;br /&gt;
{{UGC-Addressing}}&lt;br /&gt;
{{UGC-Entry|Mechanical Relays|&lt;br /&gt;
|&lt;br /&gt;
This relay is an electrically-controlled switch. For more information about how mechanical relays work and how to use them, visit the [[Mechanical Relay Guide]].&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
{{UGC-Entry|Can I use this relay without a VINT Hub?|&lt;br /&gt;
|&lt;br /&gt;
Unlike most VINT devices that communicate to the VINT Hub by sending packets on the data line, the REL2002 is simply controlled with the port in digital output mode. This means that you can control it with other digital output devices. For example, you can control it with a Phidget 1018 like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2XXX_1018.png|link=|500px]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a simplified diagram to clarify how the REL2002 works:&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2002_circuit.png|link=|650px]]&lt;br /&gt;
&lt;br /&gt;
The red wire requires 5V to power the relay coil, and the white wire requires at least 3.3V to switch the MOSFET. &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{UGC-End}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:REL2002_circuit.png&amp;diff=35637</id>
		<title>File:REL2002 circuit.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:REL2002_circuit.png&amp;diff=35637"/>
		<updated>2026-05-08T15:32:10Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=REL2001_User_Guide&amp;diff=35636</id>
		<title>REL2001 User Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=REL2001_User_Guide&amp;diff=35636"/>
		<updated>2026-05-07T22:30:27Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Part 4: Advanced Topics and Troubleshooting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOINDEX__&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&amp;lt;metadesc&amp;gt;Use a VINT port with the Relay Phidget to switch power to a circuit running at up to 210 watts DC or 1750 volt-amperes AC.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
[[Category:UserGuide]]&lt;br /&gt;
==Part 1: Setup==&lt;br /&gt;
{{PT1 Deck Sequence}}&lt;br /&gt;
&lt;br /&gt;
==Part 2: Using Your Phidget==&lt;br /&gt;
===About===&lt;br /&gt;
The REL2001 is a mechanical relay suitable for both AC and DC applications. You interact with the REL2001 through the Digital Output Channel Class to turn on and off power to your circuit or device.&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2001_About.jpg|link=|center]]&lt;br /&gt;
&lt;br /&gt;
===Explore your Phidget Channels Using the Control Panel===&lt;br /&gt;
Double click on the Digital Output channel class under the port your REL2001 is connected to.&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2001_0_Panel_Example.jpg|link=]]&lt;br /&gt;
&lt;br /&gt;
{{UG-Part3}}&lt;br /&gt;
&lt;br /&gt;
==Part 4: Advanced Topics and Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
{{UGC-Start}}&lt;br /&gt;
{{UGC-Addressing}}&lt;br /&gt;
{{UGC-Entry|Mechanical Relays|&lt;br /&gt;
|&lt;br /&gt;
This relay is an electrically-controlled switch. For more information about how mechanical relays work and how to use them, visit the [[Mechanical Relay Guide]].}}&lt;br /&gt;
{{UGC-Entry|Can I use this relay without a VINT Hub?|&lt;br /&gt;
|&lt;br /&gt;
Unlike most VINT devices that communicate to the VINT Hub by sending packets on the data line, the REL2001 is simply controlled with the port in digital output mode. This means that you can control it with other digital output devices. For example, you can control it with a Phidget 1018 like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2XXX_1018.png|link=|500px]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a simplified diagram to clarify how the REL2001 works:&lt;br /&gt;
&lt;br /&gt;
[[Image:REL2001_circuit.png|link=]]&lt;br /&gt;
&lt;br /&gt;
The red wire requires 5V to power the relay coil, and the white wire requires at least 3.3V to switch the MOSFET. &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{UGC-End}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:REL2001_circuit.png&amp;diff=35635</id>
		<title>File:REL2001 circuit.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:REL2001_circuit.png&amp;diff=35635"/>
		<updated>2026-05-07T22:29:30Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:REL2XXX_1018.png&amp;diff=35634</id>
		<title>File:REL2XXX 1018.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:REL2XXX_1018.png&amp;diff=35634"/>
		<updated>2026-05-07T22:29:18Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Swift&amp;diff=35628</id>
		<title>Language - Swift</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Swift&amp;diff=35628"/>
		<updated>2026-04-20T16:09:34Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Swift Libraries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Learn how to use Phidget USB devices with Swift.}}&lt;br /&gt;
[[Category:Language]]&lt;br /&gt;
&lt;br /&gt;
== Get Started ==&lt;br /&gt;
With the Phidget22 library, it&#039;s easy to create Swift applications that work with Phidget devices.&lt;br /&gt;
&lt;br /&gt;
== Swift Libraries ==&lt;br /&gt;
If you&#039;ve installed the Phidget drivers for  [[OS - macOS|macOS]] or [[OS - iOS|iOS]], then you already have the files you need for your project.&lt;br /&gt;
&lt;br /&gt;
====macOS Considerations====&lt;br /&gt;
Legacy Phidgets running a HID USB stack require a driver extension (macOS 10.15 and newer) or a kernel extension (macOS 10.14 and earlier). During development, we recommend downloading the appropriate [https://www.phidgets.com/docs/OS_-_macOS#Quick_Downloads package] which will install the extension. When deploying applications, review the README in the [https://cdn.phidgets.com/downloads/phidget22/libraries/macos/Phidget22_macosdevel.zip macOS Development Files] for information about bundling the extension with your application.&lt;br /&gt;
&lt;br /&gt;
=====Determining USB Stack=====&lt;br /&gt;
To determine which USB stack your device is running, navigate to the product page and then to the specification tab, and look for the &#039;&#039;USB Stack&#039;&#039; specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.&lt;br /&gt;
&lt;br /&gt;
[[Image:Javascript_networkserver_webusb_spec.png|center|600px|link=https://cdn.phidgets.com/docs/images/8/80/Javascript_networkserver_webusb_spec.png]]&lt;br /&gt;
&lt;br /&gt;
== Example Code ==&lt;br /&gt;
You can find examples for macOS and iOS on our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=Swift Code Samples] page. Make sure you download one for the correct OS. &lt;br /&gt;
&lt;br /&gt;
[[Image:swift_example2.png|link=|center|750px]]&lt;br /&gt;
&lt;br /&gt;
== XCode Configuration ==&lt;br /&gt;
[https://developer.apple.com/xcode/ Xcode] is an IDE provided by Apple that&#039;s used to develop code in a wide variety of programming languages, including Swift.&lt;br /&gt;
&lt;br /&gt;
=== macOS ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Use Our Examples}}||&lt;br /&gt;
|- &lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|Start by downloading a [https://www.phidgets.com/?view=code_samples&amp;amp;lang=Swift Swift example] that will work with your Phidget.&lt;br /&gt;
&lt;br /&gt;
Open the folder and run &#039;&#039;&#039;Package.swift&#039;&#039;&#039; to open it in Xcode.&lt;br /&gt;
|-&lt;br /&gt;
| Next, simply press run. ||[[Image:Macos_swift_run2.png|link=https://cdn.phidgets.com/docs/images/b/b9/Macos_swift_run2.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Here&#039;s what the VoltageInput example will look like when it&#039;s running. Try playing around with the device and experiment with some of its functionality. The next step is configuring a new project and writing your own code. || [[Image:Macos_swift_output.png|link=https://cdn.phidgets.com/docs/images/0/00/Macos_swift_output.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Starting a New Project}}&lt;br /&gt;
|-&lt;br /&gt;
| Create a new XCode project and select a macOS app. || [[Image:Macos_new_proj.png|link=https://cdn.phidgets.com/docs/images/0/04/Macos_new_proj.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Name the project, select Swift as the language, and continue. || [[Image:Macos_new_nameproject.png|link=https://cdn.phidgets.com/docs/images/f/fb/Macos_new_nameproject.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Now that your project is created, you need to add the Phidget libraries.&lt;br /&gt;
&lt;br /&gt;
Go to File &amp;gt; &#039;&#039;&#039;Add Package Dependencies&#039;&#039;&#039;&lt;br /&gt;
|[[Image:Macos_swift_addpackage.png|link=https://cdn.phidgets.com/docs/images/1/13/Macos_swift_addpackage.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| This will pop up the Swift package manager. || [[Image:Macos_swift_packageblank.png|link=https://cdn.phidgets.com/docs/images/3/3f/Macos_swift_packageblank.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Type this URL into the search bar in the top right:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;https://www.phidgets.com/git/phidget22-swift.git&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then select the phidget22-swift package and click &#039;&#039;&#039;Add Package&#039;&#039;&#039;.&lt;br /&gt;
| [[Image:Macos_swift_packageurl.png|link=https://cdn.phidgets.com/docs/images/f/ff/Macos_swift_packageurl.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;| Now you can access the Phidget libraries by adding the following line to the top of your files:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;import Phidget22Swift&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The project now has access to Phidgets you can begin coding. See [[Phidget Programming Basics]] for guidance on writing your own code. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== iOS ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Use Our Examples}}||&lt;br /&gt;
|- &lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|Start by downloading a [https://www.phidgets.com/?view=code_samples&amp;amp;lang=Swift Swift example] that will work with your Phidget.&lt;br /&gt;
&lt;br /&gt;
Open the folder and run &#039;&#039;&#039;Package.swift&#039;&#039;&#039; to open it in Xcode.&lt;br /&gt;
|-&lt;br /&gt;
| Next, select the type of device you would like the application to run on, and press play. || [[Image:ios_swift_select_target.png|link=https://cdn.phidgets.com/docs/images/9/90/Ios_swift_select_target.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Here&#039;s what the VoltageInput example will look like when it&#039;s running. Try playing around with the device and experiment with some of its functionality. The next step is starting a new project and writing your own code.|| [[Image:ios_swift_output.png|link=https://cdn.phidgets.com/docs/images/1/1d/Ios_swift_output.png|200px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Starting a New Project}}&lt;br /&gt;
|-&lt;br /&gt;
|  Create a new XCode project and select an iOS app. || [[Image:ios_new_proj.png|link=https://cdn.phidgets.com/docs/images/d/d9/Ios_new_proj.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Name the project, select Swift as the language, and choose which devices will be supported. || [[Image:ios_new_nameproject.png|link=https://cdn.phidgets.com/docs/images/8/86/Ios_new_nameproject.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Now that your project is created, you need to add the Phidget libraries.&lt;br /&gt;
Go to &#039;&#039;&#039;File &amp;gt; Add Package Dependencies&#039;&#039;&#039;&lt;br /&gt;
| |[[Image:Macos_swift_addpackage.png|link=https://cdn.phidgets.com/docs/images/1/13/Macos_swift_addpackage.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| This will pop up the Swift package manager. || [[Image:Macos_swift_packageblank.png|link=https://cdn.phidgets.com/docs/images/3/3f/Macos_swift_packageblank.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Type this URL into the search bar in the top right:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;https://www.phidgets.com/git/phidget22-swift.git&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then select the phidget22-swift package and click &#039;&#039;&#039;Add Package&#039;&#039;&#039;.&lt;br /&gt;
| [[Image:Macos_swift_packageurl.png|link=https://cdn.phidgets.com/docs/images/f/ff/Macos_swift_packageurl.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;| Now you can access the Phidget libraries by adding the following line to the top of your files:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;import Phidget22Swift&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The project now has access to Phidgets you can begin coding. See [[Phidget Programming Basics]] for guidance on writing your own code. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Phidget Programming Basics==&lt;br /&gt;
{{PhidgetProgrammingBasicsLink}}&lt;br /&gt;
&lt;br /&gt;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Swift Phidget22 API]&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Objective_C&amp;diff=35627</id>
		<title>Language - Objective C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Objective_C&amp;diff=35627"/>
		<updated>2026-04-20T16:09:04Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Objective C Libraries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Learn how to use Phidget USB devices with Objective C.}}&lt;br /&gt;
[[Category:Language]]&lt;br /&gt;
&lt;br /&gt;
== Get Started ==&lt;br /&gt;
With the Phidget22 library, it&#039;s easy to create Objective C applications that work with Phidget devices.&lt;br /&gt;
&lt;br /&gt;
== Objective C Libraries ==&lt;br /&gt;
If you&#039;ve installed the Phidget drivers for  [[OS - macOS|macOS]] or [[OS - iOS|iOS]], then you already have the files you need for your project.&lt;br /&gt;
&lt;br /&gt;
====macOS Considerations====&lt;br /&gt;
Legacy Phidgets running a HID USB stack require a driver extension (macOS 10.15 and newer) or a kernel extension (macOS 10.14 and earlier). During development, we recommend downloading the appropriate [https://www.phidgets.com/docs/OS_-_macOS#Quick_Downloads package] which will install the extension. When deploying applications, review the README in the [https://cdn.phidgets.com/downloads/phidget22/libraries/macos/Phidget22_macosdevel.zip macOS Development Files] for information about bundling the extension with your application.&lt;br /&gt;
&lt;br /&gt;
=====Determining USB Stack=====&lt;br /&gt;
To determine which USB stack your device is running, navigate to the product page and then to the specification tab, and look for the &#039;&#039;USB Stack&#039;&#039; specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.&lt;br /&gt;
&lt;br /&gt;
[[Image:Javascript_networkserver_webusb_spec.png|center|600px|link=https://cdn.phidgets.com/docs/images/8/80/Javascript_networkserver_webusb_spec.png]]&lt;br /&gt;
&lt;br /&gt;
== Example Code ==&lt;br /&gt;
You can find examples for macOS and iOS on our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=Objective-C Code Samples] page.&lt;br /&gt;
&lt;br /&gt;
[[Image:xcode_example2.png|link=https://cdn.phidgets.com/docs/images/3/34/Xcode_example2.png|center|750px]]&lt;br /&gt;
&lt;br /&gt;
== XCode Configuration ==&lt;br /&gt;
Xcode is an IDE provided by Apple that can be used to develop code in a wide variety of programming languages, including Objective C.&lt;br /&gt;
&lt;br /&gt;
=== macOS ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Use Our Examples}}||&lt;br /&gt;
|- &lt;br /&gt;
|Start the example by pressing the &#039;&#039;&#039;Run&#039;&#039;&#039; button:||[[Image:Macos_RunExample.png|link=https://cdn.phidgets.com/docs/images/2/20/Macos_RunExample.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|The application will attach to the Phidget and show you some basic information. Here is an example of a Digital Output channel on a RFID Phidget.||[[Image:Macos_DigitalOutputExample.png|link=https://cdn.phidgets.com/docs/images/9/94/Macos_DigitalOutputExample.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|You should now have the example up and running for your device. Play around with the device and experiment with some of the functionality. The next step is configuring your project and writing your own code.&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Starting a New Project}}&lt;br /&gt;
|-&lt;br /&gt;
|When you are building a project from scratch, or adding Phidgets to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget iOS library. To begin, create a new Xcode project and select a macOS Cocoa application.||[[Image:Macos_Cocoa_Application.png|link=https://cdn.phidgets.com/docs/images/d/d2/Macos_Cocoa_Application.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Navigate to your target&#039;s Build Settings and find the &#039;&#039;&#039;Framework Search Path&#039;&#039;&#039; setting.||[[Image:Macos_frameworksearch2.png|link=https://cdn.phidgets.com/docs/images/9/97/Macos_frameworksearch2.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Add a reference to &#039;&#039;&#039;/Library/Frameworks&#039;&#039;&#039; where the Phidget22 framework is installed.||[[Image:Macos_frameworkpath2.png|link=https://cdn.phidgets.com/docs/images/d/d3/Macos_frameworkpath2.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Next, navigate to the &#039;&#039;&#039;Linked Frameworks and Libraries&#039;&#039;&#039; setting under &#039;&#039;&#039;General&#039;&#039;&#039; and add a reference to the Phidget22 framework which is installed to /Library/Frameworks. || [[Image:Macos_linkframework2.png|link=https://cdn.phidgets.com/docs/images/9/9f/Macos_linkframework2.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|Lastly, navigate to your header file and add a reference to phidget22.h&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;#import &amp;lt;Phidget22/phidget22.h&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your project now has access to Phidgets. See [[Phidget Programming Basics]] for guidance on writing your own code. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== iOS ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Use Our Examples}}||&lt;br /&gt;
|- &lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|To develop iOS apps in Objective C, we&#039;ll be using XCode on a macOS development machine. You&#039;ll need both:&lt;br /&gt;
* [https://www.phidgets.com/docs/OS_-_macOS Phidget macOS Drivers] installed&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/ios/Phidget22_iOS.zip Phidget iOS Libraries] downloaded&lt;br /&gt;
|-&lt;br /&gt;
|Unpack the Objective-C example and navigate to Phidget.xcodeproj. Open the file in Xcode.||[[Image:ios_objc_open.png|link=https://cdn.phidgets.com/docs/images/9/9b/Ios_objc_open.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|With &#039;&#039;&#039;Phidgets&#039;&#039;&#039; as your target, navigate to Build Settings and find the &#039;&#039;&#039;Header Search Paths&#039;&#039;&#039; setting.||[[Image:ios_objc_header.png|link=https://cdn.phidgets.com/docs/images/c/c8/Ios_objc_header.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| The header file phidget22.h was included in the Phidget iOS libraries download. Add a reference to the folder that contains phidget22.h under the &#039;&#039;&#039;Header Search Paths&#039;&#039;&#039; setting.||[[Image:ios_objc_header_path.png|link=https://cdn.phidgets.com/docs/images/b/b3/Ios_objc_header_path.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Next, find the &#039;&#039;&#039;Other Linker Flags&#039;&#039;&#039; setting.||[[Image:ios_linker.png|link=https://cdn.phidgets.com/docs/images/5/59/Ios_linker.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Add a reference to the Phidget libraries that were included in the Phidget iOS libraries download.||[[Image:ios_linker_path.png|link=https://cdn.phidgets.com/docs/images/1/17/Ios_linker_path.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Now that the library files are linked, simply select the type of device you would like the application to run on and press play.||[[Image:ios_simulator.png|link=https://cdn.phidgets.com/docs/images/7/74/Ios_simulator.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|The application will detect any servers that are currently online and have Phidgets connected. Here is an example output.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;First, confirm that the Phidgets Example is working. Then, run the example for your specific device by selecting your server and then continue to navigate through the hierarchy until you reach your device. After tapping your device, the example will show automatically. Currently, we have example programs for the following classes:&lt;br /&gt;
* DigitalInput&lt;br /&gt;
* DigitalOutput&lt;br /&gt;
* VoltageInput&lt;br /&gt;
* VoltageRatioInput&lt;br /&gt;
|[[Image:ios_phidgetapp.png|link=https://cdn.phidgets.com/docs/images/d/d8/Ios_phidgetapp.png|250px]]&lt;br /&gt;
|-&lt;br /&gt;
|Here is an example of what the VoltageInput example looks like.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;You should now have the example up and running for your device. Play around with the device and experiment with some of the functionality. When you are ready, the next step is configuring your project and writing your own code!||[[Image:ios_example_run.png|link=https://cdn.phidgets.com/docs/images/2/25/Ios_example_run.png|250px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|{{hiddenh4|Starting a New Project}}&lt;br /&gt;
|-&lt;br /&gt;
|Select an iOS application. For this tutorial&#039;s purposes, we will use a Single View Application.||[[Image:ios_singleview.png|link=https://cdn.phidgets.com/docs/images/e/e8/Ios_singleview.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|Name the project, select Objective-C as the language, and choose which devices will be supported.||[[Image:ios_nameproject_objc.png|link=https://cdn.phidgets.com/docs/images/1/13/Ios_nameproject_objc.png|350px]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot;|Now that your project is created, you need to add references to the Phidget iOS libraries in the same way you added them to run our example code earlier in this guide.&lt;br /&gt;
&lt;br /&gt;
After you have linked the Phidget iOS libraries, simply add a reference to phidget22.h in your header file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;#import &amp;lt;Phidget22/phidget22.h&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to Phidgets and we are ready to begin coding. See [[Phidget Programming Basics]] for guidance on writing your own code. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Phidget Programming Basics==&lt;br /&gt;
{{PhidgetProgrammingBasicsLink}}&lt;br /&gt;
&lt;br /&gt;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=C Phidget22 API]&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=35626</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=35626"/>
		<updated>2026-04-20T16:07:17Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* MacOS Considerations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Learn how to use Phidget USB devices with C and C++.}}&lt;br /&gt;
[[Category:Language]]&lt;br /&gt;
&lt;br /&gt;
== Get Started ==&lt;br /&gt;
With the Phidget22 library, it&#039;s easy to create C or C++ applications that work with Phidget devices.&lt;br /&gt;
&lt;br /&gt;
== C Libraries ==&lt;br /&gt;
If you&#039;ve installed the Phidget drivers for [[OS - Windows|Windows]], [[OS - macOS|MacOS]], or [[OS - Linux|Linux]], then you already have the files you need for your C project. &lt;br /&gt;
&lt;br /&gt;
==== Windows Considerations ====&lt;br /&gt;
When adding directories for your project dependencies, add&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:/Program Files/Phidgets/Phidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
And for the linker, you can add&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:/Program Files/Phidgets/Phidget22/phidget22.lib}}     #(for 64-bit systems)&lt;br /&gt;
C:/Program Files/Phidgets/Phidget22/x86/phidget22.lib}} #(for 32-bit systems)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====macOS Considerations====&lt;br /&gt;
Legacy Phidgets running a HID USB stack require a driver extension (macOS 10.15 and newer) or a kernel extension (macOS 10.14 and earlier). During development, we recommend downloading the appropriate [https://www.phidgets.com/docs/OS_-_macOS#Quick_Downloads package] which will install the extension. When deploying applications, review the README in the [https://cdn.phidgets.com/downloads/phidget22/libraries/macos/Phidget22_macosdevel.zip macOS Development Files] for information about bundling the extension with your application.&lt;br /&gt;
&lt;br /&gt;
=====Determining USB Stack=====&lt;br /&gt;
To determine which USB stack your device is running, navigate to the product page and then to the specification tab, and look for the &#039;&#039;USB Stack&#039;&#039; specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.&lt;br /&gt;
&lt;br /&gt;
[[Image:Javascript_networkserver_webusb_spec.png|center|600px|link=https://cdn.phidgets.com/docs/images/8/80/Javascript_networkserver_webusb_spec.png]]&lt;br /&gt;
&lt;br /&gt;
====Linux Considerations====&lt;br /&gt;
Linux restricts access to USB devices to the root user. &lt;br /&gt;
&lt;br /&gt;
To run your C application as a regular user, you&#039;ll need to [{{SERVER}}/docs/OS_-_Linux#Setting_udev_Rules set up udev rules] on your system.&lt;br /&gt;
&lt;br /&gt;
=== Library Files ===&lt;br /&gt;
If you would like to manually manage the Phidget22 library files, you can download them [https://cdn.phidgets.com/downloads/phidget22/libraries/windows/Phidget22-windevel.zip here].&lt;br /&gt;
&lt;br /&gt;
== Development Environment Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== GCC === &lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| &lt;br /&gt;
The most common tool for C development is GCC, whether used in the command line or through an IDE. GCC is packaged with many other IDEs and packages, so you may already have it installed.&lt;br /&gt;
&lt;br /&gt;
{{hiddenh4|Windows}}&lt;br /&gt;
We recommend installing [https://www.cygwin.com/ Cygwin] or [https://sourceforge.net/projects/mingw/ MinGW], ensuring you select all gcc packages when prompted by the installer.  &lt;br /&gt;
&lt;br /&gt;
To compile your code, go to the folder where your code is and open the command prompt by typing &#039;cmd&#039; in the address bar.&lt;br /&gt;
&lt;br /&gt;
The specific command you will use depends on your compiler of choice:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#Cygwin x86:&lt;br /&gt;
gcc example.c -o example -I&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22&amp;quot;-L&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22/x86&amp;quot; -lphidget22&lt;br /&gt;
&lt;br /&gt;
#Cygwin x64:&lt;br /&gt;
gcc example.c -o example -I&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets/Phidget22&amp;quot; -lphidget22&lt;br /&gt;
&lt;br /&gt;
#MinGW:&lt;br /&gt;
gcc example.c -o example -I&amp;quot;C:/Program Files/Phidgets/Phidget22&amp;quot; -L&amp;quot;C:/Program Files/Phidgets/Phidget22/x86&amp;quot; -lphidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After running the commands above for either Cygwin or MinGW, an executable file called example.exe will be created. Enter the following command to run the program:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{hiddenh4|MacOS}}&lt;br /&gt;
If you don&#039;t already have gcc installed, you can get it by installing [https://developer.apple.com/xcode/ Xcode].&lt;br /&gt;
&lt;br /&gt;
To compile the program, enter the following command in the terminal, substituting &amp;quot;example&amp;quot; for the name of your C file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gcc example.c -o example -F /Library/Frameworks -framework Phidget22 -I /Library/Frameworks/Phidget22.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Finally, run the program by entering the following command in the terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Success! The project is now running with Phidgets.&lt;br /&gt;
&lt;br /&gt;
{{hiddenh4|Linux}}&lt;br /&gt;
On Linux, gcc is installed through the package manager:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install gcc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To compile the program, enter the following command in the terminal, substituting &amp;quot;example&amp;quot; for the name of your C file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gcc example.c -o example -lphidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After compiling, you can run the program by entering the following command in the terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Success! The project is now running with Phidgets.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Visual Studio === &lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+ &#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
| If you want to jump right into a pre-configured project, you can download one on our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=C Code Sample Generator] page. || [[Image:Language_C_VSProject.jpg|center|link=https://cdn.phidgets.com/docs/images/f/f1/Language_C_VSProject.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| To configure a new project, follow these steps. ||&lt;br /&gt;
|-&lt;br /&gt;
| First, create a new Win32 Console Application: || [[Image:Language_C_VS_step1.jpg|center|link=https://cdn.phidgets.com/docs/images/a/a1/Language_C_VS_step1.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| If you are using a 64-bit machine, select x64, otherwise, select x86: || [[Image:Language_C_VS_step2.jpg|center|link=https://cdn.phidgets.com/docs/images/6/6b/Language_C_VS_step2.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Next, right click on the source folder and click New Item: || [[Image:Language_C_VS_step3.jpg|center|link=https://cdn.phidgets.com/docs/images/e/e1/Language_C_VS_step3.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Give the source file a name and click Add: || [[Image:Language_C_VS_step4.jpg|center|link=https://cdn.phidgets.com/docs/images/e/e5/Language_C_VS_step4.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Right click your project and access its properties: || [[Image:Language_C_VS_step5.jpg|center|link=https://cdn.phidgets.com/docs/images/1/1e/Language_C_VS_step5.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Go to Configuration Properties -&amp;gt; C/C++ -&amp;gt; General and add this to the additional include directories:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:\Program Files\Phidgets\Phidget22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|| [[Image:Language_C_VS_step6.jpg|center|link=https://cdn.phidgets.com/docs/images/d/d3/Language_C_VS_step6.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Go to Configuration Properties -&amp;gt; Linker -&amp;gt; Input and add the appropriate line to additional dependencies:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
C:\Program Files\Phidgets\Phidget22\phidget22.lib #(for 64-bit systems)&lt;br /&gt;
C:\Program Files\Phidgets\Phidget22\x86\phidget22.lib #(for 32-bit systems)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|| [[Image:Language_C_VS_step7.jpg|center|link=https://cdn.phidgets.com/docs/images/0/09/Language_C_VS_step7.jpg|350px]]&lt;br /&gt;
|-&lt;br /&gt;
| Lastly, include the Phidget library at the beginning of your program:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#include &amp;lt; phidget22.h &amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
||&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== PhidgetSBC Web Interface ===&lt;br /&gt;
{| style=&amp;quot;margin:auto;&amp;quot; class=&amp;quot;table-no-border mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
|+&#039;&#039;&#039;Instructions&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;center&amp;gt;{{#ev:youtube|2hTlVexctqY|rel=0}}&amp;lt;/center&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Example Code ==&lt;br /&gt;
Navigate to our [https://www.phidgets.com/?view=code_samples&amp;amp;lang=C Code Sample Generator] to view and download code samples that are tailored to your specific device.&lt;br /&gt;
&lt;br /&gt;
[[Image:Language_c_codesample2.png|center|600px|link=]]&lt;br /&gt;
&lt;br /&gt;
===Phidget Programming Basics===&lt;br /&gt;
{{PhidgetProgrammingBasicsLink}}&lt;br /&gt;
&lt;br /&gt;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=C Phidget22 API]&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Reading_an_I2C_Color_Sensor&amp;diff=35614</id>
		<title>Reading an I2C Color Sensor</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Reading_an_I2C_Color_Sensor&amp;diff=35614"/>
		<updated>2026-04-13T22:09:26Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: Created page with &amp;quot;&amp;lt;metadesc&amp;gt;A step-by-step example writing code to interface a sensor with the ADP0001.&amp;lt;/metadesc&amp;gt;  ==Introduction== &amp;lt;center&amp;gt;[https://www.phidgets.com/?prodid=1354 I2C Adapter Phidget (ADP0001_0)] The [https://www.phidgets.com/?prodid=1354 I2C Adapter Phidget] allows you to interface with a wide range of I2C-compatible devices, including sensors, displays, and more....&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;metadesc&amp;gt;A step-by-step example writing code to interface a sensor with the ADP0001.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
[[Image:ADP0001_0_169.jpg|link=https://cdn.phidgets.com/docs/images/f/f5/ADP0001_0_169.jpg|thumb| 450px|&amp;lt;center&amp;gt;[https://www.phidgets.com/?prodid=1354 I2C Adapter Phidget (ADP0001_0)]]]&lt;br /&gt;
The [https://www.phidgets.com/?prodid=1354 I2C Adapter Phidget] allows you to interface with a wide range of I2C-compatible devices, including sensors, displays, and more. &lt;br /&gt;
&lt;br /&gt;
In this project, we will use it to read data from an RGB Color Sensor.&lt;br /&gt;
&lt;br /&gt;
===Steps===&lt;br /&gt;
To complete this project, we will work through the following steps:&lt;br /&gt;
# Determine the device&#039;s basic configuration parameters&lt;br /&gt;
# Identify the sequence of commands expected by the device&lt;br /&gt;
# Connect the device to the I2C Adapter Phidget&lt;br /&gt;
# Test the device using the Phidget Control Panel&lt;br /&gt;
# Create a custom program.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
Information from the following resource will be referenced throughout this project.&lt;br /&gt;
* [https://cdn.phidgets.com/docs/images/1/13/TCS34725.pdf TCS34725 RGB Color Sensor IC Datasheet]&lt;br /&gt;
&lt;br /&gt;
==Demonstration==&lt;br /&gt;
&amp;lt;center&amp;gt;{{#ev:youtube|dYREkxXgjEA|rel=0}}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Configuration Parameters==&lt;br /&gt;
[[Image:Adp0002_rgb_specs2.png|link=https://cdn.phidgets.com/docs/images/0/05/Adp0002_rgb_specs2.png|thumb|&amp;lt;center&amp;gt;Excerpts from Datasheet&amp;lt;/center&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
During this step, we are looking for the following information:&lt;br /&gt;
* Supply Voltage&lt;br /&gt;
* Communication Frequency&lt;br /&gt;
* Device Address&lt;br /&gt;
&lt;br /&gt;
This information is typically found using the device&#039;s product page and/or datasheet. In this case, it was all found on pages 3 to 5 of the datasheet:&lt;br /&gt;
* Supply Voltage: 3.3V&lt;br /&gt;
* Communication Frequency: 400kHz&lt;br /&gt;
* I2C Address: 0x29&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear:both&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Sequence==&lt;br /&gt;
Next, we need to determine the sequence of commands the device is expecting. The TCS34725 datasheet provides a state diagram that we can use to create a list of actions:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_states.png|link=https://cdn.phidgets.com/docs/images/0/0e/Adp0002_rgb_states.png|200px|right|thumb|&amp;lt;center&amp;gt;From datasheet (page 7)&amp;lt;/center&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Based on the state diagram, our list of actions should look like this:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Power On Steps&#039;&#039;&#039;:&lt;br /&gt;
# Enable PON (power on) to go from sleep to idle state&lt;br /&gt;
# Enable AEN (RGB enabled) to go from idle to RGBC state&lt;br /&gt;
&lt;br /&gt;
After these steps, the device should be able to provide data and respond to commands. We&#039;re not using WEN (wait enabled) since we don&#039;t need this power-saving feature at this time.&lt;br /&gt;
&lt;br /&gt;
===Writing to TCS34725 Registers===&lt;br /&gt;
I2C devices typically expect the following format:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_an_typicalcomms3.png|link=https://cdn.phidgets.com/docs/images/2/29/Adp0002_an_typicalcomms3.png|600px]]&lt;br /&gt;
&lt;br /&gt;
This protocol diagram from page 12 of the datasheet confirms that the TCS34725 behaves as expected:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_protocol.png|link=https://cdn.phidgets.com/docs/images/3/38/Adp0002_rgb_protocol.png|700px]]&lt;br /&gt;
&lt;br /&gt;
The Start (S), Stop (P), Acknowledge (A), and W/R (Write/Read) is all handled internally by the I2C Phidget, so we just need to focus on the command code and data. &lt;br /&gt;
&lt;br /&gt;
==== Command Register ====&lt;br /&gt;
&lt;br /&gt;
The command register lets us tell the sensor which register we want to read or write on our next communication. &lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_cmdreg.png|link=https://cdn.phidgets.com/docs/images/0/0d/Adp0002_rgb_cmdreg.png|750px|center]]&lt;br /&gt;
&lt;br /&gt;
* The first bit is always &#039;1&#039;&lt;br /&gt;
* The next two bits control the how the device behaves when requesting multiple bytes&lt;br /&gt;
* The last five bits hold the register address (we can ignore the special functions for this project)&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an abridged list of registers we&#039;ll be using:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_registers.png|link=https://cdn.phidgets.com/docs/images/4/48/Adp0002_rgb_registers.png|600px|center]]&lt;br /&gt;
&lt;br /&gt;
===Power On Steps===&lt;br /&gt;
====Enable the Sensor====&lt;br /&gt;
Enable is managed by register &#039;&#039;&#039;0x00&#039;&#039;&#039;, so our command register will look like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_cmdenable.png|link=https://cdn.phidgets.com/docs/images/0/03/Adp0002_rgb_cmdenable.png|center|850px]]&lt;br /&gt;
&lt;br /&gt;
So we&#039;ll send &#039;&#039;&#039;0x80&#039;&#039;&#039; to select the enable register.&lt;br /&gt;
&lt;br /&gt;
The enable register is defined in the datasheet as follows:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_enablereg.png|link=https://cdn.phidgets.com/docs/images/8/89/Adp0002_rgb_enablereg.png|center|850px]]&lt;br /&gt;
&lt;br /&gt;
* Bits 5, 6, and 7 are &#039;&#039;&#039;000&#039;&#039;&#039;, as they&#039;re reserved&lt;br /&gt;
* Bit 4 will be &#039;&#039;&#039;0&#039;&#039;&#039;, since we&#039;re not using interrupts&lt;br /&gt;
* Bit 3 will be &#039;&#039;&#039;0&#039;&#039;&#039;, since we&#039;re not using the wait feature&lt;br /&gt;
* Bit 2 is &#039;&#039;&#039;0&#039;&#039;&#039;, as it&#039;s reserved&lt;br /&gt;
* Bit 1 will be &#039;&#039;&#039;0&#039;&#039;&#039;, since we&#039;re not enabling RGBC yet&lt;br /&gt;
* Bit 0 will be &#039;&#039;&#039;1&#039;&#039;&#039;, to enable power&lt;br /&gt;
&lt;br /&gt;
That gives us &#039;&#039;&#039;0x01&#039;&#039;&#039;. Together with our command register, our first communication will be &#039;&#039;&#039;0x8001&#039;&#039;&#039;.&lt;br /&gt;
The reason we don&#039;t enable RGBC yet is because the device requires a 2.4ms delay between PON and RGBC for reliable startup.&lt;br /&gt;
&lt;br /&gt;
====Enable RGBC====&lt;br /&gt;
&lt;br /&gt;
To enable RGBC we will use the same command we used for power on, but both the AEN bit and the PON bit will be 1. This gives us &#039;&#039;&#039;0x8003&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Reading Data ===&lt;br /&gt;
&lt;br /&gt;
Now that the sensor is initialized, we can start getting data from it. We want to read all eight color registers, so we need to set auto-increment in the command register and point it to the first color register which is at 0x14:&lt;br /&gt;
&lt;br /&gt;
[[Image:Adp0002_rgb_cmdreadauto.png|link=https://cdn.phidgets.com/docs/images/8/87/Adp0002_rgb_cmdreadauto.png|center|850px]]&lt;br /&gt;
&lt;br /&gt;
This means we need to send &#039;&#039;&#039;B4&#039;&#039;&#039;. After that, we can listen for 8 bytes at a time to get all of our color data.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the ADP0001 ==&lt;br /&gt;
&lt;br /&gt;
The pinout for this sensor is printed on the PCB:&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_rgb_pinout2.png|link=|130px|left]]&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;VIN&#039;&#039;&#039; - Power&lt;br /&gt;
*&#039;&#039;&#039;GND&#039;&#039;&#039; - Ground&lt;br /&gt;
*&#039;&#039;&#039;3V3&#039;&#039;&#039; - 3.3V Output &lt;br /&gt;
*&#039;&#039;&#039;SCL&#039;&#039;&#039; - Serial Clock&lt;br /&gt;
*&#039;&#039;&#039;SDA&#039;&#039;&#039; - Serial Data&lt;br /&gt;
*&#039;&#039;&#039;INT&#039;&#039;&#039; - Interrupt&lt;br /&gt;
*&#039;&#039;&#039;LED&#039;&#039;&#039; - LED toggle&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We don&#039;t need the 3.3V output or the interrupt pin for this project. The other pins can be connected to the ADP0001 as follows:&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_rgb_connection.png|800px|link=https://cdn.phidgets.com/docs/images/d/d9/I2C_rgb_connection.png]]&lt;br /&gt;
&lt;br /&gt;
The LED toggle pin is connected to one of the ADP0001&#039;s GPIO pins so we can use it to turn off the LED when not in use.&lt;br /&gt;
&lt;br /&gt;
==Testing in the Phidget Control Panel==&lt;br /&gt;
Now that we have the command sequence and our sensor connected, we can use the Phidget Control Panel to confirm our device is working as expected.&lt;br /&gt;
&lt;br /&gt;
===Power On Steps===&lt;br /&gt;
We can set the voltage to 3.3V, the frequency to 400kHz, and the address to 0x29.&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_RGB_ControlPanel.png|link=https://cdn.phidgets.com/docs/images/2/20/I2C_RGB_ControlPanel.png|center]]&lt;br /&gt;
&lt;br /&gt;
Now we can enable the sensor with our command sequence:&lt;br /&gt;
* 0x8001 (Power on)&lt;br /&gt;
* 0x8003 (RGBC on)&lt;br /&gt;
* 0xB4 (auto increment and start from register 0x14)&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_RGB_ControlPanel2.png|link=https://cdn.phidgets.com/docs/images/4/4f/I2C_RGB_ControlPanel2.png|center]]&lt;br /&gt;
&lt;br /&gt;
===Reading Data===&lt;br /&gt;
After sending the command register B4, we can read all color registers by reading 8 bytes at a time.&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_RGB_ControlPanel3.png|link=https://cdn.phidgets.com/docs/images/0/0a/I2C_RGB_ControlPanel3.png|center]]&lt;br /&gt;
[[Image:I2C_RGB_responsegraph.png|link=https://wwwdev.int.phidgets.com/docs/images/9/97/I2C_RGB_responsegraph.png|thumb|&amp;lt;center&amp;gt;Sensor response characteristic (pg.6)&amp;lt;center&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This sensor ultimately provides us with four 16-bit values: Clear, Red, Green, and Blue. The clear light value is important for providing brightness calibration. Since the responses of the red, green and blue sensors are normalized to match the response of the clear sensor, we can use it as a baseline to determine color in both bright and dim environments. &lt;br /&gt;
&lt;br /&gt;
In the above image, we get roughly the same value when polling the sensor three times, so the value seems stable. We&#039;ll use the bottom row to see if the color makes sense. The data bytes received are sent in register order, so our values are:&lt;br /&gt;
&lt;br /&gt;
* Clear: 0x0FFD&lt;br /&gt;
* Red: 0x0A96&lt;br /&gt;
* Green: 0x0331&lt;br /&gt;
* Blue: 0x0271&lt;br /&gt;
&lt;br /&gt;
Converting to decimal, that&#039;s 4093, 2710, 817, 625. We can normalize the last three values using the clear value, and then multiply by 255 and round to get a standard RGB value:&lt;br /&gt;
&lt;br /&gt;
* Red:   (2710/4093)*255 = 169&lt;br /&gt;
* Green: (817/4093)*255  = 51&lt;br /&gt;
* Blue:  (625/4093)*255  = 39&lt;br /&gt;
&lt;br /&gt;
This RGB value &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#A93327&amp;quot;&amp;gt;(#A93327)&amp;lt;/span&amp;gt;&#039;&#039;&#039; looks to be correct, as the sensor was pointed at a roll of red electrical tape. &lt;br /&gt;
&lt;br /&gt;
==Writing a Custom Program==&lt;br /&gt;
To begin writing a custom program for your Phidget device, navigate to the product page and select the [https://www.phidgets.com/?prodid=1354#Tab_Code_Samples Code Samples tab]. From there, you can customize the code for your own purposes. Here we have modified the Python code sample to match our steps from the Phidget Control Panel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidget22.Phidget import *&lt;br /&gt;
from Phidget22.Devices.DataAdapter import *&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
def convert_rgbc(data):&lt;br /&gt;
&lt;br /&gt;
	c = data[1] &amp;lt;&amp;lt; 8 | data[0]&lt;br /&gt;
&lt;br /&gt;
	if(c &amp;lt;= 0):&lt;br /&gt;
		return [0,0,0]&lt;br /&gt;
&lt;br /&gt;
	# Combine high and low bytes for each color,&lt;br /&gt;
	# Then normalize and cap at 255&lt;br /&gt;
	r = min(255,round((data[3] &amp;lt;&amp;lt; 8 | data[2]) / c * 255))&lt;br /&gt;
	g = min(255,round((data[5] &amp;lt;&amp;lt; 8 | data[4]) / c * 255))&lt;br /&gt;
	b = min(255,round((data[7] &amp;lt;&amp;lt; 8 | data[6]) / c * 255))&lt;br /&gt;
	return [r,g,b]&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
&lt;br /&gt;
	adp = DataAdapter()&lt;br /&gt;
	adp.openWaitForAttachment(5000)&lt;br /&gt;
&lt;br /&gt;
	# Set properties&lt;br /&gt;
	adp.setFrequency(DataAdapterFrequency.FREQUENCY_400kHz)&lt;br /&gt;
	adp.setDataAdapterVoltage(DataAdapterVoltage.DATAADAPTER_VOLTAGE_3_3V)&lt;br /&gt;
	addr = 0x29&lt;br /&gt;
&lt;br /&gt;
	# Power On&lt;br /&gt;
	adp.i2cSendReceive(addr, [0x8001], 0)&lt;br /&gt;
	time.sleep(0.01)&lt;br /&gt;
&lt;br /&gt;
	# RGBC On&lt;br /&gt;
	adp.i2cSendReceive(addr, [0x8003], 0)&lt;br /&gt;
&lt;br /&gt;
	# Auto-increment starting with CDATAL&lt;br /&gt;
	adp.i2cSendReceive(addr, [0xB4], 0)&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
		while True:&lt;br /&gt;
			rgb = convert_rgbc(adp.i2cSendReceive(addr, [], 8))&lt;br /&gt;
			print(&amp;quot;R: &amp;quot; + str(rgb[0]) + &amp;quot;   G: &amp;quot; + str(rgb[1]) + &amp;quot;   B: &amp;quot; + str(rgb[2]))&lt;br /&gt;
			time.sleep(0.5)&lt;br /&gt;
			pass&lt;br /&gt;
	except KeyboardInterrupt:&lt;br /&gt;
		print(&amp;quot;Closing...&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	adp.close()&lt;br /&gt;
&lt;br /&gt;
main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That’s about it, we went from reading the datasheet to a working script. Not all datasheets are created equal, so if you’re struggling with getting your sensor set up, feel free to ask for help by [https://www.phidgets.com/?view=contact sending us an email].&lt;br /&gt;
&lt;br /&gt;
===Python Graphical Example===&lt;br /&gt;
Here is a more in-depth script that displays a graph of the raw values and shows the calculated color after gamma and saturation adjustment. &lt;br /&gt;
&lt;br /&gt;
{{UGC-Start}}&lt;br /&gt;
{{UGC-Entry|Full Script (Click to expand)||&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
import tkinter as tk&lt;br /&gt;
import math&lt;br /&gt;
from Phidget22.Phidget import *&lt;br /&gt;
from Phidget22.Devices.DataAdapter import *&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
class MultiLineGraph(tk.Canvas):&lt;br /&gt;
    def __init__(self, parent, lines=4, max_points=100, **kwargs):&lt;br /&gt;
        super().__init__(parent, bg=&amp;quot;black&amp;quot;, **kwargs)&lt;br /&gt;
        self.lines = lines&lt;br /&gt;
        self.max_points = max_points&lt;br /&gt;
        self.data = [[] for _ in range(lines)]&lt;br /&gt;
        self.colors = [&amp;quot;white&amp;quot;, &amp;quot;red&amp;quot;, &amp;quot;green&amp;quot;, &amp;quot;blue&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    def add_points(self, *values):&lt;br /&gt;
        for i, v in enumerate(values):&lt;br /&gt;
            self.data[i].append(v)&lt;br /&gt;
            if len(self.data[i]) &amp;gt; self.max_points:&lt;br /&gt;
                self.data[i].pop(0)&lt;br /&gt;
        self.draw()&lt;br /&gt;
&lt;br /&gt;
    def draw(self):&lt;br /&gt;
        self.delete(&amp;quot;all&amp;quot;)&lt;br /&gt;
        w = self.winfo_width()&lt;br /&gt;
        h = self.winfo_height()&lt;br /&gt;
&lt;br /&gt;
        if w &amp;lt; 10 or h &amp;lt; 10:&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        # Flatten all visible data&lt;br /&gt;
        all_values = [v for line in self.data for v in line]&lt;br /&gt;
&lt;br /&gt;
        if not all_values:&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        min_val = min(all_values)&lt;br /&gt;
        max_val = max(all_values)&lt;br /&gt;
&lt;br /&gt;
        # Prevent divide-by-zero&lt;br /&gt;
        if max_val == min_val:&lt;br /&gt;
            max_val += 1&lt;br /&gt;
&lt;br /&gt;
        padding = (max_val - min_val) * 0.1  # 10% padding&lt;br /&gt;
        min_val -= padding&lt;br /&gt;
        max_val += padding&lt;br /&gt;
&lt;br /&gt;
        for i, line in enumerate(self.data):&lt;br /&gt;
            if len(line) &amp;lt; 2:&lt;br /&gt;
                continue&lt;br /&gt;
&lt;br /&gt;
            points = []&lt;br /&gt;
            for j, val in enumerate(line):&lt;br /&gt;
                x = j / (self.max_points - 1) * w&lt;br /&gt;
&lt;br /&gt;
                # Normalize to 0–1&lt;br /&gt;
                norm = (val - min_val) / (max_val - min_val)&lt;br /&gt;
&lt;br /&gt;
                # Flip Y (Tkinter origin is top-left)&lt;br /&gt;
                y = h - (norm * h)&lt;br /&gt;
&lt;br /&gt;
                points.extend([x, y])&lt;br /&gt;
&lt;br /&gt;
            self.create_line(points, fill=self.colors[i], width=2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class App:&lt;br /&gt;
    def __init__(self, root):&lt;br /&gt;
        self.root = root&lt;br /&gt;
        self.root.title(&amp;quot;I2C RGB Viewer&amp;quot;)&lt;br /&gt;
        self.adp = DataAdapter()&lt;br /&gt;
        self.addr = 0x29&lt;br /&gt;
        self.sat = 1.8&lt;br /&gt;
        self.gamma = 1.3&lt;br /&gt;
&lt;br /&gt;
        # --- Define Gamma Table ---&lt;br /&gt;
        self.gamma_table = [0] * 256&lt;br /&gt;
        for i in range(256):&lt;br /&gt;
            self.gamma_table[i] = int(math.pow(i/255.0,self.gamma)*255)&lt;br /&gt;
&lt;br /&gt;
        # --- UI ---&lt;br /&gt;
        self.graph = MultiLineGraph(root, height=300)&lt;br /&gt;
        self.graph.pack(fill=&amp;quot;both&amp;quot;, expand=True)&lt;br /&gt;
&lt;br /&gt;
        self.rgb_entry = tk.Entry(root, font=(&amp;quot;Consolas&amp;quot;, 14))&lt;br /&gt;
        self.rgb_entry.pack(fill=&amp;quot;x&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.color_panel = tk.Frame(root, height=50, bg=&amp;quot;black&amp;quot;)&lt;br /&gt;
        self.color_panel.pack(fill=&amp;quot;x&amp;quot;)&lt;br /&gt;
        &lt;br /&gt;
        self.adp.openWaitForAttachment(5000)&lt;br /&gt;
&lt;br /&gt;
        # Set properties&lt;br /&gt;
        self.adp.setFrequency(DataAdapterFrequency.FREQUENCY_400kHz)&lt;br /&gt;
        self.adp.setDataAdapterVoltage(DataAdapterVoltage.DATAADAPTER_VOLTAGE_3_3V)&lt;br /&gt;
&lt;br /&gt;
        # Power On&lt;br /&gt;
        self.adp.i2cSendReceive(self.addr, [0x8001], 0)&lt;br /&gt;
        time.sleep(0.01)&lt;br /&gt;
&lt;br /&gt;
        # RGBC On&lt;br /&gt;
        self.adp.i2cSendReceive(self.addr, [0x8003], 0)&lt;br /&gt;
&lt;br /&gt;
        # Auto-increment starting with CDATAL&lt;br /&gt;
        self.adp.i2cSendReceive(self.addr, [0xB4], 0)&lt;br /&gt;
&lt;br /&gt;
        # --- Timer ---&lt;br /&gt;
        self.update_loop()&lt;br /&gt;
&lt;br /&gt;
    def read_sensor(self):&lt;br /&gt;
        &lt;br /&gt;
        data = self.adp.i2cSendReceive(self.addr, [], 8)&lt;br /&gt;
&lt;br /&gt;
        # Combine high and low bytes for clear register&lt;br /&gt;
        raw_c = data[1] &amp;lt;&amp;lt; 8 | data[0]&lt;br /&gt;
&lt;br /&gt;
        if(raw_c &amp;lt;= 0):&lt;br /&gt;
            return [0,0,0,0]&lt;br /&gt;
&lt;br /&gt;
        # Combine high and low bytes for each colour&lt;br /&gt;
        raw_r = data[3] &amp;lt;&amp;lt; 8 | data[2]&lt;br /&gt;
        raw_g = data[5] &amp;lt;&amp;lt; 8 | data[4]&lt;br /&gt;
        raw_b = data[7] &amp;lt;&amp;lt; 8 | data[6]&lt;br /&gt;
&lt;br /&gt;
        return raw_c, raw_r, raw_g, raw_b&lt;br /&gt;
&lt;br /&gt;
    def update_loop(self):&lt;br /&gt;
        raw_c, raw_r, raw_g, raw_b = self.read_sensor()&lt;br /&gt;
&lt;br /&gt;
        if raw_c &amp;gt; 0:&lt;br /&gt;
            # Normalize + gamma&lt;br /&gt;
            norm_r = self.gamma_table[int(raw_r / raw_c * 255)]&lt;br /&gt;
            norm_g = self.gamma_table[int(raw_g / raw_c * 255)]&lt;br /&gt;
            norm_b = self.gamma_table[int(raw_b / raw_c * 255)]&lt;br /&gt;
&lt;br /&gt;
            avg = (norm_r + norm_g + norm_b) / 3&lt;br /&gt;
&lt;br /&gt;
            # Saturation adjust&lt;br /&gt;
            norm_r = max(0, min(255, avg + (norm_r - avg) * self.sat))&lt;br /&gt;
            norm_g = max(0, min(255, avg + (norm_g - avg) * self.sat))&lt;br /&gt;
            norm_b = max(0, min(255, avg + (norm_b - avg) * self.sat))&lt;br /&gt;
&lt;br /&gt;
            hex_color = &amp;quot;#{:02X}{:02X}{:02X}&amp;quot;.format(&lt;br /&gt;
                int(norm_r), int(norm_g), int(norm_b)&lt;br /&gt;
            )&lt;br /&gt;
&lt;br /&gt;
            self.rgb_entry.delete(0, tk.END)&lt;br /&gt;
            self.rgb_entry.insert(0, hex_color)&lt;br /&gt;
&lt;br /&gt;
            self.color_panel.config(bg=hex_color)&lt;br /&gt;
&lt;br /&gt;
        # Update graph&lt;br /&gt;
        self.graph.add_points(raw_c, raw_r, raw_g, raw_b)&lt;br /&gt;
&lt;br /&gt;
        # Repeat every 50 ms&lt;br /&gt;
        self.root.after(50, self.update_loop)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    root = tk.Tk()&lt;br /&gt;
    app = App(root)&lt;br /&gt;
    root.geometry(&amp;quot;600x400&amp;quot;)&lt;br /&gt;
    root.mainloop()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
{{UGC-End}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:TCS34725.pdf&amp;diff=35613</id>
		<title>File:TCS34725.pdf</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:TCS34725.pdf&amp;diff=35613"/>
		<updated>2026-04-13T22:09:02Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_responsegraph.png&amp;diff=35612</id>
		<title>File:I2C RGB responsegraph.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_responsegraph.png&amp;diff=35612"/>
		<updated>2026-04-13T22:03:48Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_ControlPanel3.png&amp;diff=35611</id>
		<title>File:I2C RGB ControlPanel3.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_ControlPanel3.png&amp;diff=35611"/>
		<updated>2026-04-13T22:03:36Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_ControlPanel2.png&amp;diff=35610</id>
		<title>File:I2C RGB ControlPanel2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_ControlPanel2.png&amp;diff=35610"/>
		<updated>2026-04-13T22:03:28Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_ControlPanel.png&amp;diff=35609</id>
		<title>File:I2C RGB ControlPanel.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_RGB_ControlPanel.png&amp;diff=35609"/>
		<updated>2026-04-13T22:03:14Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
</feed>