<?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-04-15T06:44:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<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>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:I2C_rgb_connection.png&amp;diff=35608</id>
		<title>File:I2C rgb connection.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_rgb_connection.png&amp;diff=35608"/>
		<updated>2026-04-13T22:02:15Z</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_pinout2.png&amp;diff=35607</id>
		<title>File:I2C rgb pinout2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_rgb_pinout2.png&amp;diff=35607"/>
		<updated>2026-04-13T22:02: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:Adp0002_rgb_cmdreadauto.png&amp;diff=35606</id>
		<title>File:Adp0002 rgb cmdreadauto.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_cmdreadauto.png&amp;diff=35606"/>
		<updated>2026-04-13T22:01:42Z</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:Adp0002_rgb_enablereg.png&amp;diff=35605</id>
		<title>File:Adp0002 rgb enablereg.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_enablereg.png&amp;diff=35605"/>
		<updated>2026-04-13T22:01:22Z</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:Adp0002_rgb_cmdenable.png&amp;diff=35604</id>
		<title>File:Adp0002 rgb cmdenable.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_cmdenable.png&amp;diff=35604"/>
		<updated>2026-04-13T22:00:59Z</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:Adp0002_rgb_registers.png&amp;diff=35603</id>
		<title>File:Adp0002 rgb registers.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_registers.png&amp;diff=35603"/>
		<updated>2026-04-13T22:00:35Z</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:Adp0002_rgb_cmdreg.png&amp;diff=35602</id>
		<title>File:Adp0002 rgb cmdreg.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_cmdreg.png&amp;diff=35602"/>
		<updated>2026-04-13T22:00:21Z</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:Adp0002_rgb_protocol.png&amp;diff=35601</id>
		<title>File:Adp0002 rgb protocol.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_protocol.png&amp;diff=35601"/>
		<updated>2026-04-13T21:59:53Z</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:Adp0002_rgb_states.png&amp;diff=35600</id>
		<title>File:Adp0002 rgb states.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_states.png&amp;diff=35600"/>
		<updated>2026-04-13T21:59: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:Adp0002_rgb_specs2.png&amp;diff=35599</id>
		<title>File:Adp0002 rgb specs2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Adp0002_rgb_specs2.png&amp;diff=35599"/>
		<updated>2026-04-13T21:59:22Z</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=I2C_Adapter_API_Guide&amp;diff=35592</id>
		<title>I2C Adapter API Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=I2C_Adapter_API_Guide&amp;diff=35592"/>
		<updated>2026-04-09T18:16:26Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: Created page with &amp;quot;{{#seo:|description=Get started with your I2C Adapter Phidget}} Category:IntroGuide &amp;lt;div class=&amp;quot;nonumtoc&amp;quot;&amp;gt; &amp;lt;div class=&amp;quot;toclimit-4&amp;quot;&amp;gt; == Introduction == This guide will provide additional details for the DataAdapter API so you can better understand what your I2C Adapter Phidget is doing when communicating with an I2C device.  == Address Format ==  The I2C Adapter Phidget interprets the device address as follows:  550px  The read/write bit i...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Get started with your I2C Adapter 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;
This guide will provide additional details for the DataAdapter API so you can better understand what your I2C Adapter Phidget is doing when communicating with an I2C device.&lt;br /&gt;
&lt;br /&gt;
== Address Format ==&lt;br /&gt;
&lt;br /&gt;
The I2C Adapter Phidget interprets the device address as follows:&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_Addr.png|link=|550px]]&lt;br /&gt;
&lt;br /&gt;
The read/write bit is not included in the hexadecimal value for the address, as this bit is handled by the API calls. &lt;br /&gt;
You may find that datasheets for some I2C devices include the read/write bit, so a read-only device like a simple temperature sensor might specify the address as &#039;&#039;&#039;0xE3&#039;&#039;&#039; instead of &#039;&#039;&#039;0x71&#039;&#039;&#039; in this case. When using such a sensor, be sure to ignore the R/W bit and shift the remaining seven bits down to get the address you need to send to Phidgets API calls.&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
=== I2CSendReceive() ===&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* int &#039;&#039;&#039;address&#039;&#039;&#039;&lt;br /&gt;
* byte[ ] &#039;&#039;&#039;data&#039;&#039;&#039;&lt;br /&gt;
* int &#039;&#039;&#039;receiveLength&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This is the main function you&#039;ll use for simple read and write operations. &lt;br /&gt;
&lt;br /&gt;
* The first parameter is the I2C address of your device, usually specified in the datasheet or printed on the circuit board. &lt;br /&gt;
* The second parameter is the data array, which can contain up to 127 bytes. If the data array is empty, the I2C Adapter Phidget will skip sending the write address and bytes. &lt;br /&gt;
* The third parameter is the receive length, or the number of bytes you&#039;re expecting back from the device for this transaction. Maximum receive length is 127, and if it&#039;s zero the I2C Adapter Phidget will skip sending the read address and bytes. &lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data structure when using {{Code|I2CSendReceive}}:&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_SendRecv.png|link=|850px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;S&#039;&#039;&#039;&#039; represents a start condition, while &#039;&#039;&#039;&#039;P&#039;&#039;&#039;&#039; represents a stop condition. If your I2C device requires data in a different structure than this, you may need to use {{Code|I2CComplexTransaction()}}, as explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== I2CComplexTransaction() ===&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* int &#039;&#039;&#039;address&#039;&#039;&#039;&lt;br /&gt;
* string &#039;&#039;&#039;I2CPacketString&#039;&#039;&#039;&lt;br /&gt;
* byte[ ] &#039;&#039;&#039;data&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This function gives you more control over the read/write structure for more complex interactions. This is useful for longer commands that make use of repeated start conditions.&lt;br /&gt;
&lt;br /&gt;
* The first parameter is the I2C address of your device, usually specified in the datasheet or printed on the circuit board. &lt;br /&gt;
* The second parameter is a string that dictates the read/write sequence to follow.&lt;br /&gt;
* The third parameter is the data array, whose length must match the number of writes in the string, up to 127 bytes.&lt;br /&gt;
&lt;br /&gt;
The string is made up of the following characters, case-sensitive with no spaces:&lt;br /&gt;
* &#039;&#039;&#039;&#039;s&#039;&#039;&#039;&#039; for a start condition&lt;br /&gt;
* &#039;&#039;&#039;&#039;R&#039;&#039;&#039;&#039; for a read byte&lt;br /&gt;
* &#039;&#039;&#039;&#039;T&#039;&#039;&#039;&#039; for a write byte&lt;br /&gt;
* &#039;&#039;&#039;&#039;p&#039;&#039;&#039;&#039; for a stop condition&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
[[Image:I2C_Complex.png|link=|850px]]&lt;br /&gt;
&lt;br /&gt;
Numerals can also be used after a &#039;T&#039; or &#039;R&#039; to make the string compact. In this example, the data array would need to have a length of 3, since a total of three bytes are written in the sequence.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:I2C_Complex.png&amp;diff=35591</id>
		<title>File:I2C Complex.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_Complex.png&amp;diff=35591"/>
		<updated>2026-04-09T18:16:19Z</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_SendRecv.png&amp;diff=35590</id>
		<title>File:I2C SendRecv.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_SendRecv.png&amp;diff=35590"/>
		<updated>2026-04-09T18:16:09Z</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_Addr.png&amp;diff=35589</id>
		<title>File:I2C Addr.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:I2C_Addr.png&amp;diff=35589"/>
		<updated>2026-04-09T18:15:58Z</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=Rotary_Motion_Guide&amp;diff=35588</id>
		<title>Rotary Motion Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Rotary_Motion_Guide&amp;diff=35588"/>
		<updated>2026-04-08T20:25:37Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Chain/Sprockets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{#seo:|description=Rotary systems involve rotating mechanical parts such as motors, sprockets, and pulleys. Learn the basics about rotary motion here.}}&lt;br /&gt;
{{#seo:|keywords=mechanical}}&lt;br /&gt;
[[Category:IntroGuide]]&lt;br /&gt;
==Introduction==&lt;br /&gt;
In rotary systems, you have a rotating shaft which applies torque to do work.  Typically this shaft is turned by an electric motor of some kind and then, through a series of belts/chains/couplers transmits that power to a final output shaft or arm or wheel which accomplishes the desired task.  Why not just use the output shaft of the motor directly?  There are two main reasons:&lt;br /&gt;
&lt;br /&gt;
*You might want to gear the motor down further to increase the torque available by using pulleys or sprockets of differing sizes.  &lt;br /&gt;
*The shaft on the motor itself isn&#039;t really designed for forces other than torque.  It is difficult to put anything of significant size on the shaft without putting too much overhung (radial) load on the shaft which will stall the motor.  &lt;br /&gt;
&lt;br /&gt;
As a result, the base of any rotary system is the rotating shaft.  We have 4 sizes of shaft available: 8mm, 12mm, 17mm, and 25mm.  The 12, 17, and 25mm shafts also have a variant available with a keyway machined in the length of the shaft if you don&#039;t want to machine it yourself.  These shafts need to be suspended on bearings, we do not sell any bearings currently but they are commonly available components that you can find locally.  For the larger shaft sizes (17 and 25mm) we recommend using steel bearing housings.  &lt;br /&gt;
&lt;br /&gt;
==Motors==&lt;br /&gt;
Every system will need a motor or else there will be no motion (without external input).  We offer a wide selection of motors of a number of different types that would all be suitable for rotary systems.  For more information on this you can check out our guides for [[DC Motor and Controller Guide|DC motors]] and [[Stepper Motor and Controller Guide|Stepper motors]].&lt;br /&gt;
&lt;br /&gt;
==Pulleys/Timing belts==&lt;br /&gt;
A belt is simply a loop of tough, flexible material such as rubber and kevlar with a series of teeth that mesh with the teeth on specially designed pulley wheels to synchronize two (or more) rotating shafts.  Belts are a cheap option for shafts that are not axially aligned and tend to run quietly and smoothly.  Belts are typically tensioned either by adjusting center to center distance between pulleys or via a tensioner/idler pulley.  This leads to very low backlash and a high efficiency (as high as 98%).  &lt;br /&gt;
&lt;br /&gt;
We have two types of belts available, GT2 (6mm wide) and GT5 (15mm wide).  Each comes in loops of varying circumferences.  The GT2 belts are rated for 6lbs of working tension while the GT5 are rated for 100lbs.  Belt systems are fairly simple, you have 2 or more pulleys and a belt that goes around all of them.  One of the pulleys is driven by your motor and the other(s) are either connected to your load or in the case of an idler pulley are simply free spinning to act as a tensioner for the belt.  For example, here is a system that uses a belt to transmit power form a stepper motor to a ball screw:&lt;br /&gt;
&lt;br /&gt;
[[image:Belt driven ball screw.JPG|500px|center|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Chain/Sprockets==&lt;br /&gt;
Pretty much everyone has at least seen a chain system in their life in the form of a bicycle.  This system of course is driven by human input rather than a motor.  Automated systems behave no differently though, you have several sprockets, and chain that wraps around them.  One sprocket is driven and the others perform work on the load.  Chain tends to be noisier than belts and cannot be tensioned as tightly meaning there is a bit more backlash inherent in the system.  In exchange though, chain can move much heavier loads for their size.  &lt;br /&gt;
&lt;br /&gt;
We sell ANSI#25 and #40 chain and sprockets (that is 0.25&amp;quot; pitch and 0.5&amp;quot; pitch).  The #25 is rated for 100lbs of working tension while the #40 is rated for 800lbs.  Chain is sold by the meter and you can form closed loops of any length you&#039;d like with the link kits that we sell.  &lt;br /&gt;
&lt;br /&gt;
There are two ways to connect chain, you can either use a hammer and a pin of some kind to knock out one of the pins which you can then connect up with an offset link:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The other way is if you have a chain breaker tool you can remove an entire link properly and can use a normal split link.  This process is a bit more tricky but it is stronger over all and will increase the length of the chain by a standard amount unlike the offset link which adds a sort of half link to your total length.  To use a split link you must remove the snap ring and the top plate, then slot it into the chain and replace them both.  For example:&lt;br /&gt;
[[image:Chain_link_insert_wiki.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A good example of a chain system is our MURVV robot.  Here is how it&#039;s drive mechanism works:&lt;br /&gt;
[[Image:Murvv_chain.jpg|link=|center|500px]]&lt;br /&gt;
&lt;br /&gt;
==Worm Gearboxes==&lt;br /&gt;
In general, worm gearboxes are just another type of gearbox that can be fitted to a motor.  The main benefit of a worm drive is that it is all but impossible to back drive even when not powered.  This is due to the steep angle used by the gears as they mesh together.  As a result, this type of gearbox is not the most efficient.  There is a lot of frictional loss at the mesh point and they will tend to run hot.  That being said, in the context of the worm drives we sell, they are a means to substantially increase the output torque of our larger motors for applications where maximum strength is required.  All our worm gearboxes have a 30:1 gear ratio and since the bearings built into the gearbox can handle much higher axial and radial loads that motors themselves you can easily direct drive very large loads from these gearboxes without having to set up an external mechanism.&lt;br /&gt;
&lt;br /&gt;
==Bearings==&lt;br /&gt;
For the smaller bearings, installation is fairly straight forward.  Simply mount the bearing onto your surface, slot the shaft in and tighten the set screws.  However, for our larger bearings (12mm, 17mm and 25mm) there is a different system used known as an eccentric locking collar or eccentric collar lock.  This is relatively simply to set up but you may not have seen this style of attachment before so lets have a look quickly at how it works and how to install it.&lt;br /&gt;
&lt;br /&gt;
The locking mechanism works by putting a slightly eccentric hole in the bearing and using a collar with a matching hole.  This way, when the collar is twisted on the shaft it will bind.  Step by step:&lt;br /&gt;
[[image:empty_bearing.jpg|center|500px|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice how the wall of the bore is thinner on the right side than the left.  This is also true of the collar which slides over the top of the shaft once it is in position.  Insert the shaft in the bearing unit to the desired position:&lt;br /&gt;
&lt;br /&gt;
[[image:uncollared_shaft.jpg|center|500px|link=]]&lt;br /&gt;
&lt;br /&gt;
Next, put the collar onto the shaft and slide it down to the bearing.  Turn the collar slowly until it seats on the lip of the bearing (i.e. the eccentricity of the holes lines up).  Now you will want to tighten the collar by hand by turning it like you would a threaded cap.  You will notice that it will bind by turning it in either direction within 180°.  Be sure to turn the collar in the same direction the primary direction of rotation for the shaft in operation will be.  Once the collar is tight, you will need to use a punch and a hammer to tighten it the last bit.  Find the dead hole in the collar (not the set screw) and insert your punch.  Angle the punch against the wall of the direction you have tightened the collar and give it a few solid taps with the hammer:&lt;br /&gt;
&lt;br /&gt;
[[image:punch_collar.jpg|center|500px|link=]]&lt;br /&gt;
&lt;br /&gt;
Now just tighten the set screw to ensure it doesn&#039;t loosen up with use and you are finished.  To quickly demonstrate here is a video, note that I do not tighten the set screw in this video but that is straight forward enough so it was left out:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{{#ev:youtube|0v6NOY7aRbg|||||rel=0}}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35587</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35587"/>
		<updated>2026-04-02T19:01:02Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* PhidgetSBC Web Interface */&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;
=== 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=Language_-_Java&amp;diff=35582</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35582"/>
		<updated>2026-04-01T20:05:59Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Deploying Applications */&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;
&lt;br /&gt;
We recommend installing the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system. Installing the drivers will put required .dll files in the proper place where Java will look for them. If you want to run your application on a computer without installing our drivers, see the [[#Deploying Applications|Deploying Applications]] section.&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;
=== 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;
|}&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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar &lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three 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;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35581</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35581"/>
		<updated>2026-04-01T20:02:15Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Eclipse */&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;
&lt;br /&gt;
We recommend installing the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system. Installing the drivers will put required .dll files in the proper place where Java will look for them. If you want to run your application on a computer without installing our drivers, see the [[#Deploying Applications|Deploying Applications]] section.&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;
=== 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;
|}&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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35580</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35580"/>
		<updated>2026-04-01T19:59:46Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Java Libraries */&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;
&lt;br /&gt;
We recommend installing the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system. Installing the drivers will put required .dll files in the proper place where Java will look for them. If you want to run your application on a computer without installing our drivers, see the [[#Deploying Applications|Deploying Applications]] section.&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 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;
=== 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;
|}&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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35579</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35579"/>
		<updated>2026-04-01T19:48:59Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Netbeans */&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;
&lt;br /&gt;
You must install the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system to be able to compile and run Java programs.&lt;br /&gt;
&lt;br /&gt;
Your Java project will also require our Java library file:&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]. &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 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;
=== 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;
|}&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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Windows_netbeans4.png&amp;diff=35578</id>
		<title>File:Windows netbeans4.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Windows_netbeans4.png&amp;diff=35578"/>
		<updated>2026-04-01T19:48: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=Language_-_Java&amp;diff=35577</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35577"/>
		<updated>2026-04-01T19:34:01Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Eclipse */&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;
&lt;br /&gt;
You must install the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system to be able to compile and run Java programs.&lt;br /&gt;
&lt;br /&gt;
Your Java project will also require our Java library file:&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]. &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. ||&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 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;
=== 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;
|}&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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_export2.png&amp;diff=35576</id>
		<title>File:Java eclipse export2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_export2.png&amp;diff=35576"/>
		<updated>2026-04-01T19:33: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_eclipse_export.png&amp;diff=35575</id>
		<title>File:Java eclipse export.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_export.png&amp;diff=35575"/>
		<updated>2026-04-01T19:25: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:Java_eclipse_newclass2.png&amp;diff=35574</id>
		<title>File:Java eclipse newclass2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_newclass2.png&amp;diff=35574"/>
		<updated>2026-04-01T16:13:45Z</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_eclipse_newclass.png&amp;diff=35573</id>
		<title>File:Java eclipse newclass.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_newclass.png&amp;diff=35573"/>
		<updated>2026-04-01T16:13: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:Java_eclipse_library.png&amp;diff=35572</id>
		<title>File:Java eclipse library.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_library.png&amp;diff=35572"/>
		<updated>2026-04-01T16:13: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_eclipse_newproj.png&amp;diff=35571</id>
		<title>File:Java eclipse newproj.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Java_eclipse_newproj.png&amp;diff=35571"/>
		<updated>2026-04-01T16:13: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>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35570</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35570"/>
		<updated>2026-03-31T22:21:57Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Javac */&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;
&lt;br /&gt;
You must install the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system to be able to compile and run Java programs.&lt;br /&gt;
&lt;br /&gt;
Your Java project will also require our Java library file:&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]. &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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. Be sure it&#039;s being added to the classpath and not the module path. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. Since this isn&#039;t a modular project, you must delete the {{code|module-info.java}} file that it creates. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35569</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35569"/>
		<updated>2026-03-31T22:20:50Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Javac */&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;
&lt;br /&gt;
You must install the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system to be able to compile and run Java programs.&lt;br /&gt;
&lt;br /&gt;
Your Java project will also require our Java library file:&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]. &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 a 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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. Be sure it&#039;s being added to the classpath and not the module path. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. Since this isn&#039;t a modular project, you must delete the {{code|module-info.java}} file that it creates. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35568</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35568"/>
		<updated>2026-03-31T15:18:28Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Visual Studio Code */&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;
&lt;br /&gt;
You must install the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system to be able to compile and run Java programs.&lt;br /&gt;
&lt;br /&gt;
Your Java project will also require our Java library file:&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]. &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;
|Once you are ready 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;
Finally, 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;
|}&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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. Be sure it&#039;s being added to the classpath and not the module path. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. Since this isn&#039;t a modular project, you must delete the {{code|module-info.java}} file that it creates. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_jar2.png&amp;diff=35567</id>
		<title>File:Language java vscode jar2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_jar2.png&amp;diff=35567"/>
		<updated>2026-03-31T15:16:45Z</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:Language_java_vscode_jar.png&amp;diff=35566</id>
		<title>File:Language java vscode jar.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_jar.png&amp;diff=35566"/>
		<updated>2026-03-31T15:16:29Z</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_-_Java&amp;diff=35565</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35565"/>
		<updated>2026-03-23T22:28:14Z</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;
&lt;br /&gt;
You must install the [https://www.phidgets.com/docs/Operating_System_Support Phidget drivers] for your operating system to be able to compile and run Java programs.&lt;br /&gt;
&lt;br /&gt;
Your Java project will also require our Java library file:&lt;br /&gt;
* [https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]. &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;
&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;
|Once you are ready 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;
Finally, 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;
|}&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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. Be sure it&#039;s being added to the classpath and not the module path. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. Since this isn&#039;t a modular project, you must delete the {{code|module-info.java}} file that it creates. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==API==&lt;br /&gt;
[{{SERVER}}/?view=api&amp;amp;lang=Python Phidget22 API]&lt;br /&gt;
&lt;br /&gt;
== Deploying Applications ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re planning to deploy your application, it should be noted that you don&#039;t strictly need the Phidget Drivers installed. &lt;br /&gt;
&lt;br /&gt;
At a minimum, these three files are required:&lt;br /&gt;
* phidget22.jar&lt;br /&gt;
* phidget22.dll&lt;br /&gt;
* phidget22java.dll&lt;br /&gt;
&lt;br /&gt;
All three files can be gathered from the installation directory on a computer that has our drivers installed (e.g. C:/Program Files/Phidgets/Phidget22). Java will look for these files in several locations, including the classpath and the working folder of the project.&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35564</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35564"/>
		<updated>2026-03-23T22:11:16Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Java Libraries */&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;
&lt;br /&gt;
===Source Files===&lt;br /&gt;
The Phidget22 Java library source files are available [https://cdn.phidgets.com/downloads/phidget22/libraries/windows/Phidget22-windevel.zip here].&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;
&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;
|Once you are ready 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;
Finally, 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;
|}&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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. Be sure it&#039;s being added to the classpath and not the module path. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. Since this isn&#039;t a modular project, you must delete the {{code|module-info.java}} file that it creates. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==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=Language_-_Java&amp;diff=35563</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35563"/>
		<updated>2026-03-23T22:04:48Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Eclipse */&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;
&lt;br /&gt;
===Source Files===&lt;br /&gt;
The Phidget22 Java library source files are available [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;
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;
&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;
|Once you are ready 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;
Finally, 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;
|}&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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. Be sure it&#039;s being added to the classpath and not the module path. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. Since this isn&#039;t a modular project, you must delete the {{code|module-info.java}} file that it creates. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==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=Language_-_Java&amp;diff=35562</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=35562"/>
		<updated>2026-03-23T19:18:12Z</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;
&lt;br /&gt;
===Source Files===&lt;br /&gt;
The Phidget22 Java library source files are available [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;
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;
&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;
|Once you are ready 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;
Finally, 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;
|}&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. ||&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;
|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 Eclipse and create a new Java project.|| [[Image:Windows_eclipse1.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/3/3a/Windows_eclipse1.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| On the Libraries tab, click Add External JARs and add phidget22.jar to your project as an external jar. || [[Image:Windows_eclipse2.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/0/0c/Windows_eclipse2.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Create a new Class in your project. || [[Image:Windows_eclipse3.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/d/d9/Windows_eclipse3.jpg]]&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. || [[Image:Windows_eclipse4.jpg|center|350px|link=https://cdn.phidgets.com/docs/images/8/87/Windows_eclipse4.jpg]]&lt;br /&gt;
|-&lt;br /&gt;
| Your project now has access to Phidgets! ||&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|gZmWvWXICIA|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=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;
==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:Language_java_vscode_extension2.png&amp;diff=35561</id>
		<title>File:Language java vscode extension2.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_extension2.png&amp;diff=35561"/>
		<updated>2026-03-23T19:14:54Z</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:Language_java_vscode_run.png&amp;diff=35560</id>
		<title>File:Language java vscode run.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_run.png&amp;diff=35560"/>
		<updated>2026-03-23T19:13:58Z</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:Language_java_vscode_emptyproj.png&amp;diff=35559</id>
		<title>File:Language java vscode emptyproj.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_emptyproj.png&amp;diff=35559"/>
		<updated>2026-03-23T19:13:47Z</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:Language_java_vscode_extension.png&amp;diff=35558</id>
		<title>File:Language java vscode extension.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_extension.png&amp;diff=35558"/>
		<updated>2026-03-23T19:13:12Z</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:Language_java_vscode_createproj.png&amp;diff=35557</id>
		<title>File:Language java vscode createproj.png</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=File:Language_java_vscode_createproj.png&amp;diff=35557"/>
		<updated>2026-03-23T19:11: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=Controlling_an_SPI_Encoder&amp;diff=35555</id>
		<title>Controlling an SPI Encoder</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Controlling_an_SPI_Encoder&amp;diff=35555"/>
		<updated>2026-03-19T19:58:49Z</updated>

		<summary type="html">&lt;p&gt;Mparadis: /* Full Script */&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 ADP0002.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:ADP0002_0.jpg|link=|thumb| 400px|&amp;lt;center&amp;gt;[https://www.phidgets.com/?prodid=1355 SPI Adapter Phidget (ADP0002_0)]]]&lt;br /&gt;
==Introduction==&lt;br /&gt;
The [https://www.phidgets.com/?prodid=1355 SPI Adapter Phidget] allows you to interface with a wide range of SPI-compatible devices, including sensors, displays, and more. &lt;br /&gt;
&lt;br /&gt;
In this project, we will use it to control an absolute position magnetic encoder. &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 SPI 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 datasheet will be referenced throughout this project:&lt;br /&gt;
* [https://ams-osram.com/products/boards-kits-accessories/boards/ams-as5048a-ts-evm-ab-evaluation-board Device Product Page]&lt;br /&gt;
* [https://cdn.phidgets.com/docs/images/f/fd/AS5048A.pdf AS5048A Encoder Datasheet]&lt;br /&gt;
&lt;br /&gt;
==Demonstration==&lt;br /&gt;
&amp;lt;center&amp;gt;{{#ev:youtube|-TkTykk1Ris|rel=0}}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional Information===&lt;br /&gt;
[[Image:Adp0002_magnet.png|link=https://cdn.phidgets.com/docs/images/2/2e/Adp0002_magnet.png|thumb]]&lt;br /&gt;
The encoder is designed to be used with a small magnet, magnetized with the poles on the edges of the cylinder instead of the top and bottom. The magnet can be attached to the exposed rear shaft of a motor, and this sensor can use the position of the magnetic field to determine the absolute position of the shaft.&lt;br /&gt;
&lt;br /&gt;
==Configuration Parameters==&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;
* Endianness (MSB-first or LSB-first)&lt;br /&gt;
* Chip Select Polarity&lt;br /&gt;
* SPI Wire Mode&lt;br /&gt;
&lt;br /&gt;
This information is typically found using the device&#039;s product page and/or any relevant datasheets. &lt;br /&gt;
Based on the AS5048A datasheet, we will use the following parameters:&lt;br /&gt;
* Supply Voltage: 3.3V or 5V (we&#039;ll use 5V)&lt;br /&gt;
* Communication Frequency: The clock period is 100ns minimum (10MHz maximum)&lt;br /&gt;
* Endianness: MSB-first&lt;br /&gt;
* Chip Select: Active Low&lt;br /&gt;
* SPI Wire Mode: Mode = 1&lt;br /&gt;
&lt;br /&gt;
==Command Sequence==&lt;br /&gt;
Next, we need to determine the sequence of commands the device is expecting. Some devices have certain commands that must be sent to configure the device, but this one is ready to provide sensor data as soon as it&#039;s powered up.&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_commandflow.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 11)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This diagram explains that each command we send will have its response delivered during the next transaction. Since our first goal is to get a stream of angle data from the encoder, we can just continuously send the Read Angle command. &lt;br /&gt;
&lt;br /&gt;
===Reading from AS5048A Registers===&lt;br /&gt;
&lt;br /&gt;
Commands sent to the encoder must follow the following format:&lt;br /&gt;
[[Image:SPI_command_package.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 14)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
This table tells us that the 16-bit command package consists of a parity bit, a read/write bit, and then a 14-bit register address. &lt;br /&gt;
&lt;br /&gt;
There are three data readout registers we can access. Here is the definition for the angle register:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_command_angle_readout.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 17)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The register address for the angle data is &#039;&#039;&#039;0x3FFF&#039;&#039;&#039;, but this is not the complete 16-bit value we need to transmit. First, we must add the R/W bit (Read=1) and then calculate the parity bit for even parity.&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_command_parity.png|link=|center|700px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;Calculating the parity bit&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This results in &#039;&#039;&#039;0xFFFF&#039;&#039;&#039;, which is the command we need to send with the SPI Phidget.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the ADP0002 ==&lt;br /&gt;
&lt;br /&gt;
The wiring for this sensor is very straightforward with the ADP0002:&lt;br /&gt;
[[Image:SPI_encoder_pinout.png|link=|120px|left]]&lt;br /&gt;
* &#039;&#039;&#039;5V&#039;&#039;&#039; - VCC&lt;br /&gt;
* &#039;&#039;&#039;3.3V&#039;&#039;&#039; - Not connected&lt;br /&gt;
* &#039;&#039;&#039;PWM&#039;&#039;&#039; - Not connected&lt;br /&gt;
* &#039;&#039;&#039;SDA/CSn&#039;&#039;&#039; - CS&lt;br /&gt;
* &#039;&#039;&#039;SCL/SCK&#039;&#039;&#039; - SCLK&lt;br /&gt;
* &#039;&#039;&#039;A1/MOSI&#039;&#039;&#039; - MOSI&lt;br /&gt;
* &#039;&#039;&#039;A2/MISO&#039;&#039;&#039; - MISO&lt;br /&gt;
* &#039;&#039;&#039;GND&#039;&#039;&#039; - GND&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_wiring_diagram.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Testing in the Phidget Control Panel ==&lt;br /&gt;
Now that we have the configuration parameters and the command sequence, we can use the Phidget Control Panel to confirm our device is working as expected.&lt;br /&gt;
&lt;br /&gt;
=== Reading the Angle ===&lt;br /&gt;
&lt;br /&gt;
==== Reading the Angle in the Control Panel ====&lt;br /&gt;
Set the voltage to 5V, the chip select to Active Low, the wire mode to Mode_1, and the frequency to any value as they are all within the stated range.&lt;br /&gt;
&lt;br /&gt;
We can try sending our &#039;&#039;&#039;0xFFFF&#039;&#039;&#039; command we calculated in the previous step:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_angle_send.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
The first response is an empty &#039;&#039;&#039;0x0000&#039;&#039;&#039;, because responses are always sent in the next transaction. After that, we start getting data back from the encoder. In order to decode these values, we must go back to the datasheet and pay attention to the read package format.&lt;br /&gt;
&lt;br /&gt;
==== Decoding the Read Data Package ====&lt;br /&gt;
[[Image:SPI_read_package.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 15)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar to the command package, it&#039;s made up of two control bits and one 14-bit value. The control bits are a parity bit to ensure communication fidelity, and an error flag that activates if there&#039;s a problem with the previous transaction. In this example we&#039;ll ignore these bits, but in an actual deployment you&#039;d want to be checking both of these bits on each transaction.&lt;br /&gt;
&lt;br /&gt;
So to decode the response for our angle command, &#039;&#039;&#039;0x9048&#039;&#039;&#039;, we need to strip the top two bits:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_decode_response.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
This leaves us with &#039;&#039;&#039;0x1048&#039;&#039;&#039;, or 4168 in decimal. The encoder has 14-bit precision, so the formula is as follows:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;\text{Angle(°)} = \frac{\text{n}}{2^{14}} \times 360 \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &#039;n&#039; is the response in decimal. Using this equation, our angle works out to &#039;&#039;&#039;91.58 degrees&#039;&#039;&#039;. When we eventually write our own program, we&#039;ll handle all of this bit manipulation and unit conversion in code.&lt;br /&gt;
&lt;br /&gt;
=== Zeroing the Encoder ===&lt;br /&gt;
&lt;br /&gt;
The advantage of an absolute encoder is that the actual angle of the shaft will be known as soon as the system is powered, without need for calibration or homing. This also means that the &amp;quot;home position&amp;quot; of our rotary system will be an arbitrary angle. We could zero this by keeping track of the initial angle in our program, but this chip has its own zeroing feature, so let&#039;s take a look.&lt;br /&gt;
&lt;br /&gt;
==== Zeroing Command Registers and Sequence ====&lt;br /&gt;
&lt;br /&gt;
We can find the zeroing process in the datasheet:&lt;br /&gt;
# Clear zero position registers by writing &#039;0&#039; into them&lt;br /&gt;
# Read the current angle&lt;br /&gt;
# Write the angle into the zero position registers&lt;br /&gt;
# (optional) Burn the value into the register so it persists across power cycles&lt;br /&gt;
&lt;br /&gt;
For now we&#039;ll only do the steps 2 and 3, since the zero position registers will already be zero on startup by default since we haven&#039;t burned a value into the register. In our final program we&#039;ll be using the zero as a sort of &#039;tare&#039; function so we will have to do the first step there. Here are the zero register definitions:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_zero_registers.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 17)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just as before, we need to add the proper control bits to these address values before we send them.&lt;br /&gt;
* Write to Zero Position Hi: 0x0016 -&amp;gt; &#039;&#039;&#039;0x8016&#039;&#039;&#039;&lt;br /&gt;
* Write to Zero Position Lo: 0x0017 -&amp;gt; &#039;&#039;&#039;0x0017&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For each of these registers, we&#039;ll follow this flow:&lt;br /&gt;
* Write to the zero position command&lt;br /&gt;
* Send the angle data&lt;br /&gt;
* Send a NOP (empty command) to confirm data sent&lt;br /&gt;
&lt;br /&gt;
==== Zeroing in the Control Panel ====&lt;br /&gt;
&lt;br /&gt;
In this example, our received data is &#039;&#039;&#039;0xBB99&#039;&#039;&#039;. Stripping the control bits, we get &#039;&#039;&#039;0x3B99&#039;&#039;&#039; or &#039;&#039;&#039;11 1011 1001 1001&#039;&#039;&#039; in binary. According to the zero register definitions, we need the 6 least significant bits in the low register, and the other 8 in the high register. This gives us:&lt;br /&gt;
&lt;br /&gt;
* LSB: &#039;&#039;&#039;0b011001&#039;&#039;&#039; &#039;&#039;&#039;(0x19)&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;0x8019&#039;&#039;&#039;&lt;br /&gt;
* MSB: &#039;&#039;&#039;0b11101110&#039;&#039;&#039; &#039;&#039;&#039;(0xEE)&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;0x00EE&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Again, since we need to set the write bits and proper parity, we end up with &#039;&#039;&#039;0x8019&#039;&#039;&#039; and &#039;&#039;&#039;0x00EE&#039;&#039;&#039;. Here&#039;s what the zeroing process looks like in the control panel (annotations added for clarity):&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_controlpanel_zero.png|link=|center|850px]]&lt;br /&gt;
&lt;br /&gt;
There are no error bits set in the responses, and each register we set echoed back the correct value when we wrote to it. The angle response we got after zeroing is &#039;&#039;&#039;0xBFF7&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Strip control bits -&amp;gt; 0x3FF7&lt;br /&gt;
* Convert to decimal -&amp;gt; 16375&lt;br /&gt;
* Angle formula -&amp;gt; 359.80°&lt;br /&gt;
&lt;br /&gt;
Since our new angle is close to 360° (the same as 0°), it looks like the zeroing process was successful.&lt;br /&gt;
&lt;br /&gt;
== Writing a Custom Python Script ==&lt;br /&gt;
&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 code sample to demonstrate a simple readout of the encoder angle:&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 hex2angle(hex):&lt;br /&gt;
	bytes = (hex[0] &amp;lt;&amp;lt; 8) | hex[1]      # Combine MSB and LSB&lt;br /&gt;
	bytes = bytes &amp;amp; 0b0011111111111111  # Discard top two bits (parity and error flag bits)&lt;br /&gt;
	angle = round(bytes / 16348*360,3)  # Divide by 2^14, multiply by 360 to get degrees&lt;br /&gt;
	return angle&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
	# Open ADP0002&lt;br /&gt;
	adp = DataAdapter()&lt;br /&gt;
	adp.openWaitForAttachment(5000)&lt;br /&gt;
&lt;br /&gt;
	# Set properties&lt;br /&gt;
	adp.setEndianness(DataAdapterEndianness.ENDIANNESS_MSB_FIRST)&lt;br /&gt;
	adp.setFrequency(DataAdapterFrequency.FREQUENCY_1500kHz)&lt;br /&gt;
	adp.setDataAdapterVoltage(DataAdapterVoltage.DATAADAPTER_VOLTAGE_5_0V)&lt;br /&gt;
	adp.setSPIChipSelect(DataAdapterSPIChipSelect.SPI_CHIP_SELECT_ACTIVE_LOW)&lt;br /&gt;
	adp.setSPIMode(DataAdapterSPIMode.SPI_MODE_1)&lt;br /&gt;
	time.sleep(0.5)&lt;br /&gt;
&lt;br /&gt;
	# Read and print angle until keyboard interrupt&lt;br /&gt;
	print(&amp;quot;Printing encoder data. Press CTRL+C to quit.&amp;quot;)&lt;br /&gt;
	try:&lt;br /&gt;
		while True:&lt;br /&gt;
			recvData = adp.sendPacketWaitResponse([0xFF,0xFF])&lt;br /&gt;
			print(f&amp;quot;\rEncoder Angle: {hex2angle(recvData)}    &amp;quot;,end=&amp;quot;&amp;quot;,flush=True)&lt;br /&gt;
			time.sleep(0.1)&lt;br /&gt;
&lt;br /&gt;
	except KeyboardInterrupt:&lt;br /&gt;
		pass&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;
===Full Script===&lt;br /&gt;
Here is the full Python script that was used in the demonstration video. It displays the encoder angle and also provides the option to zero the encoder.&lt;br /&gt;
&lt;br /&gt;
{{UGC-Entry|Full Script (Click to expand)||&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;
import threading&lt;br /&gt;
&lt;br /&gt;
# Register definitions from datasheet&lt;br /&gt;
ANGLE = [0x3F,0xFF]&lt;br /&gt;
MAGNITUDE = [0x3F,0xFE]&lt;br /&gt;
DIAGNOSTIC = [0x3F,0xFD]&lt;br /&gt;
CLEAR_ERR = [0x00,0x01]&lt;br /&gt;
NOP = [0x00,0x00]&lt;br /&gt;
ZERO_POS_HI = [0x00,0x16]&lt;br /&gt;
ZERO_POS_LO = [0x00,0x17]&lt;br /&gt;
READ = 1&lt;br /&gt;
WRITE = 0&lt;br /&gt;
&lt;br /&gt;
adp = DataAdapter()&lt;br /&gt;
&lt;br /&gt;
# Listener for keypress during main loop&lt;br /&gt;
running = True&lt;br /&gt;
def keyboard_listener():&lt;br /&gt;
    global running&lt;br /&gt;
    while running:&lt;br /&gt;
        cmd = input().strip().lower()&lt;br /&gt;
        if cmd == &amp;quot;z&amp;quot;:&lt;br /&gt;
            zero()&lt;br /&gt;
        elif cmd == &amp;quot;q&amp;quot;:&lt;br /&gt;
            running = False&lt;br /&gt;
&lt;br /&gt;
# Adds the required RW and parity bits&lt;br /&gt;
def addBits(packet,rw):&lt;br /&gt;
	bits = ((packet[0] &amp;lt;&amp;lt; 8) | packet[1]) &amp;amp; 0x3FFF&lt;br /&gt;
&lt;br /&gt;
	if(rw):&lt;br /&gt;
		bits = bits | 0b0100000000000000&lt;br /&gt;
	else:&lt;br /&gt;
		bits = bits &amp;amp; 0b1011111111111111&lt;br /&gt;
&lt;br /&gt;
	if(bits.bit_count()%2 == 0):&lt;br /&gt;
		bits = bits &amp;amp; 0b0111111111111111&lt;br /&gt;
	else:&lt;br /&gt;
		bits = bits | 0b1000000000000000&lt;br /&gt;
		&lt;br /&gt;
	res = [(bits &amp;gt;&amp;gt; 8)&amp;amp; 0xFF,(bits &amp;amp; 0xFF)]&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def zero():&lt;br /&gt;
	# Clear zero registers - this is needed to be able to zero more than once per run&lt;br /&gt;
	adp.sendPacket(addBits(ZERO_POS_HI,WRITE))&lt;br /&gt;
	adp.sendPacket(addBits([0x00,0x00],WRITE))&lt;br /&gt;
	adp.sendPacket(addBits(NOP,WRITE))&lt;br /&gt;
	adp.sendPacket(addBits(ZERO_POS_LO,WRITE))&lt;br /&gt;
	adp.sendPacket(addBits([0x00,0x00],WRITE))&lt;br /&gt;
	adp.sendPacket(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
	# Read current angle&lt;br /&gt;
	adp.sendPacket(addBits(ANGLE,READ))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
	# Combine angle bytes and mask out err/parity bits&lt;br /&gt;
	angle = ((resp[0] &amp;lt;&amp;lt; 8) | resp[1]) &amp;amp; 0x3FFF&lt;br /&gt;
&lt;br /&gt;
	# Split out angle for sending to zero registers&lt;br /&gt;
	zposm = (angle &amp;gt;&amp;gt; 6) &amp;amp; 0xFF &lt;br /&gt;
	zposl = angle &amp;amp; 0x3F&lt;br /&gt;
&lt;br /&gt;
	# write ZPOSM (0x0016)&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(ZERO_POS_HI,WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits([0x00,zposm],WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
    # write ZPOSL (0x0017)&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(ZERO_POS_LO,WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits([0x00,zposl],WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
def hex2angle(hex):&lt;br /&gt;
	bytes = (hex[0] &amp;lt;&amp;lt; 8) | hex[1]      # Combine MSB and LSB&lt;br /&gt;
	bytes = bytes &amp;amp; 0b0011111111111111  # Discard top two bits (parity and error flag bits)&lt;br /&gt;
	angle = round(bytes / 16348*360,3)  # Divide by 2^14, multiply by 360 to get degrees&lt;br /&gt;
	return angle&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
	# Open ADP0002&lt;br /&gt;
	adp.openWaitForAttachment(5000)&lt;br /&gt;
&lt;br /&gt;
	# Set properties&lt;br /&gt;
	adp.setEndianness(DataAdapterEndianness.ENDIANNESS_MSB_FIRST)&lt;br /&gt;
	adp.setFrequency(DataAdapterFrequency.FREQUENCY_1500kHz)&lt;br /&gt;
	adp.setDataAdapterVoltage(DataAdapterVoltage.DATAADAPTER_VOLTAGE_5_0V)&lt;br /&gt;
	adp.setSPIChipSelect(DataAdapterSPIChipSelect.SPI_CHIP_SELECT_ACTIVE_LOW)&lt;br /&gt;
	adp.setSPIMode(DataAdapterSPIMode.SPI_MODE_1)&lt;br /&gt;
	time.sleep(0.5)&lt;br /&gt;
&lt;br /&gt;
	# Start thread for keypress detection during the loop&lt;br /&gt;
	threading.Thread(target=keyboard_listener, daemon=True).start()&lt;br /&gt;
	print(&amp;quot;Printing encoder data. Press &#039;z&#039; to zero and &#039;q&#039; to quit.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	# Read and print angle until &#039;q&#039; pressed&lt;br /&gt;
	try:&lt;br /&gt;
		while running:&lt;br /&gt;
			recvData = adp.sendPacketWaitResponse(addBits(ANGLE,READ))&lt;br /&gt;
			print(f&amp;quot;\rEncoder Angle: {hex2angle(recvData)}    &amp;quot;,end=&amp;quot;&amp;quot;,flush=True)&lt;br /&gt;
			time.sleep(0.1)&lt;br /&gt;
&lt;br /&gt;
	except KeyboardInterrupt:&lt;br /&gt;
		pass&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;
{{UGC-End}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Controlling_an_SPI_Encoder&amp;diff=35554</id>
		<title>Controlling an SPI Encoder</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Controlling_an_SPI_Encoder&amp;diff=35554"/>
		<updated>2026-03-19T19:57:39Z</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 ADP0002.&amp;lt;/metadesc&amp;gt;  &amp;lt;center&amp;gt;[https://www.phidgets.com/?prodid=1355 SPI Adapter Phidget (ADP0002_0)] ==Introduction== The [https://www.phidgets.com/?prodid=1355 SPI Adapter Phidget] allows you to interface with a wide range of SPI-compatible devices, including sensors, displays, and more.   In this project, we will use it to control an absolute position...&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 ADP0002.&amp;lt;/metadesc&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:ADP0002_0.jpg|link=|thumb| 400px|&amp;lt;center&amp;gt;[https://www.phidgets.com/?prodid=1355 SPI Adapter Phidget (ADP0002_0)]]]&lt;br /&gt;
==Introduction==&lt;br /&gt;
The [https://www.phidgets.com/?prodid=1355 SPI Adapter Phidget] allows you to interface with a wide range of SPI-compatible devices, including sensors, displays, and more. &lt;br /&gt;
&lt;br /&gt;
In this project, we will use it to control an absolute position magnetic encoder. &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 SPI 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 datasheet will be referenced throughout this project:&lt;br /&gt;
* [https://ams-osram.com/products/boards-kits-accessories/boards/ams-as5048a-ts-evm-ab-evaluation-board Device Product Page]&lt;br /&gt;
* [https://cdn.phidgets.com/docs/images/f/fd/AS5048A.pdf AS5048A Encoder Datasheet]&lt;br /&gt;
&lt;br /&gt;
==Demonstration==&lt;br /&gt;
&amp;lt;center&amp;gt;{{#ev:youtube|-TkTykk1Ris|rel=0}}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional Information===&lt;br /&gt;
[[Image:Adp0002_magnet.png|link=https://cdn.phidgets.com/docs/images/2/2e/Adp0002_magnet.png|thumb]]&lt;br /&gt;
The encoder is designed to be used with a small magnet, magnetized with the poles on the edges of the cylinder instead of the top and bottom. The magnet can be attached to the exposed rear shaft of a motor, and this sensor can use the position of the magnetic field to determine the absolute position of the shaft.&lt;br /&gt;
&lt;br /&gt;
==Configuration Parameters==&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;
* Endianness (MSB-first or LSB-first)&lt;br /&gt;
* Chip Select Polarity&lt;br /&gt;
* SPI Wire Mode&lt;br /&gt;
&lt;br /&gt;
This information is typically found using the device&#039;s product page and/or any relevant datasheets. &lt;br /&gt;
Based on the AS5048A datasheet, we will use the following parameters:&lt;br /&gt;
* Supply Voltage: 3.3V or 5V (we&#039;ll use 5V)&lt;br /&gt;
* Communication Frequency: The clock period is 100ns minimum (10MHz maximum)&lt;br /&gt;
* Endianness: MSB-first&lt;br /&gt;
* Chip Select: Active Low&lt;br /&gt;
* SPI Wire Mode: Mode = 1&lt;br /&gt;
&lt;br /&gt;
==Command Sequence==&lt;br /&gt;
Next, we need to determine the sequence of commands the device is expecting. Some devices have certain commands that must be sent to configure the device, but this one is ready to provide sensor data as soon as it&#039;s powered up.&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_commandflow.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 11)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This diagram explains that each command we send will have its response delivered during the next transaction. Since our first goal is to get a stream of angle data from the encoder, we can just continuously send the Read Angle command. &lt;br /&gt;
&lt;br /&gt;
===Reading from AS5048A Registers===&lt;br /&gt;
&lt;br /&gt;
Commands sent to the encoder must follow the following format:&lt;br /&gt;
[[Image:SPI_command_package.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 14)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
This table tells us that the 16-bit command package consists of a parity bit, a read/write bit, and then a 14-bit register address. &lt;br /&gt;
&lt;br /&gt;
There are three data readout registers we can access. Here is the definition for the angle register:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_command_angle_readout.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 17)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The register address for the angle data is &#039;&#039;&#039;0x3FFF&#039;&#039;&#039;, but this is not the complete 16-bit value we need to transmit. First, we must add the R/W bit (Read=1) and then calculate the parity bit for even parity.&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_command_parity.png|link=|center|700px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;Calculating the parity bit&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This results in &#039;&#039;&#039;0xFFFF&#039;&#039;&#039;, which is the command we need to send with the SPI Phidget.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the ADP0002 ==&lt;br /&gt;
&lt;br /&gt;
The wiring for this sensor is very straightforward with the ADP0002:&lt;br /&gt;
[[Image:SPI_encoder_pinout.png|link=|120px|left]]&lt;br /&gt;
* &#039;&#039;&#039;5V&#039;&#039;&#039; - VCC&lt;br /&gt;
* &#039;&#039;&#039;3.3V&#039;&#039;&#039; - Not connected&lt;br /&gt;
* &#039;&#039;&#039;PWM&#039;&#039;&#039; - Not connected&lt;br /&gt;
* &#039;&#039;&#039;SDA/CSn&#039;&#039;&#039; - CS&lt;br /&gt;
* &#039;&#039;&#039;SCL/SCK&#039;&#039;&#039; - SCLK&lt;br /&gt;
* &#039;&#039;&#039;A1/MOSI&#039;&#039;&#039; - MOSI&lt;br /&gt;
* &#039;&#039;&#039;A2/MISO&#039;&#039;&#039; - MISO&lt;br /&gt;
* &#039;&#039;&#039;GND&#039;&#039;&#039; - GND&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_wiring_diagram.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Testing in the Phidget Control Panel ==&lt;br /&gt;
Now that we have the configuration parameters and the command sequence, we can use the Phidget Control Panel to confirm our device is working as expected.&lt;br /&gt;
&lt;br /&gt;
=== Reading the Angle ===&lt;br /&gt;
&lt;br /&gt;
==== Reading the Angle in the Control Panel ====&lt;br /&gt;
Set the voltage to 5V, the chip select to Active Low, the wire mode to Mode_1, and the frequency to any value as they are all within the stated range.&lt;br /&gt;
&lt;br /&gt;
We can try sending our &#039;&#039;&#039;0xFFFF&#039;&#039;&#039; command we calculated in the previous step:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_angle_send.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
The first response is an empty &#039;&#039;&#039;0x0000&#039;&#039;&#039;, because responses are always sent in the next transaction. After that, we start getting data back from the encoder. In order to decode these values, we must go back to the datasheet and pay attention to the read package format.&lt;br /&gt;
&lt;br /&gt;
==== Decoding the Read Data Package ====&lt;br /&gt;
[[Image:SPI_read_package.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 15)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar to the command package, it&#039;s made up of two control bits and one 14-bit value. The control bits are a parity bit to ensure communication fidelity, and an error flag that activates if there&#039;s a problem with the previous transaction. In this example we&#039;ll ignore these bits, but in an actual deployment you&#039;d want to be checking both of these bits on each transaction.&lt;br /&gt;
&lt;br /&gt;
So to decode the response for our angle command, &#039;&#039;&#039;0x9048&#039;&#039;&#039;, we need to strip the top two bits:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_decode_response.png|link=|center|800px]]&lt;br /&gt;
&lt;br /&gt;
This leaves us with &#039;&#039;&#039;0x1048&#039;&#039;&#039;, or 4168 in decimal. The encoder has 14-bit precision, so the formula is as follows:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;\text{Angle(°)} = \frac{\text{n}}{2^{14}} \times 360 \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &#039;n&#039; is the response in decimal. Using this equation, our angle works out to &#039;&#039;&#039;91.58 degrees&#039;&#039;&#039;. When we eventually write our own program, we&#039;ll handle all of this bit manipulation and unit conversion in code.&lt;br /&gt;
&lt;br /&gt;
=== Zeroing the Encoder ===&lt;br /&gt;
&lt;br /&gt;
The advantage of an absolute encoder is that the actual angle of the shaft will be known as soon as the system is powered, without need for calibration or homing. This also means that the &amp;quot;home position&amp;quot; of our rotary system will be an arbitrary angle. We could zero this by keeping track of the initial angle in our program, but this chip has its own zeroing feature, so let&#039;s take a look.&lt;br /&gt;
&lt;br /&gt;
==== Zeroing Command Registers and Sequence ====&lt;br /&gt;
&lt;br /&gt;
We can find the zeroing process in the datasheet:&lt;br /&gt;
# Clear zero position registers by writing &#039;0&#039; into them&lt;br /&gt;
# Read the current angle&lt;br /&gt;
# Write the angle into the zero position registers&lt;br /&gt;
# (optional) Burn the value into the register so it persists across power cycles&lt;br /&gt;
&lt;br /&gt;
For now we&#039;ll only do the steps 2 and 3, since the zero position registers will already be zero on startup by default since we haven&#039;t burned a value into the register. In our final program we&#039;ll be using the zero as a sort of &#039;tare&#039; function so we will have to do the first step there. Here are the zero register definitions:&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_zero_registers.png|link=|center|800px]]&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;AS5048A datasheet (page 17)&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just as before, we need to add the proper control bits to these address values before we send them.&lt;br /&gt;
* Write to Zero Position Hi: 0x0016 -&amp;gt; &#039;&#039;&#039;0x8016&#039;&#039;&#039;&lt;br /&gt;
* Write to Zero Position Lo: 0x0017 -&amp;gt; &#039;&#039;&#039;0x0017&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For each of these registers, we&#039;ll follow this flow:&lt;br /&gt;
* Write to the zero position command&lt;br /&gt;
* Send the angle data&lt;br /&gt;
* Send a NOP (empty command) to confirm data sent&lt;br /&gt;
&lt;br /&gt;
==== Zeroing in the Control Panel ====&lt;br /&gt;
&lt;br /&gt;
In this example, our received data is &#039;&#039;&#039;0xBB99&#039;&#039;&#039;. Stripping the control bits, we get &#039;&#039;&#039;0x3B99&#039;&#039;&#039; or &#039;&#039;&#039;11 1011 1001 1001&#039;&#039;&#039; in binary. According to the zero register definitions, we need the 6 least significant bits in the low register, and the other 8 in the high register. This gives us:&lt;br /&gt;
&lt;br /&gt;
* LSB: &#039;&#039;&#039;0b011001&#039;&#039;&#039; &#039;&#039;&#039;(0x19)&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;0x8019&#039;&#039;&#039;&lt;br /&gt;
* MSB: &#039;&#039;&#039;0b11101110&#039;&#039;&#039; &#039;&#039;&#039;(0xEE)&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;0x00EE&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Again, since we need to set the write bits and proper parity, we end up with &#039;&#039;&#039;0x8019&#039;&#039;&#039; and &#039;&#039;&#039;0x00EE&#039;&#039;&#039;. Here&#039;s what the zeroing process looks like in the control panel (annotations added for clarity):&lt;br /&gt;
&lt;br /&gt;
[[Image:SPI_controlpanel_zero.png|link=|center|850px]]&lt;br /&gt;
&lt;br /&gt;
There are no error bits set in the responses, and each register we set echoed back the correct value when we wrote to it. The angle response we got after zeroing is &#039;&#039;&#039;0xBFF7&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Strip control bits -&amp;gt; 0x3FF7&lt;br /&gt;
* Convert to decimal -&amp;gt; 16375&lt;br /&gt;
* Angle formula -&amp;gt; 359.80°&lt;br /&gt;
&lt;br /&gt;
Since our new angle is close to 360° (the same as 0°), it looks like the zeroing process was successful.&lt;br /&gt;
&lt;br /&gt;
== Writing a Custom Python Script ==&lt;br /&gt;
&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 code sample to demonstrate a simple readout of the encoder angle:&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 hex2angle(hex):&lt;br /&gt;
	bytes = (hex[0] &amp;lt;&amp;lt; 8) | hex[1]      # Combine MSB and LSB&lt;br /&gt;
	bytes = bytes &amp;amp; 0b0011111111111111  # Discard top two bits (parity and error flag bits)&lt;br /&gt;
	angle = round(bytes / 16348*360,3)  # Divide by 2^14, multiply by 360 to get degrees&lt;br /&gt;
	return angle&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
	# Open ADP0002&lt;br /&gt;
	adp = DataAdapter()&lt;br /&gt;
	adp.openWaitForAttachment(5000)&lt;br /&gt;
&lt;br /&gt;
	# Set properties&lt;br /&gt;
	adp.setEndianness(DataAdapterEndianness.ENDIANNESS_MSB_FIRST)&lt;br /&gt;
	adp.setFrequency(DataAdapterFrequency.FREQUENCY_1500kHz)&lt;br /&gt;
	adp.setDataAdapterVoltage(DataAdapterVoltage.DATAADAPTER_VOLTAGE_5_0V)&lt;br /&gt;
	adp.setSPIChipSelect(DataAdapterSPIChipSelect.SPI_CHIP_SELECT_ACTIVE_LOW)&lt;br /&gt;
	adp.setSPIMode(DataAdapterSPIMode.SPI_MODE_1)&lt;br /&gt;
	time.sleep(0.5)&lt;br /&gt;
&lt;br /&gt;
	# Read and print angle until keyboard interrupt&lt;br /&gt;
	print(&amp;quot;Printing encoder data. Press CTRL+C to quit.&amp;quot;)&lt;br /&gt;
	try:&lt;br /&gt;
		while True:&lt;br /&gt;
			recvData = adp.sendPacketWaitResponse([0xFF,0xFF])&lt;br /&gt;
			print(f&amp;quot;\rEncoder Angle: {hex2angle(recvData)}    &amp;quot;,end=&amp;quot;&amp;quot;,flush=True)&lt;br /&gt;
			time.sleep(0.1)&lt;br /&gt;
&lt;br /&gt;
	except KeyboardInterrupt:&lt;br /&gt;
		pass&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;
===Full Script===&lt;br /&gt;
Here is the full Python script that was used in the demonstration video. It displays the encoder angle and also provides the option to zero the encoder.&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;
from Phidget22.Phidget import *&lt;br /&gt;
from Phidget22.Devices.DataAdapter import *&lt;br /&gt;
import time&lt;br /&gt;
import threading&lt;br /&gt;
&lt;br /&gt;
# Register definitions from datasheet&lt;br /&gt;
ANGLE = [0x3F,0xFF]&lt;br /&gt;
MAGNITUDE = [0x3F,0xFE]&lt;br /&gt;
DIAGNOSTIC = [0x3F,0xFD]&lt;br /&gt;
CLEAR_ERR = [0x00,0x01]&lt;br /&gt;
NOP = [0x00,0x00]&lt;br /&gt;
ZERO_POS_HI = [0x00,0x16]&lt;br /&gt;
ZERO_POS_LO = [0x00,0x17]&lt;br /&gt;
READ = 1&lt;br /&gt;
WRITE = 0&lt;br /&gt;
&lt;br /&gt;
adp = DataAdapter()&lt;br /&gt;
&lt;br /&gt;
# Listener for keypress during main loop&lt;br /&gt;
running = True&lt;br /&gt;
def keyboard_listener():&lt;br /&gt;
    global running&lt;br /&gt;
    while running:&lt;br /&gt;
        cmd = input().strip().lower()&lt;br /&gt;
        if cmd == &amp;quot;z&amp;quot;:&lt;br /&gt;
            zero()&lt;br /&gt;
        elif cmd == &amp;quot;q&amp;quot;:&lt;br /&gt;
            running = False&lt;br /&gt;
&lt;br /&gt;
# Adds the required RW and parity bits&lt;br /&gt;
def addBits(packet,rw):&lt;br /&gt;
	bits = ((packet[0] &amp;lt;&amp;lt; 8) | packet[1]) &amp;amp; 0x3FFF&lt;br /&gt;
&lt;br /&gt;
	if(rw):&lt;br /&gt;
		bits = bits | 0b0100000000000000&lt;br /&gt;
	else:&lt;br /&gt;
		bits = bits &amp;amp; 0b1011111111111111&lt;br /&gt;
&lt;br /&gt;
	if(bits.bit_count()%2 == 0):&lt;br /&gt;
		bits = bits &amp;amp; 0b0111111111111111&lt;br /&gt;
	else:&lt;br /&gt;
		bits = bits | 0b1000000000000000&lt;br /&gt;
		&lt;br /&gt;
	res = [(bits &amp;gt;&amp;gt; 8)&amp;amp; 0xFF,(bits &amp;amp; 0xFF)]&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def zero():&lt;br /&gt;
	# Clear zero registers - this is needed to be able to zero more than once per run&lt;br /&gt;
	adp.sendPacket(addBits(ZERO_POS_HI,WRITE))&lt;br /&gt;
	adp.sendPacket(addBits([0x00,0x00],WRITE))&lt;br /&gt;
	adp.sendPacket(addBits(NOP,WRITE))&lt;br /&gt;
	adp.sendPacket(addBits(ZERO_POS_LO,WRITE))&lt;br /&gt;
	adp.sendPacket(addBits([0x00,0x00],WRITE))&lt;br /&gt;
	adp.sendPacket(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
	# Read current angle&lt;br /&gt;
	adp.sendPacket(addBits(ANGLE,READ))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
	# Combine angle bytes and mask out err/parity bits&lt;br /&gt;
	angle = ((resp[0] &amp;lt;&amp;lt; 8) | resp[1]) &amp;amp; 0x3FFF&lt;br /&gt;
&lt;br /&gt;
	# Split out angle for sending to zero registers&lt;br /&gt;
	zposm = (angle &amp;gt;&amp;gt; 6) &amp;amp; 0xFF &lt;br /&gt;
	zposl = angle &amp;amp; 0x3F&lt;br /&gt;
&lt;br /&gt;
	# write ZPOSM (0x0016)&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(ZERO_POS_HI,WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits([0x00,zposm],WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
    # write ZPOSL (0x0017)&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(ZERO_POS_LO,WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits([0x00,zposl],WRITE))&lt;br /&gt;
	resp = adp.sendPacketWaitResponse(addBits(NOP,WRITE))&lt;br /&gt;
&lt;br /&gt;
def hex2angle(hex):&lt;br /&gt;
	bytes = (hex[0] &amp;lt;&amp;lt; 8) | hex[1]      # Combine MSB and LSB&lt;br /&gt;
	bytes = bytes &amp;amp; 0b0011111111111111  # Discard top two bits (parity and error flag bits)&lt;br /&gt;
	angle = round(bytes / 16348*360,3)  # Divide by 2^14, multiply by 360 to get degrees&lt;br /&gt;
	return angle&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
	# Open ADP0002&lt;br /&gt;
	adp.openWaitForAttachment(5000)&lt;br /&gt;
&lt;br /&gt;
	# Set properties&lt;br /&gt;
	adp.setEndianness(DataAdapterEndianness.ENDIANNESS_MSB_FIRST)&lt;br /&gt;
	adp.setFrequency(DataAdapterFrequency.FREQUENCY_1500kHz)&lt;br /&gt;
	adp.setDataAdapterVoltage(DataAdapterVoltage.DATAADAPTER_VOLTAGE_5_0V)&lt;br /&gt;
	adp.setSPIChipSelect(DataAdapterSPIChipSelect.SPI_CHIP_SELECT_ACTIVE_LOW)&lt;br /&gt;
	adp.setSPIMode(DataAdapterSPIMode.SPI_MODE_1)&lt;br /&gt;
	time.sleep(0.5)&lt;br /&gt;
&lt;br /&gt;
	# Start thread for keypress detection during the loop&lt;br /&gt;
	threading.Thread(target=keyboard_listener, daemon=True).start()&lt;br /&gt;
	print(&amp;quot;Printing encoder data. Press &#039;z&#039; to zero and &#039;q&#039; to quit.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	# Read and print angle until &#039;q&#039; pressed&lt;br /&gt;
	try:&lt;br /&gt;
		while running:&lt;br /&gt;
			recvData = adp.sendPacketWaitResponse(addBits(ANGLE,READ))&lt;br /&gt;
			print(f&amp;quot;\rEncoder Angle: {hex2angle(recvData)}    &amp;quot;,end=&amp;quot;&amp;quot;,flush=True)&lt;br /&gt;
			time.sleep(0.1)&lt;br /&gt;
&lt;br /&gt;
	except KeyboardInterrupt:&lt;br /&gt;
		pass&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;
{{UGC-End}}&lt;/div&gt;</summary>
		<author><name>Mparadis</name></author>
	</entry>
</feed>