<?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=Cora</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=Cora"/>
	<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/Special:Contributions/Cora"/>
	<updated>2026-04-13T04:42:39Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Software_Overview&amp;diff=20734</id>
		<title>Software Overview</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Software_Overview&amp;diff=20734"/>
		<updated>2012-06-29T21:58:25Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Overview]]&lt;br /&gt;
__NOTOC__&lt;br /&gt;
Phidgets’ philosophy is that you do not have to be an electrical engineer in order to do projects that use devices like sensors, motors, motor controllers, and interface boards. All you need to know is how to program. &lt;br /&gt;
&lt;br /&gt;
We have developed a complete set of Application Programming Interfaces (API) that are supported for many different [[#Operating System Support|operating systems]], and which can be used through many different [[#Language Support | programming languages]].&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;5px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| We suggest starting with the &#039;&#039;&#039;Getting Started&#039;&#039;&#039; guide for your device, which can be found on its product page on [{{SERVER}} our main website].  This will help you run a basic example to check your hardware and drivers.  &lt;br /&gt;
|-&lt;br /&gt;
|Have you been there but want more introduction? We have overview pages - with lots of explanatory images - for some of our high-level topics:&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* [[What is a Phidget?]]&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* [[Phidget WebService]]&lt;br /&gt;
* [[Phidget Manager]]&lt;br /&gt;
* [[Phidget Dictionary]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After that, you&#039;ll need to dive right in and write code. &lt;br /&gt;
&lt;br /&gt;
From the Getting Started Guide, you&#039;ll have already chosen your [[#Operating System Support|operating system below]], and from the operating system page you&#039;ll be directed to [[#Language Support|choose a language]].&lt;br /&gt;
&lt;br /&gt;
So if you&#039;re here, you probably want:&lt;br /&gt;
* An overview of our language and operating system support (in which case, just scroll down)&lt;br /&gt;
* A quick link to our programming overview with lots of code snippets, called the &#039;&#039;&#039;[[General Phidget Programming|General Phidget Programming Guide]]&#039;&#039;&#039;&lt;br /&gt;
* The API with syntax and function calls for your device - which you can find on the [[#Language Support | page for your language]]&lt;br /&gt;
* Or, information about your product, which can be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
We try to make our documentation as complete as possible - which means there is a lot of it!  Browse around, try the search bar, and if you can&#039;t find what you need, please [[Contact Us]].&lt;br /&gt;
&lt;br /&gt;
== Operating System Support ==&lt;br /&gt;
&lt;br /&gt;
These operating system pages provide drivers for using Phidgets.  They help you set up your system after following the &#039;&#039;&#039;Getting Started&#039;&#039;&#039; guide for your device.  The operating systems links below are also on every &#039;&#039;Getting Started&#039;&#039; guide, so if you have not yet read the one for your device, head straight to the product page for your device on [{{SERVER}} our main website] where you can find it and follow it.&lt;br /&gt;
&lt;br /&gt;
Phidgets can be run either &#039;&#039;directly&#039;&#039; through USB or &#039;&#039;remotely&#039;&#039; over a network via the [[Phidget WebService]].  Most operating systems below can run Phidgets directly, but a few can only control them over a network.  Phidgets can also probably be run on other operating systems that have support for compiling C code, and either a standard network connection for running a Phidget over a network, or a USB host controller for direct control.  We don&#039;t offer support directly for these additional operating systems, but you may find the installation and setup instructions for [[OS - Linux|Linux]] useful because compiling and custom toolchains are discussed.&lt;br /&gt;
&lt;br /&gt;
Phidgets can run either directly or over a network on these operating systems:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;7px;&amp;quot;&lt;br /&gt;
|-style=&amp;quot;background: #f0f0f0&amp;quot; align=center &lt;br /&gt;
! Operating System || Drivers and Libraries || Direct Control || Remote Network Control || Supported Version&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Desktop OSes&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Windows.png|alt=OS - Windows|24x24px|link=OS - Windows]][[OS - Windows|Windows]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - Windows#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| 2000 or Newer&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Mac-OS.png|alt=OS - OS X|24x24px|link=OS - OS X]][[OS - OS X|OS X]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - OS X#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| OS X 10.4 or newer&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Linux.png|alt=OS - Linux|24x24px|link=OS - Linux]][[OS - Linux|Linux]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - Linux#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| Kernel 2.6 or newer&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Mobile/Wireless OSes&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Linux.png|alt=OS - Phidget SBC|24x24px|link=OS - Phidget SBC]][[OS - Phidget SBC|Phidget SBC]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - Phidget SBC#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| All versions&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Android_Honeycomb.png|alt=OS - Android|24x24px|link=OS - Android]][[OS - Android|Android]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - Android#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| 3.1 and newer, with USB port&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Android.png|alt=OS - Android|link=OS - Android|24x24px|link=OS - Android]][[OS - Android|Android]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - Android#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| 1.5 to 3.0&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-iOS.png|alt=OS - iOS|link=OS - iOS|24x24px|link=OS - iOS]][[OS - iOS|iOS]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - iOS#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| 3.0 or newer&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Windows CE.png|alt=OS - Windows CE|24x24px|link=OS - Windows CE]][[OS - Windows CE|Windows CE]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[OS - Windows CE#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
| 5.0 or newer&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Language Support ==&lt;br /&gt;
&lt;br /&gt;
We provide a variety of supported languages for using Phidgets.  Each language has its own &#039;&#039;libraries&#039;&#039;, which may be found on the language pages below, along with code examples and an in-depth API. &lt;br /&gt;
&lt;br /&gt;
Many languages also depend on the &#039;&#039;core drivers&#039;&#039; being installed as well.  These drivers can be found on the [[#Operating System Support|operating system pages]] above.&lt;br /&gt;
&lt;br /&gt;
Phidgets supports the following languages.  If you have some flexibility in what language to use, we recommend using a &#039;&#039;&#039;Core Language&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;7px;&amp;quot;&lt;br /&gt;
|-style=&amp;quot;background: #f0f0f0&amp;quot; align=center &lt;br /&gt;
! Language || Libraries || API || Code Samples&amp;lt;sup&amp;gt;&amp;amp;dagger;&amp;lt;/sup&amp;gt; || [[General Phidget Programming#Event Driven Code|Events]] || [[General Phidget Programming#Logic Code|Logic Code]] || Use via Direct USB* || [[Phidget WebService]] || Native Library** || Phidget User Base&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Core Languages&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-CSharp.png|alt=C Sharp|24x24px|link=Language - C Sharp]] [[Language - C Sharp|C#]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - C Sharp#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-C++.png|alt=C/C++|24x24px|link=Language - C/C++]] [[Language - C/C++|C/C++]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - C/C++#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Java.png|alt=Java|24x24px|link=Language - Java]] [[Language - Java|Java]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Java#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Python.png|alt=Python|24x24px|link=Language - Python]] [[Language - Python|Python]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Python#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Cocoa.png|alt=Cocoa|24x24px|link=Language - Cocoa]] [[Language - Cocoa|Cocoa]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Cocoa#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Visual Basic.png|alt=Visual Basic 6.0|24x24px|link=Language - Visual Basic 6.0]] [[Language - Visual Basic 6.0|Visual Basic 6.0]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Visual Basic 6.0#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Visual Basic Net.png|alt=Visual Basic .NET|24x24px|link=Language - Visual Basic .NET]] [[Language - Visual Basic .NET|Visual Basic .NET]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Visual Basic .NET#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Mobile Languages&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-iOS.png|alt=iOS|24x24px|link=Language - iOS]] [[Language - iOS|iOS]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - iOS#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #EFE973&amp;quot; align=center| InterfaceKit Only&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-06.png|link=|alt=Moderate]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Android.png|alt=Android Java|24x24px|link=Language - Android Java]] [[Language - Android Java|Android Java]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Android Java#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #EFE973&amp;quot; align=center| InterfaceKit Only&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices [[Image:Icon-Android_Honeycomb.png|24px|link=Software_Overview#Honeycomb|alt=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-06.png|link=|alt=Moderate]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Scripting&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Applescript.png|alt=Applescript|24x24px|link=Language - Applescript]] [[Language - Applescript|Applescript]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Applescript#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-06.png|link=|alt=Moderate]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Autoit.png|alt=AutoIt|24x24px|link=Language - AutoIt]] [[Language - AutoIt|AutoIt]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - AutoIt#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| None&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Ruby.png|alt=Ruby|24x24px|link=Language - Ruby]] [[Language - Ruby|Ruby]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Ruby#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Science and Math&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-LabVIEW.png|alt=LabVIEW|24x24px|link=Language - LabVIEW]] [[Language - LabVIEW|LabVIEW]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - LabVIEW#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-06.png|link=|alt=Moderate]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Matlab.png|alt=MATLAB|24x24px|link=Language - MATLAB]] [[Language - MATLAB|MATLAB]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - MATLAB#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-06.png|link=|alt=Moderate]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Simulink.png|alt=Simulink|24x24px|link=Language - Simulink]] [[Language - Simulink|Simulink]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Simulink#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #EFE973&amp;quot; align=center| InterfaceKit Only&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Multimedia&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Adobe Director.png|alt=Adobe Director|24x24px|link=Language - Adobe Director]] [[Language - Adobe Director|Adobe Director]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Adobe Director#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| InterfaceKit Only&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Flash AS3.png|alt=Flash AS3|24x24px|link=Language - Flash AS3]] [[Language - Flash AS3|Flash AS3]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Flash AS3#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-10.png|link=|alt=Extensive]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-LiveCode.png|alt=LiveCode|24x24px|link=Language - LiveCode]] [[Language - LiveCode|LiveCode]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - LiveCode#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #EFE973&amp;quot; align=center| InterfaceKit Only &lt;br /&gt;
|style=&amp;quot;background: #EFE973&amp;quot; align=center| InterfaceKit Only&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #E28585&amp;quot; align=center| X&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-MaxMSP.png|24x24px|alt=Max/MSP|link=Language - Max/MSP]] [[Language - Max/MSP|Max/MSP]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Max/MSP#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-06.png|link=|alt=Moderate]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;Other Languages&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-CSharp.png|24x24px|alt=C Sharp (.NET Compact Framework)|link=Language - C Sharp (.NET Compact Framework)]] [[Language - C Sharp (.NET Compact Framework)|C# (.NET Compact)]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - C Sharp (.NET Compact Framework)#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Visual Basic Net.png|24x24px|alt=Visual Basic (.NET Compact Framework)|link=Visual Basic (.NET Compact Framework)]] [[Language - Visual Basic (.NET Compact Framework)|Visual Basic&amp;lt;br&amp;gt; (.NET Compact Framework)]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Visual Basic (.NET Compact Framework)#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Visual Basic for Applications.png|alt=Visual Basic for Applications|24x24px|link=Language - Visual Basic for Applications]] [[Language - Visual Basic for Applications|Visual Basic for Apps]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Visual Basic for Applications#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Visual Basic Script.png|alt=Visual Basic Script|24x24px|link=Language - Visual Basic Script]] [[Language - Visual Basic Script|Visual Basic Script]]&lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Visual Basic Script#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Delphi.png|alt=Delphi|24x24px|link=Language - Delphi]] [[Language - Delphi|Delphi]] &lt;br /&gt;
|style=&amp;quot;background: #f0f0ff&amp;quot; align=center| [[Language - Delphi#Quick Downloads|Quick Downloads]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| All Devices &lt;br /&gt;
|style=&amp;quot;background: #FFC17F&amp;quot; align=center| Some Devices&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #ade6ab&amp;quot; align=center| [[Image:Level-01.png|link=|alt=Small]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; A direct USB connection would be plugging the Phidget into a USB port and using it locally.  This is the typical way to use a Phidget.  However, some platforms (such as the iPhone platform) do not have USB ports and hence can only use a Phidget over a network, via the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; Native library support means that the calls you make to a Phidget in this language are in the language as well.  If the calls are non-native, the use of Phidgets is through an external library linker, such as callib() in MATLAB, for example.  The core Phidget library is written in C, and most other languages use this library as their core, but a &#039;Native&#039; interface cleanly hides this detail.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;&amp;amp;dagger;&amp;lt;/sup&amp;gt; Most languages have code samples for all Phidgets, but some have only some devices (visit the language page to learn which ones), and some only have an Interface Kit example. The Phidget Interface Kit is a common Phidget with provides an interface with analog sensors, digital input, and digital output.  So, when we choose which examples to write, the Interface Kit is often at the top of our customer&#039;s lists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Honeycomb&amp;quot;&amp;gt;[[Image:Icon-Android_Honeycomb.png|24px|link=]]&amp;lt;/span&amp;gt;Android Honeycomb Version 3.1 or Higher Only&lt;br /&gt;
&lt;br /&gt;
==Third Party Support==&lt;br /&gt;
&lt;br /&gt;
{{GentleAlert|&#039;&#039;&#039;These products must be purchased directly from these companies and all support calls must be directed to them&#039;&#039;&#039;}}&lt;br /&gt;
&lt;br /&gt;
Some third party companies also offer and support software programs that work with Phidgets boards. Phidgets does not have a certification program and does not make any warranty about these products.&lt;br /&gt;
&lt;br /&gt;
In alphabetical order:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;7px;&amp;quot;&lt;br /&gt;
|-style=&amp;quot;background: #f0f0f0&amp;quot; align=center &lt;br /&gt;
! Company &lt;br /&gt;
! Product&lt;br /&gt;
! Runs On&lt;br /&gt;
! Website&lt;br /&gt;
! style=&amp;quot;width:50%;&amp;quot; | Synopsis&lt;br /&gt;
! Product Information&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;24U&#039;&#039;&#039;&lt;br /&gt;
|24U Phidgets Plug-in 1.0&lt;br /&gt;
|Mac, Windows&lt;br /&gt;
|[http://www.24usoftware.com/plugins.php Website]&lt;br /&gt;
|24U Phidgets Plug-In lets you connect different kind of phidgets (www.phidgets.com) to your computer&#039;s USB port and interact with them directly from FileMaker Pro.&lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/24U.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;DSPRobotics&#039;&#039;&#039;&lt;br /&gt;
|Flowstone &lt;br /&gt;
|Windows 2000/XP/Vista/7/Embedded&lt;br /&gt;
|[http://www.dsprobotics.com/ Website]&lt;br /&gt;
|Graphical Programming Language aimed at real-time Digital Signal Processing.(DSP), Robotics and Embedded applications. FlowStone is a drag and drop environment where you combine high-level and low-level modules to build real time applications.&lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/FlowStone.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;MANIPIL&#039;&#039;&#039;&lt;br /&gt;
|Visual Domotique&lt;br /&gt;
|Windows XP/Vista/7&lt;br /&gt;
|[http://www.manipil.ch/cms1/vd/tutoriels/setup-and-to-use-a-phidget-module.html Website]&lt;br /&gt;
|Visual Domotique is a Graphical I/O programming for Windows XP/Vista/7. Various components allow you to draw electrical schema and control panel. No need to know how to program to use this software. Varied uses are possible: Home automation, security, hobby, Control process education... Available in French. &lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/Manipil_en.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;PCRBOX&#039;&#039;&#039;&lt;br /&gt;
|PCR Automation&lt;br /&gt;
|Windows XP/Vista/7 (32 &amp;amp; 64bit)&lt;br /&gt;
|[http://www.pcrbox.com/en/ Website]&lt;br /&gt;
|PCR Automation is an easy to use software that works immediately without the need for any programming. It interfaces with the 1018, 1070 and 1072. Several interfaces can be opened simultaneously, each in a different window. Each input / output can be customized (label, sensor, offset, units, sensitivity, recording ...). The log files can be automatically sent by E-mail. Users can add their own sensors to the library of thirty Phidgets sensors.&lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/pcr-automation-en.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;PiXCL Automation Technologies&#039;&#039;&#039;&lt;br /&gt;
|PiXCL Advanced Imaging 10.2&lt;br /&gt;
|Windows XP/Vista/7&lt;br /&gt;
|[http://www.pixcl.com/Using_Phidgets_with_PiXCL.htm Website]&lt;br /&gt;
|PiXCL is a powerful and easy-to-learn event driven interpreted language for the fast creation of image acquisition, processing and advanced analysis applications. The suite includes a compiler and development studio with context sensitive help and plenty of sample code. V10.1 provides you with the tools to create applications that combine Phidget devices with digital cameras and scanners.&lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/PiXCL.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;SoapBox Automation&#039;&#039;&#039;&lt;br /&gt;
|SoapBox Snap&lt;br /&gt;
|Windows XP/Vista/7&lt;br /&gt;
|[http://soapboxautomation.com/products/soapbox-snap/ Website]&lt;br /&gt;
|SoapBox Snap is a free and open source PC-based automation platform. It includes a ladder logic editor and a “soft” runtime right out of the box.&lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/SoapBox.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|&#039;&#039;&#039;UACh - Universida Austral de Chile&#039;&#039;&#039;&lt;br /&gt;
|monoBOTICS-icarus&lt;br /&gt;
|Linux&lt;br /&gt;
|[http://www.monobotics.ic.uach.cl/ Website]&lt;br /&gt;
|The monoBOTICS project aims to become an OpenSource Framework, to facilitate the tasks of design, simulation and implementation of solutions for areas of Robotics and Automation, both for people with basic knowledge of programming, as for more advanced developers.&lt;br /&gt;
|[[Image:Pdficon_small.gif|link={{SERVER}}/documentation/ThirdPartyInfo/ThirdPartySoftware/monoBOTICS.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Legacy Languages==&lt;br /&gt;
&lt;br /&gt;
Legacy languages are languages which we supported in the past; however, we no longer actively develop or support them.  We provide this software page information for the limited existing users:  &lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;7px;&amp;quot;&lt;br /&gt;
|-style=&amp;quot;background: #f0f0f0&amp;quot; align=center &lt;br /&gt;
! Language&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|[[Image:Icon-REALBasic.png|alt=REALBasic|24x24px|link=Language - REALBasic]] [[Language - REALBasic|REALBasic]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Flex AS3.png|alt=Flex AS3|24x24px|link=Language - Flex AS3]] [[Language - Flex AS3|Flex AS3]] &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|[[Image:Icon-Robot Studio.png|alt=Robotics Studio|24x24px|link=Language - Microsoft Robotics Studio]] [[Language - Microsoft Robotics Studio|Microsoft Robotics Studio]] &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you have an existing code base in these languages and the legacy status of these languages is a serious inconvenience, please [[Contact Us]].&lt;br /&gt;
&lt;br /&gt;
{{CreativeCommons}}&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20733</id>
		<title>Solid State Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20733"/>
		<updated>2012-06-29T21:55:43Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:SSR.jpg]]&lt;br /&gt;
| [[Image:3052.jpg|200px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR, so named because of its thick shape and black color. They are specifically designed to switch either AC loads or DC loads, but never both.]]&lt;br /&gt;
&lt;br /&gt;
Solid state relays (SSRs) turn on or off the power being supplied to other devices, in a similar fashion as a physical [[Switch Primer|switch]]. However, instead of being switched by human interaction like a physical switch, SSRs are switched electronically.&lt;br /&gt;
With SSRs, you can control high-current devices such as lights or appliances with low-current signals, like a standard DC signal from a [[Digital Output Primer|Digital Output]]. Most SSRs will switch on with a voltage of 3V or higher. This makes them perfect for use with Phidget [[Interface Kits]], or any device with a digital output. &lt;br /&gt;
&lt;br /&gt;
SSRs perform the same job as [[Mechanical Relay Primer|Mechanical Relays]], but have the following advantages:&lt;br /&gt;
* SSRs produce less electromagnetic interference than mechanical relays during operation. This is mostly due to the absence of a phenomenon called [[Mechanical Relay Primer#Arcing, Interference, and Sticking|contact arcing]] only present in mechanical relays, where the physical contacts of the relay tend to spark internally while switching. The reduced interference can also be attributed to the fact that SSRs do not use electromagnets to switch.&lt;br /&gt;
* The switch contacts of a mechanical relay will eventually wear down from arcing.  An SSR will have a longer life because its internals are purely digital.  Properly used, they will last for millions of cycles.&lt;br /&gt;
* SSRs turn on and off faster than mechanical relays (≈1ms compared to ≈10ms).&lt;br /&gt;
* SSRs are less susceptible to physical vibrations than mechanical relays.&lt;br /&gt;
* Since the switch inside an SSR isn&#039;t a mechanical switch, it does not suffer from [[Switch Primer#Bounce|contact bounce]] and operates silently.&lt;br /&gt;
&lt;br /&gt;
However, compared to Mechanical Relays, SSRs: &lt;br /&gt;
* Are more expensive.&lt;br /&gt;
* Will dissipate more energy in the form of heat (1-2% of the energy intended to power the load).&lt;br /&gt;
&lt;br /&gt;
==How SSRs Work==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR_Internals.png|thumb|A conceptual diagram of the insides of an SSR.]]&lt;br /&gt;
&lt;br /&gt;
The control inputs are connected internally to an LED, which shines across an air gap to light sensors.  &lt;br /&gt;
The light sensor is connected to the transistors which open or close, supplying the relay&#039;s load with power. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;closed&#039;&#039;&#039;, current can flow freely through the relay, causing the load and power supply to be connected. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;open&#039;&#039;&#039;, almost all current is blocked, causing the load to become disconnected from the power supply. &lt;br /&gt;
The pairing of an LED with light sensors is called an optocoupler, and is a common technique to link two parts of a circuit without a direct electrical connection. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling an SSR is no more complicated than turning an LED on and off. Switch it on, switch it off, it is that easy (see the [[Digital Output Primer|Digital Output Primer]], or our [{{SERVER}}/products.php?product_id=1031 specific LED controller] for more).  &lt;br /&gt;
&lt;br /&gt;
The ability of an SSR to switch a load is very similar to a [[Mechanical Relay Primer|mechanical relay]] or simple switch. &lt;br /&gt;
By turning the digital output controlling the relay on and off, you control whether or not the load is connected to its power supply.&lt;br /&gt;
&lt;br /&gt;
The challenge is to pick an appropriate type of SSR for your application. There is no single SSR perfect for all applications. To choose an SSR for your particular application, please follow the [[#Choosing an SSR|Choosing an SSR]] section.&lt;br /&gt;
&lt;br /&gt;
===Safety===&lt;br /&gt;
&lt;br /&gt;
Since relays switch high currents and voltages, standard precautions apply.  Make sure you never touch the terminals while the relay is powered. If your SSR came with a plastic cover, use it.  Even when the SSR is switched off, a very small amount of current will flow.&lt;br /&gt;
&lt;br /&gt;
When an SSR fails, it most often fails permanently closed. This is because when the transistor inside fails due to excessive current or heat, it will usually short out, allowing current to pass through unimpeded. &lt;br /&gt;
This means that as long as the power supply remains on, the load will be powered, possibly creating a fire or safety hazard.&lt;br /&gt;
&lt;br /&gt;
==Choosing an SSR==&lt;br /&gt;
&lt;br /&gt;
===Identify your voltage===&lt;br /&gt;
&lt;br /&gt;
First, determine whether you need to switch AC or DC voltage. The electrical grid, and thus your wall outlet, runs AC, whereas batteries and most small power supplies are DC.  &lt;br /&gt;
&lt;br /&gt;
Next, determine the maximum number of volts you will be switching.  If you are switching DC, particularly with batteries, assume your voltage is at least 25% more than what your battery is rated for.  Even larger fluctuations occur on AC, but AC SSRs are designed to handle these surges.  Typical AC voltage from a wall socket in North America is 110VAC, whereas in Europe it is usually 220VAC. If you are switching AC voltage from a wall socket, check which standard your country uses, and use that number as your voltage.&lt;br /&gt;
&lt;br /&gt;
===Identify your current===&lt;br /&gt;
&lt;br /&gt;
The current drawn by your load when turned on affects how large of an SSR you need, and how hot it will be when it is in use.  If you know how much current, on average, your load draws, this is what we call &#039;&#039;&#039;Average Load Current&#039;&#039;&#039;.  If you don&#039;t know the average current, but you know the wattage (power rating) of your load, you can calculate Average Load Current by:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Average Load Current} =\frac{\text{Watts}}{\text{Operating Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, you need to know the current drawn by your load when it is first turned on.  Many loads demand a huge inrush of current when the load is first turned on. This places a significant amount of stress on the electronics inside the SSR.  If you&#039;ve ever noticed the lights dimming in the house for a second when the furnace starts up, this is caused by the fan motor starting up. In the same way that it takes a lot of force to move a heavy object from rest, it initially takes a lot of current to power up a fan or incandescent bulb. It&#039;s very difficult to measure the &#039;&#039;&#039;Surge Current&#039;&#039;&#039; itself, so we use a multiplier based on your device type.  Surge Current is also referred to as &#039;&#039;&#039;inrush current&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Surge Current Multiplier&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Multiplier&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Motors || 6x&lt;br /&gt;
|-&lt;br /&gt;
| LEDs || 1x&lt;br /&gt;
|-&lt;br /&gt;
| Complex Electronics i.e., Motor Controllers, Phidgets || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures   (AC Only) || 10x&lt;br /&gt;
|-&lt;br /&gt;
| Transformers || 20x             &lt;br /&gt;
|-&lt;br /&gt;
| Heaters || 1x&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Multiply your Average Load Current by the multiplier for your device type to calculate the Surge Current.&lt;br /&gt;
&lt;br /&gt;
===I need to switch AC===&lt;br /&gt;
&lt;br /&gt;
Most AC applications will be switching 110 to 240 Volt power coming from the grid.  If that&#039;s you, go to the [[#Mains Voltage (110 to 240V AC)|Mains Voltage (110 to 240V AC)]] section.&lt;br /&gt;
&lt;br /&gt;
We also cover low voltage AC applications - 28 VAC (Volts AC) or less. For more information, visit the [[#AC/DC SSRs|AC/DC SSRs]] section.&lt;br /&gt;
&lt;br /&gt;
===I need to switch DC===&lt;br /&gt;
&lt;br /&gt;
If you only need to switch a small amount of current - 9 Amps or less, consider our compact, cost effective [[#AC/DC SSRs|AC/DC SSRs]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch more than 9 Amps, you need a serious [[#DC SSRs|DC SSR]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch up to 16 small loads of 2 Amps or less, you can use the open collector (externally powered) digital outputs on a [{{SERVER}}/products.php?product_id=10121012 PhidgetInterfaceKit 0/16/16], which can be wired to behave similarly to relays.&lt;br /&gt;
&lt;br /&gt;
==I need Gradual Dimming==&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
==Mains Voltage (110 to 240V AC)==&lt;br /&gt;
&lt;br /&gt;
We sell AC SSRs for 120 VAC or 240 VAC operation. If you are unsure what voltages you could eventually need to switch, the 240 VAC relays can be used to switch 120 VAC with no problems.  Please note we are very conservative in how we rate SSRs - our 120 VAC relays are rated by the manufacturer for 240 VAC, and the 240 VAC for 480 VAC.  We strongly recommend against using them to the manufacturer rated voltage.  To understand why, read the [[#AC SSR Protection|AC SSR Protection]] section.&lt;br /&gt;
&lt;br /&gt;
===Load Type - Inductive vs. Resistive===&lt;br /&gt;
&lt;br /&gt;
[[Image:zero cross.png|right|thumb|300px|This graph shows the difference between zero-cross and random turn-on. The blue line represents the oscillating voltage of an AC load, and the shaded areas represent the sections when the relay is turned on and letting current pass through. As you can see, the random turn-on SSR immediately opens when activated, while the zero-cross turn-on SSR waits until the voltage crosses zero before opening.]]&lt;br /&gt;
&lt;br /&gt;
If your load is inductive, you need to choose a &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; relay.  If your load is resistive, choose a &#039;&#039;&#039;Zero Crossing&#039;&#039;&#039; relay.&lt;br /&gt;
&lt;br /&gt;
Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples.  A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat.  An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.  There is no such thing as a perfectly resistive load - but a load has to be very inductive to cause the zero crossing SSRs to malfunction.&lt;br /&gt;
&lt;br /&gt;
SSRs are designed to either turn on immediately (&#039;&#039;&#039;Random Turn On&#039;&#039;&#039;), or wait until the next &#039;alternation&#039; of the voltage (&#039;&#039;&#039;Zero Crossing&#039;&#039;&#039;).  Zero Crossing SSRs create less electromagnetic &#039;noise&#039; when they turn on.  They are best used with resistive loads - Zero Crossing SSRs are not able to turn off some inductive loads.  It&#039;s very difficult to determine which inductive loads will create problems - well beyond the scope of this document.  If your load is inductive, we recommend buying the &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; SSRs.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+ &#039;&#039;&#039;Inductive and Resistive Loads&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Load Type&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs   || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures || Inductive or Resistive &amp;lt;font size=4&amp;gt;&#039;&#039;&#039;*&#039;&#039;&#039;&amp;lt;/font&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Motors                     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Transformers               || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Heaters                    || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Computer / Electronics     || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| AC/DC power supplies (brick heavy type)     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
|AC/DC Power supplies (lightweight switchers) || Resistive&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size=4&amp;gt;&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;&amp;lt;/font&amp;gt; &#039;&#039;For fluorescent light fixtures, older units (magnetic ballast) may be inductive, and newer units are often resistive (electronic ballast).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Choosing your AC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, and your load type (inductive or resistive), you can create a short list of relays whose &lt;br /&gt;
* &#039;&#039;&#039;Maximum Load Voltage&#039;&#039;&#039; are greater than or equal to your operating voltage, &lt;br /&gt;
* &#039;&#039;&#039;Maximum Surge Current&#039;&#039;&#039; are greater than or equal to your surge current, and &lt;br /&gt;
* &#039;&#039;&#039;Load type&#039;&#039;&#039; matches what you chose for random turn on/zero crossing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +ac_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3953_0 || HFS34/D-240A20PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 8   || 15  || 20  || 255 || SCR&lt;br /&gt;
|-&lt;br /&gt;
| 3954_0 || HFS34/D-240A80PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 10  || 20  || 50  || 800 || SCR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current with no heatsink.&lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===AC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:MOV.jpg|thumb|An MOV, which comes packaged with our AC &amp;quot;Hockey Puck&amp;quot; relays. ]]&lt;br /&gt;
&lt;br /&gt;
Your AC SSR from Phidgets comes with a circular disc with two legs (pictured). This is a Metal Oxide Varistor (MOV) and should be installed across the load (larger) terminals of your SSR.  MOVs are the classic surge protector - an inexpensive component that absorbs high voltage spikes.  High voltage spikes are caused by inductive loads when they are turned off, and also happen very often on the electrical grid, as nearby devices are operated.  Even if your load is resistive, use an MOV to protect the SSR.&lt;br /&gt;
&lt;br /&gt;
Matching an MOV to an SSR is not easy - this is why we include an MOV with your SSR.  If an MOV is chosen for too low of a voltage spike, it will wear out quickly.  If it is chosen for too high of a voltage spike, it will not protect the SSR adequately.  To balance SSR protection against MOV lifetime, we have found it necessary to use SSRs built for 240 VAC in 120 VAC applications, and SSRs built for 480 VAC in 240 VAC applications.  If you must operate our AC SSRs on higher voltages than we recommend, do not use the included MOV.&lt;br /&gt;
&lt;br /&gt;
As MOVs wear out from use, they will become more sensitive to common voltage spikes, causing them to wear out quicker.  When they entirely fail, they will become a short circuit, potentially creating a fire hazard.  The MOV included with your SSR has a fuse built in which will disable the MOV when it becomes a hazard. To be on the safe side, avoid mounting your SSR near any flammable material.&lt;br /&gt;
&lt;br /&gt;
===Proportional Control SSR===&lt;br /&gt;
&lt;br /&gt;
Proportional Control Relays (often simply called &amp;quot;Control Relays&amp;quot;) are SSRs you can use to control the amount of power to the load.  Rather than reduce the voltage, or somehow limit the current - which would be very expensive solutions, the Proportional SSR reduces power by turning the load on/off quickly, feeding full power in short pulses.  &lt;br /&gt;
&lt;br /&gt;
Proportional SSRs are controlled by a variable voltage - as the control voltage increases, more power is available to the load.  Our PhidgetAnalog product can be used to control Proportional SSRs, since an [[Analog Output Primer|analog output]] can output various amounts of voltage, as opposed to a digital output, which only has two states- high and low.  We don&#039;t sell Proportional SSRs - but they can be purchased from [http://www.digikey.com Digikey], where they are called AC Linear Controlled SSRs.&lt;br /&gt;
&lt;br /&gt;
A quick and dirty solution for dimming with Phidgets is to use an {{LinksNeeded|RC Servo Motor|[[Servo Motor and Controller Primer|RC Servo Motor]]}} with a PhidgetAdvancedServo controller to rotate the knob on a light dimmer.  From software, the RC Servo Motor is rotated to the desired position, cranking the knob as it turns. While this may seem like a roundabout way of achieving proportional control, dimmers tend to be much less expensive because they are less specialized and are manufactured in greater quantity.&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:AC SSR Load.png|right|thumb|300px|Schematic of an AC SSR switching a generic load. A metal oxide varistor is added across the load to protect the SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring up an AC circuit, particularly for long term installation, you may find it helpful to buy a book on residential wiring from your local hardware store.  There are many wiring conventions (and often legal codes) which will help you plan your project, and the legal codes are often a great source of wisdom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DC SSRs (0 to 50V DC)==&lt;br /&gt;
&lt;br /&gt;
We sell DC SSRs for that switch a maximum load of 50 volts. If you are unsure what voltages you could be switching in the future, higher voltage DC SSRs can be used to switch lower voltages.  Common engineering practice would be to purchase an SSR rated for 50-100% higher voltage than the voltage you plan to be switching.  For instance, if you are switching 24V, a 50V SSR is reasonable.&lt;br /&gt;
&lt;br /&gt;
===Choosing your DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +dc_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3950_0 || HFS33/D-30D50M     || DC    || N/A            || 3-32VDC || 30	     || 18  || 50  || 50  || 120  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3951_0 || HFS33/D-50D80M     || DC    || N/A            || 3-32VDC || 50           || 20  || 40  || 80  || 200  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3952_0 || HFS33/D-30D100M    || DC    || N/A            || 3-32VDC || 30           || 25  || 50  || 100 || 240  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a Heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current without a heatsink. SSRs rated for a larger load than the load you&#039;re using will be more efficient (meaning less energy lost in the form of heat) than an SSR that&#039;s being operated at its maximum load. &lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===DC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:Diode.jpg|thumb| A diode, included with our DC &amp;quot;hockey puck&amp;quot; SSRs. The cathode is marked with a line. The blue symbol shows circuit diagram equivalent of the diode.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:relaymotor.jpg|thumb| A DC SSR switching an electric motor. The 1018 Phidget InterfaceKit controls the SSR using its digital outputs. A diode is shown installed across the motor, and a fuse is hooked up between the power supply and the rest of the circuit.]]&lt;br /&gt;
&lt;br /&gt;
Your DC SSR from Phidgets comes with a diode. This diode should be installed across your load, with the Cathode installed towards the positive terminal of the power supply (as shown in the diagram).  &lt;br /&gt;
&lt;br /&gt;
If the diode is installed backwards, as soon as the SSR is turned on, the load will be shorted out, likely destroying the diode, or the SSR, or your power supply.&lt;br /&gt;
A fuse protecting your power supply is always a good idea. You can place the fuse in between the positive terminal of the power supply and the positive terminal of the load side of the SSR. &lt;br /&gt;
&lt;br /&gt;
The diode protects the SSR from powerful residual currents after the SSR is turned off.  While your load is being driven, inductance builds up magnetic fields around the wiring. &lt;br /&gt;
Every load is inductive to some degree, and when the SSR turns off, the magnetic fields will ram current against the now open SSR, easily damaging it.  The diode allows these currents to recirculate in the load until they have lost their energy. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:DC SSR Load.png|right|thumb|300px|Schematic of an DC SSR switching a generic load, which is protected by a diode connected in parallel. The circuit is protected by a fuse in series after the power supply.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a DC SSR allows them to be placed within a circuit just like a switch.  Since it is isolated, you don&#039;t have to worry about grounding or voltage offsets. &lt;br /&gt;
&lt;br /&gt;
With a DC SSR, always make sure the positive load terminal (labeled +) is facing towards the positive terminal of the power supply. If the load terminals are reversed, your load will immediately turn on. There is a diode inside of the SSR that allows current to flow freely through it when the SSR is connected incorrectly. This feature is included because this sort of wiring mistake would destroy the transistor in the DC SSR otherwise.&lt;br /&gt;
&lt;br /&gt;
The DC SSR can be installed on either side of the load, and it will work properly, but there is an advantage to installing the SSR between the power supply and the load.  If the load is connected to the power supply, it will always have a potentially dangerous voltage on it, even when it is not operating.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==AC/DC SSRs (0 to 40V DC / 0 to 28V AC)==&lt;br /&gt;
&lt;br /&gt;
[[Image:AC_DC_SSR.png|thumb|A small, versatile AC/DC SSR mounted on a Phidgets board for easy pin access.]]&lt;br /&gt;
&lt;br /&gt;
Our AC/DC SSRs are built on a small PCB, making them physically smaller than the large &amp;quot;hockey puck&amp;quot; SSRs, and less expensive.  They are limited to lower currents, and cannot be mounted on a heatsink.  &lt;br /&gt;
&lt;br /&gt;
We sell AC/DC SSRs that can switch up to 40 Volts DC or 28 Volts AC.  This is indicated on the SSR Product pages under the Maximum Load Voltage specification.  There is no lower limit on the voltages that the AC/DC SSRs can switch.  If your voltage is close - be conservative.  For instance, a 36 Volt system built from 3 Lead Acid batteries can reach 45 volts when charging.&lt;br /&gt;
&lt;br /&gt;
===Picking your AC/DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +versatile_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3052_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 2.5 || N/A || N/A || 5    || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3053_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 9   || N/A || N/A || ???  || MOSFET&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you are interested in minimum cost, you will likely choose the cheapest option that meets these criteria.  If you are interested in high efficiency operation and less heat generation, consider buying an SSR with higher current rating.&lt;br /&gt;
&lt;br /&gt;
Your AC/DC SSR from Phidgets has built in protection from static electricity, and dangerous residual currents  after the SSR is turned off.  If the load you are switching is powered by a DC source, installing a diode across the load will offer even more protection.  Refer to the [[#DC SSR Protection|DC SSR Protection]] section for more information.&lt;br /&gt;
&lt;br /&gt;
To learn more about SSRs in general, visit the [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC/DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:Versatile SSR DC Load.png|thumb|A versatile AC/DC SSR switching a DC load. The load terminals are bidirectional, so it doesn&#039;t matter which way you hook them up. The optional diode can be added to help protect the SSR when switching DC loads.]]&lt;br /&gt;
[[Image:Versatile SSR AC Load.png|thumb|A versatile AC/DC SSR switching an AC load.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a AC/DC SSR allows them to be placed within a circuit just like a switch.  Circuits without electrical isolation require a lot more care - proper grounding, careful consideration of voltage offsets.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using heatsinks with Hockey Puck SSRs==&lt;br /&gt;
&lt;br /&gt;
[[Image:3950_0 Accessories Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR with plastic cover (left), a thermal pad (right). All hockey puck SSRs sold at Phidgets come with both of these accessories plus a diode or varistor to protect the SSR.]]&lt;br /&gt;
[[Image:3955_0 Functional Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR mounted on a [[3955]] heatsink by two screws. The thermal pad is pressed between the SSR and the heatsink.]]&lt;br /&gt;
&lt;br /&gt;
SSRs will only achieve their promise of reliability and long life if they are kept cool.  Cool is relative, of course, but a good rule of thumb is to keep the metal base of the SSR at less than 85°C (185°F).  A [[Thermocouple Primer|thermocouple]] can be used to precisely measure the temperature of the metal base.&lt;br /&gt;
&lt;br /&gt;
Excess heat usually comes from too much current and too little heatsinking.  A lot of heat can also be generated by frequently turning the relay on and off.  If your relay is operated for brief periods of time, you may not need as large of a heatsink - provided the relay is never accidentally left on for extended periods.  Unless space is a concern, it&#039;s better to err on the side of caution.&lt;br /&gt;
&lt;br /&gt;
Before buying a heatsink, consider if you actually need it.  If your application is running at room temperature, and your average current is less than the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; specification of your SSR, then you don&#039;t need a heatsink.  Alternatively, if your project has a large metal chassis that the SSR can bolt to, this can be used as your heatsink.&lt;br /&gt;
&lt;br /&gt;
Each SSR suitable for use with heatsinks will include a specification of how much current it can switch with each heatsink we sell.  This specification assumes a reasonable airflow over the heatsink, and that the flowing air is at room temperature.  Our SSRs have a sheet of metal underneath, where the heat is concentrated - this is also where the heat is measured to tell if the SSR is too hot.  Phidgets includes a grey thermal pad with our Hockey Puck SSRs (see pictured). You place this pad under an SSR when mounting it on a heatsink, or on large metal surfaces that can dissipate heat.  The pad performs the same function as thermal grease - it helps conduct heat between the base of the SSR and the heatsink. If you prefer to use thermal grease, you can use it instead of the pad.  Our heatsinks include screws for mounting SSRs. Use a good size screwdriver when tightening the SSR down on the heatsink to ensure good conduction.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Product Name&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Dimensions (mm)&lt;br /&gt;
! Thermal Resistance (C/W)&lt;br /&gt;
|-&lt;br /&gt;
| 3955_0 || Small Heatsink for SSR || HF92B-80 || 50x50x80 || 2.4&lt;br /&gt;
|-&lt;br /&gt;
| 3956_0 || Large Heatsink for SSR || HF92B-150A || 55x142x150 || 0.6&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hooking up wires to the Hockey Puck SSR==&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_mov.jpg|thumb|An AC SSR with the wires attached normally and an MOV installed across the load side.]]&lt;br /&gt;
[[Image:lugs.jpg|thumb|TRM6 wiring lugs connected to a DC SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring your load to the SSR, the wire is looped clockwise around the terminal, so when the screw is tightened down, it will draw the wire in tighter.  We recommend using wires up to 10 AWG in size - any larger, and the screws will not have enough thread left to tighten down, and they will strip.  Larger wires can be attached using a wiring lug.  The lug is clamped under the SSR screw, and the wire attaches to the lug.&lt;br /&gt;
&lt;br /&gt;
Loose wire connections can generate a lot of heat - use a large enough screwdriver when clamping down the load wires to ensure that the screws are on tight enough.&lt;br /&gt;
&lt;br /&gt;
For the current ratings of various wires sizes, please see [[Page on Wire Sizes]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Did you know?==&lt;br /&gt;
&lt;br /&gt;
* Mains Voltage &#039;&#039;&#039;AC SSRs&#039;&#039;&#039; cannot switch DC. They will never turn the load off.  AC SSRs turn off twice per AC Cycle, when the current changes direction and is momentarily zero. For example, AC is 60 Hz in North America, so the AC SSR has 120 opportunities per second to turn off (the SSR will only &#039;&#039;&#039;stay&#039;&#039;&#039; off if the control signal is low).  If the SSR is operating from DC, the current will flow continuously, and the load will not turn off, even when the control input is off.&lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; turns off automatically every time the load current reaches zero. It will turn back on almost immediately as long as the signal controlling the SSR is high. An AC SSR will actually have a low, non-zero current value that it regards as &#039;zero&#039;. This specification is usually called &amp;quot;Minimum Load Current&amp;quot; in the data sheet. If your load requires less than this minimum current, your SSR will never turn on, or will not reliably turn on. The simplest solution to this problem is to connect another load in parallel with the first, increasing the Current required by the load.&lt;br /&gt;
&lt;br /&gt;
* SSR Manufacturers have started adding a simple circuit inside &#039;&#039;&#039;AC SSRs&#039;&#039;&#039;, across the load terminals, called a snubber.  The snubber absorbs very fast electrical changes that could normally cause an &#039;&#039;&#039;AC SSR&#039;&#039;&#039; to turn on accidentally. When the AC SSR is turned on, there is little voltage difference between the terminals, so the snubber has very little effect.  When the AC SSR is turned off, the snubber is actively protecting the SSR - but at a cost, as it allows a small current through the SSR, which is wasted.  &lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; uses bipolar transistors - an old technology that has been replaced by CMOS transistors in modern digital circuits.  Bipolar transistors are still superior for handling high voltages.  Bipolar transistors, and the more complex transistors built from them, will lose a constant voltage as current flows through them.  The collection of transistors in your SSR will lose about 1.7 volts - so on a 120 VAC system, you will lose about 1.5% to the SSR.  This energy converts to heat inside the SSR, and the heating from these transistors is the reason SSRs often need heatsinks.&lt;br /&gt;
&lt;br /&gt;
* SSRs, and semiconductors in general, usually fail as a short circuit. A short circuit is a circuit whose internals have been damaged such that current can flow through it freely.  This means your load will probably turn on permanently (until you disconnect the power source) - make sure this doesn&#039;t cause a safety hazard.  For instance, Sauna Heaters have a simple thermally-triggered mechanical shutdown to protect them if control electronics fails.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;DC SSRs&#039;&#039;&#039; (at least the units we sell) use Metal Oxide Semiconductor Field Effect Transistors (MOSFETs). MOSFETs do not lose a constant voltage - instead, when they turn on, they act as a very slight restriction to the flow of current - a resistor.  At low currents, the slight restriction wastes very little power, giving high efficiency and often not requiring a heatsink.  This efficiency is lost as the current increases - a doubling of current quadruples the production of heat.  &lt;br /&gt;
&lt;br /&gt;
* Normally, a MOSFET can only block current in one direction - as soon as the voltage reverses, the current flows through a diode run in parallel to the MOSFET.  If a MOSFET were used to switch AC, the load would be turned on half the time.  A common solution is to use two MOSFETs back to back - which is what we do with our &#039;&#039;&#039;AC/DC SSRs&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20732</id>
		<title>Electricity Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20732"/>
		<updated>2012-06-29T21:52:32Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Affected Products */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Design of reliable systems is really, really hard.  The main challenge is the design of reliable building blocks - i.e. circuit and board layouts - from which to create your system.  Phidgets does the majority of this work for you.  And, once you have reliable building blocks, designing a reliable system from them is much easier.  &lt;br /&gt;
&lt;br /&gt;
However, you can still make an unreliable system out of Phidgets.  In fact, if you are building a more complex system than the common examples we show through our documentation, and you have limited experience in complex electrical design, you will probably - and unintentionally - introduce design flaws that will make your system unreliable.&lt;br /&gt;
&lt;br /&gt;
There are two reasons why you should read this primer:&lt;br /&gt;
# You want to build a complex system, more complex than we illustrate in our documentation.  To succeed, you need to understand concepts.&lt;br /&gt;
# You understand how to make your system work, and you want to ensure it is well designed for maximum reliability and/or precision.&lt;br /&gt;
&lt;br /&gt;
==The Basics==&lt;br /&gt;
&lt;br /&gt;
To understand our discussion of potential problems and their solutions below, you&#039;ll need to be familiar with the basics.  For this page, &#039;being familiar&#039; means more than simply having heard of voltage, amperage, and power.  You will need to have a working, conceptual model in your head, so that you can apply that model to your own system and examine it for problems.  This section is all about giving the tools to build that mental model.&lt;br /&gt;
&lt;br /&gt;
First, some terminology.  We introduce it by analogy.  If a circuit is a water system,&lt;br /&gt;
* The &#039;&#039;&#039;voltage&#039;&#039;&#039; is the &#039;&#039;pressure&#039;&#039; in the system&lt;br /&gt;
* The &#039;&#039;&#039;power supply&#039;&#039;&#039; is the &#039;&#039;pump&#039;&#039; creating the pressure&lt;br /&gt;
* The &#039;&#039;&#039;amperage&#039;&#039;&#039;, also known as current, is the amount of &#039;&#039;flow&#039;&#039;&lt;br /&gt;
* The &#039;&#039;&#039;load&#039;&#039;&#039; is the &#039;&#039;faucet&#039;&#039; - adjusting your load will adjust the flow&lt;br /&gt;
* The &#039;&#039;&#039;resistance&#039;&#039;&#039; is an attribute of the load - how tight or loose the faucet is&lt;br /&gt;
* The &#039;&#039;&#039;ground&#039;&#039;&#039; is the return path from load to pump.&lt;br /&gt;
&lt;br /&gt;
The basic concepts for all of these terms are presented below.&lt;br /&gt;
 &lt;br /&gt;
===Load===&lt;br /&gt;
&lt;br /&gt;
We start with the load, because the load is the purpose of your entire system.  &lt;br /&gt;
&lt;br /&gt;
In simple, USB-only Phidget systems, the load is the Phidget itself.  The USB port is ready to provide power, but it does not (and cannot) until a load is applied (i.e. the Phidget is attached) and the circuit is completed.  &lt;br /&gt;
&lt;br /&gt;
Without a load that connects in a loop, it is like attaching a closed pipe to your pump.  Initially, water will fill the pipe, and pressurize it, but once the pipe fills the system as a whole will do nothing more.  To allow the pump to drive the load, and the flow to supply the load, we need to have a completed circuit, like this:&lt;br /&gt;
 &lt;br /&gt;
[[Image:elec_flow.png|150px]]&lt;br /&gt;
&lt;br /&gt;
The load and the pump must &#039;&#039;&#039;match&#039;&#039;&#039;.  If the load lets too much flow through, the pump will work too hard and burn itself out.  This is what happens when you short circuit a power supply.  The load is then simply a wire, which basically opens the flood gates and drains your power supply pump.  The load must not let too much flow through, which it does by &#039;&#039;&#039;resistance&#039;&#039;&#039;. Likewise, the pump cannot push too hard on the load, or the load will break.  This is discussed in-depth as part of [[#Voltage and Amperage|Voltage and Amperage]] below.&lt;br /&gt;
&lt;br /&gt;
===Voltage and Amperage===&lt;br /&gt;
&lt;br /&gt;
Within the flow concept [[#Load|above]], voltage is pressure.  Specifically, it is the &#039;&#039;difference&#039;&#039; in pressure between the flow and the return.  Voltage is measured in volts, and is denoted by &#039;&#039;&#039;V&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Amperage - also known as current - is the flow, or the amount of water that moves.  At the pump, the amount of current out and the amount of current in are equal.  The pressure might vary widely (highly pressurized pipes out, low pressure pipes back) but the &#039;&#039;amount&#039;&#039; of current is always the same.  Amperage is measured in Amps, and is denoted by &#039;&#039;&#039;A&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To match a pump to a load, the voltage and amperage of the power (supply) and load (sink) must line up.  We discuss picking a power supply - whether [[#Wall Power|wall mains]], or [[#Battery Power|batteries]] - in the [[#Power Needs|Power Needs section]] farther along in the document, but we need a few more concepts before we get there.&lt;br /&gt;
&lt;br /&gt;
Power supplies - whether wall power or batteries - are usually rated based on voltage and amperage.  Voltage is the specification to be the most careful with for circuits.  Too much voltage is the same as overpressurizing your pipes - they will burst.  In the case of electronics, you device will break.  &lt;br /&gt;
&lt;br /&gt;
This can be counterintuitive - in reference to safety (for humans) around electronics, you may have heard &amp;quot;It is not the voltage that will kill you, it is the amperage&amp;quot;.  Because of this, it may be tempting to think that too high of an amperage will harm your device, but this is not true.  Our hearts are very susceptible to amperage but not voltage, hence amperage is considered dangerous for us whereas voltage is not.  But a circuit is not like a human body - in a circuit trying to handle a power supply it is the voltage that matters most.  &lt;br /&gt;
&lt;br /&gt;
====Set Voltage (No Control)====&lt;br /&gt;
&lt;br /&gt;
Most loads do no power regulation of their own.  They simply take the voltage given to them and do useful things with it.  You can tell that a pre-designed load (like a Phidget) falls into this category because it gives its voltage need &#039;&#039;as an exact value&#039;&#039;.  For example, most Phdigets use exactly 5 V of USB power.  These loads will also tell you their amperage, which is a flow need that must be met or exceeded.  A load will only use as much amperage as it needs.&lt;br /&gt;
&lt;br /&gt;
====Controlled Power====&lt;br /&gt;
&lt;br /&gt;
Some loads change the voltage or current they receive.  This can be with the intent to either (a) keep a constant amount of power flowing from a draining power source like batteries, or (b) to modify a common power source (i.e. 12 V at 1 A) into an uncommon power source (i.e. 1 V at 12 A).  This process is called &#039;&#039;&#039;regulation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can tell that a pre-designed load (like a Phidget) falls into this &amp;quot;power-regulated device&amp;quot; category because it gives its voltage need &#039;&#039;as a range&#039;&#039;. For example, the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer (SBC)] can take 6 V to 15 V.  &lt;br /&gt;
&lt;br /&gt;
To understand how this works, take the example of a flywheel.  Flywheels are designed to be heavy and to take work in order to get them spinning at speed.  But once you have them spinning, you can extract that work later at a more consistent rate:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flywheel.png]]&lt;br /&gt;
&lt;br /&gt;
Flywheels can either make amperage or voltage be the more consistent blue line over time.  The most common one in Phidgets is for stable amperage.  Regulated amperage is also how LED lights can stay consistently bright for any length of time when using batteries.  Stable voltage design is usually applied when the voltage is too low to begin with (such as any device that runs on a single AA battery), and the flywheel must amplify and stabilize it over time.&lt;br /&gt;
&lt;br /&gt;
For those readers trying to envision how this works electrically, in practice the flywheel is an inductor (or, a transformer utilizing its inductor properties).  For both voltage and amperage regulation, one way relief valves (diodes) must be added. And, in amperage regulation a reservoir (capacitor) must be added to offset the current drop by pulling &#039;&#039;more&#039;&#039; amperage as a battery drains.  Then, a controller is needed to measure and then correspondingly enable and disable the flywheel system as the voltage or amperage drops from the supply.  &lt;br /&gt;
&lt;br /&gt;
But with those details in place, the inductor (and capacitor, in the case of amperage regulation) can effectively take the variety of voltages from, say, a draining battery, and still allow the board to run.  Some devices even do this naturally.  For example, motors often can take a variety of voltages because their construction (i.e. wire wrapping) naturally creates inductance.&lt;br /&gt;
&lt;br /&gt;
These regulated systems often list the power they need directly, using a type of power rating called &#039;&#039;&#039;watts&#039;&#039;&#039;.  Watts are voltage and amperage together (i.e. power):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Amperage} =\frac{\text{Watts}}{\text{Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Watts can be a handy way to describe flow and pressure together for these regulated devices.  Rather than separating voltage and amperage like the unregulated devices do (i.e. this load needs exactly 12 V, or this load will draw exactly 2 A), the unit of watts will allow different value combinations of volts and amps as long as the wattage remains the same.  For example, a 12 watt device with a voltage range of 5 to 12 volts can run on 6 V at 2 A, or 12 V at 1 A.  Either will work.  Amperage for all values in the device&#039;s range of 5 to 12 V can be found with the equation above.  Because of this, watts are often preferred when trying to match a power supply to a regulated load.&lt;br /&gt;
&lt;br /&gt;
===Ground===&lt;br /&gt;
&lt;br /&gt;
All circuits have a &#039;&#039;&#039;ground&#039;&#039;&#039;.  This is simply the return pipe to the pump.  In a circuit, it is denoted by an upside-down triangle:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground.png]]&lt;br /&gt;
&lt;br /&gt;
When drawing a circuit diagram, the symbol is placed on the wires that return to the pump:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flow_ground.png|170px]]&lt;br /&gt;
&lt;br /&gt;
This electric ground provides a voltage reference throughout the circuit.  Ground is always &#039;&#039;&#039;0&#039;&#039;&#039; volts as far as the circuit is concerned. (Remember, voltage is the &#039;&#039;difference&#039;&#039; between the flow and return pipes at the pump.)  Ground is important because it provides a reference from which all the parts of the circuit can speak the same &amp;quot;voltage language&amp;quot; to each other, which matters a lot when a certain voltage means &amp;quot;1&amp;quot; and a certain voltage means &amp;quot;0&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
There is only one &#039;&#039;&#039;absolute&#039;&#039;&#039; ground, and that is the Earth, which is taken to be 0 volts as an absolute value.  Circuits not well-grounded to the Earth (of which there are many - your cell phone, car, etc) operate at a &#039;&#039;&#039;relative&#039;&#039;&#039; voltage.  The upside-down triangle above denotes a &#039;&#039;relative&#039;&#039; ground.&lt;br /&gt;
&lt;br /&gt;
With relative voltage, only the difference between local ground and the local high voltage matters.  For example, a cell phone might operate as a 3 volt device, which means relative to its ground it always operates between 0 and 3 volts.  But if that cell phone were compared carefully to Earth ground, its absolute voltage could be, say, between 10 and 13 volts.  Until comparison, the device doesn&#039;t &amp;quot;feel&amp;quot; charged.  This is the same as how you don&#039;t &amp;quot;feel&amp;quot; charged after skidding your feet in socks across a carpeted floor.  But, when you &amp;quot;compare&amp;quot; yourself to Earth ground by touching some well-grounded metal, you receive a static electricity shock.&lt;br /&gt;
&lt;br /&gt;
The same thing can happen when you combine two different power supplies, as we discuss [[#Projects With Different Power Sources|below]].&lt;br /&gt;
&lt;br /&gt;
===Power===&lt;br /&gt;
&lt;br /&gt;
There can be different types of pumps, and at this point we should supplant our heart symbol with some actual power supply pump symbols.  For example, this is the symbol for a direct current (DC) battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
The + end is on the out flow, and the - end is on the return (ground).  Batteries are usually listed with their voltages.  This is because the resistance of the load will determine how much amperage is drawn, but too much voltage and you will harm your load.&lt;br /&gt;
&lt;br /&gt;
This is the symbol for alternating current (AC) that you would get directly from the wall:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_wall_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
Again, this is listed using voltage for the same reasons as DC.  A relative ground symbol is still used on the return line here.  AC devices can still operate on relative voltage if they do not use Earth ground (the third prong on a wall plug in North America).  This is how some loads have AC cords with only two prongs - they operate on a relative voltage and relative ground.  And relative AC voltage, having significantly more voltage (pressure) behind it, can really hit a device hard when two power supplies meet across it.&lt;br /&gt;
&lt;br /&gt;
This connecting of multiple power supplies is quite a complex subject, and is described further in both [[#Power Needs|picking different power supplies]] and [[#One Powered Phidget|connecting different power supplies]] later on in this Primer.&lt;br /&gt;
&lt;br /&gt;
===Emissions and Wires===&lt;br /&gt;
&lt;br /&gt;
To talk about emissions, it is worth speaking more precisely about what a load is.  The typical, simple Phidget setup is receiving 5 V direct current (DC) from the computer over the USB port.  Let&#039;s model this as coming from a battery so that we can examine all parts of the system.  From the point of view of the battery, the Phidget load is not just the green board with the circuitry on it.  The load &#039;&#039;also&#039;&#039; includes the power cable (i.e. two wires in the USB cable), and anything else on the path out or back from the circuitry to the battery itself:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
This is important because the wires play a role in the voltage that eventually makes it to the Phidget.  This is true all the time, even when the Phidget is attached to a computer instead of a battery.  All wires have some resistance, and so they are, in a way, in and of themselves circuits.    Therefore, because of their resistance, the wires &#039;use&#039; some of the 5 V heading out to the Phidget circuit board.  This is discussed more below, but essentially longer cables have more resistance and at some point the voltage will drop so much over the length that the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
To conceptually separate the wires from the Phidget in terms of the load, we can now start drawing the wires themselves in our circuit diagram, instead of the curved concept arrows indicating flow and return:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wires.png|200px]]&lt;br /&gt;
&lt;br /&gt;
When talking about the 5V relative ground in this system, we are in fact talking about the ground &#039;&#039;right at the battery&#039;&#039; so we move the ground symbol to the battery itself.&lt;br /&gt;
&lt;br /&gt;
Then, the resistance on these wires creates a possible problem - the emission of electromagnetic radiation as the wires naturally drop the voltage:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_emissions.png|200px]]&lt;br /&gt;
&lt;br /&gt;
These emissions are at a set frequency determined by the length of the wire:&lt;br /&gt;
* Long wires create low frequencies (harmful interference)&lt;br /&gt;
* Short wires create high frequencies (less harmful interference)&lt;br /&gt;
&lt;br /&gt;
This can be minimized by having the flow and return wires be the same length and sit right next to each other.  This way, the emissions somewhat cancel each other out from the flow and return going in opposite directions.  This is partially how USB cables minimize emissions.&lt;br /&gt;
&lt;br /&gt;
So, the way you design your connections (i.e. the resistance and placement of your wire) will have a direct affect on:&lt;br /&gt;
# The voltage that reaches the Phidget&lt;br /&gt;
# The emissions that your system produces&lt;br /&gt;
&lt;br /&gt;
With all this talk of emissions, you might be tempted to try to shield parts or all of your system from emissions that either your system or external systems create.  &lt;br /&gt;
&lt;br /&gt;
Keep in mind that shielding is actually really hard to do correctly.  Especially when grounding your shielding, with ad-hoc design you have a high chance of having an interfering signal (that has traveled out to the shield and traveled back via ground) creating a larger problem than not having a shield at all.  Rather than shielding, it is easier to simply keep your cables short and with as low a resistance as possible throughout your system to minimize your emissions in the first place.&lt;br /&gt;
&lt;br /&gt;
Identification of and solutions to these (and other more complex) problems are discussed in detail in the [[#Selecting Cables|section on choosing cables]] and the [[#Hooking Up The Pieces|section on connecting the pieces]] below.&lt;br /&gt;
&lt;br /&gt;
===Multiple Loads===&lt;br /&gt;
&lt;br /&gt;
The easiest way to hook up multiple Phidgets is in parallel, where the voltage stays the same but they share the amperage.  Here the DC supply is two USB ports, each at 5 V and 0.5 A:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
However, the length of your wires comes into play again, because the voltage that actually reaches the Phidgets above is somewhat less than 5 V.  So if your wires are long, or mismatched, the voltage may not match and will give you strange results.  The voltage is both affected on the way out, and on the way back.  Assuming the wires are the same length:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wire_drop.png|350px]]&lt;br /&gt;
&lt;br /&gt;
In this way, you can create difficult-to-debug problems within a complex system, where one Phidget works but others mysteriously fail.&lt;br /&gt;
&lt;br /&gt;
==Power Needs==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve understood the basics, it is time to actually talk about decisions and design.  This section will help you choose a power supply for your Phidget.  Let&#039;s say you want to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] off of a battery.  Or you want to run a motor controller with a power supply you bought from the hobby store.  What do you need to buy?  Will one you already have work?  It is worth it to spend a moment with pencil and paper to work through this section and identify your power needs.&lt;br /&gt;
&lt;br /&gt;
As described [[#Voltage and Amperage|earlier]], voltage is pressure. Too much pressure behind your faucet, and the water mains or faucet will break.  Likewise, if you have too much voltage from a power supply, your circuit will break.  You should choose a supply with voltage that &#039;&#039;matches the range the Phidget can accept&#039;&#039;.  The voltage cannot be over the maximum (otherwise, like pressure in a pipe, the pipe will burst), and the voltage cannot be under the minimum (otherwise, like pressure in a pipe, no flow will occur).  Also, generally, a device (like a motor controller) will perform better at its maximum rated voltage if a range is available.&lt;br /&gt;
&lt;br /&gt;
But the faucet doesn&#039;t care whether there is a big reservoir or small reservoir feeding the system, as long as the pressure is managed.  Likewise, you can choose a power supply with more amperage than you need (a big reservoir to draw from) as long as the voltage matches.  In the same way that a faucet restricts water by design, loads draw and allow only the amperage that they need. However, the amperage cannot be less than the Phidget needs.  In that case, you will either overextend (and break) your power supply, or the circuit simply will not turn on at all.&lt;br /&gt;
&lt;br /&gt;
The specification [[#Device List|for your specific device]] will list its power needs. For most devices, the external power supply needs will simply be listed in voltage and amperage.  USB power is 5V at up to 500 mA (0.5 Amps).  Most Phidgets will draw less than this - if you need precision, you can check the specification for your particular Phidget.  And, if it is an Interface Kit, you can add the draw of each analog sensor and digital in/out from their specifications.&lt;br /&gt;
&lt;br /&gt;
However, some Phidgets (e.g. motors, and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]) do not have a straight amperage and voltage specification.  Instead, their power draw will be listed in watts, for which you [[#Voltage and Amperage|saw a relation earlier]] to convert to the values you need.&lt;br /&gt;
&lt;br /&gt;
===Wall Power===&lt;br /&gt;
&lt;br /&gt;
Wall power sources usually take the alternating current (AC) from the wall and convert it into a direct current (DC).  These power supplies often take your familiar two-or-three prong wall connector and put power out via a barrel plug-type connector.  AC power (typically 110 or 240 volts, depending where you live in the world) goes in the typical wall plug, and DC power (typically 5 to 24 volts) comes out the barrel plug.  Most power supplies of this type list the conversion explicitly, such as: 110-240 Volts to 12 Volts at 2 Amps.  You&#039;ll want to match your Phidget&#039;s needs against the 12 Volts at 2 Amps. &lt;br /&gt;
&lt;br /&gt;
*The voltage must match exactly&lt;br /&gt;
**If the Phidget takes a range of voltages, the supply must fall within the range&lt;br /&gt;
*The amperage can be equal to or greater than the Phidget needs&lt;br /&gt;
&lt;br /&gt;
A wall power supply is essentially an inexhaustible supply of current, so you don&#039;t need to worry about it running out like you would with batteries.&lt;br /&gt;
&lt;br /&gt;
===Battery Power===&lt;br /&gt;
&lt;br /&gt;
If you intend to use a battery bank (even of only one battery) to power your Phidget, you probably want to know what type of battery to purchase.  &lt;br /&gt;
&lt;br /&gt;
====Battery Chemistries====&lt;br /&gt;
The first thing that sets batteries apart is the type of materials used in their construction.  The following table shows several of the more common battery chemistries as well as the voltage per cell they produce and the specific energy of the chemistry.  &lt;br /&gt;
&lt;br /&gt;
{| border = 1&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Chemistry&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Nominal Cell Voltage&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Specific Energy (MJ/kg)&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Primary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| Alkaline||1.5||0.4||These are the most common form of battery.  Many commercially available AA and AAA batteries are alkaline. &lt;br /&gt;
|-&lt;br /&gt;
| Lithium (LiMnO2)||3||0.83-1.01||These are used in high drain devices or devices with a long shelf life as they have a very low self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Silver-oxide||1.55||0.47||Only used in small button cells as these are quite expensive.&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Secondary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| NiCd||1.2||0.14||Older technology, suffers from [[Electricity Primer#Memory Effect|memory effect]].  Capable of very high discharge rates with no ill effects.  Moderate self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Lead-acid||2.1||0.14||Not particularly good with high discharge rate.  Moderate rate of self discharge.  &lt;br /&gt;
|-&lt;br /&gt;
| NiMH||1.2||0.36||Very heavy.  Good performance in high drain devices.  Very high energy density naturally, at the cost of a high self discharge rate.  Newer versions are able to get rid of some of the self discharge though they suffer ~25% lower energy densities as a result.  &lt;br /&gt;
|-&lt;br /&gt;
| Lithium Ion||3.6||0.46||Expensive to produce but very high energy density.  Very low self discharge rate.  Safety hazard as short circuiting can yield explosive or fiery results. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Choosing a Battery====&lt;br /&gt;
Batteries are chosen first by their voltage (V).  Match the voltage exactly to the voltage the Phidget needs.  Over or under this value, you could harm the board or have it simply fail to turn on.&lt;br /&gt;
&lt;br /&gt;
Next, choose a battery that has adequate amperage to feed your device for the time you need. The lifespan of the battery will usually be listed in Amp-Hours (or Ah).  For example, a double wide 12 V lantern battery will have usually around 7-8 amp hours.  This means if you drew one amp from it for seven to eight hours, the battery would be totally drained.  Or you could draw two amps from it and drain it in 3.5-4 hours.  This does not mean however, that you can draw 36A for 15 minutes.  It is important to understand that there is a limit at which more power simply cannot be drawn from the battery.  Effectively, high drain devices will decrease the rated Ah.  The amount  differs from battery to battery so to be sure it is recommended to check the data sheets for the battery you are using.  If the battery did not come with a data sheet they can usually be found on the manufacturers website.  The data sheets should have a graph that shows the relationship between current draw (usually in mA) and capacity (Ah or mAh).  Another useful thing that can be gathered from the datasheets is the batteries response to temperature.  Batteries tend to not work as well in cold environments, most manufacturers will provide graphs of how the batteries lifespans will shorten at different temperatures.  This is often very significant, causing the battery to last a fraction of its normal lifespan at temperatures below -10&amp;amp;deg;C.&lt;br /&gt;
&lt;br /&gt;
Finding the amperage or voltage sometimes needs to be done indirectly by using a specification of watts.  The relationship between amperage, voltage, and watts is given above in the [[#Voltage and Amperage|voltage and amperage section]].&lt;br /&gt;
&lt;br /&gt;
For an example, let us say you want to use battery power to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer].  The specifications say that it uses 1.2 watts as a base value.  The specifications also say that it can take 12 V DC power.  If we choose to use a 12 V battery, at 1.2 watts it will use 0.1 amps according to the equation [[#Voltage and Amperage|shown earlier]].  Going by amp-hours alone, if our battery is a double-wide lantern type 12 V battery, with 7 amp hours, with 0.1 amp draw it will last 70 hours, or almost three days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Maximum Running Days} =\frac{\text{Battery Amp Hours}}{\text{Device Amps} * \text{24}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, to estimate &#039;&#039;average&#039;&#039; running time (rather than maximum running time possible), amp-hours cannot be used so directly.  Over time, batteries decrease in voltage as their power is used up.  Practically speaking, this means one of two things for your load.  For loads that do not regulate voltage or current, the amperage will also decrease over time.  The classic example is an LED light source that grows dimmer and dimmer as the batteries are used up.&lt;br /&gt;
&lt;br /&gt;
You should usually only count on about 60% of the stated amp hour rating to apply before expecting to run into problems from escalated drain due to battery voltage drop.  This is especially true for deep cycle rechargeable batteries left in an installation, where draining more than 60% could also harm the battery.  &lt;br /&gt;
&lt;br /&gt;
Then, for lead-acid batteries, a typical battery is tested from full to complete drain over 20 hours by the manufacturer to obtain the advertised amp-hour rating.  Draining a battery at a faster rate than this will result in even more reduction in capacity, by 10% or even more.  This due to [http://en.wikipedia.org/wiki/Peukert%27s_law Peukert&#039;s Law].&lt;br /&gt;
&lt;br /&gt;
There are plenty of [http://www.google.ca/search?&amp;amp;q=battery+calculator battery calculators] around the Internet which take most or all of these additional factors into account when recommending an amp-hour rating.  For longer-term installations, the solar power online community has some excellent resources.&lt;br /&gt;
&lt;br /&gt;
====Setting up Multiple Batteries====&lt;br /&gt;
You can hook up multiple batteries in series to get more voltage at the same amperage.  The amperage is additive.  For example, you can hook up two single-wide 6 V lantern batteries in series to produce 12 V.  Or two 12 V batteries in series to produce 24 volts.  This system would still only have the amp hours of &#039;&#039;one&#039;&#039; of the lantern batteries, because you will be essentially using them both at once: &lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_series.png|250px]]&lt;br /&gt;
&lt;br /&gt;
The upside down triangle (ground) is explained above in a [[#Ground|section of its own]].&lt;br /&gt;
&lt;br /&gt;
Or, you can hook up multiple batteries in parallel to get more amperage at the same voltage.  For example, you could hook up two 12 V deep cycle batteries in parallel to provide more amperage at 12 V, which is like having a deeper reservoir of power for your device to use:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
====Heat====&lt;br /&gt;
*all batteries have some sort of internal resistance&lt;br /&gt;
*can be found on the battery&#039;s data sheet&lt;br /&gt;
*the more power you pull from the battery the more heat is going to build up as a consequence of the internal resistance.&lt;br /&gt;
*larger internal resistances will cause heat to build up faster.&lt;br /&gt;
*when charging a battery you are not just limited to the power in the battery.  nothing stops you from dumping energy into the battery past the point where it is fully charged&lt;br /&gt;
**this is why charging batteries is a bit of a tricky business.&lt;br /&gt;
**many batteries come with custom chargers that have control systems to prevent this type of overcharging.&lt;br /&gt;
&lt;br /&gt;
====Weight====&lt;br /&gt;
Finally, weight matters - a car battery is much heavier than a lantern battery.  Batteries vary widely by weight per amperage.  Lithium batteries are usually very light for their power, followed by alkaline, followed by lead acid.  This may not seem important at first, but if you are building a mobile robot it is worth calculating in the work of carting around a battery.  You may find that, for the length of time you want it to run, your battery requires some system redesign.&lt;br /&gt;
&lt;br /&gt;
==Selecting Cables==&lt;br /&gt;
&lt;br /&gt;
===USB Cables===&lt;br /&gt;
&lt;br /&gt;
In general, use the shortest cables possible.  There are many reasons for this [[#Emissions and Wires|described above]], but as a summary:&lt;br /&gt;
&lt;br /&gt;
; Long cables reduce the voltage that reaches the Phidget.&lt;br /&gt;
: This happens in both directions.  So, for every unit cable length added, the voltage decreases by twice the electrical resistance of that length of cable. With especially long cables the Phidget may drop below its 4.6 volt threshold and simply never turn on.&lt;br /&gt;
&lt;br /&gt;
; Long cables increase the width of your circuit.  &lt;br /&gt;
:All circuits act as emitting antennas for the resonance frequency of the circuit structure.  The longer the wires in the circuit, the lower the frequency, and the higher chance that it will be emissions that will interfere with your data and system.&lt;br /&gt;
&lt;br /&gt;
; Longer cables have more length exposed to external interfering emissions.&lt;br /&gt;
&lt;br /&gt;
Also, use thick cables that are built to specification.  Some USB cables with thinner wiring have higher electrical resistance.  This can be equal to what a much longer wire would have, and thus create a similar voltage drop where the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
====Options for longer cables====&lt;br /&gt;
The maximum length for a USB cable is 5m.  This is laid out in the USB specifications.  Often times however a system requires more reach.  In this case there are a few options available to you.  You can use what is known as an active extension cable or USB extender.  These cables act like extension cables and add power to the line so that the signal can travel further.  A second option is to use a Cat5 extender.  These extenders are 2 USB dongles that connect on either end of your system.  You join them up with Cat5 cable.  This allows you to run over much longer distances than USB traditionally allows.&lt;br /&gt;
&lt;br /&gt;
===Power Cables===&lt;br /&gt;
&lt;br /&gt;
There are &amp;quot;DC Wire Table&amp;quot; references on the Internet which describe how to pick a wire appropriate for your voltage and amperage.  When selecting AC wires, you will probably be using pre-made extension cords.  Cords add interference resonance length to your circuit, just like USB cables do as [[#USB Cables|described above]].  A long extension cord can create huge electromagnetic interference for your circuit and other systems in the area when first plugged in.&lt;br /&gt;
&lt;br /&gt;
Also as with the USB cables above, cut the cables to the shortest length possible.  This is again both for voltage drop reasons and frequency emission reasons.&lt;br /&gt;
&lt;br /&gt;
===Hubs===&lt;br /&gt;
&lt;br /&gt;
Avoid hubs where possible.  Unpowered hubs are good for reading data from memory keys, but not for powering many external devices.  If you must use a hub, buy a powered one.&lt;br /&gt;
&lt;br /&gt;
===Sensor and Motor Wiring===&lt;br /&gt;
All Phidgets sensor class devices (products whose part numbers start with 11 such as the 1129) use a 3 channel ribbon cable for power and data transmission.  Similarly, all our motors and load cells use multichannel wire interfaces.  As mentioned previously, USB spec limits cables to 5m, this is not the case for these wires.  The biggest concerns are electromagnetic interference (EMI) and voltage drop.  In general you should be able to run these wires over significant distances (30m or more) with the load cells in particular having very long range.  If EMI starts causing issues you can always use ferrite beads on the cable near the sensor or motor and the controller to reduce noise.&lt;br /&gt;
&lt;br /&gt;
===Cable Gauges for Terminal Blocks===&lt;br /&gt;
&lt;br /&gt;
Many Phidgets products feature green terminal blocks that use screws to hold wires in place, making it easy to take apart and rebuild connections in your project. The size of the terminal block determines the gauge of wire you should use.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Terminal Block Size and Wire Gauge&#039;&#039;&#039;&lt;br /&gt;
! Terminal Block Width (mm/port)&lt;br /&gt;
! Recommended Wire Gauge (AWG)&lt;br /&gt;
|-&lt;br /&gt;
| 3.81&lt;br /&gt;
| 14 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 5.0&lt;br /&gt;
| 12 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 9.5&lt;br /&gt;
| 10 to 26&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The gauge of cables and wires is measured in AWG, which is the American Wire Gauge standard. The following table lists the properties of wire gauges commonly used with Phidgets:&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;American Wire Gauge Sizes&#039;&#039;&#039;&lt;br /&gt;
! AWG Size&lt;br /&gt;
! Diameter (mm)&lt;br /&gt;
! Area (mm²)&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| 2.588&lt;br /&gt;
| 5.26&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| 2.305&lt;br /&gt;
| 4.17&lt;br /&gt;
|-&lt;br /&gt;
| 12&lt;br /&gt;
| 2.053&lt;br /&gt;
| 3.31&lt;br /&gt;
|-&lt;br /&gt;
| 13&lt;br /&gt;
| 1.828&lt;br /&gt;
| 2.62&lt;br /&gt;
|-&lt;br /&gt;
| 14&lt;br /&gt;
| 1.628&lt;br /&gt;
| 2.08&lt;br /&gt;
|-&lt;br /&gt;
| 15&lt;br /&gt;
| 1.450&lt;br /&gt;
| 1.65&lt;br /&gt;
|-&lt;br /&gt;
| 16&lt;br /&gt;
| 1.291&lt;br /&gt;
| 1.31&lt;br /&gt;
|-&lt;br /&gt;
| 17&lt;br /&gt;
| 1.150&lt;br /&gt;
| 1.04&lt;br /&gt;
|-&lt;br /&gt;
| 18&lt;br /&gt;
| 1.024&lt;br /&gt;
| 0.823&lt;br /&gt;
|-&lt;br /&gt;
| 19&lt;br /&gt;
| 0.912&lt;br /&gt;
| 0.653&lt;br /&gt;
|-&lt;br /&gt;
| 20&lt;br /&gt;
| 0.812&lt;br /&gt;
| 0.518&lt;br /&gt;
|-&lt;br /&gt;
| 21&lt;br /&gt;
| 0.723&lt;br /&gt;
| 0.410&lt;br /&gt;
|-&lt;br /&gt;
| 22&lt;br /&gt;
| 0.644&lt;br /&gt;
| 0.326&lt;br /&gt;
|-&lt;br /&gt;
| 23&lt;br /&gt;
| 0.573&lt;br /&gt;
| 0.258&lt;br /&gt;
|-&lt;br /&gt;
| 24&lt;br /&gt;
| 0.511&lt;br /&gt;
| 0.205&lt;br /&gt;
|-&lt;br /&gt;
| 25&lt;br /&gt;
| 0.455&lt;br /&gt;
| 0.162&lt;br /&gt;
|-&lt;br /&gt;
| 26&lt;br /&gt;
| 0.405&lt;br /&gt;
| 0.129&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Hooking Up The Pieces==&lt;br /&gt;
&lt;br /&gt;
Here, things can be tricky.  You might think: just plug everything in and go!  But often it is not that simple.  Many Phidgets require special care when hooking up.  We encourage a process where you apply the concepts in this Primer, through analysis, to your system.  So, we don&#039;t explicitly list the boards most commonly affected until the [[#Affected Products|end of this Primer]].&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;categories&#039;&#039; of the boards which require special attention within a complex system are:&lt;br /&gt;
&lt;br /&gt;
# Phidgets with more than one power source, and&lt;br /&gt;
# Phidgets needing precise measuring or control of an external power source&lt;br /&gt;
&lt;br /&gt;
If you are already thinking about your boards in your head and trying to figure out whether they fit into one category or another, you&#039;re on the right track!  The list of [[#Affected Products|commonly affected boards]] are only the common ones... with a sufficiently complex system, you could conceivably create problems with &#039;&#039;any&#039;&#039; boards.&lt;br /&gt;
&lt;br /&gt;
Both types of projects require a full understanding of [[#The Basics|electrical basics]].  Using those concepts, below we first describe problems that arise when hooking up different power sources, and extend that into using the solution to give more precise measurement and control.  &lt;br /&gt;
&lt;br /&gt;
===Shared Grounds===&lt;br /&gt;
&lt;br /&gt;
Shared grounds can occur in Phidgets that handle two different power sources.  Recognizing the sharing of a ground is not always easy.  We show what it is, how it can be possible, and why it creates problems by starting with the most basic Phidget system.  The simplest setup for a Phidget is to use the [[#Ground|ground]] of the computer it gets data and power from over a USB port:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_simple_case.png]]&lt;br /&gt;
&lt;br /&gt;
In this case, there is only one relative ground, and it is the PC ground, which is ground #1 in the image.  The PC ground determines what is considered 0 volts for all signals on the Phidget.  When you add different power sources or sinks in the system, you are pulling the system relative to the PC ground.  &lt;br /&gt;
&lt;br /&gt;
=====One Powered Phidget=====&lt;br /&gt;
&lt;br /&gt;
The next most complicated system is one Phidget that handles two power sources.  Let us say you have a motor controller, which takes power from USB, and which also takes power from a second power source.  Although the second power source is usually just a wall plug, the simpler case for thinking about ground is actually a battery.  A battery creates a second &#039;&#039;relative&#039;&#039; ground.  Through the Phidget, relative ground #1 (from the PC) and #2 (from the battery) actually become the same ground:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_wall_power.png]]&lt;br /&gt;
&lt;br /&gt;
This is the first reason why systems with powered Phidgets have to carefully manage ground.  If ground #1 and ground #2 are different with respect to each other (see the static shock analogy in the [[#Ground|ground section]] above), then whatever circuitry along the red dashed arrow must deal with the initial static shock.  In this case it would be the circuitry of the Phidget.  In the case of a battery, after the initial equalizing shock the battery will be whatever relative voltage the PC ground needs it to be.  Hence a battery relative ground can &#039;float&#039;.&lt;br /&gt;
&lt;br /&gt;
If ground #2 comes from the wall, on the other hand, the ground does not &#039;float&#039; and instead is always absolute 0 volts Earth ground.  With the PC giving the power, this is not a problem in practice because the PC can also float (as with a laptop), or it uses Earth ground.  But if you were using a different and more powerful USB power supply instead of a PC, and then connected it to the absolute Earth ground through the Phidget, the Phidget would bear the brunt of any ground equalization that would occur.  If neither the new ground nor the old ground float, and the power supplies were powerful enough, this would eventually destroy the Phidget.  In this case, you would want to use isolation, as described in [[#How To Fix This|How To Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Multiple Powered Phidgets=====&lt;br /&gt;
&lt;br /&gt;
A worse case comes in when you are using two powered Phidgets and one external power source.  Again, say you are using a battery as the external power source.  It would be tempting to simply wire both grounds from the Phidgets to the ground on the battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_phidget.png]]&lt;br /&gt;
&lt;br /&gt;
Although this looks benign, you have actually created a new circuit.  The circuit is a second path, via ground, for the current to return to the voltage source.  This is also known as a &#039;&#039;&#039;ground loop&#039;&#039;&#039;. The path we intuitively think of the current returning by is  &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;, but the sharing of grounds has created a new path through the motherboard, &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_paths.png]]&lt;br /&gt;
&lt;br /&gt;
All current gets &#039;pumped&#039; in a loop by voltage, and so it will use all return paths available to it, assuming all paths are equally easy (electrically) to use.  This extends the pipe analogy, where water will flow in every path that exists.  So, if your battery (or other power source with ground #2) is quite powerful, you can actually harm your motherboard within your PC (or at least your USB bus ground), because &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039; runs through the motherboard circuitry on the way back to the voltage source.&lt;br /&gt;
&lt;br /&gt;
This problem does &#039;&#039;not&#039;&#039; apply to using a different power source between a black power plug and for the green control terminal block on, say, a [[DC Motor and Controller Primer|DC motor controller]].  Although the grounds are connected, and they run across a part of a Phidget board, creating a ground loop does not actually run through any circuitry if only these types of boards are used.  If you have a complex system with other types of boards and therefore circuitry between black plug power port and green terminal block connections, draw out your system carefully to identify the loops.&lt;br /&gt;
&lt;br /&gt;
Ground loops can be fixed by one of the ways described in [[#How To Fix This|How to Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Single Board Computer And Powered Hub=====&lt;br /&gt;
&lt;br /&gt;
When combining one externally powered Phidget and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] or the [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]] on the same external power source, you still may inadvertently create a ground loop as described above in [[#Multiple Powered Phidgets|the multiple powered Phidgets section]].  If they share a true [[#Ground|Earth ground]], this is not a problem.  But if the ground is from a battery, or uninterruptible power supply, etc. then you should carefully draw out your system circuit and examine it for ground loops.&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
Once you are aware of shared grounds in your system, you have two options.  &lt;br /&gt;
&lt;br /&gt;
One, for ground loop problems in simple systems (two Phidgets), you could make the normal return path (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;) the most electrically desirable path.  This is best for simple systems where you have a lot of control over all of the ground wires within your system.  For the ground wires leading directly from the Phidget to the external power supply (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;), lower the resistance in the wire as much as possible.  You can do this by keeping the wires short, and using a thick (large gague) wire for the hookups.  &lt;br /&gt;
&lt;br /&gt;
Although this solution works, sometimes you do not have much choice on how long your ground return wires can be, because the location of your power supply and and Phidgets are set by your system design.  If you cannot be totally sure that the direct ground path is the shortest and most electrically desirable path, it is best to use the second option: a &#039;&#039;&#039;USB Isolator&#039;&#039;&#039; such as the [[Product - 3060 - USB Isolator|Phidget 3060]].  This isolator is like any other USB isolator - it can be used on a Phidget system, as well as any system that needs ground isolation.&lt;br /&gt;
&lt;br /&gt;
You need isolators for every USB cable in your system, less one.  If you have two USB connections, you need one isolator; three USB connections, two isolators, and so on.  The one USB connection can remain non-isolated because a single ground connection cannot form a loop.  However, if you are concerned about connecting the grounds as described in the [[#One Powered Phidget|single connected Phidget section above]], use a USB isolator on every cable.&lt;br /&gt;
&lt;br /&gt;
===Precise Voltage Control===&lt;br /&gt;
&lt;br /&gt;
Precise voltage (or other system) control and measurement is related to the concept of [[#Shared Ground|shared ground above]].  But here, you want to keep grounds separate not only to prevent ground loops, but also to make your system more sensitive to what it will control or measure.&lt;br /&gt;
&lt;br /&gt;
For example, we make Phidgets that can create power precisely, or that can take it in and measure it.  One such product is the 1002, which outputs a precise analog voltage with which to control an analog system.  Now that you know about [[#Ground|relative ground]], however, you would be right to expect that you do not want to combine the ground in the PC and the ground in the system.&lt;br /&gt;
&lt;br /&gt;
Even if you don&#039;t care about system sensitivity, you can still create [[#Multiple Powered Phidgets|ground loops]] in a system with multiple of these types of Phidgets.  In addition, if you are using the Phidget to control a large, powerful system, even a single Phidget can receive damage from connecting two powerful power sources meeting across it, also as [[#One Powered Phidget|described earlier]].&lt;br /&gt;
&lt;br /&gt;
But above and beyond the powered Phidget problems, there is another reason to separate (isolate) the electrical grounds in your system.  The reason is: to make your system control more precise.  For example, with the 1002, if you are trying to control an external system with an Phidget output voltage, that output voltage should be relative to the &#039;&#039;system you are trying to control&#039;&#039;, not relative to the PC.  Rather than forcing the grounds - and therefore the relative voltages - to be equal to each other, you can provide more precise control by isolating the grounds and working with the relative voltage of the controlled system on its own terms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Schematic-type image of a ground isolated analog out on a 1002&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
The solution to all of these problems in precise voltage control systems is to use USB isolation, even for a single Phidget.  The [[Product - 3060 - USB Isolator|Phidget 3060]] is one such isolator.  It inserts along the USB connection between your PC and the Phidget, and it separates the Phidget (and controlled system) ground from the PC ground.  This fixes ground loops, separates relative voltage mis-matches, and isolates the control system for better precision.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Image of 1002 and Isolator connected, with lines superimposed on the image to show non-copper connection in isolator&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Affected Products==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure whether a certain concept applies to your Phidget within a complex system, the best way to figure this out is by doing some mental (or pencil and paper) simulation.  Draw the inputs and outputs for the entire board, and label them with voltage, list their required amperage (or watts), and draw connections (such as ground connections) through any circuitry.  &lt;br /&gt;
&lt;br /&gt;
With a technique like this, it is easy to see that some products - such as the [{{SERVER}}/products.php?product_id=1049 Phidget Spatial] - are simply not complex at all. Although you could conceivably create problems (such as by using separate power supplies instead of using USB power and connecting the grounds incorrectly, or by using really long wires), this would be an exceptional case.  &lt;br /&gt;
&lt;br /&gt;
Other Phidgets can be more easily used incorrectly without realizing it.  These are often devices that are simple in some systems and yet complex in others.  Your primary defense against designing unreliable systems is to draw the system out and identifying any problems using the concepts in this primer. To help you, however, you can generally think of two classes of Phidgets which usually need careful handling when they are part of complex systems:&lt;br /&gt;
# Phidgets with more than one power source, (these can be subject to the [[#Shared Grounds|multiple power source problems]] described above)&lt;br /&gt;
# Phidgets needing precise measuring of an external power source (these can be subject to the [[#Shared Grounds|multiple power source problems]] &#039;&#039;and&#039;&#039; [[#Precise Voltage Control|precise voltage control]] problems)&lt;br /&gt;
&lt;br /&gt;
Expanded into individual products, the Phidgets which are most often affected are.....&lt;br /&gt;
&lt;br /&gt;
# These Phidgets use a second type of external power:&lt;br /&gt;
#* Motor controllers &lt;br /&gt;
#**{{LinksNeeded|DC Motors and Controllers|[[DC Motor and Controller Primer|DC controllers]]}}&lt;br /&gt;
#**[[Stepper Motor and Controller Primer|Stepper controllers]]&lt;br /&gt;
#**{{LinksNeeded|Servo controllers|[[Servo Motor and Controller Primer|Servo controllers]]}}&lt;br /&gt;
#* Pure relay boards &lt;br /&gt;
#**[[Solid State Relay Primer|Solid state relay boards]]&lt;br /&gt;
#**[[Mechanical Relay Primer|Mechanical relay boards]]&lt;br /&gt;
#* Interface kits with relays &lt;br /&gt;
#**[{{SERVER}}/products.php?product_id=1017 1017 - PhidgetInterfaceKit 0/0/8]&lt;br /&gt;
#**[{{SERVER}}/products.php?product_id=1014 1014 - PhidgetInterfaceKit 0/0/4]&lt;br /&gt;
#* Powered Digital Output Interface Kits &lt;br /&gt;
#** [{{SERVER}}/products.php?product_id=1012 1012 - PhidgetInterfaceKit 0/16/16]&lt;br /&gt;
#* Interface Kits with Powered Hubs&lt;br /&gt;
#** The [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]&lt;br /&gt;
#** [{{SERVER}}/products.php?product_id=1019 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]&lt;br /&gt;
# And these Phidgets may have a need to be sensitive to external power:&lt;br /&gt;
#* {{LinksNeeded|Thermocouple|[[Temperature Sensor Primer|Thermocouple]]}} control&lt;br /&gt;
#* Analog Output ([{{SERVER}}/products.php?product_id=1002 1002 - PhidgetAnalog 4-Output])&lt;br /&gt;
#* Frequency Counter ([{{SERVER}}/products.php?product_id=1002 1054 - PhidgetFrequencyCounter])&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
&lt;br /&gt;
This page should have helped you to: &lt;br /&gt;
*Choose a power supply from either the [[#Wall Power|wall]] or a [[#Battery Power|battery]]&lt;br /&gt;
*Properly [[#Ground|ground]] and/or [[#How To Fix This|isolate]] that power supply from looping through other circuitry&lt;br /&gt;
*Also use [[#How To Fix This|isolation]] to make your control or measurement system more precise&lt;br /&gt;
*Keep your cables short and thick to reduce electromagnetic emissions and limit voltage drop&lt;br /&gt;
*Be more aware of system-wide power problems in general, and use drawing and analysis of systems to identify problems&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
===Memory Effect===&lt;br /&gt;
Memory effect is an effect observed in NiCd batteries that causes them to hold less charge.  It pertains to the specific situation in which NiCd batteries lose their maximum capacity if they are repeatedly recharged without being fully discharged.  The battery appears to remember the smaller capacity.  The term is often misused in cases where other batteries seem to hold less charge than originally, however this is most likely due to age and use.  This phenomenon is unique NiCd batteries.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20731</id>
		<title>Electricity Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20731"/>
		<updated>2012-06-29T21:51:33Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Affected Products */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Design of reliable systems is really, really hard.  The main challenge is the design of reliable building blocks - i.e. circuit and board layouts - from which to create your system.  Phidgets does the majority of this work for you.  And, once you have reliable building blocks, designing a reliable system from them is much easier.  &lt;br /&gt;
&lt;br /&gt;
However, you can still make an unreliable system out of Phidgets.  In fact, if you are building a more complex system than the common examples we show through our documentation, and you have limited experience in complex electrical design, you will probably - and unintentionally - introduce design flaws that will make your system unreliable.&lt;br /&gt;
&lt;br /&gt;
There are two reasons why you should read this primer:&lt;br /&gt;
# You want to build a complex system, more complex than we illustrate in our documentation.  To succeed, you need to understand concepts.&lt;br /&gt;
# You understand how to make your system work, and you want to ensure it is well designed for maximum reliability and/or precision.&lt;br /&gt;
&lt;br /&gt;
==The Basics==&lt;br /&gt;
&lt;br /&gt;
To understand our discussion of potential problems and their solutions below, you&#039;ll need to be familiar with the basics.  For this page, &#039;being familiar&#039; means more than simply having heard of voltage, amperage, and power.  You will need to have a working, conceptual model in your head, so that you can apply that model to your own system and examine it for problems.  This section is all about giving the tools to build that mental model.&lt;br /&gt;
&lt;br /&gt;
First, some terminology.  We introduce it by analogy.  If a circuit is a water system,&lt;br /&gt;
* The &#039;&#039;&#039;voltage&#039;&#039;&#039; is the &#039;&#039;pressure&#039;&#039; in the system&lt;br /&gt;
* The &#039;&#039;&#039;power supply&#039;&#039;&#039; is the &#039;&#039;pump&#039;&#039; creating the pressure&lt;br /&gt;
* The &#039;&#039;&#039;amperage&#039;&#039;&#039;, also known as current, is the amount of &#039;&#039;flow&#039;&#039;&lt;br /&gt;
* The &#039;&#039;&#039;load&#039;&#039;&#039; is the &#039;&#039;faucet&#039;&#039; - adjusting your load will adjust the flow&lt;br /&gt;
* The &#039;&#039;&#039;resistance&#039;&#039;&#039; is an attribute of the load - how tight or loose the faucet is&lt;br /&gt;
* The &#039;&#039;&#039;ground&#039;&#039;&#039; is the return path from load to pump.&lt;br /&gt;
&lt;br /&gt;
The basic concepts for all of these terms are presented below.&lt;br /&gt;
 &lt;br /&gt;
===Load===&lt;br /&gt;
&lt;br /&gt;
We start with the load, because the load is the purpose of your entire system.  &lt;br /&gt;
&lt;br /&gt;
In simple, USB-only Phidget systems, the load is the Phidget itself.  The USB port is ready to provide power, but it does not (and cannot) until a load is applied (i.e. the Phidget is attached) and the circuit is completed.  &lt;br /&gt;
&lt;br /&gt;
Without a load that connects in a loop, it is like attaching a closed pipe to your pump.  Initially, water will fill the pipe, and pressurize it, but once the pipe fills the system as a whole will do nothing more.  To allow the pump to drive the load, and the flow to supply the load, we need to have a completed circuit, like this:&lt;br /&gt;
 &lt;br /&gt;
[[Image:elec_flow.png|150px]]&lt;br /&gt;
&lt;br /&gt;
The load and the pump must &#039;&#039;&#039;match&#039;&#039;&#039;.  If the load lets too much flow through, the pump will work too hard and burn itself out.  This is what happens when you short circuit a power supply.  The load is then simply a wire, which basically opens the flood gates and drains your power supply pump.  The load must not let too much flow through, which it does by &#039;&#039;&#039;resistance&#039;&#039;&#039;. Likewise, the pump cannot push too hard on the load, or the load will break.  This is discussed in-depth as part of [[#Voltage and Amperage|Voltage and Amperage]] below.&lt;br /&gt;
&lt;br /&gt;
===Voltage and Amperage===&lt;br /&gt;
&lt;br /&gt;
Within the flow concept [[#Load|above]], voltage is pressure.  Specifically, it is the &#039;&#039;difference&#039;&#039; in pressure between the flow and the return.  Voltage is measured in volts, and is denoted by &#039;&#039;&#039;V&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Amperage - also known as current - is the flow, or the amount of water that moves.  At the pump, the amount of current out and the amount of current in are equal.  The pressure might vary widely (highly pressurized pipes out, low pressure pipes back) but the &#039;&#039;amount&#039;&#039; of current is always the same.  Amperage is measured in Amps, and is denoted by &#039;&#039;&#039;A&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To match a pump to a load, the voltage and amperage of the power (supply) and load (sink) must line up.  We discuss picking a power supply - whether [[#Wall Power|wall mains]], or [[#Battery Power|batteries]] - in the [[#Power Needs|Power Needs section]] farther along in the document, but we need a few more concepts before we get there.&lt;br /&gt;
&lt;br /&gt;
Power supplies - whether wall power or batteries - are usually rated based on voltage and amperage.  Voltage is the specification to be the most careful with for circuits.  Too much voltage is the same as overpressurizing your pipes - they will burst.  In the case of electronics, you device will break.  &lt;br /&gt;
&lt;br /&gt;
This can be counterintuitive - in reference to safety (for humans) around electronics, you may have heard &amp;quot;It is not the voltage that will kill you, it is the amperage&amp;quot;.  Because of this, it may be tempting to think that too high of an amperage will harm your device, but this is not true.  Our hearts are very susceptible to amperage but not voltage, hence amperage is considered dangerous for us whereas voltage is not.  But a circuit is not like a human body - in a circuit trying to handle a power supply it is the voltage that matters most.  &lt;br /&gt;
&lt;br /&gt;
====Set Voltage (No Control)====&lt;br /&gt;
&lt;br /&gt;
Most loads do no power regulation of their own.  They simply take the voltage given to them and do useful things with it.  You can tell that a pre-designed load (like a Phidget) falls into this category because it gives its voltage need &#039;&#039;as an exact value&#039;&#039;.  For example, most Phdigets use exactly 5 V of USB power.  These loads will also tell you their amperage, which is a flow need that must be met or exceeded.  A load will only use as much amperage as it needs.&lt;br /&gt;
&lt;br /&gt;
====Controlled Power====&lt;br /&gt;
&lt;br /&gt;
Some loads change the voltage or current they receive.  This can be with the intent to either (a) keep a constant amount of power flowing from a draining power source like batteries, or (b) to modify a common power source (i.e. 12 V at 1 A) into an uncommon power source (i.e. 1 V at 12 A).  This process is called &#039;&#039;&#039;regulation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can tell that a pre-designed load (like a Phidget) falls into this &amp;quot;power-regulated device&amp;quot; category because it gives its voltage need &#039;&#039;as a range&#039;&#039;. For example, the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer (SBC)] can take 6 V to 15 V.  &lt;br /&gt;
&lt;br /&gt;
To understand how this works, take the example of a flywheel.  Flywheels are designed to be heavy and to take work in order to get them spinning at speed.  But once you have them spinning, you can extract that work later at a more consistent rate:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flywheel.png]]&lt;br /&gt;
&lt;br /&gt;
Flywheels can either make amperage or voltage be the more consistent blue line over time.  The most common one in Phidgets is for stable amperage.  Regulated amperage is also how LED lights can stay consistently bright for any length of time when using batteries.  Stable voltage design is usually applied when the voltage is too low to begin with (such as any device that runs on a single AA battery), and the flywheel must amplify and stabilize it over time.&lt;br /&gt;
&lt;br /&gt;
For those readers trying to envision how this works electrically, in practice the flywheel is an inductor (or, a transformer utilizing its inductor properties).  For both voltage and amperage regulation, one way relief valves (diodes) must be added. And, in amperage regulation a reservoir (capacitor) must be added to offset the current drop by pulling &#039;&#039;more&#039;&#039; amperage as a battery drains.  Then, a controller is needed to measure and then correspondingly enable and disable the flywheel system as the voltage or amperage drops from the supply.  &lt;br /&gt;
&lt;br /&gt;
But with those details in place, the inductor (and capacitor, in the case of amperage regulation) can effectively take the variety of voltages from, say, a draining battery, and still allow the board to run.  Some devices even do this naturally.  For example, motors often can take a variety of voltages because their construction (i.e. wire wrapping) naturally creates inductance.&lt;br /&gt;
&lt;br /&gt;
These regulated systems often list the power they need directly, using a type of power rating called &#039;&#039;&#039;watts&#039;&#039;&#039;.  Watts are voltage and amperage together (i.e. power):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Amperage} =\frac{\text{Watts}}{\text{Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Watts can be a handy way to describe flow and pressure together for these regulated devices.  Rather than separating voltage and amperage like the unregulated devices do (i.e. this load needs exactly 12 V, or this load will draw exactly 2 A), the unit of watts will allow different value combinations of volts and amps as long as the wattage remains the same.  For example, a 12 watt device with a voltage range of 5 to 12 volts can run on 6 V at 2 A, or 12 V at 1 A.  Either will work.  Amperage for all values in the device&#039;s range of 5 to 12 V can be found with the equation above.  Because of this, watts are often preferred when trying to match a power supply to a regulated load.&lt;br /&gt;
&lt;br /&gt;
===Ground===&lt;br /&gt;
&lt;br /&gt;
All circuits have a &#039;&#039;&#039;ground&#039;&#039;&#039;.  This is simply the return pipe to the pump.  In a circuit, it is denoted by an upside-down triangle:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground.png]]&lt;br /&gt;
&lt;br /&gt;
When drawing a circuit diagram, the symbol is placed on the wires that return to the pump:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flow_ground.png|170px]]&lt;br /&gt;
&lt;br /&gt;
This electric ground provides a voltage reference throughout the circuit.  Ground is always &#039;&#039;&#039;0&#039;&#039;&#039; volts as far as the circuit is concerned. (Remember, voltage is the &#039;&#039;difference&#039;&#039; between the flow and return pipes at the pump.)  Ground is important because it provides a reference from which all the parts of the circuit can speak the same &amp;quot;voltage language&amp;quot; to each other, which matters a lot when a certain voltage means &amp;quot;1&amp;quot; and a certain voltage means &amp;quot;0&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
There is only one &#039;&#039;&#039;absolute&#039;&#039;&#039; ground, and that is the Earth, which is taken to be 0 volts as an absolute value.  Circuits not well-grounded to the Earth (of which there are many - your cell phone, car, etc) operate at a &#039;&#039;&#039;relative&#039;&#039;&#039; voltage.  The upside-down triangle above denotes a &#039;&#039;relative&#039;&#039; ground.&lt;br /&gt;
&lt;br /&gt;
With relative voltage, only the difference between local ground and the local high voltage matters.  For example, a cell phone might operate as a 3 volt device, which means relative to its ground it always operates between 0 and 3 volts.  But if that cell phone were compared carefully to Earth ground, its absolute voltage could be, say, between 10 and 13 volts.  Until comparison, the device doesn&#039;t &amp;quot;feel&amp;quot; charged.  This is the same as how you don&#039;t &amp;quot;feel&amp;quot; charged after skidding your feet in socks across a carpeted floor.  But, when you &amp;quot;compare&amp;quot; yourself to Earth ground by touching some well-grounded metal, you receive a static electricity shock.&lt;br /&gt;
&lt;br /&gt;
The same thing can happen when you combine two different power supplies, as we discuss [[#Projects With Different Power Sources|below]].&lt;br /&gt;
&lt;br /&gt;
===Power===&lt;br /&gt;
&lt;br /&gt;
There can be different types of pumps, and at this point we should supplant our heart symbol with some actual power supply pump symbols.  For example, this is the symbol for a direct current (DC) battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
The + end is on the out flow, and the - end is on the return (ground).  Batteries are usually listed with their voltages.  This is because the resistance of the load will determine how much amperage is drawn, but too much voltage and you will harm your load.&lt;br /&gt;
&lt;br /&gt;
This is the symbol for alternating current (AC) that you would get directly from the wall:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_wall_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
Again, this is listed using voltage for the same reasons as DC.  A relative ground symbol is still used on the return line here.  AC devices can still operate on relative voltage if they do not use Earth ground (the third prong on a wall plug in North America).  This is how some loads have AC cords with only two prongs - they operate on a relative voltage and relative ground.  And relative AC voltage, having significantly more voltage (pressure) behind it, can really hit a device hard when two power supplies meet across it.&lt;br /&gt;
&lt;br /&gt;
This connecting of multiple power supplies is quite a complex subject, and is described further in both [[#Power Needs|picking different power supplies]] and [[#One Powered Phidget|connecting different power supplies]] later on in this Primer.&lt;br /&gt;
&lt;br /&gt;
===Emissions and Wires===&lt;br /&gt;
&lt;br /&gt;
To talk about emissions, it is worth speaking more precisely about what a load is.  The typical, simple Phidget setup is receiving 5 V direct current (DC) from the computer over the USB port.  Let&#039;s model this as coming from a battery so that we can examine all parts of the system.  From the point of view of the battery, the Phidget load is not just the green board with the circuitry on it.  The load &#039;&#039;also&#039;&#039; includes the power cable (i.e. two wires in the USB cable), and anything else on the path out or back from the circuitry to the battery itself:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
This is important because the wires play a role in the voltage that eventually makes it to the Phidget.  This is true all the time, even when the Phidget is attached to a computer instead of a battery.  All wires have some resistance, and so they are, in a way, in and of themselves circuits.    Therefore, because of their resistance, the wires &#039;use&#039; some of the 5 V heading out to the Phidget circuit board.  This is discussed more below, but essentially longer cables have more resistance and at some point the voltage will drop so much over the length that the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
To conceptually separate the wires from the Phidget in terms of the load, we can now start drawing the wires themselves in our circuit diagram, instead of the curved concept arrows indicating flow and return:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wires.png|200px]]&lt;br /&gt;
&lt;br /&gt;
When talking about the 5V relative ground in this system, we are in fact talking about the ground &#039;&#039;right at the battery&#039;&#039; so we move the ground symbol to the battery itself.&lt;br /&gt;
&lt;br /&gt;
Then, the resistance on these wires creates a possible problem - the emission of electromagnetic radiation as the wires naturally drop the voltage:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_emissions.png|200px]]&lt;br /&gt;
&lt;br /&gt;
These emissions are at a set frequency determined by the length of the wire:&lt;br /&gt;
* Long wires create low frequencies (harmful interference)&lt;br /&gt;
* Short wires create high frequencies (less harmful interference)&lt;br /&gt;
&lt;br /&gt;
This can be minimized by having the flow and return wires be the same length and sit right next to each other.  This way, the emissions somewhat cancel each other out from the flow and return going in opposite directions.  This is partially how USB cables minimize emissions.&lt;br /&gt;
&lt;br /&gt;
So, the way you design your connections (i.e. the resistance and placement of your wire) will have a direct affect on:&lt;br /&gt;
# The voltage that reaches the Phidget&lt;br /&gt;
# The emissions that your system produces&lt;br /&gt;
&lt;br /&gt;
With all this talk of emissions, you might be tempted to try to shield parts or all of your system from emissions that either your system or external systems create.  &lt;br /&gt;
&lt;br /&gt;
Keep in mind that shielding is actually really hard to do correctly.  Especially when grounding your shielding, with ad-hoc design you have a high chance of having an interfering signal (that has traveled out to the shield and traveled back via ground) creating a larger problem than not having a shield at all.  Rather than shielding, it is easier to simply keep your cables short and with as low a resistance as possible throughout your system to minimize your emissions in the first place.&lt;br /&gt;
&lt;br /&gt;
Identification of and solutions to these (and other more complex) problems are discussed in detail in the [[#Selecting Cables|section on choosing cables]] and the [[#Hooking Up The Pieces|section on connecting the pieces]] below.&lt;br /&gt;
&lt;br /&gt;
===Multiple Loads===&lt;br /&gt;
&lt;br /&gt;
The easiest way to hook up multiple Phidgets is in parallel, where the voltage stays the same but they share the amperage.  Here the DC supply is two USB ports, each at 5 V and 0.5 A:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
However, the length of your wires comes into play again, because the voltage that actually reaches the Phidgets above is somewhat less than 5 V.  So if your wires are long, or mismatched, the voltage may not match and will give you strange results.  The voltage is both affected on the way out, and on the way back.  Assuming the wires are the same length:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wire_drop.png|350px]]&lt;br /&gt;
&lt;br /&gt;
In this way, you can create difficult-to-debug problems within a complex system, where one Phidget works but others mysteriously fail.&lt;br /&gt;
&lt;br /&gt;
==Power Needs==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve understood the basics, it is time to actually talk about decisions and design.  This section will help you choose a power supply for your Phidget.  Let&#039;s say you want to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] off of a battery.  Or you want to run a motor controller with a power supply you bought from the hobby store.  What do you need to buy?  Will one you already have work?  It is worth it to spend a moment with pencil and paper to work through this section and identify your power needs.&lt;br /&gt;
&lt;br /&gt;
As described [[#Voltage and Amperage|earlier]], voltage is pressure. Too much pressure behind your faucet, and the water mains or faucet will break.  Likewise, if you have too much voltage from a power supply, your circuit will break.  You should choose a supply with voltage that &#039;&#039;matches the range the Phidget can accept&#039;&#039;.  The voltage cannot be over the maximum (otherwise, like pressure in a pipe, the pipe will burst), and the voltage cannot be under the minimum (otherwise, like pressure in a pipe, no flow will occur).  Also, generally, a device (like a motor controller) will perform better at its maximum rated voltage if a range is available.&lt;br /&gt;
&lt;br /&gt;
But the faucet doesn&#039;t care whether there is a big reservoir or small reservoir feeding the system, as long as the pressure is managed.  Likewise, you can choose a power supply with more amperage than you need (a big reservoir to draw from) as long as the voltage matches.  In the same way that a faucet restricts water by design, loads draw and allow only the amperage that they need. However, the amperage cannot be less than the Phidget needs.  In that case, you will either overextend (and break) your power supply, or the circuit simply will not turn on at all.&lt;br /&gt;
&lt;br /&gt;
The specification [[#Device List|for your specific device]] will list its power needs. For most devices, the external power supply needs will simply be listed in voltage and amperage.  USB power is 5V at up to 500 mA (0.5 Amps).  Most Phidgets will draw less than this - if you need precision, you can check the specification for your particular Phidget.  And, if it is an Interface Kit, you can add the draw of each analog sensor and digital in/out from their specifications.&lt;br /&gt;
&lt;br /&gt;
However, some Phidgets (e.g. motors, and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]) do not have a straight amperage and voltage specification.  Instead, their power draw will be listed in watts, for which you [[#Voltage and Amperage|saw a relation earlier]] to convert to the values you need.&lt;br /&gt;
&lt;br /&gt;
===Wall Power===&lt;br /&gt;
&lt;br /&gt;
Wall power sources usually take the alternating current (AC) from the wall and convert it into a direct current (DC).  These power supplies often take your familiar two-or-three prong wall connector and put power out via a barrel plug-type connector.  AC power (typically 110 or 240 volts, depending where you live in the world) goes in the typical wall plug, and DC power (typically 5 to 24 volts) comes out the barrel plug.  Most power supplies of this type list the conversion explicitly, such as: 110-240 Volts to 12 Volts at 2 Amps.  You&#039;ll want to match your Phidget&#039;s needs against the 12 Volts at 2 Amps. &lt;br /&gt;
&lt;br /&gt;
*The voltage must match exactly&lt;br /&gt;
**If the Phidget takes a range of voltages, the supply must fall within the range&lt;br /&gt;
*The amperage can be equal to or greater than the Phidget needs&lt;br /&gt;
&lt;br /&gt;
A wall power supply is essentially an inexhaustible supply of current, so you don&#039;t need to worry about it running out like you would with batteries.&lt;br /&gt;
&lt;br /&gt;
===Battery Power===&lt;br /&gt;
&lt;br /&gt;
If you intend to use a battery bank (even of only one battery) to power your Phidget, you probably want to know what type of battery to purchase.  &lt;br /&gt;
&lt;br /&gt;
====Battery Chemistries====&lt;br /&gt;
The first thing that sets batteries apart is the type of materials used in their construction.  The following table shows several of the more common battery chemistries as well as the voltage per cell they produce and the specific energy of the chemistry.  &lt;br /&gt;
&lt;br /&gt;
{| border = 1&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Chemistry&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Nominal Cell Voltage&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Specific Energy (MJ/kg)&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Primary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| Alkaline||1.5||0.4||These are the most common form of battery.  Many commercially available AA and AAA batteries are alkaline. &lt;br /&gt;
|-&lt;br /&gt;
| Lithium (LiMnO2)||3||0.83-1.01||These are used in high drain devices or devices with a long shelf life as they have a very low self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Silver-oxide||1.55||0.47||Only used in small button cells as these are quite expensive.&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Secondary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| NiCd||1.2||0.14||Older technology, suffers from [[Electricity Primer#Memory Effect|memory effect]].  Capable of very high discharge rates with no ill effects.  Moderate self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Lead-acid||2.1||0.14||Not particularly good with high discharge rate.  Moderate rate of self discharge.  &lt;br /&gt;
|-&lt;br /&gt;
| NiMH||1.2||0.36||Very heavy.  Good performance in high drain devices.  Very high energy density naturally, at the cost of a high self discharge rate.  Newer versions are able to get rid of some of the self discharge though they suffer ~25% lower energy densities as a result.  &lt;br /&gt;
|-&lt;br /&gt;
| Lithium Ion||3.6||0.46||Expensive to produce but very high energy density.  Very low self discharge rate.  Safety hazard as short circuiting can yield explosive or fiery results. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Choosing a Battery====&lt;br /&gt;
Batteries are chosen first by their voltage (V).  Match the voltage exactly to the voltage the Phidget needs.  Over or under this value, you could harm the board or have it simply fail to turn on.&lt;br /&gt;
&lt;br /&gt;
Next, choose a battery that has adequate amperage to feed your device for the time you need. The lifespan of the battery will usually be listed in Amp-Hours (or Ah).  For example, a double wide 12 V lantern battery will have usually around 7-8 amp hours.  This means if you drew one amp from it for seven to eight hours, the battery would be totally drained.  Or you could draw two amps from it and drain it in 3.5-4 hours.  This does not mean however, that you can draw 36A for 15 minutes.  It is important to understand that there is a limit at which more power simply cannot be drawn from the battery.  Effectively, high drain devices will decrease the rated Ah.  The amount  differs from battery to battery so to be sure it is recommended to check the data sheets for the battery you are using.  If the battery did not come with a data sheet they can usually be found on the manufacturers website.  The data sheets should have a graph that shows the relationship between current draw (usually in mA) and capacity (Ah or mAh).  Another useful thing that can be gathered from the datasheets is the batteries response to temperature.  Batteries tend to not work as well in cold environments, most manufacturers will provide graphs of how the batteries lifespans will shorten at different temperatures.  This is often very significant, causing the battery to last a fraction of its normal lifespan at temperatures below -10&amp;amp;deg;C.&lt;br /&gt;
&lt;br /&gt;
Finding the amperage or voltage sometimes needs to be done indirectly by using a specification of watts.  The relationship between amperage, voltage, and watts is given above in the [[#Voltage and Amperage|voltage and amperage section]].&lt;br /&gt;
&lt;br /&gt;
For an example, let us say you want to use battery power to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer].  The specifications say that it uses 1.2 watts as a base value.  The specifications also say that it can take 12 V DC power.  If we choose to use a 12 V battery, at 1.2 watts it will use 0.1 amps according to the equation [[#Voltage and Amperage|shown earlier]].  Going by amp-hours alone, if our battery is a double-wide lantern type 12 V battery, with 7 amp hours, with 0.1 amp draw it will last 70 hours, or almost three days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Maximum Running Days} =\frac{\text{Battery Amp Hours}}{\text{Device Amps} * \text{24}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, to estimate &#039;&#039;average&#039;&#039; running time (rather than maximum running time possible), amp-hours cannot be used so directly.  Over time, batteries decrease in voltage as their power is used up.  Practically speaking, this means one of two things for your load.  For loads that do not regulate voltage or current, the amperage will also decrease over time.  The classic example is an LED light source that grows dimmer and dimmer as the batteries are used up.&lt;br /&gt;
&lt;br /&gt;
You should usually only count on about 60% of the stated amp hour rating to apply before expecting to run into problems from escalated drain due to battery voltage drop.  This is especially true for deep cycle rechargeable batteries left in an installation, where draining more than 60% could also harm the battery.  &lt;br /&gt;
&lt;br /&gt;
Then, for lead-acid batteries, a typical battery is tested from full to complete drain over 20 hours by the manufacturer to obtain the advertised amp-hour rating.  Draining a battery at a faster rate than this will result in even more reduction in capacity, by 10% or even more.  This due to [http://en.wikipedia.org/wiki/Peukert%27s_law Peukert&#039;s Law].&lt;br /&gt;
&lt;br /&gt;
There are plenty of [http://www.google.ca/search?&amp;amp;q=battery+calculator battery calculators] around the Internet which take most or all of these additional factors into account when recommending an amp-hour rating.  For longer-term installations, the solar power online community has some excellent resources.&lt;br /&gt;
&lt;br /&gt;
====Setting up Multiple Batteries====&lt;br /&gt;
You can hook up multiple batteries in series to get more voltage at the same amperage.  The amperage is additive.  For example, you can hook up two single-wide 6 V lantern batteries in series to produce 12 V.  Or two 12 V batteries in series to produce 24 volts.  This system would still only have the amp hours of &#039;&#039;one&#039;&#039; of the lantern batteries, because you will be essentially using them both at once: &lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_series.png|250px]]&lt;br /&gt;
&lt;br /&gt;
The upside down triangle (ground) is explained above in a [[#Ground|section of its own]].&lt;br /&gt;
&lt;br /&gt;
Or, you can hook up multiple batteries in parallel to get more amperage at the same voltage.  For example, you could hook up two 12 V deep cycle batteries in parallel to provide more amperage at 12 V, which is like having a deeper reservoir of power for your device to use:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
====Heat====&lt;br /&gt;
*all batteries have some sort of internal resistance&lt;br /&gt;
*can be found on the battery&#039;s data sheet&lt;br /&gt;
*the more power you pull from the battery the more heat is going to build up as a consequence of the internal resistance.&lt;br /&gt;
*larger internal resistances will cause heat to build up faster.&lt;br /&gt;
*when charging a battery you are not just limited to the power in the battery.  nothing stops you from dumping energy into the battery past the point where it is fully charged&lt;br /&gt;
**this is why charging batteries is a bit of a tricky business.&lt;br /&gt;
**many batteries come with custom chargers that have control systems to prevent this type of overcharging.&lt;br /&gt;
&lt;br /&gt;
====Weight====&lt;br /&gt;
Finally, weight matters - a car battery is much heavier than a lantern battery.  Batteries vary widely by weight per amperage.  Lithium batteries are usually very light for their power, followed by alkaline, followed by lead acid.  This may not seem important at first, but if you are building a mobile robot it is worth calculating in the work of carting around a battery.  You may find that, for the length of time you want it to run, your battery requires some system redesign.&lt;br /&gt;
&lt;br /&gt;
==Selecting Cables==&lt;br /&gt;
&lt;br /&gt;
===USB Cables===&lt;br /&gt;
&lt;br /&gt;
In general, use the shortest cables possible.  There are many reasons for this [[#Emissions and Wires|described above]], but as a summary:&lt;br /&gt;
&lt;br /&gt;
; Long cables reduce the voltage that reaches the Phidget.&lt;br /&gt;
: This happens in both directions.  So, for every unit cable length added, the voltage decreases by twice the electrical resistance of that length of cable. With especially long cables the Phidget may drop below its 4.6 volt threshold and simply never turn on.&lt;br /&gt;
&lt;br /&gt;
; Long cables increase the width of your circuit.  &lt;br /&gt;
:All circuits act as emitting antennas for the resonance frequency of the circuit structure.  The longer the wires in the circuit, the lower the frequency, and the higher chance that it will be emissions that will interfere with your data and system.&lt;br /&gt;
&lt;br /&gt;
; Longer cables have more length exposed to external interfering emissions.&lt;br /&gt;
&lt;br /&gt;
Also, use thick cables that are built to specification.  Some USB cables with thinner wiring have higher electrical resistance.  This can be equal to what a much longer wire would have, and thus create a similar voltage drop where the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
====Options for longer cables====&lt;br /&gt;
The maximum length for a USB cable is 5m.  This is laid out in the USB specifications.  Often times however a system requires more reach.  In this case there are a few options available to you.  You can use what is known as an active extension cable or USB extender.  These cables act like extension cables and add power to the line so that the signal can travel further.  A second option is to use a Cat5 extender.  These extenders are 2 USB dongles that connect on either end of your system.  You join them up with Cat5 cable.  This allows you to run over much longer distances than USB traditionally allows.&lt;br /&gt;
&lt;br /&gt;
===Power Cables===&lt;br /&gt;
&lt;br /&gt;
There are &amp;quot;DC Wire Table&amp;quot; references on the Internet which describe how to pick a wire appropriate for your voltage and amperage.  When selecting AC wires, you will probably be using pre-made extension cords.  Cords add interference resonance length to your circuit, just like USB cables do as [[#USB Cables|described above]].  A long extension cord can create huge electromagnetic interference for your circuit and other systems in the area when first plugged in.&lt;br /&gt;
&lt;br /&gt;
Also as with the USB cables above, cut the cables to the shortest length possible.  This is again both for voltage drop reasons and frequency emission reasons.&lt;br /&gt;
&lt;br /&gt;
===Hubs===&lt;br /&gt;
&lt;br /&gt;
Avoid hubs where possible.  Unpowered hubs are good for reading data from memory keys, but not for powering many external devices.  If you must use a hub, buy a powered one.&lt;br /&gt;
&lt;br /&gt;
===Sensor and Motor Wiring===&lt;br /&gt;
All Phidgets sensor class devices (products whose part numbers start with 11 such as the 1129) use a 3 channel ribbon cable for power and data transmission.  Similarly, all our motors and load cells use multichannel wire interfaces.  As mentioned previously, USB spec limits cables to 5m, this is not the case for these wires.  The biggest concerns are electromagnetic interference (EMI) and voltage drop.  In general you should be able to run these wires over significant distances (30m or more) with the load cells in particular having very long range.  If EMI starts causing issues you can always use ferrite beads on the cable near the sensor or motor and the controller to reduce noise.&lt;br /&gt;
&lt;br /&gt;
===Cable Gauges for Terminal Blocks===&lt;br /&gt;
&lt;br /&gt;
Many Phidgets products feature green terminal blocks that use screws to hold wires in place, making it easy to take apart and rebuild connections in your project. The size of the terminal block determines the gauge of wire you should use.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Terminal Block Size and Wire Gauge&#039;&#039;&#039;&lt;br /&gt;
! Terminal Block Width (mm/port)&lt;br /&gt;
! Recommended Wire Gauge (AWG)&lt;br /&gt;
|-&lt;br /&gt;
| 3.81&lt;br /&gt;
| 14 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 5.0&lt;br /&gt;
| 12 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 9.5&lt;br /&gt;
| 10 to 26&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The gauge of cables and wires is measured in AWG, which is the American Wire Gauge standard. The following table lists the properties of wire gauges commonly used with Phidgets:&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;American Wire Gauge Sizes&#039;&#039;&#039;&lt;br /&gt;
! AWG Size&lt;br /&gt;
! Diameter (mm)&lt;br /&gt;
! Area (mm²)&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| 2.588&lt;br /&gt;
| 5.26&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| 2.305&lt;br /&gt;
| 4.17&lt;br /&gt;
|-&lt;br /&gt;
| 12&lt;br /&gt;
| 2.053&lt;br /&gt;
| 3.31&lt;br /&gt;
|-&lt;br /&gt;
| 13&lt;br /&gt;
| 1.828&lt;br /&gt;
| 2.62&lt;br /&gt;
|-&lt;br /&gt;
| 14&lt;br /&gt;
| 1.628&lt;br /&gt;
| 2.08&lt;br /&gt;
|-&lt;br /&gt;
| 15&lt;br /&gt;
| 1.450&lt;br /&gt;
| 1.65&lt;br /&gt;
|-&lt;br /&gt;
| 16&lt;br /&gt;
| 1.291&lt;br /&gt;
| 1.31&lt;br /&gt;
|-&lt;br /&gt;
| 17&lt;br /&gt;
| 1.150&lt;br /&gt;
| 1.04&lt;br /&gt;
|-&lt;br /&gt;
| 18&lt;br /&gt;
| 1.024&lt;br /&gt;
| 0.823&lt;br /&gt;
|-&lt;br /&gt;
| 19&lt;br /&gt;
| 0.912&lt;br /&gt;
| 0.653&lt;br /&gt;
|-&lt;br /&gt;
| 20&lt;br /&gt;
| 0.812&lt;br /&gt;
| 0.518&lt;br /&gt;
|-&lt;br /&gt;
| 21&lt;br /&gt;
| 0.723&lt;br /&gt;
| 0.410&lt;br /&gt;
|-&lt;br /&gt;
| 22&lt;br /&gt;
| 0.644&lt;br /&gt;
| 0.326&lt;br /&gt;
|-&lt;br /&gt;
| 23&lt;br /&gt;
| 0.573&lt;br /&gt;
| 0.258&lt;br /&gt;
|-&lt;br /&gt;
| 24&lt;br /&gt;
| 0.511&lt;br /&gt;
| 0.205&lt;br /&gt;
|-&lt;br /&gt;
| 25&lt;br /&gt;
| 0.455&lt;br /&gt;
| 0.162&lt;br /&gt;
|-&lt;br /&gt;
| 26&lt;br /&gt;
| 0.405&lt;br /&gt;
| 0.129&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Hooking Up The Pieces==&lt;br /&gt;
&lt;br /&gt;
Here, things can be tricky.  You might think: just plug everything in and go!  But often it is not that simple.  Many Phidgets require special care when hooking up.  We encourage a process where you apply the concepts in this Primer, through analysis, to your system.  So, we don&#039;t explicitly list the boards most commonly affected until the [[#Affected Products|end of this Primer]].&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;categories&#039;&#039; of the boards which require special attention within a complex system are:&lt;br /&gt;
&lt;br /&gt;
# Phidgets with more than one power source, and&lt;br /&gt;
# Phidgets needing precise measuring or control of an external power source&lt;br /&gt;
&lt;br /&gt;
If you are already thinking about your boards in your head and trying to figure out whether they fit into one category or another, you&#039;re on the right track!  The list of [[#Affected Products|commonly affected boards]] are only the common ones... with a sufficiently complex system, you could conceivably create problems with &#039;&#039;any&#039;&#039; boards.&lt;br /&gt;
&lt;br /&gt;
Both types of projects require a full understanding of [[#The Basics|electrical basics]].  Using those concepts, below we first describe problems that arise when hooking up different power sources, and extend that into using the solution to give more precise measurement and control.  &lt;br /&gt;
&lt;br /&gt;
===Shared Grounds===&lt;br /&gt;
&lt;br /&gt;
Shared grounds can occur in Phidgets that handle two different power sources.  Recognizing the sharing of a ground is not always easy.  We show what it is, how it can be possible, and why it creates problems by starting with the most basic Phidget system.  The simplest setup for a Phidget is to use the [[#Ground|ground]] of the computer it gets data and power from over a USB port:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_simple_case.png]]&lt;br /&gt;
&lt;br /&gt;
In this case, there is only one relative ground, and it is the PC ground, which is ground #1 in the image.  The PC ground determines what is considered 0 volts for all signals on the Phidget.  When you add different power sources or sinks in the system, you are pulling the system relative to the PC ground.  &lt;br /&gt;
&lt;br /&gt;
=====One Powered Phidget=====&lt;br /&gt;
&lt;br /&gt;
The next most complicated system is one Phidget that handles two power sources.  Let us say you have a motor controller, which takes power from USB, and which also takes power from a second power source.  Although the second power source is usually just a wall plug, the simpler case for thinking about ground is actually a battery.  A battery creates a second &#039;&#039;relative&#039;&#039; ground.  Through the Phidget, relative ground #1 (from the PC) and #2 (from the battery) actually become the same ground:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_wall_power.png]]&lt;br /&gt;
&lt;br /&gt;
This is the first reason why systems with powered Phidgets have to carefully manage ground.  If ground #1 and ground #2 are different with respect to each other (see the static shock analogy in the [[#Ground|ground section]] above), then whatever circuitry along the red dashed arrow must deal with the initial static shock.  In this case it would be the circuitry of the Phidget.  In the case of a battery, after the initial equalizing shock the battery will be whatever relative voltage the PC ground needs it to be.  Hence a battery relative ground can &#039;float&#039;.&lt;br /&gt;
&lt;br /&gt;
If ground #2 comes from the wall, on the other hand, the ground does not &#039;float&#039; and instead is always absolute 0 volts Earth ground.  With the PC giving the power, this is not a problem in practice because the PC can also float (as with a laptop), or it uses Earth ground.  But if you were using a different and more powerful USB power supply instead of a PC, and then connected it to the absolute Earth ground through the Phidget, the Phidget would bear the brunt of any ground equalization that would occur.  If neither the new ground nor the old ground float, and the power supplies were powerful enough, this would eventually destroy the Phidget.  In this case, you would want to use isolation, as described in [[#How To Fix This|How To Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Multiple Powered Phidgets=====&lt;br /&gt;
&lt;br /&gt;
A worse case comes in when you are using two powered Phidgets and one external power source.  Again, say you are using a battery as the external power source.  It would be tempting to simply wire both grounds from the Phidgets to the ground on the battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_phidget.png]]&lt;br /&gt;
&lt;br /&gt;
Although this looks benign, you have actually created a new circuit.  The circuit is a second path, via ground, for the current to return to the voltage source.  This is also known as a &#039;&#039;&#039;ground loop&#039;&#039;&#039;. The path we intuitively think of the current returning by is  &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;, but the sharing of grounds has created a new path through the motherboard, &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_paths.png]]&lt;br /&gt;
&lt;br /&gt;
All current gets &#039;pumped&#039; in a loop by voltage, and so it will use all return paths available to it, assuming all paths are equally easy (electrically) to use.  This extends the pipe analogy, where water will flow in every path that exists.  So, if your battery (or other power source with ground #2) is quite powerful, you can actually harm your motherboard within your PC (or at least your USB bus ground), because &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039; runs through the motherboard circuitry on the way back to the voltage source.&lt;br /&gt;
&lt;br /&gt;
This problem does &#039;&#039;not&#039;&#039; apply to using a different power source between a black power plug and for the green control terminal block on, say, a [[DC Motor and Controller Primer|DC motor controller]].  Although the grounds are connected, and they run across a part of a Phidget board, creating a ground loop does not actually run through any circuitry if only these types of boards are used.  If you have a complex system with other types of boards and therefore circuitry between black plug power port and green terminal block connections, draw out your system carefully to identify the loops.&lt;br /&gt;
&lt;br /&gt;
Ground loops can be fixed by one of the ways described in [[#How To Fix This|How to Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Single Board Computer And Powered Hub=====&lt;br /&gt;
&lt;br /&gt;
When combining one externally powered Phidget and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] or the [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]] on the same external power source, you still may inadvertently create a ground loop as described above in [[#Multiple Powered Phidgets|the multiple powered Phidgets section]].  If they share a true [[#Ground|Earth ground]], this is not a problem.  But if the ground is from a battery, or uninterruptible power supply, etc. then you should carefully draw out your system circuit and examine it for ground loops.&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
Once you are aware of shared grounds in your system, you have two options.  &lt;br /&gt;
&lt;br /&gt;
One, for ground loop problems in simple systems (two Phidgets), you could make the normal return path (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;) the most electrically desirable path.  This is best for simple systems where you have a lot of control over all of the ground wires within your system.  For the ground wires leading directly from the Phidget to the external power supply (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;), lower the resistance in the wire as much as possible.  You can do this by keeping the wires short, and using a thick (large gague) wire for the hookups.  &lt;br /&gt;
&lt;br /&gt;
Although this solution works, sometimes you do not have much choice on how long your ground return wires can be, because the location of your power supply and and Phidgets are set by your system design.  If you cannot be totally sure that the direct ground path is the shortest and most electrically desirable path, it is best to use the second option: a &#039;&#039;&#039;USB Isolator&#039;&#039;&#039; such as the [[Product - 3060 - USB Isolator|Phidget 3060]].  This isolator is like any other USB isolator - it can be used on a Phidget system, as well as any system that needs ground isolation.&lt;br /&gt;
&lt;br /&gt;
You need isolators for every USB cable in your system, less one.  If you have two USB connections, you need one isolator; three USB connections, two isolators, and so on.  The one USB connection can remain non-isolated because a single ground connection cannot form a loop.  However, if you are concerned about connecting the grounds as described in the [[#One Powered Phidget|single connected Phidget section above]], use a USB isolator on every cable.&lt;br /&gt;
&lt;br /&gt;
===Precise Voltage Control===&lt;br /&gt;
&lt;br /&gt;
Precise voltage (or other system) control and measurement is related to the concept of [[#Shared Ground|shared ground above]].  But here, you want to keep grounds separate not only to prevent ground loops, but also to make your system more sensitive to what it will control or measure.&lt;br /&gt;
&lt;br /&gt;
For example, we make Phidgets that can create power precisely, or that can take it in and measure it.  One such product is the 1002, which outputs a precise analog voltage with which to control an analog system.  Now that you know about [[#Ground|relative ground]], however, you would be right to expect that you do not want to combine the ground in the PC and the ground in the system.&lt;br /&gt;
&lt;br /&gt;
Even if you don&#039;t care about system sensitivity, you can still create [[#Multiple Powered Phidgets|ground loops]] in a system with multiple of these types of Phidgets.  In addition, if you are using the Phidget to control a large, powerful system, even a single Phidget can receive damage from connecting two powerful power sources meeting across it, also as [[#One Powered Phidget|described earlier]].&lt;br /&gt;
&lt;br /&gt;
But above and beyond the powered Phidget problems, there is another reason to separate (isolate) the electrical grounds in your system.  The reason is: to make your system control more precise.  For example, with the 1002, if you are trying to control an external system with an Phidget output voltage, that output voltage should be relative to the &#039;&#039;system you are trying to control&#039;&#039;, not relative to the PC.  Rather than forcing the grounds - and therefore the relative voltages - to be equal to each other, you can provide more precise control by isolating the grounds and working with the relative voltage of the controlled system on its own terms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Schematic-type image of a ground isolated analog out on a 1002&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
The solution to all of these problems in precise voltage control systems is to use USB isolation, even for a single Phidget.  The [[Product - 3060 - USB Isolator|Phidget 3060]] is one such isolator.  It inserts along the USB connection between your PC and the Phidget, and it separates the Phidget (and controlled system) ground from the PC ground.  This fixes ground loops, separates relative voltage mis-matches, and isolates the control system for better precision.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Image of 1002 and Isolator connected, with lines superimposed on the image to show non-copper connection in isolator&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Affected Products==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure whether a certain concept applies to your Phidget within a complex system, the best way to figure this out is by doing some mental (or pencil and paper) simulation.  Draw the inputs and outputs for the entire board, and label them with voltage, list their required amperage (or watts), and draw connections (such as ground connections) through any circuitry.  &lt;br /&gt;
&lt;br /&gt;
With a technique like this, it is easy to see that some products - such as the [[Product - 1049 - PhidgetSpatial 0/0/3|Phidget Spatial]] - are simply not complex at all. Although you could conceivably create problems (such as by using separate power supplies instead of using USB power and connecting the grounds incorrectly, or by using really long wires), this would be an exceptional case.  &lt;br /&gt;
&lt;br /&gt;
Other Phidgets can be more easily used incorrectly without realizing it.  These are often devices that are simple in some systems and yet complex in others.  Your primary defense against designing unreliable systems is to draw the system out and identifying any problems using the concepts in this primer. To help you, however, you can generally think of two classes of Phidgets which usually need careful handling when they are part of complex systems:&lt;br /&gt;
# Phidgets with more than one power source, (these can be subject to the [[#Shared Grounds|multiple power source problems]] described above)&lt;br /&gt;
# Phidgets needing precise measuring of an external power source (these can be subject to the [[#Shared Grounds|multiple power source problems]] &#039;&#039;and&#039;&#039; [[#Precise Voltage Control|precise voltage control]] problems)&lt;br /&gt;
&lt;br /&gt;
Expanded into individual products, the Phidgets which are most often affected are.....&lt;br /&gt;
&lt;br /&gt;
# These Phidgets use a second type of external power:&lt;br /&gt;
#* Motor controllers &lt;br /&gt;
#**{{LinksNeeded|DC Motors and Controllers|[[DC Motor and Controller Primer|DC controllers]]}}&lt;br /&gt;
#**[[Stepper Motor and Controller Primer|Stepper controllers]]&lt;br /&gt;
#**{{LinksNeeded|Servo controllers|[[Servo Motor and Controller Primer|Servo controllers]]}}&lt;br /&gt;
#* Pure relay boards &lt;br /&gt;
#**[[Solid State Relay Primer|Solid state relay boards]]&lt;br /&gt;
#**[[Mechanical Relay Primer|Mechanical relay boards]]&lt;br /&gt;
#* Interface kits with relays &lt;br /&gt;
#**[{{SERVER}}/products.php?product_id=1017 1017 - PhidgetInterfaceKit 0/0/8]&lt;br /&gt;
#**[{{SERVER}}/products.php?product_id=1014 1014 - PhidgetInterfaceKit 0/0/4]&lt;br /&gt;
#* Powered Digital Output Interface Kits &lt;br /&gt;
#** [{{SERVER}}/products.php?product_id=1012 1012 - PhidgetInterfaceKit 0/16/16]&lt;br /&gt;
#* Interface Kits with Powered Hubs&lt;br /&gt;
#** The [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]&lt;br /&gt;
#** [{{SERVER}}/products.php?product_id=1019 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]&lt;br /&gt;
# And these Phidgets may have a need to be sensitive to external power:&lt;br /&gt;
#* [[Temperature Sensor Primer|Thermocouple]] control&lt;br /&gt;
#* Analog Output ([{{SERVER}}/products.php?product_id=1002 1002 - PhidgetAnalog 4-Output])&lt;br /&gt;
#* Frequency Counter ([{{SERVER}}/products.php?product_id=1002 1054 - PhidgetFrequencyCounter])&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
&lt;br /&gt;
This page should have helped you to: &lt;br /&gt;
*Choose a power supply from either the [[#Wall Power|wall]] or a [[#Battery Power|battery]]&lt;br /&gt;
*Properly [[#Ground|ground]] and/or [[#How To Fix This|isolate]] that power supply from looping through other circuitry&lt;br /&gt;
*Also use [[#How To Fix This|isolation]] to make your control or measurement system more precise&lt;br /&gt;
*Keep your cables short and thick to reduce electromagnetic emissions and limit voltage drop&lt;br /&gt;
*Be more aware of system-wide power problems in general, and use drawing and analysis of systems to identify problems&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
===Memory Effect===&lt;br /&gt;
Memory effect is an effect observed in NiCd batteries that causes them to hold less charge.  It pertains to the specific situation in which NiCd batteries lose their maximum capacity if they are repeatedly recharged without being fully discharged.  The battery appears to remember the smaller capacity.  The term is often misused in cases where other batteries seem to hold less charge than originally, however this is most likely due to age and use.  This phenomenon is unique NiCd batteries.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Phidget_SBC&amp;diff=20730</id>
		<title>OS - Phidget SBC</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Phidget_SBC&amp;diff=20730"/>
		<updated>2012-06-29T21:46:02Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:icon-Linux.png|64x64px|link=OS - Linux]]|On the Single Board Computer (SBC), Phidgets can be either plugged directly into one of the USB ports or run over a network using the [[#WebService | WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
Unlike our other supported operating systems, the SBC &#039;&#039;&#039;does not require downloads&#039;&#039;&#039; unless you are doing something advanced like loading the firmware or developing your own kernel.  You will know if you need these downloads, otherwise, the SBC should work as described on the [[1072_-_Getting_Started|SBC2 Getting Started Guide]] right out of the box.&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetsbc2.bin SBC2 Firmware]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC2 Kernel Development Package] (How-to and patch file)&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#SBC2 License]&lt;br /&gt;
&lt;br /&gt;
Note that, instead of using the firmware to update your SBC, updates should normally be done via the System -&amp;gt; Packages page on your SBC2 web interface. It is rarely necessary to completely re-flash your device.&lt;br /&gt;
&lt;br /&gt;
==Getting Started with the Phidget SBC Debian Linux==&lt;br /&gt;
&lt;br /&gt;
The Single Board Computer (SBC) is a unique Phidget.  It is a computer with a Linux operating system.  It can compile code, save files, manage background jobs, host information over the web, and more.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If this is your first time&#039;&#039;&#039; using the Phidget SBC, you will want to start with the [[1072 - Getting Started | Getting Started Guide for the SBC]].  After that, here we will get you started on topics beyond those in the getting started guide, including how to write Phidget code to run on the SBC.  You &#039;&#039;&#039;do not need this page&#039;&#039;&#039; if you are simply using the SBC to broadcast data from Phidgets over the network - it does that automatically.  We describe how to verify and use this in the [[1072 - Getting Started | Getting Started Guide]].&lt;br /&gt;
&lt;br /&gt;
This page will show you how to:&lt;br /&gt;
* Install the ability to write and develop code on the SBC itself&lt;br /&gt;
* Use the command line for basic coding tasks&lt;br /&gt;
* Troubleshoot the SBC&#039;s network&lt;br /&gt;
It will also give additional specifications, which are useful for doing more advanced things with the SBC hardware and software.&lt;br /&gt;
&lt;br /&gt;
Before reading this page, you should have done the following via the Getting Started Guide:&lt;br /&gt;
* Set up networking on your SBC, via either Ethernet or wireless&lt;br /&gt;
* Set up an admin password&lt;br /&gt;
* Learned the IP address or link local address of the SBC&lt;br /&gt;
We will use this information in setting up the libraries and drivers to use the SBC for writing and running code.&lt;br /&gt;
&lt;br /&gt;
Conceivably, you could simply use the SBC like any Linux computer, and do all of your development and compiling of Phidget code on the SBC itself.  In practice this gets complicated as the SBC does not have a keyboard or screen.  So usually, you will want to develop your code an external computer and copy files and settings over to the SBC via a network.  This makes this Getting Started section unique, in that we show you how to set up both computers:&lt;br /&gt;
* Your [[#Getting Started - External Computer | External Development Computer]], usually your main desktop or laptop which will transfer files and settings to and from the SBC&lt;br /&gt;
* The [[#Getting Started - The SBC (Debian Linux) | SBC]] itself, which needs programming language libraries to use Phidgets.&lt;br /&gt;
&lt;br /&gt;
===Getting Started - External Computer===&lt;br /&gt;
&lt;br /&gt;
You have two ways to connect to the SBC from an external computer: via the [[#SBC Web Interface|SBC Web Interface]] and over the more powerful but complex [[#SSH | Secure Shell (SSH)]].&lt;br /&gt;
&lt;br /&gt;
====SBC Web Interface====&lt;br /&gt;
&lt;br /&gt;
You have already worked extensively with the web interface in the [[1072 - Getting Started | Getting Started Guide for the SBC]].  This was the tool within a web browser which was opened either via the Phidget control panel on Windows, or by simply entering the IP or link local address into an internet browser.  It allowed you to set the password, set up internet connectivity, and so on.  &lt;br /&gt;
&lt;br /&gt;
This section doesn&#039;t have more information on the interface; rather, it simply serves as a reminder that you have the web interface as an available tool.  Examples, including screenshots, are placed where appropriate in this document.  The web interface will probably stay your initial go-to way to connect to the SBC, especially for tasks that benefit from graphical interaction, like setting up wireless or using the webcam.&lt;br /&gt;
&lt;br /&gt;
====SSH====&lt;br /&gt;
&lt;br /&gt;
The most flexible way to transfer files and commands to and from the SBC is via a program called &#039;&#039;&#039;ssh&#039;&#039;&#039;.  The ssh program provides command line text access over a network into the SBC.  Using it, you can run programs and give the SBC commands.  The ssh program has a companion program called &#039;&#039;&#039;scp&#039;&#039;&#039; which can copy files back and forth.  If you are unfamiliar with ssh, you can think of it like the command line or a Mac terminal, but with a remote connection to a different computer.  It is a minimal yet effective way to interact with a remote computer.&lt;br /&gt;
&lt;br /&gt;
Before connecting over ssh, you will need:&lt;br /&gt;
* The &#039;&#039;&#039;IP address&#039;&#039;&#039; (such as 168.254.3.0) or &#039;&#039;&#039;link local address&#039;&#039;&#039; (such as phidgetsbc.local) of the SBC&lt;br /&gt;
* The &#039;&#039;&#039;admin password&#039;&#039;&#039; for the SBC&lt;br /&gt;
Both of these items can be found by following the steps in the [[1072 - Getting Started | Getting Started Guide for the SBC]].&lt;br /&gt;
&lt;br /&gt;
You will also need to enable SSH on the SBC side.  This can be done through the [[#SBC Web Interface| Web Interface]], under {{Code|Network &amp;amp;rarr; Settings}}, by changing the &#039;&#039;SSH Server&#039;&#039; radio button to &#039;&#039;Enabled&#039;&#039; and saving your changes:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_turn_on_ssh.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
=====SSH on Windows=====&lt;br /&gt;
&lt;br /&gt;
The ssh program is not installed on Windows by default.  But, there are a variety of SSH programs available for free. One simple and commonly used program is [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY], and it has the advantage that the executable doesn&#039;t need to install, it just runs.&lt;br /&gt;
&lt;br /&gt;
With PuTTY, when you first run the program it will ask you what to connect to.  Enter the IP address or link local address of the SBC, and then click the SSH radio button right below the address, which will change the port to 22.  Then click open, and you&#039;ll have an ssh connection to the SBC open in a terminal.  It will prompt you for a user name ({{Code|root}}) and password (the admin password).&lt;br /&gt;
&lt;br /&gt;
To copy files back and forth, there is an SCP component to PuTTY, called PSCP, which is available from the same [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY download page].  Use of PSCP will be similar with the address, username, and password, except that you will be transferring files instead of sending commands.&lt;br /&gt;
&lt;br /&gt;
=====SSH on Linux and Mac OS=====&lt;br /&gt;
&lt;br /&gt;
Linux and Mac OS already have ssh installed by default.  To run ssh simply open a terminal...&lt;br /&gt;
* {{Code|Ctrl-Alt-T}} on Linux &lt;br /&gt;
* {{Code|Applications &amp;amp;rarr; Utilities &amp;amp;rarr; Terminal}} on Mac OS &lt;br /&gt;
...and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
ssh root@phidgetsbc.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have re-named your SBC, include that name instead of the {{Code|phidgetsbc.local}} link address.  Or, you can use the SBC&#039;s IP address, e.g. something like {{Code|ssh root@168.254.3.0}}&lt;br /&gt;
&lt;br /&gt;
To copy files back and forth, the command follows the form of: {{Code|scp from to}}&lt;br /&gt;
&lt;br /&gt;
So, to copy a file {{Code|/root/data.txt}} from the SBC to your local machine, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
scp root@phidgetsbc.local:/root/data.txt .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the use of the dot &#039;&#039;&#039;.&#039;&#039;&#039; to indicate that scp should put the file in the current local directory.   If you&#039;re not sure what folder the terminal is operating in type {{Code|pwd}} to print the working directory.  Terminals usually start by default in your home folder.&lt;br /&gt;
&lt;br /&gt;
===Getting Started - The SBC (Debian Linux)===&lt;br /&gt;
&lt;br /&gt;
The SBC runs Linux, which is a full operating system. It is stripped down compared to a full desktop release of Linux, but you can compile code on it, run programs, schedule tasks, create and manage files, run a web server, and much, much more.&lt;br /&gt;
&lt;br /&gt;
At this point you have connected to the SBC via the [[#SBC Web Interface|web interface]], and probably also through [[#SSH|SSH]].  This section will help you install libraries and drivers that you probably want - i.e. support for C, Java, and Python.  After this section, you&#039;ll be well into the depths of using the SBC as a computer, and so you&#039;ll probably want to keep the [[#Using SBC Linux|Using SBC Linux section]] open for reference while you work if you are not already familiar with Linux.&lt;br /&gt;
&lt;br /&gt;
The SBC comes with the following Phidget functionality installed:&lt;br /&gt;
* The Phidget C libraries {{Code|libphidget21.so}}&lt;br /&gt;
* The Phidget [[#WebService | WebService]]&lt;br /&gt;
(If you are simply curious what these are and how they get installed, we describe the process on the [[OS - Linux | general Linux page]].)&lt;br /&gt;
&lt;br /&gt;
But to compile C programs, or run Java programs, or use Python, you will need to install these languages onto the SBC.  &lt;br /&gt;
&lt;br /&gt;
Before installing anything on the SBC, however, (even via a button on the web interface) make sure that the &#039;&#039;Include full Debian Package Repository&#039;&#039; option is checked in the web interface under {{Code|System &amp;amp;rarr; Packages}}.&lt;br /&gt;
&lt;br /&gt;
====Installing C/C++ and Java====&lt;br /&gt;
&lt;br /&gt;
The simplest way to install C/C++  and Java on the SBC is via the web interface.  There is a button under {{Code|System &amp;amp;rarr; Packages}} to install C support (including {{Code|gcc}}) and another button to install Java support:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_packages_web.png|link-|alt=]]&lt;br /&gt;
&lt;br /&gt;
Now you&#039;re ready to begin programming.  We have programming pages for both [[Language - C/C++|C/C++]] and for [[Language - Java|Java]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].  &lt;br /&gt;
&lt;br /&gt;
If you want to avoid using the [[#SSH|SSH]] interface on the SBC entirely, and you want to write your program in Java and run it continuously from boot (which is the only option if you want to avoid [[#SSH|SSH]]), we have a [[#Program in Java with the Web Interface|very in-depth section]] on that topic.&lt;br /&gt;
&lt;br /&gt;
====Installing Python====&lt;br /&gt;
&lt;br /&gt;
Installing Python has two steps.  First, you&#039;ll need to install the basic ability to run python, and then you&#039;ll need to install the Phidget Python module.  Both steps (and both options) require that you issue the relevant commands through an [[#SSH|SSH terminal]].&lt;br /&gt;
&lt;br /&gt;
=====Basic Python=====&lt;br /&gt;
&lt;br /&gt;
The base Python functionality can be downloaded and installed in one step with [[#apt|apt]] (i.e. in a terminal, type):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install python&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will give you Python, and now you just have to install the Phidget Python module to gain Phidget functionality.&lt;br /&gt;
&lt;br /&gt;
=====Install Phidget Python Method 1: Use a USB Key=====&lt;br /&gt;
&lt;br /&gt;
Copy the [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Python Libraries] onto a USB key.  Unpack the zip file into a folder on the USB key.  Insert the key into the SBC.&lt;br /&gt;
&lt;br /&gt;
You will have to figure out where the USB key (and the Phidget Python library folder) is now located.  We describe how in the general [[#Using USB Data Keys | Using USB Data Keys]] section.&lt;br /&gt;
&lt;br /&gt;
After you know the place where the USB key is mounted, in a terminal go to that directory (e.g. type {{Code|cd /media/usb0/}}), enter the unpacked Phidget Python Library folder, and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, you&#039;re ready to begin writing Python code for the SBC.  For more help on writing and using Python with Phidgets, we have an whole [[Language - Python | page on that topic]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].&lt;br /&gt;
&lt;br /&gt;
=====Install Phidget Python Method 2: Use the Internet=====&lt;br /&gt;
&lt;br /&gt;
Rather than using a USB key to transfer the file, the SBC can download it directly from the internet.  You will need {{Code|wget}} and {{Code|unzip}} installed, both of which are small:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install wget&lt;br /&gt;
apt-get install unzip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the web link address for the [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Python Libraries].&lt;br /&gt;
&lt;br /&gt;
In an SSH terminal to the SBC, type: {{Code|wget http://www.python_library_link}} where instead of http://www.python_library_link you insert the link you just copied. Copying into a terminal can usually be done via the right-click menu.&lt;br /&gt;
&lt;br /&gt;
This will download the Phidget python libraries to the folder you ran the {{Code|wget}} command in.  Unzip the downloaded file using the command {{Code|unzip file}}, where file is the filename from {{Code|wget}}. Or try typing {{Code|ls}} to list the names of a file in the directory, which should include the unzipped folder.  Enter the unzipped folder (e.g. use {{Code|cd}} to change directory), and install the Phidget Python libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, you&#039;re ready to begin writing Python code for the SBC.  For more help on writing and using Python with Phidgets, we have a whole [[Language - Python | page on that topic]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].&lt;br /&gt;
&lt;br /&gt;
====Installing Other Languages====&lt;br /&gt;
&lt;br /&gt;
You may also be able to program on the SBC using [[Language - Ruby|Ruby]] and [[Language - C Sharp|C# under Mono]], though we do not offer in-depth support for these languages on the SBC.  The installation procedures should more or less follow that of [[#Installing Python|installing python]] on the SBC, except you will be installing Ruby or Mono.  Performing package searches using [[#apt|apt cache search]] can help you find the relevant software.&lt;br /&gt;
&lt;br /&gt;
For C#, as of 2012 the {{Code|mono-complete}} package is broken on the Debian Squeeze repository.  Rather, you have to install the Mono runtime and Mono compiler separately.&lt;br /&gt;
&lt;br /&gt;
To install the runtime package (and its dependencies), use [[#apt|apt]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-runtime&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to install the C# compiler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-gmcs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or the Visual Basic compiler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-vbnc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, the system and library packages do not link correctly for the version 2.0 of Mono.  If this is the case, your code will compile fine, but when you try to run it, you will get an error like:&lt;br /&gt;
&lt;br /&gt;
:{{Code|The assembly mscorlib.dll was not found or could not be loaded.}}&lt;br /&gt;
:{{Code|It should have been installed in the `/usr/lib/mono/1.0/mscorlib.dll&#039; directory.}}&lt;br /&gt;
&lt;br /&gt;
In this case, you need to install these two packages:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install libmono-corlib1.0-cil&lt;br /&gt;
apt-get install libmono-system1.0-cil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we found these packages to work by working through the tree structure.  As a general rule, you can find these dependencies by using install (here, {{Code|apt-get install mono-complete}}) to get a sense of the package tree structure.  This will possibly tell you that the packages are broken, but at the same time this will list the dependencies of the packages.  Trying to install individual dependencies will show you that although a root-package fails, the sub-packages will sometimes succeed, and install what you need.&lt;br /&gt;
&lt;br /&gt;
If you want to use a specific dll or library that is not available in this reduced version of mono, you can install mono complete by switching from Emdebian+Debian to just Debian.  To do this:&lt;br /&gt;
&lt;br /&gt;
In {{Code|/etc/apt/preferences}} make the following changes:&lt;br /&gt;
:{{Code|Package: *}}&lt;br /&gt;
:{{Code|&amp;lt;nowiki&amp;gt;Pin: release a=stable&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
:{{Code|Pin-Priority: 1010}}&lt;br /&gt;
	&lt;br /&gt;
In {{Code|/etc/apt/sources.list/mutistrap-debian.list}} remove the emdebian line.&lt;br /&gt;
&lt;br /&gt;
Apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get dist-upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many packages will be &#039;downgraded&#039; from the emdebian to debian versions.  Delete the {{Code|&amp;lt;nowiki&amp;gt;/etc/apt/preferences&amp;lt;/nowiki&amp;gt;}} file and install mono-complete:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install monodoc-http mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose monodoc-http explicitly, because otherwise the install fails on monodoc-browser.&lt;br /&gt;
&lt;br /&gt;
After this process, you can compile your C# Code.cs Phidget source file the same way as on a generic [[Language - C Sharp#Linux|Linux with Mono]] system.  Please refer to that page on how to obtain the *.dll Phidget resource file and compile your code.  On the SBC, however, because you are already running as root (the Super User), you do not need &#039;sudo&#039; and indeed the SBC will give you an error if you use it.  Instead, compiling and running will look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Code.cs -r:Phidget21.NET.dll&lt;br /&gt;
mono Code.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using SBC Linux==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve set up communication with the SBC, and installed whichever programming language support you need, you&#039;re probably ready for a short tour of useful tools on the SBC&#039;s version of Linux.&lt;br /&gt;
&lt;br /&gt;
First, you will by default be running on the SBC as &#039;&#039;&#039;root&#039;&#039;&#039;, which is the super-user.  For Linux users, this probably makes you nervous because you know you can overwrite important system files without the system asking for additional permission.  As a Windows or Mac OS user - although you may usually run your computer as an administrator - your familiar system usually prompts you to confirm before you do anything really dangerous, and this will &#039;&#039;&#039;not&#039;&#039;&#039; happen on the SBC as the root user.&lt;br /&gt;
&lt;br /&gt;
Next, there is no installed help on the SBC.  Help on Linux is usually called &#039;man pages&#039; which is short for &#039;the manual pages&#039;.  On a full Linux system, usually if you need help with any command you can type, for example, {{Code|man ls}} and it will give you help with the program [[#ls|ls]].  But these help pages take up significant space, and they are widely available online.  So, if you need more help with a certain command, you can always type {{Code|man command}} into your favourite search engine.&lt;br /&gt;
&lt;br /&gt;
Finally, the SBC has no windowing system.  For Linux users, this means no X-windows (Gnome, KDE, etc).  And as a Windows or Mac user, you can think of it as running all of your programs and commands through the terminal or DOS prompt command line.  The SBC provides all of the functionality of an operating system (e.g. process scheduling, file management, etc) but without any graphical interface.  The only exception is the [[#SBC Web Interface|web interface]], which gives graphical access to a limited part of what the SBC can do.&lt;br /&gt;
&lt;br /&gt;
===Some Useful Commands===&lt;br /&gt;
&lt;br /&gt;
If you are doing more with the SBC than simply running pre-written programs [[#Writing a Phidget Program|in Java to run continuously from boot]], you will be interacting with the SBC&#039;s Linux operating system over the command line by using [[#SSH|SSH]].  This section discusses useful programs already installed on the SBC, and how to run them on the command line.&lt;br /&gt;
&lt;br /&gt;
====ls====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ls&#039;&#039;&#039; program lists the contents of a directory.&lt;br /&gt;
&lt;br /&gt;
It will show both files and folders, but not files that start with a &amp;quot;.&amp;quot; (these are hidden files on Linux).&lt;br /&gt;
*If you also want to show hidden files, use {{Code|ls -a}}&lt;br /&gt;
*If you want more information, such as size and date modified, use {{Code|ls -l}}&lt;br /&gt;
*Commands can be combined, like {{Code|ls -al}}&lt;br /&gt;
&lt;br /&gt;
====cd====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;cd&#039;&#039;&#039; program changes to a new directory.&lt;br /&gt;
&lt;br /&gt;
For example, {{Code|cd /root}} changes into the directory at the base of the file tree called &#039;&#039;root&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
* Linux uses forward slashes&lt;br /&gt;
* The base of all directories is &amp;quot;/&amp;quot; (not &amp;quot;C:\&amp;quot;)&lt;br /&gt;
* The tilde symbol (~) is short for your home directory (i.e. when you are root, this is short for &amp;quot;/root&amp;quot;)&lt;br /&gt;
* The double dot &amp;quot;..&amp;quot; means move one directory higher (for example from {{Code|/root/data/}} to {{Code|/root/}})&lt;br /&gt;
&lt;br /&gt;
====pwd====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;pwd&#039;&#039;&#039; program prints the current directory you are working in.  (&#039;P&#039;rint &#039;W&#039;orking &#039;D&#039;irectory)&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
:{{Code|root@phidgetsbc:~# pwd}}&lt;br /&gt;
:{{Code|/root}}&lt;br /&gt;
&lt;br /&gt;
====cp, mv, and rm====&lt;br /&gt;
&lt;br /&gt;
These programs are copy (&#039;&#039;&#039;cp&#039;&#039;&#039;), move (&#039;&#039;&#039;mv&#039;&#039;&#039;), and remove (&#039;&#039;&#039;rm&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Copy copies a file from one location and pastes it to another.&lt;br /&gt;
&lt;br /&gt;
For example, if you have a file {{Code|data.txt}}, typing {{Code|cp data.txt data_backup.txt}} will put a copy of the file {{Code|data.txt}} into {{Code|data_backup.txt}}&lt;br /&gt;
&lt;br /&gt;
Move moves a file (this is also useful for renaming files) to a new destination.&lt;br /&gt;
&lt;br /&gt;
For example, if you have a file {{Code|data.txt}}, typing {{Code|mv data.txt data_backup.txt}} will put the contents of {{Code|data.txt}} into {{Code|data_backup.txt}}, and then will remove {{Code|data.txt}}.&lt;br /&gt;
&lt;br /&gt;
Remove deletes a file.&lt;br /&gt;
&lt;br /&gt;
For example, typing {{Code|rm data.txt}} will delete {{Code|data.txt}}.&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;&#039;rm&#039;&#039;&#039; is final.  Once you remove a file using {{Code|rm}}, it is gone forever.  There is no recycle bin, no temporary trash, nothing other than backups you may have personally created in the past!&lt;br /&gt;
&lt;br /&gt;
Directories can only be removed with {{Code|rmdir}}, and then only if they are empty.  If you want to remove a directory and all the files in it, use {{Code|rm -rf directory}} but be &#039;&#039;&#039;very, very careful&#039;&#039;&#039; with this command.  Trying to remove everything within a directory (e.g. {{Code|rm -rf *}}) is one of the most dangerous commands you can run on a Linux system, as running it from the wrong directory will result in Linux happily removing everything under that directory -- which could be your entire filesystem.&lt;br /&gt;
&lt;br /&gt;
====find====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;find&#039;&#039;&#039; program does what it says - it finds things.  &lt;br /&gt;
&lt;br /&gt;
Unfortunately for the casual user, the find program is very flexible and powerful, and thus not especially intuitive to use.  But, here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;15px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! SSH Command&lt;br /&gt;
! What it Does&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|find folder -name file.txt}}&lt;br /&gt;
| Looks for all files in a folder (/ for root - or all - folders) with a certain name (* for wildcard)&lt;br /&gt;
| {{Code|find / -name *.jpg}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|find folder -mtime +X}}&lt;br /&gt;
| Looks for all files in a folder modified less than X days ago&lt;br /&gt;
| {{Code|find /root -mtime +30}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====grep====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; program takes text input and searches for a term. &lt;br /&gt;
&lt;br /&gt;
For example, if you type {{Code|mount}} to view what devices are mounted (e.g. loaded) on your SBC, you will see:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may be a lot of information you don&#039;t need.  If you are only interested in a USB key attachment (as described in the [[#Using USB Data Keys|Using USB Data Keys]] section), you can use grep to filter that one response:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount | grep sda1&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====nano====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;nano&#039;&#039;&#039; program is a small text editor that you can use within an SSH terminal. &lt;br /&gt;
&lt;br /&gt;
Nano can be surprisingly useful for writing short lengths of code right on the SBC, so there is no need to transfer files and keep track of different file versions on different computers.&lt;br /&gt;
&lt;br /&gt;
Nano has all keyboard commands which are listed at the bottom of the screen at all times as a reminder (Ctrl-O to save, Ctrl-X to exit, these expand with a larger terminal window).  And, nano provides what is called &#039;syntax highlighting&#039;, which colours reserved keywords, comments, strings, and so on as appropriate to the programming language you are using.  Nano detects the programming language via the extension of the file ({{Code|.java}} for Java, {{Code|.c}} for C/C++, and {{Code|.py}} for Python).&lt;br /&gt;
&lt;br /&gt;
Typing {{Code|nano test.py}} on an SSH command line and then entering a few lines of Python into the new empty file results in:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_nano_python.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
====apt====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apt&#039;&#039;&#039; program allows you to install, uninstall, upgrade, and search software available for the SBC.&lt;br /&gt;
For a non-Linux user, the apt framework may be daunting at first, but it actually allows you to keep your system up to date and install and manage software quickly, easily, and for free.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Before installing anything on the SBC, make sure that the &#039;&#039;Include full Debian Package Repository&#039;&#039; option is checked in the web interface under {{Code|System &amp;amp;rarr; Packages}}.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;15px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! SSH Command&lt;br /&gt;
! What it Does&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|apt-cache search term}}&lt;br /&gt;
| Looks for all programs (packages) that have {{Code|term}} in the title or description&lt;br /&gt;
| {{Code|apt-cache search opencv}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|apt-cache show package}}&lt;br /&gt;
| Shows a lot of data about {{Code|package}} including size, version, etc&lt;br /&gt;
| {{Code|apt-cache show unzip}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|apt-get update}}&lt;br /&gt;
| Gets the most recent listing of available software&lt;br /&gt;
| {{Code|apt-get update}}  (No options)&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|apt-get install program}}&lt;br /&gt;
| Installs {{Code|program}} from the internet&lt;br /&gt;
| {{Code|apt-get install python}}&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====mount====&lt;br /&gt;
&lt;br /&gt;
The program {{Code|mount}} shows you all of the mounted devices on your SBC.  &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the non-Linux user, the concept of a device may be quite strange.  To give a short summary, everything on Linux that you can read or write is a file.  Webcams are files (i.e. you can &#039;read&#039; photos from them), USB keys are files, and each filesystem (tmp storage, the kernel portion, the main filesystem) are also themselves files.  These files specify what and how something can be written.  These are not necessarily linear, for example, you can see above that the USB key ({{Code|/media/usb0}} is mounted &#039;&#039;within&#039;&#039; the root file system {{Code|rootfs}} which is /.   &lt;br /&gt;
&lt;br /&gt;
So mount gives you an idea of what devices have been &#039;mounted&#039; for reading or writing, and how you can read and write to them.  More information on mount (and its various forms, like {{Code|umount}}) is available widely around the Internet.&lt;br /&gt;
&lt;br /&gt;
====which====&lt;br /&gt;
&lt;br /&gt;
The program {{Code|which}} tells you if and where a program is installed.&lt;br /&gt;
&lt;br /&gt;
For example, on a default SBC, typing {{Code|which python}} will return no results.  But after successfully [[#Installing Python | installing python]], it will return {{Code|/usr/bin/python}} as the location of the python program/binary/executable.&lt;br /&gt;
&lt;br /&gt;
===Some Useful Commands to Install===&lt;br /&gt;
&lt;br /&gt;
These are other programs you may find useful on the command line.  Although they are not on the SBC by default, these and other programs can usually be installed simply by using [[#apt|apt-get install]], with the exception of gcc.  For example, {{Code|apt-get install wget}} will download and install [[#wget|wget]].  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This section and the section on [[#Some Useful Commands|pre-installed commands]] can hardly cover all of the complexities and power of the Linux operating system.  There are many excellent tutorials online, and between them and using [[#apt|apt]] to find and install programs you should be able to learn a lot and perform any number of complex useful tasks.&lt;br /&gt;
&lt;br /&gt;
====gcc====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;gcc&#039;&#039;&#039; program is the C compiler for Linux.&lt;br /&gt;
&lt;br /&gt;
If you are an experienced C/C++ user on Mac or Linux, or if you&#039;ve already read our [[Language - C/C++ | C Language page]], you might think you need to install gcc via {{Code|apt-get}} to compile C code.  However, gcc is not in the package repository for the SBC, so {{Code|apt-get install gcc}} will fail.  Rather, to install gcc, you can do it via the web interface, as described in the [[#Installing C/C++ and Java|Installing C/C++ and Java]] section.&lt;br /&gt;
&lt;br /&gt;
After installing it via the SBC web interface, you can use {{Code|gcc}} normally.&lt;br /&gt;
&lt;br /&gt;
====less====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;less&#039;&#039;&#039; program displays the contents of a text or source code file.  When displaying the file, {{Code|less}} allows you to scroll up and down to read it.&lt;br /&gt;
&lt;br /&gt;
This is useful if you are writing your sensor readings to a data file, and you want to read the data file while it is being written by your main code.  If your data file is called {{Code|data.txt}}, you can type {{Code|less data.txt}} and see the lines in the file, and what they are.&lt;br /&gt;
&lt;br /&gt;
The {{Code|less}} program output can also be piped into another program.  For example, you can use {{Code|less}} and the word search program {{Code|grep}} to find lines within a file with a search term.  For instance, if you have a C source code file {{Code|Program.c}} on the SBC, and you want to see all the lines in {{Code|Program.c}} that contain a variable name {{Code|var}}, you can type: &lt;br /&gt;
:&amp;lt;code&amp;gt;less Program.c | grep var&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====wget====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;wget&#039;&#039;&#039; program allows you to get an online file (over http) and download it to the SBC.&lt;br /&gt;
&lt;br /&gt;
For example, to get the source file (HTML) from the Phidgets home page, you can type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
wget http://www.phidgets.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is most useful for downloading libraries, drivers, or anything (zip, tar, etc) you need from the web which is not available by [[#apt|using apt]].&lt;br /&gt;
&lt;br /&gt;
===Writing a Phidget Program===&lt;br /&gt;
&lt;br /&gt;
We provide two ways to write and upload a Phidget Program:&lt;br /&gt;
# The [[#SBC Web Interface|web interface]]:&lt;br /&gt;
#* This is useful for simple projects written in Java that you want to start only at boot&lt;br /&gt;
#* You can also use C projects, but they must be compiled off the SBC for an ARM processor&lt;br /&gt;
# Over [[#SSH|SSH]], which will allow you to write or transfer source code directly to and from the SBC&lt;br /&gt;
#* This is useful for all other projects, such as:&lt;br /&gt;
#** Projects that run at scheduled times (e.g. once per minute)&lt;br /&gt;
#** Projects that use languages other than Java or ARM-compiled C&lt;br /&gt;
Note that you can still run an [[#SSH|SSH]] project at boot, you just have to write and install a startup script.  This is a bit complex, but we do have an example that starts the program {{Code|phidgetwebservice21}} [[OS - Linux#As A Service|at boot using a script]].&lt;br /&gt;
&lt;br /&gt;
Once you know which method you&#039;d like to use, you can continue on to learn how to [[#Program in Java with the Web Interface|Program in Java with the Web Interface]], or how to [[#Program with SSH|Program with SSH]] using Java, C, or Python.  If you are actually typing in source code on the SBC, you&#039;ll find our [[#Developing Code on the SBC|developing code on the SBC section]] useful.&lt;br /&gt;
&lt;br /&gt;
====Program in Java with the Web Interface====&lt;br /&gt;
&lt;br /&gt;
To show how to write, compile, and install Java programs on the SBC, we&#039;ll use the [[Language - Java|Java Hello World]] example code.  You can download the HelloWorld example by downloading the whole [{{SERVER}}/downloads/examples/JavaJNI.zip Java example package].  Make sure you have [[#Installing C/C++ and Java|Java installed on the SBC]].&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to get the HelloWorld code running on the SBC.  On your external computer:&lt;br /&gt;
&lt;br /&gt;
1. Download the SBC version of the Phidget Java libraries ({{Code|phidget21.jar}}).  You can download this from the [[#SBC Web Interface|web interface]], on the page under {{Code|Projects &amp;amp;rarr; Projects}}, under the &#039;&#039;&#039;Notes&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
2. Place the SBC version of {{Code|phidget21.jar}} into a directory on your external computer.  This will be your working directory that you will use to compile the Java files.&lt;br /&gt;
&lt;br /&gt;
3. Also copy the {{Code|HelloWorld.java}} file into that working directory.&lt;br /&gt;
&lt;br /&gt;
4. Compile the {{Code|HelloWorld.java}} file from within that working directory.  From the command line prompt on Windows, this will be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
In a terminal on Linux or Mac OS, this will be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. You should now have three compiled class files: {{Code|HelloWorld.class}}, {{Code|HelloWorld$1.class}}, and {{Code|HelloWorld$2.class}}.  You don&#039;t need to try and run them, and if you do you may encounter an error because the SBC {{Code|phidget21.jar}} may be slightly different than the Phidget support you have installed on your external computer.&lt;br /&gt;
&lt;br /&gt;
Now we move onto the SBC:&lt;br /&gt;
&lt;br /&gt;
6. Create a new project on the SBC, in the web interface under {{Code|Projects &amp;amp;rarr; Projects}}.  Call it HelloWorld:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_create_project.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
7. On the next screen, you will be prompted to upload your files.  We will upload the three Java class files, and then click the {{Code|Start}} button:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_web_run_project.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
8. You&#039;ll note that as it runs, there are two links below the {{Code|Stop}} button: One called {{Code|stdout}}, which is &#039;&#039;Standard Output&#039;&#039;, and one called {{Code|stderr}}, which is &#039;&#039;Standard Error&#039;&#039;.  Usually, when you run a program on the command line, you see both standard out and standard error at the same time - i.e. you get all program output right there in your terminal or command prompt.  But when running a program in the background, Linux splits the output up into normal output and error output as this is very useful for debugging (i.e. you can check if standard error is empty).  &lt;br /&gt;
&lt;br /&gt;
Here, however, if you&#039;re not sure whether the program will run correctly, you should first check {{Code|stderr}} to see if any errors were generated, and then check {{Code|stdout}} to see if the output looks as expected.&lt;br /&gt;
&lt;br /&gt;
To write your own Java program, follow the same process but use your own source code instead of the {{Code|HelloWorld.java}} example.&lt;br /&gt;
&lt;br /&gt;
Now that you have a running program, we offer additional help on [[#Via the Web Interface|running a program automatically using the web interface]].&lt;br /&gt;
&lt;br /&gt;
====Program with SSH====&lt;br /&gt;
&lt;br /&gt;
Similarly to starting a program via the [[#Program in Java with the Web Interface|web interface]], we use the Phidget Java {{Code|HelloWorld}} example here.&lt;br /&gt;
&lt;br /&gt;
Make sure you have [[#Installing C/C++ and Java|Java installed on the SBC]].  To compile and run the {{Code|HelloWorld}} example:&lt;br /&gt;
&lt;br /&gt;
1. Open an [[#SSH|SSH terminal]] to the SBC&lt;br /&gt;
&lt;br /&gt;
2. Download the [{{SERVER}}/downloads/examples/JavaJNI.zip Phidget Java Examples] to the SBC, using [[#wget|wget]] (you may need to install {{Code|wget}} using [[#apt|apt]].)&lt;br /&gt;
&lt;br /&gt;
3. Unpack the examples using [[#unzip|unzip]] (you may need to install {{Code|unzip}} using [[#apt|apt]].)&lt;br /&gt;
&lt;br /&gt;
4. The location of {{Code|phidget21.jar}} on the SBC is {{Code|/usr/share/java/phidget21.jar}}.  Within the unzipped example directory, compile the {{Code|HelloWorld.java}} example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:/usr/share/java/phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. To run the {{Code|HelloWorld}} program, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:/usr/share/java/phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that you have a running program, you&#039;ll probably want to learn to [[#Running a Program Automatically|run this Java program automatically]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Permissions Note:&#039;&#039;&#039; If you&#039;re used to using Linux with Phidgets already, you&#039;ll probably notice that you don&#039;t need to switch into root using {{Code|sudo}} on the SBC in order to run programs.  This is because you already are running as root, not because the [[OS - Linux#Setting udev Rules|udev rules are set up]].  So if you set up another user, or [[#Via Cron|run a cron job]] as anything other than root or system, you&#039;ll need to add permission for the Phidget program to run in your [[OS - Linux#Setting udev Rules|udev rules]].&lt;br /&gt;
&lt;br /&gt;
====Developing Code on the SBC====&lt;br /&gt;
&lt;br /&gt;
When you&#039;re not just using pre-written source code, and you&#039;re writing code actually on the SBC itself, you&#039;ll probably want to use [[#nano|nano]].  Other terminal editors on the SBC include {{Code|vi}} which is already installed, and {{Code|emacs}}, which you can install using [[#apt|apt]].  Both {{Code|vi}} and {{Code|emacs}} are much more efficient for the experienced user, but they contain modes and keyboard shortcuts that can seem strange or almost hindering to the casual user.&lt;br /&gt;
&lt;br /&gt;
Regardless of which editor you choose to use, some of your keyboard habits may not transfer well.  For example, in the Linux command line, the command {{Code|Ctrl-C}} means &#039;&#039;stop the currently running program&#039;&#039;, (i.e. your open editor) not copy.  Within most SSH terminals, you can copy and paste using the right-mouse button, and on some terminals (and all native Linux terminals) you can copy by simply highlighting text, and you can paste it using the middle (scroll) mouse button.  On the other hand, if you write a program that hangs on the command line, {{Code|Ctrl-C}} can actually be useful to terminate it.&lt;br /&gt;
&lt;br /&gt;
Also {{Code|Ctrl-Z}} does not mean &#039;&#039;undo&#039;&#039;, rather it means &#039;&#039;run the current program in the background&#039;&#039;.  This is useful because running a program in an SSH terminal simply hangs your SSH input until the program is done.  So typing {{Code|Ctrl-Z}} while the program is running frees up the command line for more input.  But if you accidentally hit {{Code|Ctrl-Z}} while running an editor like [[#nano|nano]], the editor will immediately exit to the command line.  Don&#039;t worry though, it will not stop or lose your work.  You can bring it back up by using the {{Code|fg}} (e.g. &#039;foreground&#039;) command, like {{Code|fg nano}}, and this will automatically bring your nano process back to the front.&lt;br /&gt;
&lt;br /&gt;
===Running a Program Automatically===&lt;br /&gt;
&lt;br /&gt;
For testing your program, you will certainly want to run it via [[#SSH|SSH]] or via the {{Code|Start}} button on the project page on the web interface until you are quite sure it runs well.  However, eventually you will probably want the program to run without your input, either [[#Via the Web Interface|continuously, and starting at boot]], or via a task scheduled to [[#Via Cron|run to completion at certain times]].&lt;br /&gt;
&lt;br /&gt;
Both have their advantages and disadvantages.  Usually, you would want to use the continuous, from-boot methods for event driven code that has to handle a wide variety of user input that could occur at any time.  You would want to use the scheduled method when the SBC needs to perform a repeated task (e.g. reading sensor data) again and again.  The main difference is:&lt;br /&gt;
* With the continuous (boot) method you can have any Phidgets (including sensors, LEDs, input switches, etc) attached and giving events to your code all the time, and&lt;br /&gt;
* With the scheduled (cron) method you have much less of a chance to run into long-term memory management and instability problems with any code you write, because your program runs for only a short time before exiting and getting cleaned up.&lt;br /&gt;
&lt;br /&gt;
====Via the Web Interface====&lt;br /&gt;
&lt;br /&gt;
To use this method, you must have created the program you want to run as [[#Program in Java with the Web Interface | a Java or ARM-compiled C project in the web interface]].  If you would like to use another language, or another way of uploading your project, but you still want to start at boot and run continuously, you will need to use a [[#Via a Boot Script|boot script]].&lt;br /&gt;
&lt;br /&gt;
In the web interface, go to the {{Code|Projects}} tab, and click on the project you would like to run.  Near the bottom of the project page (the one with the {{Code|Start}} and {{Code|Stop}} buttons at the top), there will be a section called {{Code|Startup Settings}}.  You can see a screenshot of the whole project page, including these settings, in the [[#Program in Java with the Web Interface | web interface project section]].&lt;br /&gt;
&lt;br /&gt;
Select the {{Code|Enabled}} radio button.  The other defaults should be fine, unless you specifically know otherwise:&lt;br /&gt;
* For &#039;&#039;Boot Order&#039;&#039;, lower numbers boot first.  Booting later means more programs are available for use, booting earlier means other programs can use your program.  &lt;br /&gt;
* &#039;&#039;Run as a daemon&#039;&#039; starts the program as a daemon, which is a program that runs in the background.  Unless you have &#039;&#039;explicitly&#039;&#039; written your program as a daemon, leave this checked.  (If you don&#039;t know what a daemon is, don&#039;t worry, you haven&#039;t written one, so leave it checked.)  &#039;&#039;Un&#039;&#039;checking this when your program is a normal program will cause the SBC to hang while booting.&lt;br /&gt;
* The &#039;&#039;Executable or Class&#039;&#039; name should be automatically sensed to be your main Java class&lt;br /&gt;
* &#039;&#039;Arguments&#039;&#039; are any command line arguments you need, just as you would type them into the command line&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Your program must be very, very stable to run properly via the web interface.  Imagine your program running continuously for days, or months on end.  Any memory leaks, over time, will render your program (and the SBC) unusable until a reboot.  Counts or other variables that increase within your program and never reset may create a segmentation fault eventually.&lt;br /&gt;
&lt;br /&gt;
If, for stability purposes, you want your program to start, run for a little while, and then exit so that the SBC operating system can clean up the memory each time, you&#039;ll probably want to use [[#Via Cron|Cron]] to run your program instead.&lt;br /&gt;
&lt;br /&gt;
====Via Cron====&lt;br /&gt;
&lt;br /&gt;
Cron can automatically schedule programs - known as &#039;jobs&#039;, or &#039;cron jobs&#039; - at most once per minute.  Less often than that, it is very flexible, allowing you to run it on certain months, weekdays, hours, etc.  Cron simply reads a special file (your {{Code|crontab}}) and runs whatever programs are listed, with whatever timing they are listed with.  The cron program runs all the time in the background, making it what is known as a Linux &#039;&#039;daemon&#039;&#039;, but the programs it starts as jobs run only as long as they naturally would, and then they exit.&lt;br /&gt;
&lt;br /&gt;
If you need your program to run more often than once per minute, have the program schedule itself while still running.  For example, to run every five seconds, run a fast loop,  and sleep for five seconds. Do this twenty times and exit.  Then schedule this once per minute using cron, and your program will in essence run every five seconds.&lt;br /&gt;
&lt;br /&gt;
Setting up a cron job simply entails editing your {{Code|crontab}} file.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll probably want to specify your default editor to be [[#nano|nano]]. Otherwise it will default to {{Code|vi}} and you&#039;ll have to figure out {{Code|vi}} in order to add lines to your crontab:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
export EDITOR=nano&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to edit your crontab file, simply type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
crontab -e&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each line of the crontab file is one scheduled job.  Lines that start with a hash &amp;quot;#&amp;quot; are comments and are ignored.  There is an example line in the crontab, and a reminder line at the very end.  Essentially, each line should contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
minute hour dayOfMonth month dayOfWeek  command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
*{{Code|command}} is the program you want to run (with absolute path, and arguments)&lt;br /&gt;
** For example, {{Code|./myprogram argument1}} won&#039;t work, but {{Code|/root/code/myprogram argument1}} will&lt;br /&gt;
* Each time argument is either a number, a list of numbers separated by commas, or an asterisk&lt;br /&gt;
** For example, * * * * * means every minute for all days and months, 0,30 * * * * means every thirty minutes (i.e. at the top of the hour and at 30 minutes in) for all days and months&lt;br /&gt;
&lt;br /&gt;
If you already have jobs scheduled, you&#039;ll see them in the file that comes up.  You can edit, add, or delete.  &lt;br /&gt;
&lt;br /&gt;
After you save, you&#039;ll see a little message back in the terminal that says the new crontab file was installed, and it is now scheduled!  Cron always starts every boot, and so if you have edited and installed your crontab as above, the scheduling of your program will start properly even after a reboot of the SBC.  However, if you are having strange scheduling problems, you may want to familiarize yourself with the [[#Software Details|software details]] of how the SBC as a whole determines the current date and time.&lt;br /&gt;
&lt;br /&gt;
=====My Cron Job Doesn&#039;t Work!=====&lt;br /&gt;
&lt;br /&gt;
It is actually very common for a script or program to work on the command line but then &#039;&#039;not&#039;&#039; work as a cron job.  The most common reason for this, by far, is that you specify &#039;&#039;relative&#039;&#039; paths in your program to access files rather than &#039;&#039;absolute&#039;&#039; paths.  For example:&lt;br /&gt;
* {{Code|code/project.c}} is a relative path (bad for cron)&lt;br /&gt;
* {{Code|/root/code/project.c}} is an absolute path (good for cron)&lt;br /&gt;
The cron jobs are &#039;&#039;not&#039;&#039; executed from your home directory, or your code directory, so they will not be using the same location you may be using to test your code.  So always use absolute paths.&lt;br /&gt;
&lt;br /&gt;
Another common reason is you may be using environment variables or other settings that are true in a terminal but are &#039;&#039;not&#039;&#039; true by default in the raw system.  You can end up taking many things for granted in a shell, for example the shortcut &amp;quot;~&amp;quot; means home directory in a shell, but not by default in the raw system.  The things that get loaded for a shell (but which are not present in the raw system) are:&lt;br /&gt;
* The settings loaded by {{Code|/etc/profile}}&lt;br /&gt;
* Any settings in {{Code|~/.bashrc}}, which is nothing by default on the SBC&lt;br /&gt;
&lt;br /&gt;
On a full Linux operating system, you would use the logs written to by cron to find the error output and debug it.  On the SBC, however, cron does not write logs (otherwise, these logs would eat up the SBC memory very quickly even for routine jobs).  For short-term debugging, you can write output from your program to a file, and read that file afterwards to figure out what your program is doing.&lt;br /&gt;
&lt;br /&gt;
====Via a Boot Script====&lt;br /&gt;
&lt;br /&gt;
If you want to run your program constantly and for it to start at boot like the [[#Via the Web Interface|web interface would do]], you can install your program into the boot order using a script.  This is a somewhat involved process, and you should be familiar with shell programming in Linux.  For this process, we only offer a [[OS - Linux#As A Service|similar example]] which installs and runs the program {{Code|phidgetwebservice21}} within the boot sequence.&lt;br /&gt;
&lt;br /&gt;
===Using USB Data Keys===&lt;br /&gt;
&lt;br /&gt;
After plugging the USB key in, it won&#039;t just appear on your desktop, so to speak, so you&#039;ll need to figure out where you can read and write to it within the SSH directory structure.&lt;br /&gt;
&lt;br /&gt;
The web interface program can help with this.  After you plug a USB key in, it will show up under {{Code|Status &amp;amp;rarr; System}}.  Or, the USB key and all other attached devices can be seen at {{Code|Status &amp;amp;rarr; USB}}:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_mounted_devices.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, you can see that the USB key is located in {{Code|/media/usb0}}.&lt;br /&gt;
&lt;br /&gt;
Alternately, you can use the SSH command {{Code|mount}}, and the searching program {{Code|grep}} which will filter the response of {{Code|mount}} and only return the lines with your search term ({{Code|usb}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount | grep usb&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the USB key can be written to and read from using the {{Code|/media/usb0}} directory.  Copying a file to {{Code|/media/usb0}} will copy a file to the USB key.  The same goes for removing, renaming, opening files within your program, etc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Mount points like {{Code|/media/usb0}} should not be hard-coded into any of your programs.  (See the [[#Common Problems and Solutions | Common Problems and Solutions]] section for more information.)  If you need to obtain the mount point for a freshly mounted USB key within your code, have your code obtain the mount tables and search on the &#039;&#039;device&#039;&#039;  (e.g. {{Code|/dev/sda1}} or {{Code|/dev/sdb1}}) and obtain the corresponding mounted {{Code|/media/usbN}} location, where N is a number 0-9.&lt;br /&gt;
&lt;br /&gt;
===Saving and Retrieving Data===&lt;br /&gt;
&lt;br /&gt;
This section covers getting data on and off of the SBC.  There are two main methods of simply moving data on and off the SBC - via a [[#Via a USB Key|USB key]], and via [[#Over the Network (SCP)|copy over the network]] - and a third method for moving and installing data when it concerns [[#Backing Up Your Data|backing up lower level system data]].&lt;br /&gt;
&lt;br /&gt;
====Via a USB Key====&lt;br /&gt;
&lt;br /&gt;
After plugging in a USB data key, first you need to [[#Using USB Data Keys | find out the location]] where that data key was mounted.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say the location of the USB key is {{Code|/media/usb0/}}, and we want to copy the file {{Code|data.txt}} to the USB key.  Your SSH session might look something like this, using [[#ls|ls]] and [[#mount|mount]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# ls&lt;br /&gt;
data.txt&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
root@phidgetsbc:~# cp data.txt /media/usb0/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;cp&#039;&#039;&#039; program copies data from a source to a destination.  The syntax is {{Code|cp from to}}, where here we are copying from {{Code|data.txt}} to {{Code|/media/usb0/}}.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution:&#039;&#039;&#039; Even if there is no USB key mounted at {{Code|/media/usb0/}}, this use of {{Code|cp}} will still work &#039;&#039;with no errors&#039;&#039;!  This is because there is still a file called {{Code|/media/usb0/}}, there is just no USB key file system &#039;&#039;mounted&#039;&#039; to that point.  So be sure to run [[#mount|mount]] or use some other method of determining that there is, in fact, a USB data key attached and where it is mounted to.&lt;br /&gt;
&lt;br /&gt;
====Over the Network (SCP)====&lt;br /&gt;
&lt;br /&gt;
SCP is a command line program already installed on Linux and Mac OS, and downloadable for free on Windows.  We discuss it and give examples in the [[#SSH|SSH]] section, but remember it here when you&#039;re trying to get data on and off of the SBC.  With SSH or a terminal already open, you&#039;ll probably find it to be much faster and easier than dealing with a USB key.&lt;br /&gt;
&lt;br /&gt;
====Backing Up Your Data====&lt;br /&gt;
&lt;br /&gt;
For the web interface, you can save and restore all web interface settings under the {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore}} tab.&lt;br /&gt;
&lt;br /&gt;
To save the settings of what packages are installed for later re-installation, you can type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
dpkg --get-selections &amp;gt; installedPrograms.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then save the file {{Code|installedPrograms.txt}} externally.  If you have to completely wipe the SBC, you can just reinstall the whole list by moving the {{Code|installedPrograms.txt}} file back onto the SBC, and then typing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
dpkg –set-selections &amp;lt; installedPrograms.txt&lt;br /&gt;
apt-get dselect-upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also remember to externally save:&lt;br /&gt;
* Your {{Code|~/.bashrc}} settings file if you&#039;ve changed it&lt;br /&gt;
* Your {{Code|crontab}} file if [[#Via Cron|you&#039;ve edited it]]&lt;br /&gt;
* Any data files or code you&#039;ve created&lt;br /&gt;
&lt;br /&gt;
It is important to save these settings often, and at points where you know the system is running well.  It may be tempting to create a backup right before you [[#Recovery System|wipe the SBC and start from scratch]], but often the reason you are having problems then is some setting or change, and backing these up and reinstalling them will only reinstall the problem.&lt;br /&gt;
&lt;br /&gt;
To truly back the files up, you must copy them to an external computer or location using either a [[#Via a USB Key|USB Key]] or [[#Over the Network (SCP) | over the network]].  Then they can be copied back if needed later.&lt;br /&gt;
&lt;br /&gt;
If you are looking to restore data on an SBC that will not boot properly, you&#039;ll want to be in the [[#Partial Recovery|partial recovery]] portion of our Troubleshooting section.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
The SBC can be quite tricky to debug, because it is a complex and flexible computer.  Common problems and solutions include:&lt;br /&gt;
* You can&#039;t find the SBC on the network at all - refer to the [[#Initial Internet Setup|Initial Internet Setup]] section&lt;br /&gt;
* You have changed some setting or file such that the SBC doesn&#039;t run anymore, or doesn&#039;t run as expected - refer to the [[#Recovery|Recovery]] section&lt;br /&gt;
&lt;br /&gt;
If you are having trouble using Phidgets on the SBC, you should go through the [[OS - Linux#Troubleshooting | Troubleshooting section on the general Linux page]].  Some of the problems on the Linux page (such as library problems) are easier to fix by simply working through the [[#Recovery|Recovery]] section when they occur on the SBC.&lt;br /&gt;
&lt;br /&gt;
Namely, it often helps to simply perform a [[#Factory Reset|factory reset]] on the SBC (save your files and installed program list first, as [[#Backing Up Your Data|described here]]).  Sometimes you change a file or setting within the operating system when you are trying to get something up and running, and this unintentionally affects other programs too.  Performing a factory reset starts you with a clean slate.&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, or the information within this guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
===Initial Internet Setup===&lt;br /&gt;
&lt;br /&gt;
To set up the SBC, you almost always need a &#039;&#039;wired&#039;&#039; Ethernet connection with DHCP (Dynamic Host Configuration Protocol), and without a firewall.  This connection should be to a &#039;&#039;router&#039;&#039;, not directly plugged in to your computer.&lt;br /&gt;
&lt;br /&gt;
Even if you do not have this type of a connection at home, these types of connections are very common at both offices and universities.  On a Windows or Mac OS computer, you can bring up the Phidget Control Panel as described in the SBC&#039;s [[1072 - Getting Started|Getting Started Page]].  Failing this, or on a Linux computer, we discuss some alternate setup methods in this section.  Keep in mind that without a wired, open DHCP connection these setup methods can be difficult and fickle. &lt;br /&gt;
&lt;br /&gt;
====No Wired-Only Connection====&lt;br /&gt;
&lt;br /&gt;
Sometimes it can work to plug the SBC, using Ethernet, directly into an Ethernet port on your home wireless router.  Do not plug it directly into your computer!  (Although in some instances, a direct connection can be made to work on Linux, see the [[#No DHCP|No DHCP]] section below) &lt;br /&gt;
&lt;br /&gt;
This direct-router method is a very picky process, however, and can fail because:&lt;br /&gt;
* Some home and office routers place a firewall between wireless connections (clients) and wired connections (the local area network)&lt;br /&gt;
* Some home and office routers do not by default allow both Ethernet DHCP and wireless DHCP.&lt;br /&gt;
* Some routers and DHCP hubs only provide access to an internet connection, and do not provide local area network inter-connections (this is common on mobile device tethering hubs)&lt;br /&gt;
&lt;br /&gt;
Routers are quite complex, and even with admin privileges it can be a painstaking process to find all the right firewall settings to turn off in order to allow two computers on the network to talk to one another, rather than just connect to the internet.  This is why university or office networks are often ideal for the purpose of setting up the SBC, because these institutions depend on computers on a local network being able to talk together.  University libraries in particular can be a good source of wired DHCP connection ports.  &lt;br /&gt;
&lt;br /&gt;
Covering all of the different router configuration possibilities here, and how to change them to make the SBC work, is essentially impossible.  If you try using the SBC at home or at work, the SBC does not work on the first try when plugged directly into the router via Ethernet, and you want to make that connection work rather than seeking out an alternate for the initial setup, you should find documentation specific to your router (usually available online) and properly configure it.&lt;br /&gt;
&lt;br /&gt;
The good news is that if you can find an Ethernet DHCP connection &#039;&#039;just once&#039;&#039; for a short time, you can use that connection to configure the SBC to work on your home wireless network.  During that initial connection, you can enable wireless and set up as many wireless DHCP connections (with passwords) that you need.  Once wireless is enabled and set up, you can take the SBC home to your wireless router and the SBC will automatically seek out and connect to its remembered networks as they appear.  At that point, you can also use wireless like a normal internet, web interface, and SSH connection.&lt;br /&gt;
&lt;br /&gt;
====No Link Local Addressing====&lt;br /&gt;
&lt;br /&gt;
If you have a wired DHCP connection, no firewall, and no link local addressing (e.g. bonjour or avahi is not installed) then you will need access to the DHCP router logs.  From the router logs, you should see the connection (or attempted connection) by the SBC within the logs.  From that log entry, you should either be able to determine the IP address for the SBC, or see what happens when the router blocks access.  The IP address can be used in place of the link local address for both the web interface and for SSH.&lt;br /&gt;
&lt;br /&gt;
====No DHCP====&lt;br /&gt;
&lt;br /&gt;
The SBC will first try to use DHCP, but then it will revert to responding to a link local address under bonjour and avahi.  If you are depending on this, please wait &#039;&#039;&#039;at least three minutes&#039;&#039;&#039; after the SBC boots for the SBC to fail in obtaining a DHCP connection and properly revert to link local addressing.&lt;br /&gt;
&lt;br /&gt;
If you have a static IP setup, and want to use link local addressing rather than accessing the router logs, this should usually work by default on Windows and Mac OS (e.g. type the address such as {{Code|phidgetsbc.local}} into a web browser).  If it doesn&#039;t work automatically, there is not much you can do and you should seek out a wired DHCP connection elsewhere.&lt;br /&gt;
&lt;br /&gt;
On Linux, it also should work by default, but you have the additional option of explicitly adding routes that look within the default network settings for the SBC.  From a terminal (as root), type:&lt;br /&gt;
* {{Code|route add -net 169.254.0.0 netmask 255.255.0.0 dev eth0 metric 99}}&lt;br /&gt;
* {{Code|route add default dev eth0 metric 99}}&lt;br /&gt;
You can also compile and use the {{Code|phidgetsbclist.c}} example (use the provided Makefile, don&#039;t use gcc) in the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Linux Libraries] package, under the {{Code|examples}} folder.  This will allow you to see if the SBC is detected on the network at all.   Note that to use this option you must have the Phidget Libraries and the Phidget WebService installed on your Linux computer - in-depth instructions to do this are on the [[OS - Linux|main Linux page]].&lt;br /&gt;
&lt;br /&gt;
===Recovery System===&lt;br /&gt;
&lt;br /&gt;
You can either boot the SBC into recovery mode and attempt to recover files and settings, or you can completely wipe the SBC by performing a factory reset.  If the LEDs do not turn on normally (red on constantly, green on at first start, then off, then on when fully booted) then you&#039;ll want to read the [[#Hardware Issues|hardware issues]] section.&lt;br /&gt;
&lt;br /&gt;
====Partial Recovery====&lt;br /&gt;
&lt;br /&gt;
The recovery system can be entered in two ways:&lt;br /&gt;
# From the {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore}} web interface page.&lt;br /&gt;
# By holding down the reset button for 20+ seconds - until the green light has switched from flashing slowly to flashing quickly.&lt;br /&gt;
&lt;br /&gt;
The recovery system runs an [[#SSH|SSH]] server where the username and password both are {{Code|root}}.&lt;br /&gt;
&lt;br /&gt;
If the main filesystem has been damaged/misconfigured in such a way that it won’t boot, you may be able to fix the issue or recover important files before running a full factory reset. From an SSH connection to the recovery system, you can mount the main root filesystem with the following commands (assuming it’s not damaged):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
ubiattach /dev/ubi_ctrl -m 6&lt;br /&gt;
mount -t ubifs /dev/ubi0_0 /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Factory Reset====&lt;br /&gt;
&lt;br /&gt;
This restores the kernel and root filesystem from backup, overwriting any changes that may have been made and &#039;&#039;completely wiping the system&#039;&#039; to the state that it got shipped in. (You can save your files and installed program list first, as [[#Backing Up Your Data|described here]].)  This can be enacted one of two ways.&lt;br /&gt;
# Use the reset button:&lt;br /&gt;
##Enter the recovery mode by holding down the reset button for 20+ seconds as above (until fast flashing)&lt;br /&gt;
##Wait for a full boot (i.e. you can see it on the Phidget control panel, or can SSH with username and password as {{Code|root}})&lt;br /&gt;
##Hold down the reset button again, but this time for only 10 seconds (until slow flashing)&lt;br /&gt;
##Wait for the SBC to fully reset and reboot (at least three minutes) - the LED will turn off and on again when this occurs&lt;br /&gt;
##*Note that after a factory reboot the SSH server will be disabled&lt;br /&gt;
##*Also note that after a factory reboot the SBC creates new SSH keys, and reverts to the {{Code|phidgetsbc.local}} address&lt;br /&gt;
# Via the web interface, under {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore &amp;amp;rarr; Go button}}, where you can follow the instructions&lt;br /&gt;
&lt;br /&gt;
====Hardware Issues====&lt;br /&gt;
&lt;br /&gt;
The LEDs are an indicator of the hardware working properly.  The normal boot process is:&lt;br /&gt;
* Red LED: Turns on from moment of power being applied.&lt;br /&gt;
* Green LED: Turns on momentarily when power applied, then turns off momentarily, then turns on and stays on when booted.&lt;br /&gt;
&lt;br /&gt;
If the green status LED never turns on (or fails to turn on the second time), the boot process is failing somewhere.  This could be due to:&lt;br /&gt;
* A damaged OS - Try performing a [[#Factory Reset|Factory Reset]]&lt;br /&gt;
* If this fails, it is likely hardware damage (very difficult to diagnose, please [[Contact Us|contact us]])&lt;br /&gt;
&lt;br /&gt;
If neither LED turns on, hardware damage is even more likely.  Unless the path to the red LED is the one thing that has been damaged, the device is likely not receiving and using power.&lt;br /&gt;
* Try performing a [[#Factory Reset|Factory Reset]], and if that does not work please [[Contact Us|contact us]]&lt;br /&gt;
&lt;br /&gt;
=====USB Issues=====&lt;br /&gt;
&lt;br /&gt;
On the Phidget SBC2, there is a hardware issue that is unrelated to the LEDs.  It is a USB problem, and manifests in many ways:&lt;br /&gt;
* Strange behaviour when some devices but not others are plugged in to the SBC&lt;br /&gt;
* Strange behaviour with combinations of devices&lt;br /&gt;
* Failure (or intermittent failure) to see Phidgets on the USB hub, or USB keys on the hub&lt;br /&gt;
&lt;br /&gt;
This problem is fixable, either on your own or by sending your SBC back to Phidgets.  For an in-depth solution, see the [[SBC2_USB_Hub_Fix | SBC2 Hub Fix Page]].&lt;br /&gt;
&lt;br /&gt;
===Updating Your SBC===&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve owned your SBC for a while and want to update your packages, you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to &#039;&#039;update&#039;&#039; your software source list and then &#039;&#039;upgrade&#039;&#039; to the latest version of all installed software.  If you are used to Mac OS or Windows, note that this does not just update the non-kernel parts of the operating system, it updates every additional piece of software you have installed.&lt;br /&gt;
&lt;br /&gt;
To update the SBC software itself (e.g. the kernel), it is easiest to use the web interface, under {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore &amp;amp;rarr; Go button}}, to enter a page that will give you the option to update.  You will need to have an update file on a USB key inserted into the SBC, of type:&lt;br /&gt;
* UBI Image (system_ubi.img), or &lt;br /&gt;
* Kernel image (uImage), or&lt;br /&gt;
* Phidget Upgrade package containing both UBI and Kernel images (phidgetsbc*.bin)&lt;br /&gt;
&lt;br /&gt;
These are either obtained from the Phidgets website, or are a custom kernel / filesystem that you can create yourself, if you are experienced.&lt;br /&gt;
&lt;br /&gt;
The reason why this information is in troubleshooting is that you should certainly [[#Backing Up Your Data|back up your system]] before trying this.  And, it is quite rare to need to upgrade the kernel or filesystem on the SBC, so something serious should be going on before you attempt it.  Try using the [[#Recovery System|recovery system]] first.&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic libraries installed, you can pick your language and begin programming!  &lt;br /&gt;
&lt;br /&gt;
If you are not using the [[#WebService | webservice]] to control a Phidget over a network, your next step will be to delve into the use of your specific language.  Each page has its own set of specific libraries, code examples, and setup instructions.  &lt;br /&gt;
&lt;br /&gt;
On SBC Linux, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Java | Java]]&lt;br /&gt;
*[[Language - Python | Python]]&lt;br /&gt;
&lt;br /&gt;
These languages may also run on the SBC, but we do not yet directly offer SBC support for them:&lt;br /&gt;
* [[Language - Ruby|Ruby]]&lt;br /&gt;
* [[Language - C Sharp|C#]] (using Mono)&lt;br /&gt;
&lt;br /&gt;
You can probably figure out how to install and use them by a combination of the language pages linked above, and the section on [[#Installing Other Languages|installing other languages on the SBC]].&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The SBC comes with the [[Phidget WebService]] installed, and the SBC automatically starts the WebService at boot.&lt;br /&gt;
&lt;br /&gt;
To practice using the WebService, and to learn more about it, we have hands-on examples on the [[OS - Linux|general Linux page]], starting in the [[OS - Linux#Using the WebService|using the WebService section]].&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Using a Different Wireless Adapter===&lt;br /&gt;
&lt;br /&gt;
The support for the wireless adaptor that Phidgets sells is written into the SBC kernel.  Hence, we do not support using other adaptors. &lt;br /&gt;
&lt;br /&gt;
However, Linux is very flexible, and it is possible (though not easy) to write a custom kernel for the SBC and add support for a new wireless adaptor.  We can&#039;t help you with this, but we do provide some basic guidelines for [[#Custom Kernel and Filesystem|building your own kernel]].&lt;br /&gt;
&lt;br /&gt;
===Using a Different Webcam===&lt;br /&gt;
&lt;br /&gt;
In addition to the webcam that Phidgets sells, you have the option to use many different webcams with the SBC.  There is a [http://www.ideasonboard.org/uvc/#devices long list] of compatible webcams.&lt;br /&gt;
&lt;br /&gt;
The common thread for these webcams is that they use UVC - the USB Video Class - drivers for Linux.  You can then use [[#mount|mount]] to find out what video device your webcam is mounted under.&lt;br /&gt;
&lt;br /&gt;
===Taking Pictures With the Webcam===&lt;br /&gt;
&lt;br /&gt;
Probably the most straightforward way to use a webcam for pictures rather than video is to use the {{Code|opencv}} library.  You can get it by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install libcv2.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there is no {{Code|libcv2.1}} package, you can perform {{Code|apt-cache search libcv}} to find the current version.&lt;br /&gt;
&lt;br /&gt;
The opencv libraries can also be used within Python, by installing the link between them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install python-opencv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then taking pictures from within code becomes quite simple.  For example, in Python, taking and saving an image is four lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
import cv&lt;br /&gt;
&lt;br /&gt;
# The webcam is located at /dev/video0 &lt;br /&gt;
# OpenCV only needs the number after video&lt;br /&gt;
webcam = cv.CaptureFromCAM(0)&lt;br /&gt;
&lt;br /&gt;
frame = cv.QueryFrame(webcam)&lt;br /&gt;
&lt;br /&gt;
cv.SaveImage(&amp;quot;image.jpg&amp;quot;, frame)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the complete OpenCV documentation, see [http://opencv.willowgarage.com/documentation/index.html The OpenCV Reference], and specifically the section on [http://opencv.willowgarage.com/documentation/reading_and_writing_images_and_video.html Reading and Writing Images].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The SBC is probably not as powerful for image processing and transport when compared to your desktop computer.  Try running your image processing code on the SBC from an early point in development.  During those test runs, you can visit the first System page of the [[#SBC Web Interface|SBC Web Interface]] to check the processor and memory use.  For more information on processor power, check the specification for your SBC (on the product page on [{{SERVER}} our main website]) as well as our discussion of [[#Pushing Processor Limits|pushing processor limits]] below.&lt;br /&gt;
&lt;br /&gt;
===Checking System Logs===&lt;br /&gt;
&lt;br /&gt;
The SBC maintains two logs: a kernel log and a system log.  &lt;br /&gt;
&lt;br /&gt;
The kernel log is for low-level occurrences, such as devices attaching and leaving the USB hub, recording what drivers are being used, and so on.&lt;br /&gt;
&lt;br /&gt;
The system log (syslog) is for normal chatter from the operating system.  Any program with the right permissions can use it (though you need to know the method to write to it, information all around the Internet can help) and it contains everything from the Ethernet going up and down, to webserver requests, and so on.  If you don&#039;t run many programs or services on the SBC, the syslog will essentially be a mirror of the kernel log, because the kernel is the only thing talking.&lt;br /&gt;
&lt;br /&gt;
You can check these logs by using the web interface in the {{Code|System &amp;amp;rarr; Logs}} tab.&lt;br /&gt;
&lt;br /&gt;
Or you can perform more powerful filtering and displaying via an SSH terminal.  For example, {{Code|dmesg}} is the command to display the kernel log, and {{Code|tail}} prints the last ten lines of input.  So, if you are trying to see if you can get a device to be detected on USB, you can run &amp;lt;code&amp;gt;dmesg | tail&amp;lt;/code&amp;gt; to print the latest ten lines of kernel log data.&lt;br /&gt;
&lt;br /&gt;
The actual locations of the log files (for filtering and reading) are:&lt;br /&gt;
* {{Code|/var/log/syslog}} &lt;br /&gt;
* {{Code|/var/log/dmesg}}&lt;br /&gt;
But don&#039;t edit them directly!  Always follow the advice and procedures around the Internet on how to properly log items to syslog.&lt;br /&gt;
&lt;br /&gt;
===X Forwarding===&lt;br /&gt;
&lt;br /&gt;
Although most tasks can be done using the [[#SBC Web Interface|SBC Web Interface]] or [[#SSH|SSH]], you can also set up X11 forwarding on the SBC.  X11 is the window manager base, which provides a graphical windowing system on the SBC.  Although you probably won&#039;t connect directly to the X11 manager (i.e. by plugging a screen directly into the SBC), X11 also gives a user the ability to forward graphical windows over SSH.  You will need the following packages installed:&lt;br /&gt;
* {{Code|x11-common}}&lt;br /&gt;
* {{Code|xbase-clients}}&lt;br /&gt;
After installing, make sure that the line in {{Code|/etc/ssh/sshd_config}} has a line that says:&lt;br /&gt;
:{{Code|X11Forwarding yes}}&lt;br /&gt;
Then log out and log back into the SBC.  This second time you log in, use the {{Code|-X}} switch to turn on X forwarding for that connection:&lt;br /&gt;
:{{Code|ssh -X root@phidgetsbc.local}}&lt;br /&gt;
Then you should be able to run programs that launch a window, and it will launch remotely and appear on the computer you have the SSH connection from.&lt;br /&gt;
&lt;br /&gt;
===Pushing Processor Limits===&lt;br /&gt;
&lt;br /&gt;
The SBC, though more powerful than many embedded computers out there, is probably about as powerful as your smartphone.  If you hook up 1 ms Phidget sampling devices to all six of its USB ports, events and packets will probably get lost.  The exact data rates you can accomplish depend on:&lt;br /&gt;
* What else is running on the SBC&lt;br /&gt;
* How efficient your code is for external operations (like File I/O)&lt;br /&gt;
* Other minor details (e.g. the temperature of the SBC, etc)&lt;br /&gt;
&lt;br /&gt;
If you want to achieve data rates as fast as possible, try these tips:&lt;br /&gt;
* Program in C, not in an interpreted language (Python, Java, .NET)&lt;br /&gt;
* Perform file I/O as little as possible.  Locally cache data, manage your writing to a file in a separate thread, and use low-level write calls.&lt;br /&gt;
* Change the [[#Custom Kernel and Filesystem|filesystem]] to a faster, non-compressed file system.&lt;br /&gt;
** Alternatively, use a high-data-rate USB key.&lt;br /&gt;
* Keep other running processes to a minimum. &lt;br /&gt;
** If you are running code locally right on the SBC, turn off the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
===Custom Kernel and Filesystem===&lt;br /&gt;
&lt;br /&gt;
You can compile your own kernel and flash it to the board. It is left up to the user to configure an appropriate cross-compiler for kernel development. You may also be able to compile a new kernel on-board.  We have a kernel development kit, complete with patch file and README:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC Kernel Development Package]&lt;br /&gt;
&lt;br /&gt;
Compiling a new, custom kernel is somewhat complex.  If the SBC is your first experience with Linux, writing a custom kernel will be difficult.  However, it will probably also be very rewarding because you can put whatever you like into it.  We might be able to offer additional suggestions, but ultimately you&#039;re on your own here. &lt;br /&gt;
&lt;br /&gt;
You may be able to write a custom kernel right on the SBC, but the easiest way is to develop the kernel on an external computer.  And the easiest way to develop on an external computer is for that computer to also be Linux, even just in a Virtual Machine.  The time spent loading a copy of Linux into a virtual machine (such as VirtualBox, which is free) onto your computer will probably be less time than setting up a standard compiler on Windows to cross-compile.&lt;br /&gt;
&lt;br /&gt;
On your external Linux system, you will need:&lt;br /&gt;
* A cross-compiling toolchain for the ARM processor, which we briefly describe on the [[OS - Linux#Cross-Compiling with a Custom Toolchain | main Linux page]], and &lt;br /&gt;
* The [{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC Kernel Development Package] from the Phidgets website.  &lt;br /&gt;
The kernel development kit has a brief README file which describes how to obtain the proper kernel and patch, configure, customize, and build it.&lt;br /&gt;
&lt;br /&gt;
We have an application guide in progress, which walks through building a custom kernel to add Bluetooth support to the SBC.  Please contact us if you would like more information.  Even if you are trying to add support for hardware other than a bluetooth modem, or wondering if support even exists in the kernel for your modem (3G, alternate wireless, etc) you will probably find the application guide helpful.  Follow it up to the point where you run the program {{Code|menuconfig}} (you don&#039;t need an SBC to do this), which will give you a menu of all drivers you can enable in the SBC kernel.&lt;br /&gt;
&lt;br /&gt;
After making your new kernel, you should have a uImage and modules target for your Makefile.  At this point you can transfer your kernel files onto the SBC, make their targets, and transfer them into the nand memory.  This involves erasing the old kernel, flashing the new kernel, installing the new kernel modules, and rebooting.  From the SBC, in the kernel directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make uImage; make modules&lt;br /&gt;
flash-eraseall /dev/mtd3&lt;br /&gt;
nandwrite -p /dev/mtd3 arch/arm/boot/uImage&lt;br /&gt;
make modules-install&lt;br /&gt;
reboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Custom kernels can also be flashed from the [[#Recovery System | Recovery System]].&lt;br /&gt;
&lt;br /&gt;
If you need to create a root filesystem image, the filesystem type is UBIFS, and the commands to create it are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mkfs.ubifs -m 2KiB -e 126KiB -c 4050 -r $ROOTFS/ system_ubifs.img&lt;br /&gt;
ubinize -o system_ubi.img -m 2KiB -p 128KiB -s 512 ubinize.cfg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where {{Code|ubinize.cfg}} contains:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
# Section header&lt;br /&gt;
[rootfs]		&lt;br /&gt;
# Volume mode (other option is static)&lt;br /&gt;
mode=ubi		&lt;br /&gt;
# Source image&lt;br /&gt;
image=system_ubifs.img	&lt;br /&gt;
# Volume ID in UBI image&lt;br /&gt;
vol_id=0		&lt;br /&gt;
# Volume size&lt;br /&gt;
vol_size=64128KiB&lt;br /&gt;
# Allow for dynamic resize&lt;br /&gt;
vol_type=dynamic	&lt;br /&gt;
# Volume name&lt;br /&gt;
vol_name=rootfs		&lt;br /&gt;
# Autoresize volume at first mount&lt;br /&gt;
vol_flags=autoresize&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You then flash ‘system_ubi.img’ (not ‘system_ubifs.img’) from the recovery system.&lt;br /&gt;
&lt;br /&gt;
Again, like the custom kernel creation, the need to create a custom root filesystem is essentially non-existent except for those advanced users who already know they need it... and furthermore, you are almost entirely on your own.&lt;br /&gt;
&lt;br /&gt;
==Software Details==&lt;br /&gt;
&lt;br /&gt;
For even more advanced uses of the SBC, it may help to know the gritty details of the SBC software system.&lt;br /&gt;
&lt;br /&gt;
;Operating System&lt;br /&gt;
:Debian/GNU Linux&lt;br /&gt;
:Kernel 2.6.X or higher (generally kept up to date with latest releases, use {{Code|uname -r}} to check the kernel version)&lt;br /&gt;
&lt;br /&gt;
;Main Filesystem (rootfs)&lt;br /&gt;
:UBIFS (a raw flash type of file system)&lt;br /&gt;
:Mounted in a 460 MB Nand partition (in Read/Write mode)&lt;br /&gt;
&lt;br /&gt;
;Kernel&lt;br /&gt;
:uImage format&lt;br /&gt;
:Has its own 3MiB partition on bare Nand&lt;br /&gt;
&lt;br /&gt;
;Web Interface Scripts and Configuration Data&lt;br /&gt;
:Located in {{Code|/etc/webif}}&lt;br /&gt;
:Modifying these scripts can be done; however, it is very easy to enter invalid data that could cause the system to behave unexpectedly or not boot.&lt;br /&gt;
&lt;br /&gt;
;User Applications uploaded through Web Interface&lt;br /&gt;
:Located in {{Code|/usr/userapps}}&lt;br /&gt;
&lt;br /&gt;
;Webcam Device Location&lt;br /&gt;
:{{Code|/dev/video0}}&lt;br /&gt;
:Numbers increase with more webcams&lt;br /&gt;
&lt;br /&gt;
;Date and Time&lt;br /&gt;
:Set using ntp (network time protocol) at boot&lt;br /&gt;
:The ntp daemon continues to run in the background and will periodically update the clock &lt;br /&gt;
:The network keeps the SBC very close to real time&lt;br /&gt;
:Also there is a real-time clock with battery backup which will preserve date/time across reboots, power removal&lt;br /&gt;
:The real-time clock is synced to system time during reboot/shutdown&lt;br /&gt;
:If power is unplugged suddenly, and the network not restored, the real-time clock may not have the correct time&lt;br /&gt;
&lt;br /&gt;
;Wireless Networking System&lt;br /&gt;
:Wireless adapter support for the wireless adapter that Phidgets sells is written into the kernel&lt;br /&gt;
:It supports WEP and WPA&lt;br /&gt;
:It is best configured through the configuration interface.&lt;br /&gt;
&lt;br /&gt;
;Nand Layout&lt;br /&gt;
:The board contains 512MiB on Nand. This nand is split into 7 partitions as follows:&lt;br /&gt;
:0: u-boot		 size: 256K		 Read Only&lt;br /&gt;
:1: u-boot_env		 size: 128K		 Read Only&lt;br /&gt;
:2: recovery_kernel	 size: 2M		 Read Only&lt;br /&gt;
:3: kernel		 size: 3M		 Writable&lt;br /&gt;
:4: flashfs	 	 size: ~3.625M	 	 Read Only&lt;br /&gt;
:5: recovery_fs		 size: ~ 43M		 Read Only&lt;br /&gt;
:6: rootfs		 size: ~ 460M		 Writable&lt;br /&gt;
: The final size of flashfs/recovery_fs/rootfs depends on the image size at production, and on the number/location of bad blocks in the NAND.&lt;br /&gt;
: &#039;&#039;&#039;Note&#039;&#039;&#039;: U-Boot and recovery kernel and filesystem cannot be written from Linux - this is a safety measure.&lt;br /&gt;
&lt;br /&gt;
;Boot Loader&lt;br /&gt;
:U-Boot is used for setting up the processor and booting Linux, and is only accessible via a serial connection. &lt;br /&gt;
:Normal users will not need to use or modify it.&lt;br /&gt;
:Be very careful when modifying the u-boot partition. If it is damaged or overwritten, it is difficult to fix.&lt;br /&gt;
:When using U-Boot, a prompt will appear via serial shortly after power on.  &lt;br /&gt;
:The environment variables will help you determine how to boot Linux on the SBC&lt;br /&gt;
:You can also refer to the [http://www.denx.de/wiki/DULG/Manual U-Boot documentation]&lt;br /&gt;
&lt;br /&gt;
;Boot Process&lt;br /&gt;
:From power on...&lt;br /&gt;
:1. Processor loads first 4 bytes from NAND into Steppingstone and runs it.&lt;br /&gt;
:2. Steppingstone sets up RAM, copies u-boot from NAND into RAM and runs U-Boot.&lt;br /&gt;
:3. U-Boot initializes the processor, sets GPIO state, etc., copies the linux kernel into RAM, sets up the kernel command line arguments, checks that the kernel image is valid, and boots it.&lt;br /&gt;
:4. Linux boots, bringing up USB, Networking, NAND, etc. and then mounts the rootfs NAND partition on /.&lt;br /&gt;
:5. init gets run as the parents of all processes, as uses the /etc/inittab script to bring up the system. This includes mounting other filesystems, settings the hostname, and running the scripts in /etc/init.d, among other things.&lt;br /&gt;
:6. inittab then turns the green LED on.&lt;br /&gt;
:7. inittab then sets up a getty on the first serial port, ready for interfacing using the debug board.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|USB Memory Key mounting|Sometimes USB Memory Keys mount at more than one location}}&lt;br /&gt;
&lt;br /&gt;
When you insert a memory key, the SBC will load it as a device (e.g. {{Code|/dev/sda1}}) and it will also &#039;&#039;mount&#039;&#039; the key for reading and writing within the {{Code|/media/}} directory.  The {{Code|/media/}} directory version will be called something like {{Code|usb0}}.  &lt;br /&gt;
At times, an inserted memory key will get mounted in more than one location.  You can observe if this occurs by checking the currently mounted devices with the command {{Code|mount}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
/dev/sda1 on /media/usb1 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will note that the same device ({{Code|/dev/sda1}}) is now mounted at &#039;&#039;both&#039;&#039; {{Code|/media/usb0}} and {{Code|/media/usb1}}.  To fix this problem as it occurs, you can use {{Code|umount}} (notice there is no letter &#039;n&#039;) to unmount the second instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# umount /media/usb1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In practice, this should not be a problem, because writing to or reading from either {{Code|usb0}} or {{Code|usb1}} will have the same effect on the memory key.  However, if you hard-code a media location into your program (i.e. expecting {{Code|/media/usb0}} to be the first USB key you insert and {{Code|/media/usb1}} to be the second key) your program will sometimes work and sometimes fail.  &lt;br /&gt;
&lt;br /&gt;
To get around this within code, find the mount point for each device as it appears.  The devices, such as {{Code|/dev/sda1}} will always refer to the actual memory key.  But, they cannot be written to directly without being mounted, so you will have to parse the mount table (what is returned from {{Code|mount}}) within your code to find the device and its corresponding mount point.&lt;br /&gt;
&lt;br /&gt;
This is a problem with the standard embedded Debian automount program, and we have no known fix.&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Perl Locale Errors on SSH|No Locales Installed}}&lt;br /&gt;
&lt;br /&gt;
By default, no locales are installed on the SBC.  If you use [[#apt|apt]] a lot to install and manage your software on the SBC, you will get messages like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
perl: warning: Setting locale failed.&lt;br /&gt;
perl: warning: Please check that your locale settings:&lt;br /&gt;
	LANGUAGE = (unset),&lt;br /&gt;
	LC_ALL = (unset),&lt;br /&gt;
	LANG = &amp;quot;en_CA.UTF-8&amp;quot;&lt;br /&gt;
    are supported and installed on your system.&lt;br /&gt;
perl: warning: Falling back to the standard locale (&amp;quot;C&amp;quot;).&lt;br /&gt;
locale: Cannot set LC_CTYPE to default locale: No such file or directory&lt;br /&gt;
locale: Cannot set LC_MESSAGES to default locale: No such file or directory&lt;br /&gt;
locale: Cannot set LC_ALL to default locale: No such file or directory&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To squelch these messages, you should install and reconfigure your locale like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt-get install locales&lt;br /&gt;
dpkg-reconfigure locales&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The last command will show you a long list from which you should pick your location, by language.  For example, en_CA is english_Canada.  Here in Calgary, we use en_CA.UTF-8 and so for the first question we would input locale &amp;quot;114&amp;quot; and for the second (system) question we would input {{Code|en_CA}} for the locale.&lt;br /&gt;
&lt;br /&gt;
This might give you a locale undefined error, in which case you can generate the locale (for us, again, it is en_CA):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
locale-gen en_CA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Phidget_SBC&amp;diff=20729</id>
		<title>OS - Phidget SBC</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Phidget_SBC&amp;diff=20729"/>
		<updated>2012-06-29T21:45:29Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:icon-Linux.png|64x64px|link=OS - Linux]]|On the Single Board Computer (SBC), Phidgets can be either plugged directly into one of the USB ports or run over a network using the [[#WebService | WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
Unlike our other supported operating systems, the SBC &#039;&#039;&#039;does not require downloads&#039;&#039;&#039; unless you are doing something advanced like loading the firmware or developing your own kernel.  You will know if you need these downloads, otherwise, the SBC should work as described on the [[1072_-_Getting_Started|SBC2 Getting Started Guide]] right out of the box.&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetsbc2.bin SBC2 Firmware]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC2 Kernel Development Package] (How-to and patch file)&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#SBC2 License]&lt;br /&gt;
&lt;br /&gt;
Note that, instead of using the firmware to update your SBC, updates should normally be done via the System -&amp;gt; Packages page on your SBC2 web interface. It is rarely necessary to completely re-flash your device.&lt;br /&gt;
&lt;br /&gt;
==Getting Started with the Phidget SBC Debian Linux==&lt;br /&gt;
&lt;br /&gt;
The Single Board Computer (SBC) is a unique Phidget.  It is a computer with a Linux operating system.  It can compile code, save files, manage background jobs, host information over the web, and more.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If this is your first time&#039;&#039;&#039; using the Phidget SBC, you will want to start with the [[1072 - Getting Started | Getting Started Guide for the SBC]].  After that, here we will get you started on topics beyond those in the getting started guide, including how to write Phidget code to run on the SBC.  You &#039;&#039;&#039;do not need this page&#039;&#039;&#039; if you are simply using the SBC to broadcast data from Phidgets over the network - it does that automatically.  We describe how to verify and use this in the [[1072 - Getting Started | Getting Started Guide]].&lt;br /&gt;
&lt;br /&gt;
This page will show you how to:&lt;br /&gt;
* Install the ability to write and develop code on the SBC itself&lt;br /&gt;
* Use the command line for basic coding tasks&lt;br /&gt;
* Troubleshoot the SBC&#039;s network&lt;br /&gt;
It will also give additional specifications, which are useful for doing more advanced things with the SBC hardware and software.&lt;br /&gt;
&lt;br /&gt;
Before reading this page, you should have done the following via the Getting Started Guide:&lt;br /&gt;
* Set up networking on your SBC, via either Ethernet or wireless&lt;br /&gt;
* Set up an admin password&lt;br /&gt;
* Learned the IP address or link local address of the SBC&lt;br /&gt;
We will use this information in setting up the libraries and drivers to use the SBC for writing and running code.&lt;br /&gt;
&lt;br /&gt;
Conceivably, you could simply use the SBC like any Linux computer, and do all of your development and compiling of Phidget code on the SBC itself.  In practice this gets complicated as the SBC does not have a keyboard or screen.  So usually, you will want to develop your code an external computer and copy files and settings over to the SBC via a network.  This makes this Getting Started section unique, in that we show you how to set up both computers:&lt;br /&gt;
* Your [[#Getting Started - External Computer | External Development Computer]], usually your main desktop or laptop which will transfer files and settings to and from the SBC&lt;br /&gt;
* The [[#Getting Started - The SBC (Debian Linux) | SBC]] itself, which needs programming language libraries to use Phidgets.&lt;br /&gt;
&lt;br /&gt;
===Getting Started - External Computer===&lt;br /&gt;
&lt;br /&gt;
You have two ways to connect to the SBC from an external computer: via the [[#SBC Web Interface|SBC Web Interface]] and over the more powerful but complex [[#SSH | Secure Shell (SSH)]].&lt;br /&gt;
&lt;br /&gt;
====SBC Web Interface====&lt;br /&gt;
&lt;br /&gt;
You have already worked extensively with the web interface in the [[1072 - Getting Started | Getting Started Guide for the SBC]].  This was the tool within a web browser which was opened either via the Phidget control panel on Windows, or by simply entering the IP or link local address into an internet browser.  It allowed you to set the password, set up internet connectivity, and so on.  &lt;br /&gt;
&lt;br /&gt;
This section doesn&#039;t have more information on the interface; rather, it simply serves as a reminder that you have the web interface as an available tool.  Examples, including screenshots, are placed where appropriate in this document.  The web interface will probably stay your initial go-to way to connect to the SBC, especially for tasks that benefit from graphical interaction, like setting up wireless or using the webcam.&lt;br /&gt;
&lt;br /&gt;
====SSH====&lt;br /&gt;
&lt;br /&gt;
The most flexible way to transfer files and commands to and from the SBC is via a program called &#039;&#039;&#039;ssh&#039;&#039;&#039;.  The ssh program provides command line text access over a network into the SBC.  Using it, you can run programs and give the SBC commands.  The ssh program has a companion program called &#039;&#039;&#039;scp&#039;&#039;&#039; which can copy files back and forth.  If you are unfamiliar with ssh, you can think of it like the command line or a Mac terminal, but with a remote connection to a different computer.  It is a minimal yet effective way to interact with a remote computer.&lt;br /&gt;
&lt;br /&gt;
Before connecting over ssh, you will need:&lt;br /&gt;
* The &#039;&#039;&#039;IP address&#039;&#039;&#039; (such as 168.254.3.0) or &#039;&#039;&#039;link local address&#039;&#039;&#039; (such as phidgetsbc.local) of the SBC&lt;br /&gt;
* The &#039;&#039;&#039;admin password&#039;&#039;&#039; for the SBC&lt;br /&gt;
Both of these items can be found by following the steps in the [[1072 0 - Getting Started | Getting Started Guide for the SBC]].&lt;br /&gt;
&lt;br /&gt;
You will also need to enable SSH on the SBC side.  This can be done through the [[#SBC Web Interface| Web Interface]], under {{Code|Network &amp;amp;rarr; Settings}}, by changing the &#039;&#039;SSH Server&#039;&#039; radio button to &#039;&#039;Enabled&#039;&#039; and saving your changes:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_turn_on_ssh.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
=====SSH on Windows=====&lt;br /&gt;
&lt;br /&gt;
The ssh program is not installed on Windows by default.  But, there are a variety of SSH programs available for free. One simple and commonly used program is [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY], and it has the advantage that the executable doesn&#039;t need to install, it just runs.&lt;br /&gt;
&lt;br /&gt;
With PuTTY, when you first run the program it will ask you what to connect to.  Enter the IP address or link local address of the SBC, and then click the SSH radio button right below the address, which will change the port to 22.  Then click open, and you&#039;ll have an ssh connection to the SBC open in a terminal.  It will prompt you for a user name ({{Code|root}}) and password (the admin password).&lt;br /&gt;
&lt;br /&gt;
To copy files back and forth, there is an SCP component to PuTTY, called PSCP, which is available from the same [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY download page].  Use of PSCP will be similar with the address, username, and password, except that you will be transferring files instead of sending commands.&lt;br /&gt;
&lt;br /&gt;
=====SSH on Linux and Mac OS=====&lt;br /&gt;
&lt;br /&gt;
Linux and Mac OS already have ssh installed by default.  To run ssh simply open a terminal...&lt;br /&gt;
* {{Code|Ctrl-Alt-T}} on Linux &lt;br /&gt;
* {{Code|Applications &amp;amp;rarr; Utilities &amp;amp;rarr; Terminal}} on Mac OS &lt;br /&gt;
...and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
ssh root@phidgetsbc.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have re-named your SBC, include that name instead of the {{Code|phidgetsbc.local}} link address.  Or, you can use the SBC&#039;s IP address, e.g. something like {{Code|ssh root@168.254.3.0}}&lt;br /&gt;
&lt;br /&gt;
To copy files back and forth, the command follows the form of: {{Code|scp from to}}&lt;br /&gt;
&lt;br /&gt;
So, to copy a file {{Code|/root/data.txt}} from the SBC to your local machine, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
scp root@phidgetsbc.local:/root/data.txt .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the use of the dot &#039;&#039;&#039;.&#039;&#039;&#039; to indicate that scp should put the file in the current local directory.   If you&#039;re not sure what folder the terminal is operating in type {{Code|pwd}} to print the working directory.  Terminals usually start by default in your home folder.&lt;br /&gt;
&lt;br /&gt;
===Getting Started - The SBC (Debian Linux)===&lt;br /&gt;
&lt;br /&gt;
The SBC runs Linux, which is a full operating system. It is stripped down compared to a full desktop release of Linux, but you can compile code on it, run programs, schedule tasks, create and manage files, run a web server, and much, much more.&lt;br /&gt;
&lt;br /&gt;
At this point you have connected to the SBC via the [[#SBC Web Interface|web interface]], and probably also through [[#SSH|SSH]].  This section will help you install libraries and drivers that you probably want - i.e. support for C, Java, and Python.  After this section, you&#039;ll be well into the depths of using the SBC as a computer, and so you&#039;ll probably want to keep the [[#Using SBC Linux|Using SBC Linux section]] open for reference while you work if you are not already familiar with Linux.&lt;br /&gt;
&lt;br /&gt;
The SBC comes with the following Phidget functionality installed:&lt;br /&gt;
* The Phidget C libraries {{Code|libphidget21.so}}&lt;br /&gt;
* The Phidget [[#WebService | WebService]]&lt;br /&gt;
(If you are simply curious what these are and how they get installed, we describe the process on the [[OS - Linux | general Linux page]].)&lt;br /&gt;
&lt;br /&gt;
But to compile C programs, or run Java programs, or use Python, you will need to install these languages onto the SBC.  &lt;br /&gt;
&lt;br /&gt;
Before installing anything on the SBC, however, (even via a button on the web interface) make sure that the &#039;&#039;Include full Debian Package Repository&#039;&#039; option is checked in the web interface under {{Code|System &amp;amp;rarr; Packages}}.&lt;br /&gt;
&lt;br /&gt;
====Installing C/C++ and Java====&lt;br /&gt;
&lt;br /&gt;
The simplest way to install C/C++  and Java on the SBC is via the web interface.  There is a button under {{Code|System &amp;amp;rarr; Packages}} to install C support (including {{Code|gcc}}) and another button to install Java support:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_packages_web.png|link-|alt=]]&lt;br /&gt;
&lt;br /&gt;
Now you&#039;re ready to begin programming.  We have programming pages for both [[Language - C/C++|C/C++]] and for [[Language - Java|Java]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].  &lt;br /&gt;
&lt;br /&gt;
If you want to avoid using the [[#SSH|SSH]] interface on the SBC entirely, and you want to write your program in Java and run it continuously from boot (which is the only option if you want to avoid [[#SSH|SSH]]), we have a [[#Program in Java with the Web Interface|very in-depth section]] on that topic.&lt;br /&gt;
&lt;br /&gt;
====Installing Python====&lt;br /&gt;
&lt;br /&gt;
Installing Python has two steps.  First, you&#039;ll need to install the basic ability to run python, and then you&#039;ll need to install the Phidget Python module.  Both steps (and both options) require that you issue the relevant commands through an [[#SSH|SSH terminal]].&lt;br /&gt;
&lt;br /&gt;
=====Basic Python=====&lt;br /&gt;
&lt;br /&gt;
The base Python functionality can be downloaded and installed in one step with [[#apt|apt]] (i.e. in a terminal, type):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install python&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will give you Python, and now you just have to install the Phidget Python module to gain Phidget functionality.&lt;br /&gt;
&lt;br /&gt;
=====Install Phidget Python Method 1: Use a USB Key=====&lt;br /&gt;
&lt;br /&gt;
Copy the [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Python Libraries] onto a USB key.  Unpack the zip file into a folder on the USB key.  Insert the key into the SBC.&lt;br /&gt;
&lt;br /&gt;
You will have to figure out where the USB key (and the Phidget Python library folder) is now located.  We describe how in the general [[#Using USB Data Keys | Using USB Data Keys]] section.&lt;br /&gt;
&lt;br /&gt;
After you know the place where the USB key is mounted, in a terminal go to that directory (e.g. type {{Code|cd /media/usb0/}}), enter the unpacked Phidget Python Library folder, and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, you&#039;re ready to begin writing Python code for the SBC.  For more help on writing and using Python with Phidgets, we have an whole [[Language - Python | page on that topic]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].&lt;br /&gt;
&lt;br /&gt;
=====Install Phidget Python Method 2: Use the Internet=====&lt;br /&gt;
&lt;br /&gt;
Rather than using a USB key to transfer the file, the SBC can download it directly from the internet.  You will need {{Code|wget}} and {{Code|unzip}} installed, both of which are small:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install wget&lt;br /&gt;
apt-get install unzip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the web link address for the [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Python Libraries].&lt;br /&gt;
&lt;br /&gt;
In an SSH terminal to the SBC, type: {{Code|wget http://www.python_library_link}} where instead of http://www.python_library_link you insert the link you just copied. Copying into a terminal can usually be done via the right-click menu.&lt;br /&gt;
&lt;br /&gt;
This will download the Phidget python libraries to the folder you ran the {{Code|wget}} command in.  Unzip the downloaded file using the command {{Code|unzip file}}, where file is the filename from {{Code|wget}}. Or try typing {{Code|ls}} to list the names of a file in the directory, which should include the unzipped folder.  Enter the unzipped folder (e.g. use {{Code|cd}} to change directory), and install the Phidget Python libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, you&#039;re ready to begin writing Python code for the SBC.  For more help on writing and using Python with Phidgets, we have a whole [[Language - Python | page on that topic]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].&lt;br /&gt;
&lt;br /&gt;
====Installing Other Languages====&lt;br /&gt;
&lt;br /&gt;
You may also be able to program on the SBC using [[Language - Ruby|Ruby]] and [[Language - C Sharp|C# under Mono]], though we do not offer in-depth support for these languages on the SBC.  The installation procedures should more or less follow that of [[#Installing Python|installing python]] on the SBC, except you will be installing Ruby or Mono.  Performing package searches using [[#apt|apt cache search]] can help you find the relevant software.&lt;br /&gt;
&lt;br /&gt;
For C#, as of 2012 the {{Code|mono-complete}} package is broken on the Debian Squeeze repository.  Rather, you have to install the Mono runtime and Mono compiler separately.&lt;br /&gt;
&lt;br /&gt;
To install the runtime package (and its dependencies), use [[#apt|apt]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-runtime&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to install the C# compiler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-gmcs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or the Visual Basic compiler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-vbnc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, the system and library packages do not link correctly for the version 2.0 of Mono.  If this is the case, your code will compile fine, but when you try to run it, you will get an error like:&lt;br /&gt;
&lt;br /&gt;
:{{Code|The assembly mscorlib.dll was not found or could not be loaded.}}&lt;br /&gt;
:{{Code|It should have been installed in the `/usr/lib/mono/1.0/mscorlib.dll&#039; directory.}}&lt;br /&gt;
&lt;br /&gt;
In this case, you need to install these two packages:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install libmono-corlib1.0-cil&lt;br /&gt;
apt-get install libmono-system1.0-cil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we found these packages to work by working through the tree structure.  As a general rule, you can find these dependencies by using install (here, {{Code|apt-get install mono-complete}}) to get a sense of the package tree structure.  This will possibly tell you that the packages are broken, but at the same time this will list the dependencies of the packages.  Trying to install individual dependencies will show you that although a root-package fails, the sub-packages will sometimes succeed, and install what you need.&lt;br /&gt;
&lt;br /&gt;
If you want to use a specific dll or library that is not available in this reduced version of mono, you can install mono complete by switching from Emdebian+Debian to just Debian.  To do this:&lt;br /&gt;
&lt;br /&gt;
In {{Code|/etc/apt/preferences}} make the following changes:&lt;br /&gt;
:{{Code|Package: *}}&lt;br /&gt;
:{{Code|&amp;lt;nowiki&amp;gt;Pin: release a=stable&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
:{{Code|Pin-Priority: 1010}}&lt;br /&gt;
	&lt;br /&gt;
In {{Code|/etc/apt/sources.list/mutistrap-debian.list}} remove the emdebian line.&lt;br /&gt;
&lt;br /&gt;
Apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get dist-upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many packages will be &#039;downgraded&#039; from the emdebian to debian versions.  Delete the {{Code|&amp;lt;nowiki&amp;gt;/etc/apt/preferences&amp;lt;/nowiki&amp;gt;}} file and install mono-complete:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install monodoc-http mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose monodoc-http explicitly, because otherwise the install fails on monodoc-browser.&lt;br /&gt;
&lt;br /&gt;
After this process, you can compile your C# Code.cs Phidget source file the same way as on a generic [[Language - C Sharp#Linux|Linux with Mono]] system.  Please refer to that page on how to obtain the *.dll Phidget resource file and compile your code.  On the SBC, however, because you are already running as root (the Super User), you do not need &#039;sudo&#039; and indeed the SBC will give you an error if you use it.  Instead, compiling and running will look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Code.cs -r:Phidget21.NET.dll&lt;br /&gt;
mono Code.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using SBC Linux==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve set up communication with the SBC, and installed whichever programming language support you need, you&#039;re probably ready for a short tour of useful tools on the SBC&#039;s version of Linux.&lt;br /&gt;
&lt;br /&gt;
First, you will by default be running on the SBC as &#039;&#039;&#039;root&#039;&#039;&#039;, which is the super-user.  For Linux users, this probably makes you nervous because you know you can overwrite important system files without the system asking for additional permission.  As a Windows or Mac OS user - although you may usually run your computer as an administrator - your familiar system usually prompts you to confirm before you do anything really dangerous, and this will &#039;&#039;&#039;not&#039;&#039;&#039; happen on the SBC as the root user.&lt;br /&gt;
&lt;br /&gt;
Next, there is no installed help on the SBC.  Help on Linux is usually called &#039;man pages&#039; which is short for &#039;the manual pages&#039;.  On a full Linux system, usually if you need help with any command you can type, for example, {{Code|man ls}} and it will give you help with the program [[#ls|ls]].  But these help pages take up significant space, and they are widely available online.  So, if you need more help with a certain command, you can always type {{Code|man command}} into your favourite search engine.&lt;br /&gt;
&lt;br /&gt;
Finally, the SBC has no windowing system.  For Linux users, this means no X-windows (Gnome, KDE, etc).  And as a Windows or Mac user, you can think of it as running all of your programs and commands through the terminal or DOS prompt command line.  The SBC provides all of the functionality of an operating system (e.g. process scheduling, file management, etc) but without any graphical interface.  The only exception is the [[#SBC Web Interface|web interface]], which gives graphical access to a limited part of what the SBC can do.&lt;br /&gt;
&lt;br /&gt;
===Some Useful Commands===&lt;br /&gt;
&lt;br /&gt;
If you are doing more with the SBC than simply running pre-written programs [[#Writing a Phidget Program|in Java to run continuously from boot]], you will be interacting with the SBC&#039;s Linux operating system over the command line by using [[#SSH|SSH]].  This section discusses useful programs already installed on the SBC, and how to run them on the command line.&lt;br /&gt;
&lt;br /&gt;
====ls====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ls&#039;&#039;&#039; program lists the contents of a directory.&lt;br /&gt;
&lt;br /&gt;
It will show both files and folders, but not files that start with a &amp;quot;.&amp;quot; (these are hidden files on Linux).&lt;br /&gt;
*If you also want to show hidden files, use {{Code|ls -a}}&lt;br /&gt;
*If you want more information, such as size and date modified, use {{Code|ls -l}}&lt;br /&gt;
*Commands can be combined, like {{Code|ls -al}}&lt;br /&gt;
&lt;br /&gt;
====cd====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;cd&#039;&#039;&#039; program changes to a new directory.&lt;br /&gt;
&lt;br /&gt;
For example, {{Code|cd /root}} changes into the directory at the base of the file tree called &#039;&#039;root&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
* Linux uses forward slashes&lt;br /&gt;
* The base of all directories is &amp;quot;/&amp;quot; (not &amp;quot;C:\&amp;quot;)&lt;br /&gt;
* The tilde symbol (~) is short for your home directory (i.e. when you are root, this is short for &amp;quot;/root&amp;quot;)&lt;br /&gt;
* The double dot &amp;quot;..&amp;quot; means move one directory higher (for example from {{Code|/root/data/}} to {{Code|/root/}})&lt;br /&gt;
&lt;br /&gt;
====pwd====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;pwd&#039;&#039;&#039; program prints the current directory you are working in.  (&#039;P&#039;rint &#039;W&#039;orking &#039;D&#039;irectory)&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
:{{Code|root@phidgetsbc:~# pwd}}&lt;br /&gt;
:{{Code|/root}}&lt;br /&gt;
&lt;br /&gt;
====cp, mv, and rm====&lt;br /&gt;
&lt;br /&gt;
These programs are copy (&#039;&#039;&#039;cp&#039;&#039;&#039;), move (&#039;&#039;&#039;mv&#039;&#039;&#039;), and remove (&#039;&#039;&#039;rm&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Copy copies a file from one location and pastes it to another.&lt;br /&gt;
&lt;br /&gt;
For example, if you have a file {{Code|data.txt}}, typing {{Code|cp data.txt data_backup.txt}} will put a copy of the file {{Code|data.txt}} into {{Code|data_backup.txt}}&lt;br /&gt;
&lt;br /&gt;
Move moves a file (this is also useful for renaming files) to a new destination.&lt;br /&gt;
&lt;br /&gt;
For example, if you have a file {{Code|data.txt}}, typing {{Code|mv data.txt data_backup.txt}} will put the contents of {{Code|data.txt}} into {{Code|data_backup.txt}}, and then will remove {{Code|data.txt}}.&lt;br /&gt;
&lt;br /&gt;
Remove deletes a file.&lt;br /&gt;
&lt;br /&gt;
For example, typing {{Code|rm data.txt}} will delete {{Code|data.txt}}.&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;&#039;rm&#039;&#039;&#039; is final.  Once you remove a file using {{Code|rm}}, it is gone forever.  There is no recycle bin, no temporary trash, nothing other than backups you may have personally created in the past!&lt;br /&gt;
&lt;br /&gt;
Directories can only be removed with {{Code|rmdir}}, and then only if they are empty.  If you want to remove a directory and all the files in it, use {{Code|rm -rf directory}} but be &#039;&#039;&#039;very, very careful&#039;&#039;&#039; with this command.  Trying to remove everything within a directory (e.g. {{Code|rm -rf *}}) is one of the most dangerous commands you can run on a Linux system, as running it from the wrong directory will result in Linux happily removing everything under that directory -- which could be your entire filesystem.&lt;br /&gt;
&lt;br /&gt;
====find====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;find&#039;&#039;&#039; program does what it says - it finds things.  &lt;br /&gt;
&lt;br /&gt;
Unfortunately for the casual user, the find program is very flexible and powerful, and thus not especially intuitive to use.  But, here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;15px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! SSH Command&lt;br /&gt;
! What it Does&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|find folder -name file.txt}}&lt;br /&gt;
| Looks for all files in a folder (/ for root - or all - folders) with a certain name (* for wildcard)&lt;br /&gt;
| {{Code|find / -name *.jpg}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|find folder -mtime +X}}&lt;br /&gt;
| Looks for all files in a folder modified less than X days ago&lt;br /&gt;
| {{Code|find /root -mtime +30}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====grep====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; program takes text input and searches for a term. &lt;br /&gt;
&lt;br /&gt;
For example, if you type {{Code|mount}} to view what devices are mounted (e.g. loaded) on your SBC, you will see:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may be a lot of information you don&#039;t need.  If you are only interested in a USB key attachment (as described in the [[#Using USB Data Keys|Using USB Data Keys]] section), you can use grep to filter that one response:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount | grep sda1&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====nano====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;nano&#039;&#039;&#039; program is a small text editor that you can use within an SSH terminal. &lt;br /&gt;
&lt;br /&gt;
Nano can be surprisingly useful for writing short lengths of code right on the SBC, so there is no need to transfer files and keep track of different file versions on different computers.&lt;br /&gt;
&lt;br /&gt;
Nano has all keyboard commands which are listed at the bottom of the screen at all times as a reminder (Ctrl-O to save, Ctrl-X to exit, these expand with a larger terminal window).  And, nano provides what is called &#039;syntax highlighting&#039;, which colours reserved keywords, comments, strings, and so on as appropriate to the programming language you are using.  Nano detects the programming language via the extension of the file ({{Code|.java}} for Java, {{Code|.c}} for C/C++, and {{Code|.py}} for Python).&lt;br /&gt;
&lt;br /&gt;
Typing {{Code|nano test.py}} on an SSH command line and then entering a few lines of Python into the new empty file results in:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_nano_python.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
====apt====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apt&#039;&#039;&#039; program allows you to install, uninstall, upgrade, and search software available for the SBC.&lt;br /&gt;
For a non-Linux user, the apt framework may be daunting at first, but it actually allows you to keep your system up to date and install and manage software quickly, easily, and for free.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Before installing anything on the SBC, make sure that the &#039;&#039;Include full Debian Package Repository&#039;&#039; option is checked in the web interface under {{Code|System &amp;amp;rarr; Packages}}.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;15px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! SSH Command&lt;br /&gt;
! What it Does&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|apt-cache search term}}&lt;br /&gt;
| Looks for all programs (packages) that have {{Code|term}} in the title or description&lt;br /&gt;
| {{Code|apt-cache search opencv}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|apt-cache show package}}&lt;br /&gt;
| Shows a lot of data about {{Code|package}} including size, version, etc&lt;br /&gt;
| {{Code|apt-cache show unzip}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|apt-get update}}&lt;br /&gt;
| Gets the most recent listing of available software&lt;br /&gt;
| {{Code|apt-get update}}  (No options)&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|apt-get install program}}&lt;br /&gt;
| Installs {{Code|program}} from the internet&lt;br /&gt;
| {{Code|apt-get install python}}&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====mount====&lt;br /&gt;
&lt;br /&gt;
The program {{Code|mount}} shows you all of the mounted devices on your SBC.  &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the non-Linux user, the concept of a device may be quite strange.  To give a short summary, everything on Linux that you can read or write is a file.  Webcams are files (i.e. you can &#039;read&#039; photos from them), USB keys are files, and each filesystem (tmp storage, the kernel portion, the main filesystem) are also themselves files.  These files specify what and how something can be written.  These are not necessarily linear, for example, you can see above that the USB key ({{Code|/media/usb0}} is mounted &#039;&#039;within&#039;&#039; the root file system {{Code|rootfs}} which is /.   &lt;br /&gt;
&lt;br /&gt;
So mount gives you an idea of what devices have been &#039;mounted&#039; for reading or writing, and how you can read and write to them.  More information on mount (and its various forms, like {{Code|umount}}) is available widely around the Internet.&lt;br /&gt;
&lt;br /&gt;
====which====&lt;br /&gt;
&lt;br /&gt;
The program {{Code|which}} tells you if and where a program is installed.&lt;br /&gt;
&lt;br /&gt;
For example, on a default SBC, typing {{Code|which python}} will return no results.  But after successfully [[#Installing Python | installing python]], it will return {{Code|/usr/bin/python}} as the location of the python program/binary/executable.&lt;br /&gt;
&lt;br /&gt;
===Some Useful Commands to Install===&lt;br /&gt;
&lt;br /&gt;
These are other programs you may find useful on the command line.  Although they are not on the SBC by default, these and other programs can usually be installed simply by using [[#apt|apt-get install]], with the exception of gcc.  For example, {{Code|apt-get install wget}} will download and install [[#wget|wget]].  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This section and the section on [[#Some Useful Commands|pre-installed commands]] can hardly cover all of the complexities and power of the Linux operating system.  There are many excellent tutorials online, and between them and using [[#apt|apt]] to find and install programs you should be able to learn a lot and perform any number of complex useful tasks.&lt;br /&gt;
&lt;br /&gt;
====gcc====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;gcc&#039;&#039;&#039; program is the C compiler for Linux.&lt;br /&gt;
&lt;br /&gt;
If you are an experienced C/C++ user on Mac or Linux, or if you&#039;ve already read our [[Language - C/C++ | C Language page]], you might think you need to install gcc via {{Code|apt-get}} to compile C code.  However, gcc is not in the package repository for the SBC, so {{Code|apt-get install gcc}} will fail.  Rather, to install gcc, you can do it via the web interface, as described in the [[#Installing C/C++ and Java|Installing C/C++ and Java]] section.&lt;br /&gt;
&lt;br /&gt;
After installing it via the SBC web interface, you can use {{Code|gcc}} normally.&lt;br /&gt;
&lt;br /&gt;
====less====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;less&#039;&#039;&#039; program displays the contents of a text or source code file.  When displaying the file, {{Code|less}} allows you to scroll up and down to read it.&lt;br /&gt;
&lt;br /&gt;
This is useful if you are writing your sensor readings to a data file, and you want to read the data file while it is being written by your main code.  If your data file is called {{Code|data.txt}}, you can type {{Code|less data.txt}} and see the lines in the file, and what they are.&lt;br /&gt;
&lt;br /&gt;
The {{Code|less}} program output can also be piped into another program.  For example, you can use {{Code|less}} and the word search program {{Code|grep}} to find lines within a file with a search term.  For instance, if you have a C source code file {{Code|Program.c}} on the SBC, and you want to see all the lines in {{Code|Program.c}} that contain a variable name {{Code|var}}, you can type: &lt;br /&gt;
:&amp;lt;code&amp;gt;less Program.c | grep var&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====wget====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;wget&#039;&#039;&#039; program allows you to get an online file (over http) and download it to the SBC.&lt;br /&gt;
&lt;br /&gt;
For example, to get the source file (HTML) from the Phidgets home page, you can type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
wget http://www.phidgets.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is most useful for downloading libraries, drivers, or anything (zip, tar, etc) you need from the web which is not available by [[#apt|using apt]].&lt;br /&gt;
&lt;br /&gt;
===Writing a Phidget Program===&lt;br /&gt;
&lt;br /&gt;
We provide two ways to write and upload a Phidget Program:&lt;br /&gt;
# The [[#SBC Web Interface|web interface]]:&lt;br /&gt;
#* This is useful for simple projects written in Java that you want to start only at boot&lt;br /&gt;
#* You can also use C projects, but they must be compiled off the SBC for an ARM processor&lt;br /&gt;
# Over [[#SSH|SSH]], which will allow you to write or transfer source code directly to and from the SBC&lt;br /&gt;
#* This is useful for all other projects, such as:&lt;br /&gt;
#** Projects that run at scheduled times (e.g. once per minute)&lt;br /&gt;
#** Projects that use languages other than Java or ARM-compiled C&lt;br /&gt;
Note that you can still run an [[#SSH|SSH]] project at boot, you just have to write and install a startup script.  This is a bit complex, but we do have an example that starts the program {{Code|phidgetwebservice21}} [[OS - Linux#As A Service|at boot using a script]].&lt;br /&gt;
&lt;br /&gt;
Once you know which method you&#039;d like to use, you can continue on to learn how to [[#Program in Java with the Web Interface|Program in Java with the Web Interface]], or how to [[#Program with SSH|Program with SSH]] using Java, C, or Python.  If you are actually typing in source code on the SBC, you&#039;ll find our [[#Developing Code on the SBC|developing code on the SBC section]] useful.&lt;br /&gt;
&lt;br /&gt;
====Program in Java with the Web Interface====&lt;br /&gt;
&lt;br /&gt;
To show how to write, compile, and install Java programs on the SBC, we&#039;ll use the [[Language - Java|Java Hello World]] example code.  You can download the HelloWorld example by downloading the whole [{{SERVER}}/downloads/examples/JavaJNI.zip Java example package].  Make sure you have [[#Installing C/C++ and Java|Java installed on the SBC]].&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to get the HelloWorld code running on the SBC.  On your external computer:&lt;br /&gt;
&lt;br /&gt;
1. Download the SBC version of the Phidget Java libraries ({{Code|phidget21.jar}}).  You can download this from the [[#SBC Web Interface|web interface]], on the page under {{Code|Projects &amp;amp;rarr; Projects}}, under the &#039;&#039;&#039;Notes&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
2. Place the SBC version of {{Code|phidget21.jar}} into a directory on your external computer.  This will be your working directory that you will use to compile the Java files.&lt;br /&gt;
&lt;br /&gt;
3. Also copy the {{Code|HelloWorld.java}} file into that working directory.&lt;br /&gt;
&lt;br /&gt;
4. Compile the {{Code|HelloWorld.java}} file from within that working directory.  From the command line prompt on Windows, this will be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
In a terminal on Linux or Mac OS, this will be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. You should now have three compiled class files: {{Code|HelloWorld.class}}, {{Code|HelloWorld$1.class}}, and {{Code|HelloWorld$2.class}}.  You don&#039;t need to try and run them, and if you do you may encounter an error because the SBC {{Code|phidget21.jar}} may be slightly different than the Phidget support you have installed on your external computer.&lt;br /&gt;
&lt;br /&gt;
Now we move onto the SBC:&lt;br /&gt;
&lt;br /&gt;
6. Create a new project on the SBC, in the web interface under {{Code|Projects &amp;amp;rarr; Projects}}.  Call it HelloWorld:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_create_project.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
7. On the next screen, you will be prompted to upload your files.  We will upload the three Java class files, and then click the {{Code|Start}} button:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_web_run_project.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
8. You&#039;ll note that as it runs, there are two links below the {{Code|Stop}} button: One called {{Code|stdout}}, which is &#039;&#039;Standard Output&#039;&#039;, and one called {{Code|stderr}}, which is &#039;&#039;Standard Error&#039;&#039;.  Usually, when you run a program on the command line, you see both standard out and standard error at the same time - i.e. you get all program output right there in your terminal or command prompt.  But when running a program in the background, Linux splits the output up into normal output and error output as this is very useful for debugging (i.e. you can check if standard error is empty).  &lt;br /&gt;
&lt;br /&gt;
Here, however, if you&#039;re not sure whether the program will run correctly, you should first check {{Code|stderr}} to see if any errors were generated, and then check {{Code|stdout}} to see if the output looks as expected.&lt;br /&gt;
&lt;br /&gt;
To write your own Java program, follow the same process but use your own source code instead of the {{Code|HelloWorld.java}} example.&lt;br /&gt;
&lt;br /&gt;
Now that you have a running program, we offer additional help on [[#Via the Web Interface|running a program automatically using the web interface]].&lt;br /&gt;
&lt;br /&gt;
====Program with SSH====&lt;br /&gt;
&lt;br /&gt;
Similarly to starting a program via the [[#Program in Java with the Web Interface|web interface]], we use the Phidget Java {{Code|HelloWorld}} example here.&lt;br /&gt;
&lt;br /&gt;
Make sure you have [[#Installing C/C++ and Java|Java installed on the SBC]].  To compile and run the {{Code|HelloWorld}} example:&lt;br /&gt;
&lt;br /&gt;
1. Open an [[#SSH|SSH terminal]] to the SBC&lt;br /&gt;
&lt;br /&gt;
2. Download the [{{SERVER}}/downloads/examples/JavaJNI.zip Phidget Java Examples] to the SBC, using [[#wget|wget]] (you may need to install {{Code|wget}} using [[#apt|apt]].)&lt;br /&gt;
&lt;br /&gt;
3. Unpack the examples using [[#unzip|unzip]] (you may need to install {{Code|unzip}} using [[#apt|apt]].)&lt;br /&gt;
&lt;br /&gt;
4. The location of {{Code|phidget21.jar}} on the SBC is {{Code|/usr/share/java/phidget21.jar}}.  Within the unzipped example directory, compile the {{Code|HelloWorld.java}} example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:/usr/share/java/phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. To run the {{Code|HelloWorld}} program, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:/usr/share/java/phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that you have a running program, you&#039;ll probably want to learn to [[#Running a Program Automatically|run this Java program automatically]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Permissions Note:&#039;&#039;&#039; If you&#039;re used to using Linux with Phidgets already, you&#039;ll probably notice that you don&#039;t need to switch into root using {{Code|sudo}} on the SBC in order to run programs.  This is because you already are running as root, not because the [[OS - Linux#Setting udev Rules|udev rules are set up]].  So if you set up another user, or [[#Via Cron|run a cron job]] as anything other than root or system, you&#039;ll need to add permission for the Phidget program to run in your [[OS - Linux#Setting udev Rules|udev rules]].&lt;br /&gt;
&lt;br /&gt;
====Developing Code on the SBC====&lt;br /&gt;
&lt;br /&gt;
When you&#039;re not just using pre-written source code, and you&#039;re writing code actually on the SBC itself, you&#039;ll probably want to use [[#nano|nano]].  Other terminal editors on the SBC include {{Code|vi}} which is already installed, and {{Code|emacs}}, which you can install using [[#apt|apt]].  Both {{Code|vi}} and {{Code|emacs}} are much more efficient for the experienced user, but they contain modes and keyboard shortcuts that can seem strange or almost hindering to the casual user.&lt;br /&gt;
&lt;br /&gt;
Regardless of which editor you choose to use, some of your keyboard habits may not transfer well.  For example, in the Linux command line, the command {{Code|Ctrl-C}} means &#039;&#039;stop the currently running program&#039;&#039;, (i.e. your open editor) not copy.  Within most SSH terminals, you can copy and paste using the right-mouse button, and on some terminals (and all native Linux terminals) you can copy by simply highlighting text, and you can paste it using the middle (scroll) mouse button.  On the other hand, if you write a program that hangs on the command line, {{Code|Ctrl-C}} can actually be useful to terminate it.&lt;br /&gt;
&lt;br /&gt;
Also {{Code|Ctrl-Z}} does not mean &#039;&#039;undo&#039;&#039;, rather it means &#039;&#039;run the current program in the background&#039;&#039;.  This is useful because running a program in an SSH terminal simply hangs your SSH input until the program is done.  So typing {{Code|Ctrl-Z}} while the program is running frees up the command line for more input.  But if you accidentally hit {{Code|Ctrl-Z}} while running an editor like [[#nano|nano]], the editor will immediately exit to the command line.  Don&#039;t worry though, it will not stop or lose your work.  You can bring it back up by using the {{Code|fg}} (e.g. &#039;foreground&#039;) command, like {{Code|fg nano}}, and this will automatically bring your nano process back to the front.&lt;br /&gt;
&lt;br /&gt;
===Running a Program Automatically===&lt;br /&gt;
&lt;br /&gt;
For testing your program, you will certainly want to run it via [[#SSH|SSH]] or via the {{Code|Start}} button on the project page on the web interface until you are quite sure it runs well.  However, eventually you will probably want the program to run without your input, either [[#Via the Web Interface|continuously, and starting at boot]], or via a task scheduled to [[#Via Cron|run to completion at certain times]].&lt;br /&gt;
&lt;br /&gt;
Both have their advantages and disadvantages.  Usually, you would want to use the continuous, from-boot methods for event driven code that has to handle a wide variety of user input that could occur at any time.  You would want to use the scheduled method when the SBC needs to perform a repeated task (e.g. reading sensor data) again and again.  The main difference is:&lt;br /&gt;
* With the continuous (boot) method you can have any Phidgets (including sensors, LEDs, input switches, etc) attached and giving events to your code all the time, and&lt;br /&gt;
* With the scheduled (cron) method you have much less of a chance to run into long-term memory management and instability problems with any code you write, because your program runs for only a short time before exiting and getting cleaned up.&lt;br /&gt;
&lt;br /&gt;
====Via the Web Interface====&lt;br /&gt;
&lt;br /&gt;
To use this method, you must have created the program you want to run as [[#Program in Java with the Web Interface | a Java or ARM-compiled C project in the web interface]].  If you would like to use another language, or another way of uploading your project, but you still want to start at boot and run continuously, you will need to use a [[#Via a Boot Script|boot script]].&lt;br /&gt;
&lt;br /&gt;
In the web interface, go to the {{Code|Projects}} tab, and click on the project you would like to run.  Near the bottom of the project page (the one with the {{Code|Start}} and {{Code|Stop}} buttons at the top), there will be a section called {{Code|Startup Settings}}.  You can see a screenshot of the whole project page, including these settings, in the [[#Program in Java with the Web Interface | web interface project section]].&lt;br /&gt;
&lt;br /&gt;
Select the {{Code|Enabled}} radio button.  The other defaults should be fine, unless you specifically know otherwise:&lt;br /&gt;
* For &#039;&#039;Boot Order&#039;&#039;, lower numbers boot first.  Booting later means more programs are available for use, booting earlier means other programs can use your program.  &lt;br /&gt;
* &#039;&#039;Run as a daemon&#039;&#039; starts the program as a daemon, which is a program that runs in the background.  Unless you have &#039;&#039;explicitly&#039;&#039; written your program as a daemon, leave this checked.  (If you don&#039;t know what a daemon is, don&#039;t worry, you haven&#039;t written one, so leave it checked.)  &#039;&#039;Un&#039;&#039;checking this when your program is a normal program will cause the SBC to hang while booting.&lt;br /&gt;
* The &#039;&#039;Executable or Class&#039;&#039; name should be automatically sensed to be your main Java class&lt;br /&gt;
* &#039;&#039;Arguments&#039;&#039; are any command line arguments you need, just as you would type them into the command line&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Your program must be very, very stable to run properly via the web interface.  Imagine your program running continuously for days, or months on end.  Any memory leaks, over time, will render your program (and the SBC) unusable until a reboot.  Counts or other variables that increase within your program and never reset may create a segmentation fault eventually.&lt;br /&gt;
&lt;br /&gt;
If, for stability purposes, you want your program to start, run for a little while, and then exit so that the SBC operating system can clean up the memory each time, you&#039;ll probably want to use [[#Via Cron|Cron]] to run your program instead.&lt;br /&gt;
&lt;br /&gt;
====Via Cron====&lt;br /&gt;
&lt;br /&gt;
Cron can automatically schedule programs - known as &#039;jobs&#039;, or &#039;cron jobs&#039; - at most once per minute.  Less often than that, it is very flexible, allowing you to run it on certain months, weekdays, hours, etc.  Cron simply reads a special file (your {{Code|crontab}}) and runs whatever programs are listed, with whatever timing they are listed with.  The cron program runs all the time in the background, making it what is known as a Linux &#039;&#039;daemon&#039;&#039;, but the programs it starts as jobs run only as long as they naturally would, and then they exit.&lt;br /&gt;
&lt;br /&gt;
If you need your program to run more often than once per minute, have the program schedule itself while still running.  For example, to run every five seconds, run a fast loop,  and sleep for five seconds. Do this twenty times and exit.  Then schedule this once per minute using cron, and your program will in essence run every five seconds.&lt;br /&gt;
&lt;br /&gt;
Setting up a cron job simply entails editing your {{Code|crontab}} file.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll probably want to specify your default editor to be [[#nano|nano]]. Otherwise it will default to {{Code|vi}} and you&#039;ll have to figure out {{Code|vi}} in order to add lines to your crontab:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
export EDITOR=nano&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to edit your crontab file, simply type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
crontab -e&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each line of the crontab file is one scheduled job.  Lines that start with a hash &amp;quot;#&amp;quot; are comments and are ignored.  There is an example line in the crontab, and a reminder line at the very end.  Essentially, each line should contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
minute hour dayOfMonth month dayOfWeek  command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
*{{Code|command}} is the program you want to run (with absolute path, and arguments)&lt;br /&gt;
** For example, {{Code|./myprogram argument1}} won&#039;t work, but {{Code|/root/code/myprogram argument1}} will&lt;br /&gt;
* Each time argument is either a number, a list of numbers separated by commas, or an asterisk&lt;br /&gt;
** For example, * * * * * means every minute for all days and months, 0,30 * * * * means every thirty minutes (i.e. at the top of the hour and at 30 minutes in) for all days and months&lt;br /&gt;
&lt;br /&gt;
If you already have jobs scheduled, you&#039;ll see them in the file that comes up.  You can edit, add, or delete.  &lt;br /&gt;
&lt;br /&gt;
After you save, you&#039;ll see a little message back in the terminal that says the new crontab file was installed, and it is now scheduled!  Cron always starts every boot, and so if you have edited and installed your crontab as above, the scheduling of your program will start properly even after a reboot of the SBC.  However, if you are having strange scheduling problems, you may want to familiarize yourself with the [[#Software Details|software details]] of how the SBC as a whole determines the current date and time.&lt;br /&gt;
&lt;br /&gt;
=====My Cron Job Doesn&#039;t Work!=====&lt;br /&gt;
&lt;br /&gt;
It is actually very common for a script or program to work on the command line but then &#039;&#039;not&#039;&#039; work as a cron job.  The most common reason for this, by far, is that you specify &#039;&#039;relative&#039;&#039; paths in your program to access files rather than &#039;&#039;absolute&#039;&#039; paths.  For example:&lt;br /&gt;
* {{Code|code/project.c}} is a relative path (bad for cron)&lt;br /&gt;
* {{Code|/root/code/project.c}} is an absolute path (good for cron)&lt;br /&gt;
The cron jobs are &#039;&#039;not&#039;&#039; executed from your home directory, or your code directory, so they will not be using the same location you may be using to test your code.  So always use absolute paths.&lt;br /&gt;
&lt;br /&gt;
Another common reason is you may be using environment variables or other settings that are true in a terminal but are &#039;&#039;not&#039;&#039; true by default in the raw system.  You can end up taking many things for granted in a shell, for example the shortcut &amp;quot;~&amp;quot; means home directory in a shell, but not by default in the raw system.  The things that get loaded for a shell (but which are not present in the raw system) are:&lt;br /&gt;
* The settings loaded by {{Code|/etc/profile}}&lt;br /&gt;
* Any settings in {{Code|~/.bashrc}}, which is nothing by default on the SBC&lt;br /&gt;
&lt;br /&gt;
On a full Linux operating system, you would use the logs written to by cron to find the error output and debug it.  On the SBC, however, cron does not write logs (otherwise, these logs would eat up the SBC memory very quickly even for routine jobs).  For short-term debugging, you can write output from your program to a file, and read that file afterwards to figure out what your program is doing.&lt;br /&gt;
&lt;br /&gt;
====Via a Boot Script====&lt;br /&gt;
&lt;br /&gt;
If you want to run your program constantly and for it to start at boot like the [[#Via the Web Interface|web interface would do]], you can install your program into the boot order using a script.  This is a somewhat involved process, and you should be familiar with shell programming in Linux.  For this process, we only offer a [[OS - Linux#As A Service|similar example]] which installs and runs the program {{Code|phidgetwebservice21}} within the boot sequence.&lt;br /&gt;
&lt;br /&gt;
===Using USB Data Keys===&lt;br /&gt;
&lt;br /&gt;
After plugging the USB key in, it won&#039;t just appear on your desktop, so to speak, so you&#039;ll need to figure out where you can read and write to it within the SSH directory structure.&lt;br /&gt;
&lt;br /&gt;
The web interface program can help with this.  After you plug a USB key in, it will show up under {{Code|Status &amp;amp;rarr; System}}.  Or, the USB key and all other attached devices can be seen at {{Code|Status &amp;amp;rarr; USB}}:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_mounted_devices.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, you can see that the USB key is located in {{Code|/media/usb0}}.&lt;br /&gt;
&lt;br /&gt;
Alternately, you can use the SSH command {{Code|mount}}, and the searching program {{Code|grep}} which will filter the response of {{Code|mount}} and only return the lines with your search term ({{Code|usb}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount | grep usb&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the USB key can be written to and read from using the {{Code|/media/usb0}} directory.  Copying a file to {{Code|/media/usb0}} will copy a file to the USB key.  The same goes for removing, renaming, opening files within your program, etc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Mount points like {{Code|/media/usb0}} should not be hard-coded into any of your programs.  (See the [[#Common Problems and Solutions | Common Problems and Solutions]] section for more information.)  If you need to obtain the mount point for a freshly mounted USB key within your code, have your code obtain the mount tables and search on the &#039;&#039;device&#039;&#039;  (e.g. {{Code|/dev/sda1}} or {{Code|/dev/sdb1}}) and obtain the corresponding mounted {{Code|/media/usbN}} location, where N is a number 0-9.&lt;br /&gt;
&lt;br /&gt;
===Saving and Retrieving Data===&lt;br /&gt;
&lt;br /&gt;
This section covers getting data on and off of the SBC.  There are two main methods of simply moving data on and off the SBC - via a [[#Via a USB Key|USB key]], and via [[#Over the Network (SCP)|copy over the network]] - and a third method for moving and installing data when it concerns [[#Backing Up Your Data|backing up lower level system data]].&lt;br /&gt;
&lt;br /&gt;
====Via a USB Key====&lt;br /&gt;
&lt;br /&gt;
After plugging in a USB data key, first you need to [[#Using USB Data Keys | find out the location]] where that data key was mounted.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say the location of the USB key is {{Code|/media/usb0/}}, and we want to copy the file {{Code|data.txt}} to the USB key.  Your SSH session might look something like this, using [[#ls|ls]] and [[#mount|mount]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# ls&lt;br /&gt;
data.txt&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
root@phidgetsbc:~# cp data.txt /media/usb0/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;cp&#039;&#039;&#039; program copies data from a source to a destination.  The syntax is {{Code|cp from to}}, where here we are copying from {{Code|data.txt}} to {{Code|/media/usb0/}}.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution:&#039;&#039;&#039; Even if there is no USB key mounted at {{Code|/media/usb0/}}, this use of {{Code|cp}} will still work &#039;&#039;with no errors&#039;&#039;!  This is because there is still a file called {{Code|/media/usb0/}}, there is just no USB key file system &#039;&#039;mounted&#039;&#039; to that point.  So be sure to run [[#mount|mount]] or use some other method of determining that there is, in fact, a USB data key attached and where it is mounted to.&lt;br /&gt;
&lt;br /&gt;
====Over the Network (SCP)====&lt;br /&gt;
&lt;br /&gt;
SCP is a command line program already installed on Linux and Mac OS, and downloadable for free on Windows.  We discuss it and give examples in the [[#SSH|SSH]] section, but remember it here when you&#039;re trying to get data on and off of the SBC.  With SSH or a terminal already open, you&#039;ll probably find it to be much faster and easier than dealing with a USB key.&lt;br /&gt;
&lt;br /&gt;
====Backing Up Your Data====&lt;br /&gt;
&lt;br /&gt;
For the web interface, you can save and restore all web interface settings under the {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore}} tab.&lt;br /&gt;
&lt;br /&gt;
To save the settings of what packages are installed for later re-installation, you can type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
dpkg --get-selections &amp;gt; installedPrograms.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then save the file {{Code|installedPrograms.txt}} externally.  If you have to completely wipe the SBC, you can just reinstall the whole list by moving the {{Code|installedPrograms.txt}} file back onto the SBC, and then typing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
dpkg –set-selections &amp;lt; installedPrograms.txt&lt;br /&gt;
apt-get dselect-upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also remember to externally save:&lt;br /&gt;
* Your {{Code|~/.bashrc}} settings file if you&#039;ve changed it&lt;br /&gt;
* Your {{Code|crontab}} file if [[#Via Cron|you&#039;ve edited it]]&lt;br /&gt;
* Any data files or code you&#039;ve created&lt;br /&gt;
&lt;br /&gt;
It is important to save these settings often, and at points where you know the system is running well.  It may be tempting to create a backup right before you [[#Recovery System|wipe the SBC and start from scratch]], but often the reason you are having problems then is some setting or change, and backing these up and reinstalling them will only reinstall the problem.&lt;br /&gt;
&lt;br /&gt;
To truly back the files up, you must copy them to an external computer or location using either a [[#Via a USB Key|USB Key]] or [[#Over the Network (SCP) | over the network]].  Then they can be copied back if needed later.&lt;br /&gt;
&lt;br /&gt;
If you are looking to restore data on an SBC that will not boot properly, you&#039;ll want to be in the [[#Partial Recovery|partial recovery]] portion of our Troubleshooting section.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
The SBC can be quite tricky to debug, because it is a complex and flexible computer.  Common problems and solutions include:&lt;br /&gt;
* You can&#039;t find the SBC on the network at all - refer to the [[#Initial Internet Setup|Initial Internet Setup]] section&lt;br /&gt;
* You have changed some setting or file such that the SBC doesn&#039;t run anymore, or doesn&#039;t run as expected - refer to the [[#Recovery|Recovery]] section&lt;br /&gt;
&lt;br /&gt;
If you are having trouble using Phidgets on the SBC, you should go through the [[OS - Linux#Troubleshooting | Troubleshooting section on the general Linux page]].  Some of the problems on the Linux page (such as library problems) are easier to fix by simply working through the [[#Recovery|Recovery]] section when they occur on the SBC.&lt;br /&gt;
&lt;br /&gt;
Namely, it often helps to simply perform a [[#Factory Reset|factory reset]] on the SBC (save your files and installed program list first, as [[#Backing Up Your Data|described here]]).  Sometimes you change a file or setting within the operating system when you are trying to get something up and running, and this unintentionally affects other programs too.  Performing a factory reset starts you with a clean slate.&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, or the information within this guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
===Initial Internet Setup===&lt;br /&gt;
&lt;br /&gt;
To set up the SBC, you almost always need a &#039;&#039;wired&#039;&#039; Ethernet connection with DHCP (Dynamic Host Configuration Protocol), and without a firewall.  This connection should be to a &#039;&#039;router&#039;&#039;, not directly plugged in to your computer.&lt;br /&gt;
&lt;br /&gt;
Even if you do not have this type of a connection at home, these types of connections are very common at both offices and universities.  On a Windows or Mac OS computer, you can bring up the Phidget Control Panel as described in the SBC&#039;s [[1072 0 - Getting Started|Getting Started Page]].  Failing this, or on a Linux computer, we discuss some alternate setup methods in this section.  Keep in mind that without a wired, open DHCP connection these setup methods can be difficult and fickle. &lt;br /&gt;
&lt;br /&gt;
====No Wired-Only Connection====&lt;br /&gt;
&lt;br /&gt;
Sometimes it can work to plug the SBC, using Ethernet, directly into an Ethernet port on your home wireless router.  Do not plug it directly into your computer!  (Although in some instances, a direct connection can be made to work on Linux, see the [[#No DHCP|No DHCP]] section below) &lt;br /&gt;
&lt;br /&gt;
This direct-router method is a very picky process, however, and can fail because:&lt;br /&gt;
* Some home and office routers place a firewall between wireless connections (clients) and wired connections (the local area network)&lt;br /&gt;
* Some home and office routers do not by default allow both Ethernet DHCP and wireless DHCP.&lt;br /&gt;
* Some routers and DHCP hubs only provide access to an internet connection, and do not provide local area network inter-connections (this is common on mobile device tethering hubs)&lt;br /&gt;
&lt;br /&gt;
Routers are quite complex, and even with admin privileges it can be a painstaking process to find all the right firewall settings to turn off in order to allow two computers on the network to talk to one another, rather than just connect to the internet.  This is why university or office networks are often ideal for the purpose of setting up the SBC, because these institutions depend on computers on a local network being able to talk together.  University libraries in particular can be a good source of wired DHCP connection ports.  &lt;br /&gt;
&lt;br /&gt;
Covering all of the different router configuration possibilities here, and how to change them to make the SBC work, is essentially impossible.  If you try using the SBC at home or at work, the SBC does not work on the first try when plugged directly into the router via Ethernet, and you want to make that connection work rather than seeking out an alternate for the initial setup, you should find documentation specific to your router (usually available online) and properly configure it.&lt;br /&gt;
&lt;br /&gt;
The good news is that if you can find an Ethernet DHCP connection &#039;&#039;just once&#039;&#039; for a short time, you can use that connection to configure the SBC to work on your home wireless network.  During that initial connection, you can enable wireless and set up as many wireless DHCP connections (with passwords) that you need.  Once wireless is enabled and set up, you can take the SBC home to your wireless router and the SBC will automatically seek out and connect to its remembered networks as they appear.  At that point, you can also use wireless like a normal internet, web interface, and SSH connection.&lt;br /&gt;
&lt;br /&gt;
====No Link Local Addressing====&lt;br /&gt;
&lt;br /&gt;
If you have a wired DHCP connection, no firewall, and no link local addressing (e.g. bonjour or avahi is not installed) then you will need access to the DHCP router logs.  From the router logs, you should see the connection (or attempted connection) by the SBC within the logs.  From that log entry, you should either be able to determine the IP address for the SBC, or see what happens when the router blocks access.  The IP address can be used in place of the link local address for both the web interface and for SSH.&lt;br /&gt;
&lt;br /&gt;
====No DHCP====&lt;br /&gt;
&lt;br /&gt;
The SBC will first try to use DHCP, but then it will revert to responding to a link local address under bonjour and avahi.  If you are depending on this, please wait &#039;&#039;&#039;at least three minutes&#039;&#039;&#039; after the SBC boots for the SBC to fail in obtaining a DHCP connection and properly revert to link local addressing.&lt;br /&gt;
&lt;br /&gt;
If you have a static IP setup, and want to use link local addressing rather than accessing the router logs, this should usually work by default on Windows and Mac OS (e.g. type the address such as {{Code|phidgetsbc.local}} into a web browser).  If it doesn&#039;t work automatically, there is not much you can do and you should seek out a wired DHCP connection elsewhere.&lt;br /&gt;
&lt;br /&gt;
On Linux, it also should work by default, but you have the additional option of explicitly adding routes that look within the default network settings for the SBC.  From a terminal (as root), type:&lt;br /&gt;
* {{Code|route add -net 169.254.0.0 netmask 255.255.0.0 dev eth0 metric 99}}&lt;br /&gt;
* {{Code|route add default dev eth0 metric 99}}&lt;br /&gt;
You can also compile and use the {{Code|phidgetsbclist.c}} example (use the provided Makefile, don&#039;t use gcc) in the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Linux Libraries] package, under the {{Code|examples}} folder.  This will allow you to see if the SBC is detected on the network at all.   Note that to use this option you must have the Phidget Libraries and the Phidget WebService installed on your Linux computer - in-depth instructions to do this are on the [[OS - Linux|main Linux page]].&lt;br /&gt;
&lt;br /&gt;
===Recovery System===&lt;br /&gt;
&lt;br /&gt;
You can either boot the SBC into recovery mode and attempt to recover files and settings, or you can completely wipe the SBC by performing a factory reset.  If the LEDs do not turn on normally (red on constantly, green on at first start, then off, then on when fully booted) then you&#039;ll want to read the [[#Hardware Issues|hardware issues]] section.&lt;br /&gt;
&lt;br /&gt;
====Partial Recovery====&lt;br /&gt;
&lt;br /&gt;
The recovery system can be entered in two ways:&lt;br /&gt;
# From the {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore}} web interface page.&lt;br /&gt;
# By holding down the reset button for 20+ seconds - until the green light has switched from flashing slowly to flashing quickly.&lt;br /&gt;
&lt;br /&gt;
The recovery system runs an [[#SSH|SSH]] server where the username and password both are {{Code|root}}.&lt;br /&gt;
&lt;br /&gt;
If the main filesystem has been damaged/misconfigured in such a way that it won’t boot, you may be able to fix the issue or recover important files before running a full factory reset. From an SSH connection to the recovery system, you can mount the main root filesystem with the following commands (assuming it’s not damaged):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
ubiattach /dev/ubi_ctrl -m 6&lt;br /&gt;
mount -t ubifs /dev/ubi0_0 /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Factory Reset====&lt;br /&gt;
&lt;br /&gt;
This restores the kernel and root filesystem from backup, overwriting any changes that may have been made and &#039;&#039;completely wiping the system&#039;&#039; to the state that it got shipped in. (You can save your files and installed program list first, as [[#Backing Up Your Data|described here]].)  This can be enacted one of two ways.&lt;br /&gt;
# Use the reset button:&lt;br /&gt;
##Enter the recovery mode by holding down the reset button for 20+ seconds as above (until fast flashing)&lt;br /&gt;
##Wait for a full boot (i.e. you can see it on the Phidget control panel, or can SSH with username and password as {{Code|root}})&lt;br /&gt;
##Hold down the reset button again, but this time for only 10 seconds (until slow flashing)&lt;br /&gt;
##Wait for the SBC to fully reset and reboot (at least three minutes) - the LED will turn off and on again when this occurs&lt;br /&gt;
##*Note that after a factory reboot the SSH server will be disabled&lt;br /&gt;
##*Also note that after a factory reboot the SBC creates new SSH keys, and reverts to the {{Code|phidgetsbc.local}} address&lt;br /&gt;
# Via the web interface, under {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore &amp;amp;rarr; Go button}}, where you can follow the instructions&lt;br /&gt;
&lt;br /&gt;
====Hardware Issues====&lt;br /&gt;
&lt;br /&gt;
The LEDs are an indicator of the hardware working properly.  The normal boot process is:&lt;br /&gt;
* Red LED: Turns on from moment of power being applied.&lt;br /&gt;
* Green LED: Turns on momentarily when power applied, then turns off momentarily, then turns on and stays on when booted.&lt;br /&gt;
&lt;br /&gt;
If the green status LED never turns on (or fails to turn on the second time), the boot process is failing somewhere.  This could be due to:&lt;br /&gt;
* A damaged OS - Try performing a [[#Factory Reset|Factory Reset]]&lt;br /&gt;
* If this fails, it is likely hardware damage (very difficult to diagnose, please [[Contact Us|contact us]])&lt;br /&gt;
&lt;br /&gt;
If neither LED turns on, hardware damage is even more likely.  Unless the path to the red LED is the one thing that has been damaged, the device is likely not receiving and using power.&lt;br /&gt;
* Try performing a [[#Factory Reset|Factory Reset]], and if that does not work please [[Contact Us|contact us]]&lt;br /&gt;
&lt;br /&gt;
=====USB Issues=====&lt;br /&gt;
&lt;br /&gt;
On the Phidget SBC2, there is a hardware issue that is unrelated to the LEDs.  It is a USB problem, and manifests in many ways:&lt;br /&gt;
* Strange behaviour when some devices but not others are plugged in to the SBC&lt;br /&gt;
* Strange behaviour with combinations of devices&lt;br /&gt;
* Failure (or intermittent failure) to see Phidgets on the USB hub, or USB keys on the hub&lt;br /&gt;
&lt;br /&gt;
This problem is fixable, either on your own or by sending your SBC back to Phidgets.  For an in-depth solution, see the [[SBC2_USB_Hub_Fix | SBC2 Hub Fix Page]].&lt;br /&gt;
&lt;br /&gt;
===Updating Your SBC===&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve owned your SBC for a while and want to update your packages, you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to &#039;&#039;update&#039;&#039; your software source list and then &#039;&#039;upgrade&#039;&#039; to the latest version of all installed software.  If you are used to Mac OS or Windows, note that this does not just update the non-kernel parts of the operating system, it updates every additional piece of software you have installed.&lt;br /&gt;
&lt;br /&gt;
To update the SBC software itself (e.g. the kernel), it is easiest to use the web interface, under {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore &amp;amp;rarr; Go button}}, to enter a page that will give you the option to update.  You will need to have an update file on a USB key inserted into the SBC, of type:&lt;br /&gt;
* UBI Image (system_ubi.img), or &lt;br /&gt;
* Kernel image (uImage), or&lt;br /&gt;
* Phidget Upgrade package containing both UBI and Kernel images (phidgetsbc*.bin)&lt;br /&gt;
&lt;br /&gt;
These are either obtained from the Phidgets website, or are a custom kernel / filesystem that you can create yourself, if you are experienced.&lt;br /&gt;
&lt;br /&gt;
The reason why this information is in troubleshooting is that you should certainly [[#Backing Up Your Data|back up your system]] before trying this.  And, it is quite rare to need to upgrade the kernel or filesystem on the SBC, so something serious should be going on before you attempt it.  Try using the [[#Recovery System|recovery system]] first.&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic libraries installed, you can pick your language and begin programming!  &lt;br /&gt;
&lt;br /&gt;
If you are not using the [[#WebService | webservice]] to control a Phidget over a network, your next step will be to delve into the use of your specific language.  Each page has its own set of specific libraries, code examples, and setup instructions.  &lt;br /&gt;
&lt;br /&gt;
On SBC Linux, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Java | Java]]&lt;br /&gt;
*[[Language - Python | Python]]&lt;br /&gt;
&lt;br /&gt;
These languages may also run on the SBC, but we do not yet directly offer SBC support for them:&lt;br /&gt;
* [[Language - Ruby|Ruby]]&lt;br /&gt;
* [[Language - C Sharp|C#]] (using Mono)&lt;br /&gt;
&lt;br /&gt;
You can probably figure out how to install and use them by a combination of the language pages linked above, and the section on [[#Installing Other Languages|installing other languages on the SBC]].&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The SBC comes with the [[Phidget WebService]] installed, and the SBC automatically starts the WebService at boot.&lt;br /&gt;
&lt;br /&gt;
To practice using the WebService, and to learn more about it, we have hands-on examples on the [[OS - Linux|general Linux page]], starting in the [[OS - Linux#Using the WebService|using the WebService section]].&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Using a Different Wireless Adapter===&lt;br /&gt;
&lt;br /&gt;
The support for the wireless adaptor that Phidgets sells is written into the SBC kernel.  Hence, we do not support using other adaptors. &lt;br /&gt;
&lt;br /&gt;
However, Linux is very flexible, and it is possible (though not easy) to write a custom kernel for the SBC and add support for a new wireless adaptor.  We can&#039;t help you with this, but we do provide some basic guidelines for [[#Custom Kernel and Filesystem|building your own kernel]].&lt;br /&gt;
&lt;br /&gt;
===Using a Different Webcam===&lt;br /&gt;
&lt;br /&gt;
In addition to the webcam that Phidgets sells, you have the option to use many different webcams with the SBC.  There is a [http://www.ideasonboard.org/uvc/#devices long list] of compatible webcams.&lt;br /&gt;
&lt;br /&gt;
The common thread for these webcams is that they use UVC - the USB Video Class - drivers for Linux.  You can then use [[#mount|mount]] to find out what video device your webcam is mounted under.&lt;br /&gt;
&lt;br /&gt;
===Taking Pictures With the Webcam===&lt;br /&gt;
&lt;br /&gt;
Probably the most straightforward way to use a webcam for pictures rather than video is to use the {{Code|opencv}} library.  You can get it by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install libcv2.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there is no {{Code|libcv2.1}} package, you can perform {{Code|apt-cache search libcv}} to find the current version.&lt;br /&gt;
&lt;br /&gt;
The opencv libraries can also be used within Python, by installing the link between them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install python-opencv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then taking pictures from within code becomes quite simple.  For example, in Python, taking and saving an image is four lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
import cv&lt;br /&gt;
&lt;br /&gt;
# The webcam is located at /dev/video0 &lt;br /&gt;
# OpenCV only needs the number after video&lt;br /&gt;
webcam = cv.CaptureFromCAM(0)&lt;br /&gt;
&lt;br /&gt;
frame = cv.QueryFrame(webcam)&lt;br /&gt;
&lt;br /&gt;
cv.SaveImage(&amp;quot;image.jpg&amp;quot;, frame)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the complete OpenCV documentation, see [http://opencv.willowgarage.com/documentation/index.html The OpenCV Reference], and specifically the section on [http://opencv.willowgarage.com/documentation/reading_and_writing_images_and_video.html Reading and Writing Images].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The SBC is probably not as powerful for image processing and transport when compared to your desktop computer.  Try running your image processing code on the SBC from an early point in development.  During those test runs, you can visit the first System page of the [[#SBC Web Interface|SBC Web Interface]] to check the processor and memory use.  For more information on processor power, check the specification for your SBC (on the product page on [{{SERVER}} our main website]) as well as our discussion of [[#Pushing Processor Limits|pushing processor limits]] below.&lt;br /&gt;
&lt;br /&gt;
===Checking System Logs===&lt;br /&gt;
&lt;br /&gt;
The SBC maintains two logs: a kernel log and a system log.  &lt;br /&gt;
&lt;br /&gt;
The kernel log is for low-level occurrences, such as devices attaching and leaving the USB hub, recording what drivers are being used, and so on.&lt;br /&gt;
&lt;br /&gt;
The system log (syslog) is for normal chatter from the operating system.  Any program with the right permissions can use it (though you need to know the method to write to it, information all around the Internet can help) and it contains everything from the Ethernet going up and down, to webserver requests, and so on.  If you don&#039;t run many programs or services on the SBC, the syslog will essentially be a mirror of the kernel log, because the kernel is the only thing talking.&lt;br /&gt;
&lt;br /&gt;
You can check these logs by using the web interface in the {{Code|System &amp;amp;rarr; Logs}} tab.&lt;br /&gt;
&lt;br /&gt;
Or you can perform more powerful filtering and displaying via an SSH terminal.  For example, {{Code|dmesg}} is the command to display the kernel log, and {{Code|tail}} prints the last ten lines of input.  So, if you are trying to see if you can get a device to be detected on USB, you can run &amp;lt;code&amp;gt;dmesg | tail&amp;lt;/code&amp;gt; to print the latest ten lines of kernel log data.&lt;br /&gt;
&lt;br /&gt;
The actual locations of the log files (for filtering and reading) are:&lt;br /&gt;
* {{Code|/var/log/syslog}} &lt;br /&gt;
* {{Code|/var/log/dmesg}}&lt;br /&gt;
But don&#039;t edit them directly!  Always follow the advice and procedures around the Internet on how to properly log items to syslog.&lt;br /&gt;
&lt;br /&gt;
===X Forwarding===&lt;br /&gt;
&lt;br /&gt;
Although most tasks can be done using the [[#SBC Web Interface|SBC Web Interface]] or [[#SSH|SSH]], you can also set up X11 forwarding on the SBC.  X11 is the window manager base, which provides a graphical windowing system on the SBC.  Although you probably won&#039;t connect directly to the X11 manager (i.e. by plugging a screen directly into the SBC), X11 also gives a user the ability to forward graphical windows over SSH.  You will need the following packages installed:&lt;br /&gt;
* {{Code|x11-common}}&lt;br /&gt;
* {{Code|xbase-clients}}&lt;br /&gt;
After installing, make sure that the line in {{Code|/etc/ssh/sshd_config}} has a line that says:&lt;br /&gt;
:{{Code|X11Forwarding yes}}&lt;br /&gt;
Then log out and log back into the SBC.  This second time you log in, use the {{Code|-X}} switch to turn on X forwarding for that connection:&lt;br /&gt;
:{{Code|ssh -X root@phidgetsbc.local}}&lt;br /&gt;
Then you should be able to run programs that launch a window, and it will launch remotely and appear on the computer you have the SSH connection from.&lt;br /&gt;
&lt;br /&gt;
===Pushing Processor Limits===&lt;br /&gt;
&lt;br /&gt;
The SBC, though more powerful than many embedded computers out there, is probably about as powerful as your smartphone.  If you hook up 1 ms Phidget sampling devices to all six of its USB ports, events and packets will probably get lost.  The exact data rates you can accomplish depend on:&lt;br /&gt;
* What else is running on the SBC&lt;br /&gt;
* How efficient your code is for external operations (like File I/O)&lt;br /&gt;
* Other minor details (e.g. the temperature of the SBC, etc)&lt;br /&gt;
&lt;br /&gt;
If you want to achieve data rates as fast as possible, try these tips:&lt;br /&gt;
* Program in C, not in an interpreted language (Python, Java, .NET)&lt;br /&gt;
* Perform file I/O as little as possible.  Locally cache data, manage your writing to a file in a separate thread, and use low-level write calls.&lt;br /&gt;
* Change the [[#Custom Kernel and Filesystem|filesystem]] to a faster, non-compressed file system.&lt;br /&gt;
** Alternatively, use a high-data-rate USB key.&lt;br /&gt;
* Keep other running processes to a minimum. &lt;br /&gt;
** If you are running code locally right on the SBC, turn off the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
===Custom Kernel and Filesystem===&lt;br /&gt;
&lt;br /&gt;
You can compile your own kernel and flash it to the board. It is left up to the user to configure an appropriate cross-compiler for kernel development. You may also be able to compile a new kernel on-board.  We have a kernel development kit, complete with patch file and README:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC Kernel Development Package]&lt;br /&gt;
&lt;br /&gt;
Compiling a new, custom kernel is somewhat complex.  If the SBC is your first experience with Linux, writing a custom kernel will be difficult.  However, it will probably also be very rewarding because you can put whatever you like into it.  We might be able to offer additional suggestions, but ultimately you&#039;re on your own here. &lt;br /&gt;
&lt;br /&gt;
You may be able to write a custom kernel right on the SBC, but the easiest way is to develop the kernel on an external computer.  And the easiest way to develop on an external computer is for that computer to also be Linux, even just in a Virtual Machine.  The time spent loading a copy of Linux into a virtual machine (such as VirtualBox, which is free) onto your computer will probably be less time than setting up a standard compiler on Windows to cross-compile.&lt;br /&gt;
&lt;br /&gt;
On your external Linux system, you will need:&lt;br /&gt;
* A cross-compiling toolchain for the ARM processor, which we briefly describe on the [[OS - Linux#Cross-Compiling with a Custom Toolchain | main Linux page]], and &lt;br /&gt;
* The [{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC Kernel Development Package] from the Phidgets website.  &lt;br /&gt;
The kernel development kit has a brief README file which describes how to obtain the proper kernel and patch, configure, customize, and build it.&lt;br /&gt;
&lt;br /&gt;
We have an application guide in progress, which walks through building a custom kernel to add Bluetooth support to the SBC.  Please contact us if you would like more information.  Even if you are trying to add support for hardware other than a bluetooth modem, or wondering if support even exists in the kernel for your modem (3G, alternate wireless, etc) you will probably find the application guide helpful.  Follow it up to the point where you run the program {{Code|menuconfig}} (you don&#039;t need an SBC to do this), which will give you a menu of all drivers you can enable in the SBC kernel.&lt;br /&gt;
&lt;br /&gt;
After making your new kernel, you should have a uImage and modules target for your Makefile.  At this point you can transfer your kernel files onto the SBC, make their targets, and transfer them into the nand memory.  This involves erasing the old kernel, flashing the new kernel, installing the new kernel modules, and rebooting.  From the SBC, in the kernel directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make uImage; make modules&lt;br /&gt;
flash-eraseall /dev/mtd3&lt;br /&gt;
nandwrite -p /dev/mtd3 arch/arm/boot/uImage&lt;br /&gt;
make modules-install&lt;br /&gt;
reboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Custom kernels can also be flashed from the [[#Recovery System | Recovery System]].&lt;br /&gt;
&lt;br /&gt;
If you need to create a root filesystem image, the filesystem type is UBIFS, and the commands to create it are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mkfs.ubifs -m 2KiB -e 126KiB -c 4050 -r $ROOTFS/ system_ubifs.img&lt;br /&gt;
ubinize -o system_ubi.img -m 2KiB -p 128KiB -s 512 ubinize.cfg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where {{Code|ubinize.cfg}} contains:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
# Section header&lt;br /&gt;
[rootfs]		&lt;br /&gt;
# Volume mode (other option is static)&lt;br /&gt;
mode=ubi		&lt;br /&gt;
# Source image&lt;br /&gt;
image=system_ubifs.img	&lt;br /&gt;
# Volume ID in UBI image&lt;br /&gt;
vol_id=0		&lt;br /&gt;
# Volume size&lt;br /&gt;
vol_size=64128KiB&lt;br /&gt;
# Allow for dynamic resize&lt;br /&gt;
vol_type=dynamic	&lt;br /&gt;
# Volume name&lt;br /&gt;
vol_name=rootfs		&lt;br /&gt;
# Autoresize volume at first mount&lt;br /&gt;
vol_flags=autoresize&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You then flash ‘system_ubi.img’ (not ‘system_ubifs.img’) from the recovery system.&lt;br /&gt;
&lt;br /&gt;
Again, like the custom kernel creation, the need to create a custom root filesystem is essentially non-existent except for those advanced users who already know they need it... and furthermore, you are almost entirely on your own.&lt;br /&gt;
&lt;br /&gt;
==Software Details==&lt;br /&gt;
&lt;br /&gt;
For even more advanced uses of the SBC, it may help to know the gritty details of the SBC software system.&lt;br /&gt;
&lt;br /&gt;
;Operating System&lt;br /&gt;
:Debian/GNU Linux&lt;br /&gt;
:Kernel 2.6.X or higher (generally kept up to date with latest releases, use {{Code|uname -r}} to check the kernel version)&lt;br /&gt;
&lt;br /&gt;
;Main Filesystem (rootfs)&lt;br /&gt;
:UBIFS (a raw flash type of file system)&lt;br /&gt;
:Mounted in a 460 MB Nand partition (in Read/Write mode)&lt;br /&gt;
&lt;br /&gt;
;Kernel&lt;br /&gt;
:uImage format&lt;br /&gt;
:Has its own 3MiB partition on bare Nand&lt;br /&gt;
&lt;br /&gt;
;Web Interface Scripts and Configuration Data&lt;br /&gt;
:Located in {{Code|/etc/webif}}&lt;br /&gt;
:Modifying these scripts can be done; however, it is very easy to enter invalid data that could cause the system to behave unexpectedly or not boot.&lt;br /&gt;
&lt;br /&gt;
;User Applications uploaded through Web Interface&lt;br /&gt;
:Located in {{Code|/usr/userapps}}&lt;br /&gt;
&lt;br /&gt;
;Webcam Device Location&lt;br /&gt;
:{{Code|/dev/video0}}&lt;br /&gt;
:Numbers increase with more webcams&lt;br /&gt;
&lt;br /&gt;
;Date and Time&lt;br /&gt;
:Set using ntp (network time protocol) at boot&lt;br /&gt;
:The ntp daemon continues to run in the background and will periodically update the clock &lt;br /&gt;
:The network keeps the SBC very close to real time&lt;br /&gt;
:Also there is a real-time clock with battery backup which will preserve date/time across reboots, power removal&lt;br /&gt;
:The real-time clock is synced to system time during reboot/shutdown&lt;br /&gt;
:If power is unplugged suddenly, and the network not restored, the real-time clock may not have the correct time&lt;br /&gt;
&lt;br /&gt;
;Wireless Networking System&lt;br /&gt;
:Wireless adapter support for the wireless adapter that Phidgets sells is written into the kernel&lt;br /&gt;
:It supports WEP and WPA&lt;br /&gt;
:It is best configured through the configuration interface.&lt;br /&gt;
&lt;br /&gt;
;Nand Layout&lt;br /&gt;
:The board contains 512MiB on Nand. This nand is split into 7 partitions as follows:&lt;br /&gt;
:0: u-boot		 size: 256K		 Read Only&lt;br /&gt;
:1: u-boot_env		 size: 128K		 Read Only&lt;br /&gt;
:2: recovery_kernel	 size: 2M		 Read Only&lt;br /&gt;
:3: kernel		 size: 3M		 Writable&lt;br /&gt;
:4: flashfs	 	 size: ~3.625M	 	 Read Only&lt;br /&gt;
:5: recovery_fs		 size: ~ 43M		 Read Only&lt;br /&gt;
:6: rootfs		 size: ~ 460M		 Writable&lt;br /&gt;
: The final size of flashfs/recovery_fs/rootfs depends on the image size at production, and on the number/location of bad blocks in the NAND.&lt;br /&gt;
: &#039;&#039;&#039;Note&#039;&#039;&#039;: U-Boot and recovery kernel and filesystem cannot be written from Linux - this is a safety measure.&lt;br /&gt;
&lt;br /&gt;
;Boot Loader&lt;br /&gt;
:U-Boot is used for setting up the processor and booting Linux, and is only accessible via a serial connection. &lt;br /&gt;
:Normal users will not need to use or modify it.&lt;br /&gt;
:Be very careful when modifying the u-boot partition. If it is damaged or overwritten, it is difficult to fix.&lt;br /&gt;
:When using U-Boot, a prompt will appear via serial shortly after power on.  &lt;br /&gt;
:The environment variables will help you determine how to boot Linux on the SBC&lt;br /&gt;
:You can also refer to the [http://www.denx.de/wiki/DULG/Manual U-Boot documentation]&lt;br /&gt;
&lt;br /&gt;
;Boot Process&lt;br /&gt;
:From power on...&lt;br /&gt;
:1. Processor loads first 4 bytes from NAND into Steppingstone and runs it.&lt;br /&gt;
:2. Steppingstone sets up RAM, copies u-boot from NAND into RAM and runs U-Boot.&lt;br /&gt;
:3. U-Boot initializes the processor, sets GPIO state, etc., copies the linux kernel into RAM, sets up the kernel command line arguments, checks that the kernel image is valid, and boots it.&lt;br /&gt;
:4. Linux boots, bringing up USB, Networking, NAND, etc. and then mounts the rootfs NAND partition on /.&lt;br /&gt;
:5. init gets run as the parents of all processes, as uses the /etc/inittab script to bring up the system. This includes mounting other filesystems, settings the hostname, and running the scripts in /etc/init.d, among other things.&lt;br /&gt;
:6. inittab then turns the green LED on.&lt;br /&gt;
:7. inittab then sets up a getty on the first serial port, ready for interfacing using the debug board.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|USB Memory Key mounting|Sometimes USB Memory Keys mount at more than one location}}&lt;br /&gt;
&lt;br /&gt;
When you insert a memory key, the SBC will load it as a device (e.g. {{Code|/dev/sda1}}) and it will also &#039;&#039;mount&#039;&#039; the key for reading and writing within the {{Code|/media/}} directory.  The {{Code|/media/}} directory version will be called something like {{Code|usb0}}.  &lt;br /&gt;
At times, an inserted memory key will get mounted in more than one location.  You can observe if this occurs by checking the currently mounted devices with the command {{Code|mount}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
/dev/sda1 on /media/usb1 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will note that the same device ({{Code|/dev/sda1}}) is now mounted at &#039;&#039;both&#039;&#039; {{Code|/media/usb0}} and {{Code|/media/usb1}}.  To fix this problem as it occurs, you can use {{Code|umount}} (notice there is no letter &#039;n&#039;) to unmount the second instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# umount /media/usb1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In practice, this should not be a problem, because writing to or reading from either {{Code|usb0}} or {{Code|usb1}} will have the same effect on the memory key.  However, if you hard-code a media location into your program (i.e. expecting {{Code|/media/usb0}} to be the first USB key you insert and {{Code|/media/usb1}} to be the second key) your program will sometimes work and sometimes fail.  &lt;br /&gt;
&lt;br /&gt;
To get around this within code, find the mount point for each device as it appears.  The devices, such as {{Code|/dev/sda1}} will always refer to the actual memory key.  But, they cannot be written to directly without being mounted, so you will have to parse the mount table (what is returned from {{Code|mount}}) within your code to find the device and its corresponding mount point.&lt;br /&gt;
&lt;br /&gt;
This is a problem with the standard embedded Debian automount program, and we have no known fix.&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Perl Locale Errors on SSH|No Locales Installed}}&lt;br /&gt;
&lt;br /&gt;
By default, no locales are installed on the SBC.  If you use [[#apt|apt]] a lot to install and manage your software on the SBC, you will get messages like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
perl: warning: Setting locale failed.&lt;br /&gt;
perl: warning: Please check that your locale settings:&lt;br /&gt;
	LANGUAGE = (unset),&lt;br /&gt;
	LC_ALL = (unset),&lt;br /&gt;
	LANG = &amp;quot;en_CA.UTF-8&amp;quot;&lt;br /&gt;
    are supported and installed on your system.&lt;br /&gt;
perl: warning: Falling back to the standard locale (&amp;quot;C&amp;quot;).&lt;br /&gt;
locale: Cannot set LC_CTYPE to default locale: No such file or directory&lt;br /&gt;
locale: Cannot set LC_MESSAGES to default locale: No such file or directory&lt;br /&gt;
locale: Cannot set LC_ALL to default locale: No such file or directory&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To squelch these messages, you should install and reconfigure your locale like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt-get install locales&lt;br /&gt;
dpkg-reconfigure locales&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The last command will show you a long list from which you should pick your location, by language.  For example, en_CA is english_Canada.  Here in Calgary, we use en_CA.UTF-8 and so for the first question we would input locale &amp;quot;114&amp;quot; and for the second (system) question we would input {{Code|en_CA}} for the locale.&lt;br /&gt;
&lt;br /&gt;
This might give you a locale undefined error, in which case you can generate the locale (for us, again, it is en_CA):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
locale-gen en_CA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20726</id>
		<title>Electricity Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20726"/>
		<updated>2012-06-29T21:42:20Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Design of reliable systems is really, really hard.  The main challenge is the design of reliable building blocks - i.e. circuit and board layouts - from which to create your system.  Phidgets does the majority of this work for you.  And, once you have reliable building blocks, designing a reliable system from them is much easier.  &lt;br /&gt;
&lt;br /&gt;
However, you can still make an unreliable system out of Phidgets.  In fact, if you are building a more complex system than the common examples we show through our documentation, and you have limited experience in complex electrical design, you will probably - and unintentionally - introduce design flaws that will make your system unreliable.&lt;br /&gt;
&lt;br /&gt;
There are two reasons why you should read this primer:&lt;br /&gt;
# You want to build a complex system, more complex than we illustrate in our documentation.  To succeed, you need to understand concepts.&lt;br /&gt;
# You understand how to make your system work, and you want to ensure it is well designed for maximum reliability and/or precision.&lt;br /&gt;
&lt;br /&gt;
==The Basics==&lt;br /&gt;
&lt;br /&gt;
To understand our discussion of potential problems and their solutions below, you&#039;ll need to be familiar with the basics.  For this page, &#039;being familiar&#039; means more than simply having heard of voltage, amperage, and power.  You will need to have a working, conceptual model in your head, so that you can apply that model to your own system and examine it for problems.  This section is all about giving the tools to build that mental model.&lt;br /&gt;
&lt;br /&gt;
First, some terminology.  We introduce it by analogy.  If a circuit is a water system,&lt;br /&gt;
* The &#039;&#039;&#039;voltage&#039;&#039;&#039; is the &#039;&#039;pressure&#039;&#039; in the system&lt;br /&gt;
* The &#039;&#039;&#039;power supply&#039;&#039;&#039; is the &#039;&#039;pump&#039;&#039; creating the pressure&lt;br /&gt;
* The &#039;&#039;&#039;amperage&#039;&#039;&#039;, also known as current, is the amount of &#039;&#039;flow&#039;&#039;&lt;br /&gt;
* The &#039;&#039;&#039;load&#039;&#039;&#039; is the &#039;&#039;faucet&#039;&#039; - adjusting your load will adjust the flow&lt;br /&gt;
* The &#039;&#039;&#039;resistance&#039;&#039;&#039; is an attribute of the load - how tight or loose the faucet is&lt;br /&gt;
* The &#039;&#039;&#039;ground&#039;&#039;&#039; is the return path from load to pump.&lt;br /&gt;
&lt;br /&gt;
The basic concepts for all of these terms are presented below.&lt;br /&gt;
 &lt;br /&gt;
===Load===&lt;br /&gt;
&lt;br /&gt;
We start with the load, because the load is the purpose of your entire system.  &lt;br /&gt;
&lt;br /&gt;
In simple, USB-only Phidget systems, the load is the Phidget itself.  The USB port is ready to provide power, but it does not (and cannot) until a load is applied (i.e. the Phidget is attached) and the circuit is completed.  &lt;br /&gt;
&lt;br /&gt;
Without a load that connects in a loop, it is like attaching a closed pipe to your pump.  Initially, water will fill the pipe, and pressurize it, but once the pipe fills the system as a whole will do nothing more.  To allow the pump to drive the load, and the flow to supply the load, we need to have a completed circuit, like this:&lt;br /&gt;
 &lt;br /&gt;
[[Image:elec_flow.png|150px]]&lt;br /&gt;
&lt;br /&gt;
The load and the pump must &#039;&#039;&#039;match&#039;&#039;&#039;.  If the load lets too much flow through, the pump will work too hard and burn itself out.  This is what happens when you short circuit a power supply.  The load is then simply a wire, which basically opens the flood gates and drains your power supply pump.  The load must not let too much flow through, which it does by &#039;&#039;&#039;resistance&#039;&#039;&#039;. Likewise, the pump cannot push too hard on the load, or the load will break.  This is discussed in-depth as part of [[#Voltage and Amperage|Voltage and Amperage]] below.&lt;br /&gt;
&lt;br /&gt;
===Voltage and Amperage===&lt;br /&gt;
&lt;br /&gt;
Within the flow concept [[#Load|above]], voltage is pressure.  Specifically, it is the &#039;&#039;difference&#039;&#039; in pressure between the flow and the return.  Voltage is measured in volts, and is denoted by &#039;&#039;&#039;V&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Amperage - also known as current - is the flow, or the amount of water that moves.  At the pump, the amount of current out and the amount of current in are equal.  The pressure might vary widely (highly pressurized pipes out, low pressure pipes back) but the &#039;&#039;amount&#039;&#039; of current is always the same.  Amperage is measured in Amps, and is denoted by &#039;&#039;&#039;A&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To match a pump to a load, the voltage and amperage of the power (supply) and load (sink) must line up.  We discuss picking a power supply - whether [[#Wall Power|wall mains]], or [[#Battery Power|batteries]] - in the [[#Power Needs|Power Needs section]] farther along in the document, but we need a few more concepts before we get there.&lt;br /&gt;
&lt;br /&gt;
Power supplies - whether wall power or batteries - are usually rated based on voltage and amperage.  Voltage is the specification to be the most careful with for circuits.  Too much voltage is the same as overpressurizing your pipes - they will burst.  In the case of electronics, you device will break.  &lt;br /&gt;
&lt;br /&gt;
This can be counterintuitive - in reference to safety (for humans) around electronics, you may have heard &amp;quot;It is not the voltage that will kill you, it is the amperage&amp;quot;.  Because of this, it may be tempting to think that too high of an amperage will harm your device, but this is not true.  Our hearts are very susceptible to amperage but not voltage, hence amperage is considered dangerous for us whereas voltage is not.  But a circuit is not like a human body - in a circuit trying to handle a power supply it is the voltage that matters most.  &lt;br /&gt;
&lt;br /&gt;
====Set Voltage (No Control)====&lt;br /&gt;
&lt;br /&gt;
Most loads do no power regulation of their own.  They simply take the voltage given to them and do useful things with it.  You can tell that a pre-designed load (like a Phidget) falls into this category because it gives its voltage need &#039;&#039;as an exact value&#039;&#039;.  For example, most Phdigets use exactly 5 V of USB power.  These loads will also tell you their amperage, which is a flow need that must be met or exceeded.  A load will only use as much amperage as it needs.&lt;br /&gt;
&lt;br /&gt;
====Controlled Power====&lt;br /&gt;
&lt;br /&gt;
Some loads change the voltage or current they receive.  This can be with the intent to either (a) keep a constant amount of power flowing from a draining power source like batteries, or (b) to modify a common power source (i.e. 12 V at 1 A) into an uncommon power source (i.e. 1 V at 12 A).  This process is called &#039;&#039;&#039;regulation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can tell that a pre-designed load (like a Phidget) falls into this &amp;quot;power-regulated device&amp;quot; category because it gives its voltage need &#039;&#039;as a range&#039;&#039;. For example, the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer (SBC)] can take 6 V to 15 V.  &lt;br /&gt;
&lt;br /&gt;
To understand how this works, take the example of a flywheel.  Flywheels are designed to be heavy and to take work in order to get them spinning at speed.  But once you have them spinning, you can extract that work later at a more consistent rate:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flywheel.png]]&lt;br /&gt;
&lt;br /&gt;
Flywheels can either make amperage or voltage be the more consistent blue line over time.  The most common one in Phidgets is for stable amperage.  Regulated amperage is also how LED lights can stay consistently bright for any length of time when using batteries.  Stable voltage design is usually applied when the voltage is too low to begin with (such as any device that runs on a single AA battery), and the flywheel must amplify and stabilize it over time.&lt;br /&gt;
&lt;br /&gt;
For those readers trying to envision how this works electrically, in practice the flywheel is an inductor (or, a transformer utilizing its inductor properties).  For both voltage and amperage regulation, one way relief valves (diodes) must be added. And, in amperage regulation a reservoir (capacitor) must be added to offset the current drop by pulling &#039;&#039;more&#039;&#039; amperage as a battery drains.  Then, a controller is needed to measure and then correspondingly enable and disable the flywheel system as the voltage or amperage drops from the supply.  &lt;br /&gt;
&lt;br /&gt;
But with those details in place, the inductor (and capacitor, in the case of amperage regulation) can effectively take the variety of voltages from, say, a draining battery, and still allow the board to run.  Some devices even do this naturally.  For example, motors often can take a variety of voltages because their construction (i.e. wire wrapping) naturally creates inductance.&lt;br /&gt;
&lt;br /&gt;
These regulated systems often list the power they need directly, using a type of power rating called &#039;&#039;&#039;watts&#039;&#039;&#039;.  Watts are voltage and amperage together (i.e. power):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Amperage} =\frac{\text{Watts}}{\text{Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Watts can be a handy way to describe flow and pressure together for these regulated devices.  Rather than separating voltage and amperage like the unregulated devices do (i.e. this load needs exactly 12 V, or this load will draw exactly 2 A), the unit of watts will allow different value combinations of volts and amps as long as the wattage remains the same.  For example, a 12 watt device with a voltage range of 5 to 12 volts can run on 6 V at 2 A, or 12 V at 1 A.  Either will work.  Amperage for all values in the device&#039;s range of 5 to 12 V can be found with the equation above.  Because of this, watts are often preferred when trying to match a power supply to a regulated load.&lt;br /&gt;
&lt;br /&gt;
===Ground===&lt;br /&gt;
&lt;br /&gt;
All circuits have a &#039;&#039;&#039;ground&#039;&#039;&#039;.  This is simply the return pipe to the pump.  In a circuit, it is denoted by an upside-down triangle:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground.png]]&lt;br /&gt;
&lt;br /&gt;
When drawing a circuit diagram, the symbol is placed on the wires that return to the pump:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flow_ground.png|170px]]&lt;br /&gt;
&lt;br /&gt;
This electric ground provides a voltage reference throughout the circuit.  Ground is always &#039;&#039;&#039;0&#039;&#039;&#039; volts as far as the circuit is concerned. (Remember, voltage is the &#039;&#039;difference&#039;&#039; between the flow and return pipes at the pump.)  Ground is important because it provides a reference from which all the parts of the circuit can speak the same &amp;quot;voltage language&amp;quot; to each other, which matters a lot when a certain voltage means &amp;quot;1&amp;quot; and a certain voltage means &amp;quot;0&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
There is only one &#039;&#039;&#039;absolute&#039;&#039;&#039; ground, and that is the Earth, which is taken to be 0 volts as an absolute value.  Circuits not well-grounded to the Earth (of which there are many - your cell phone, car, etc) operate at a &#039;&#039;&#039;relative&#039;&#039;&#039; voltage.  The upside-down triangle above denotes a &#039;&#039;relative&#039;&#039; ground.&lt;br /&gt;
&lt;br /&gt;
With relative voltage, only the difference between local ground and the local high voltage matters.  For example, a cell phone might operate as a 3 volt device, which means relative to its ground it always operates between 0 and 3 volts.  But if that cell phone were compared carefully to Earth ground, its absolute voltage could be, say, between 10 and 13 volts.  Until comparison, the device doesn&#039;t &amp;quot;feel&amp;quot; charged.  This is the same as how you don&#039;t &amp;quot;feel&amp;quot; charged after skidding your feet in socks across a carpeted floor.  But, when you &amp;quot;compare&amp;quot; yourself to Earth ground by touching some well-grounded metal, you receive a static electricity shock.&lt;br /&gt;
&lt;br /&gt;
The same thing can happen when you combine two different power supplies, as we discuss [[#Projects With Different Power Sources|below]].&lt;br /&gt;
&lt;br /&gt;
===Power===&lt;br /&gt;
&lt;br /&gt;
There can be different types of pumps, and at this point we should supplant our heart symbol with some actual power supply pump symbols.  For example, this is the symbol for a direct current (DC) battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
The + end is on the out flow, and the - end is on the return (ground).  Batteries are usually listed with their voltages.  This is because the resistance of the load will determine how much amperage is drawn, but too much voltage and you will harm your load.&lt;br /&gt;
&lt;br /&gt;
This is the symbol for alternating current (AC) that you would get directly from the wall:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_wall_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
Again, this is listed using voltage for the same reasons as DC.  A relative ground symbol is still used on the return line here.  AC devices can still operate on relative voltage if they do not use Earth ground (the third prong on a wall plug in North America).  This is how some loads have AC cords with only two prongs - they operate on a relative voltage and relative ground.  And relative AC voltage, having significantly more voltage (pressure) behind it, can really hit a device hard when two power supplies meet across it.&lt;br /&gt;
&lt;br /&gt;
This connecting of multiple power supplies is quite a complex subject, and is described further in both [[#Power Needs|picking different power supplies]] and [[#One Powered Phidget|connecting different power supplies]] later on in this Primer.&lt;br /&gt;
&lt;br /&gt;
===Emissions and Wires===&lt;br /&gt;
&lt;br /&gt;
To talk about emissions, it is worth speaking more precisely about what a load is.  The typical, simple Phidget setup is receiving 5 V direct current (DC) from the computer over the USB port.  Let&#039;s model this as coming from a battery so that we can examine all parts of the system.  From the point of view of the battery, the Phidget load is not just the green board with the circuitry on it.  The load &#039;&#039;also&#039;&#039; includes the power cable (i.e. two wires in the USB cable), and anything else on the path out or back from the circuitry to the battery itself:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
This is important because the wires play a role in the voltage that eventually makes it to the Phidget.  This is true all the time, even when the Phidget is attached to a computer instead of a battery.  All wires have some resistance, and so they are, in a way, in and of themselves circuits.    Therefore, because of their resistance, the wires &#039;use&#039; some of the 5 V heading out to the Phidget circuit board.  This is discussed more below, but essentially longer cables have more resistance and at some point the voltage will drop so much over the length that the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
To conceptually separate the wires from the Phidget in terms of the load, we can now start drawing the wires themselves in our circuit diagram, instead of the curved concept arrows indicating flow and return:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wires.png|200px]]&lt;br /&gt;
&lt;br /&gt;
When talking about the 5V relative ground in this system, we are in fact talking about the ground &#039;&#039;right at the battery&#039;&#039; so we move the ground symbol to the battery itself.&lt;br /&gt;
&lt;br /&gt;
Then, the resistance on these wires creates a possible problem - the emission of electromagnetic radiation as the wires naturally drop the voltage:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_emissions.png|200px]]&lt;br /&gt;
&lt;br /&gt;
These emissions are at a set frequency determined by the length of the wire:&lt;br /&gt;
* Long wires create low frequencies (harmful interference)&lt;br /&gt;
* Short wires create high frequencies (less harmful interference)&lt;br /&gt;
&lt;br /&gt;
This can be minimized by having the flow and return wires be the same length and sit right next to each other.  This way, the emissions somewhat cancel each other out from the flow and return going in opposite directions.  This is partially how USB cables minimize emissions.&lt;br /&gt;
&lt;br /&gt;
So, the way you design your connections (i.e. the resistance and placement of your wire) will have a direct affect on:&lt;br /&gt;
# The voltage that reaches the Phidget&lt;br /&gt;
# The emissions that your system produces&lt;br /&gt;
&lt;br /&gt;
With all this talk of emissions, you might be tempted to try to shield parts or all of your system from emissions that either your system or external systems create.  &lt;br /&gt;
&lt;br /&gt;
Keep in mind that shielding is actually really hard to do correctly.  Especially when grounding your shielding, with ad-hoc design you have a high chance of having an interfering signal (that has traveled out to the shield and traveled back via ground) creating a larger problem than not having a shield at all.  Rather than shielding, it is easier to simply keep your cables short and with as low a resistance as possible throughout your system to minimize your emissions in the first place.&lt;br /&gt;
&lt;br /&gt;
Identification of and solutions to these (and other more complex) problems are discussed in detail in the [[#Selecting Cables|section on choosing cables]] and the [[#Hooking Up The Pieces|section on connecting the pieces]] below.&lt;br /&gt;
&lt;br /&gt;
===Multiple Loads===&lt;br /&gt;
&lt;br /&gt;
The easiest way to hook up multiple Phidgets is in parallel, where the voltage stays the same but they share the amperage.  Here the DC supply is two USB ports, each at 5 V and 0.5 A:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
However, the length of your wires comes into play again, because the voltage that actually reaches the Phidgets above is somewhat less than 5 V.  So if your wires are long, or mismatched, the voltage may not match and will give you strange results.  The voltage is both affected on the way out, and on the way back.  Assuming the wires are the same length:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wire_drop.png|350px]]&lt;br /&gt;
&lt;br /&gt;
In this way, you can create difficult-to-debug problems within a complex system, where one Phidget works but others mysteriously fail.&lt;br /&gt;
&lt;br /&gt;
==Power Needs==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve understood the basics, it is time to actually talk about decisions and design.  This section will help you choose a power supply for your Phidget.  Let&#039;s say you want to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] off of a battery.  Or you want to run a motor controller with a power supply you bought from the hobby store.  What do you need to buy?  Will one you already have work?  It is worth it to spend a moment with pencil and paper to work through this section and identify your power needs.&lt;br /&gt;
&lt;br /&gt;
As described [[#Voltage and Amperage|earlier]], voltage is pressure. Too much pressure behind your faucet, and the water mains or faucet will break.  Likewise, if you have too much voltage from a power supply, your circuit will break.  You should choose a supply with voltage that &#039;&#039;matches the range the Phidget can accept&#039;&#039;.  The voltage cannot be over the maximum (otherwise, like pressure in a pipe, the pipe will burst), and the voltage cannot be under the minimum (otherwise, like pressure in a pipe, no flow will occur).  Also, generally, a device (like a motor controller) will perform better at its maximum rated voltage if a range is available.&lt;br /&gt;
&lt;br /&gt;
But the faucet doesn&#039;t care whether there is a big reservoir or small reservoir feeding the system, as long as the pressure is managed.  Likewise, you can choose a power supply with more amperage than you need (a big reservoir to draw from) as long as the voltage matches.  In the same way that a faucet restricts water by design, loads draw and allow only the amperage that they need. However, the amperage cannot be less than the Phidget needs.  In that case, you will either overextend (and break) your power supply, or the circuit simply will not turn on at all.&lt;br /&gt;
&lt;br /&gt;
The specification [[#Device List|for your specific device]] will list its power needs. For most devices, the external power supply needs will simply be listed in voltage and amperage.  USB power is 5V at up to 500 mA (0.5 Amps).  Most Phidgets will draw less than this - if you need precision, you can check the specification for your particular Phidget.  And, if it is an Interface Kit, you can add the draw of each analog sensor and digital in/out from their specifications.&lt;br /&gt;
&lt;br /&gt;
However, some Phidgets (e.g. motors, and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]) do not have a straight amperage and voltage specification.  Instead, their power draw will be listed in watts, for which you [[#Voltage and Amperage|saw a relation earlier]] to convert to the values you need.&lt;br /&gt;
&lt;br /&gt;
===Wall Power===&lt;br /&gt;
&lt;br /&gt;
Wall power sources usually take the alternating current (AC) from the wall and convert it into a direct current (DC).  These power supplies often take your familiar two-or-three prong wall connector and put power out via a barrel plug-type connector.  AC power (typically 110 or 240 volts, depending where you live in the world) goes in the typical wall plug, and DC power (typically 5 to 24 volts) comes out the barrel plug.  Most power supplies of this type list the conversion explicitly, such as: 110-240 Volts to 12 Volts at 2 Amps.  You&#039;ll want to match your Phidget&#039;s needs against the 12 Volts at 2 Amps. &lt;br /&gt;
&lt;br /&gt;
*The voltage must match exactly&lt;br /&gt;
**If the Phidget takes a range of voltages, the supply must fall within the range&lt;br /&gt;
*The amperage can be equal to or greater than the Phidget needs&lt;br /&gt;
&lt;br /&gt;
A wall power supply is essentially an inexhaustible supply of current, so you don&#039;t need to worry about it running out like you would with batteries.&lt;br /&gt;
&lt;br /&gt;
===Battery Power===&lt;br /&gt;
&lt;br /&gt;
If you intend to use a battery bank (even of only one battery) to power your Phidget, you probably want to know what type of battery to purchase.  &lt;br /&gt;
&lt;br /&gt;
====Battery Chemistries====&lt;br /&gt;
The first thing that sets batteries apart is the type of materials used in their construction.  The following table shows several of the more common battery chemistries as well as the voltage per cell they produce and the specific energy of the chemistry.  &lt;br /&gt;
&lt;br /&gt;
{| border = 1&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Chemistry&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Nominal Cell Voltage&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Specific Energy (MJ/kg)&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Primary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| Alkaline||1.5||0.4||These are the most common form of battery.  Many commercially available AA and AAA batteries are alkaline. &lt;br /&gt;
|-&lt;br /&gt;
| Lithium (LiMnO2)||3||0.83-1.01||These are used in high drain devices or devices with a long shelf life as they have a very low self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Silver-oxide||1.55||0.47||Only used in small button cells as these are quite expensive.&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Secondary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| NiCd||1.2||0.14||Older technology, suffers from [[Electricity Primer#Memory Effect|memory effect]].  Capable of very high discharge rates with no ill effects.  Moderate self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Lead-acid||2.1||0.14||Not particularly good with high discharge rate.  Moderate rate of self discharge.  &lt;br /&gt;
|-&lt;br /&gt;
| NiMH||1.2||0.36||Very heavy.  Good performance in high drain devices.  Very high energy density naturally, at the cost of a high self discharge rate.  Newer versions are able to get rid of some of the self discharge though they suffer ~25% lower energy densities as a result.  &lt;br /&gt;
|-&lt;br /&gt;
| Lithium Ion||3.6||0.46||Expensive to produce but very high energy density.  Very low self discharge rate.  Safety hazard as short circuiting can yield explosive or fiery results. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Choosing a Battery====&lt;br /&gt;
Batteries are chosen first by their voltage (V).  Match the voltage exactly to the voltage the Phidget needs.  Over or under this value, you could harm the board or have it simply fail to turn on.&lt;br /&gt;
&lt;br /&gt;
Next, choose a battery that has adequate amperage to feed your device for the time you need. The lifespan of the battery will usually be listed in Amp-Hours (or Ah).  For example, a double wide 12 V lantern battery will have usually around 7-8 amp hours.  This means if you drew one amp from it for seven to eight hours, the battery would be totally drained.  Or you could draw two amps from it and drain it in 3.5-4 hours.  This does not mean however, that you can draw 36A for 15 minutes.  It is important to understand that there is a limit at which more power simply cannot be drawn from the battery.  Effectively, high drain devices will decrease the rated Ah.  The amount  differs from battery to battery so to be sure it is recommended to check the data sheets for the battery you are using.  If the battery did not come with a data sheet they can usually be found on the manufacturers website.  The data sheets should have a graph that shows the relationship between current draw (usually in mA) and capacity (Ah or mAh).  Another useful thing that can be gathered from the datasheets is the batteries response to temperature.  Batteries tend to not work as well in cold environments, most manufacturers will provide graphs of how the batteries lifespans will shorten at different temperatures.  This is often very significant, causing the battery to last a fraction of its normal lifespan at temperatures below -10&amp;amp;deg;C.&lt;br /&gt;
&lt;br /&gt;
Finding the amperage or voltage sometimes needs to be done indirectly by using a specification of watts.  The relationship between amperage, voltage, and watts is given above in the [[#Voltage and Amperage|voltage and amperage section]].&lt;br /&gt;
&lt;br /&gt;
For an example, let us say you want to use battery power to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer].  The specifications say that it uses 1.2 watts as a base value.  The specifications also say that it can take 12 V DC power.  If we choose to use a 12 V battery, at 1.2 watts it will use 0.1 amps according to the equation [[#Voltage and Amperage|shown earlier]].  Going by amp-hours alone, if our battery is a double-wide lantern type 12 V battery, with 7 amp hours, with 0.1 amp draw it will last 70 hours, or almost three days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Maximum Running Days} =\frac{\text{Battery Amp Hours}}{\text{Device Amps} * \text{24}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, to estimate &#039;&#039;average&#039;&#039; running time (rather than maximum running time possible), amp-hours cannot be used so directly.  Over time, batteries decrease in voltage as their power is used up.  Practically speaking, this means one of two things for your load.  For loads that do not regulate voltage or current, the amperage will also decrease over time.  The classic example is an LED light source that grows dimmer and dimmer as the batteries are used up.&lt;br /&gt;
&lt;br /&gt;
You should usually only count on about 60% of the stated amp hour rating to apply before expecting to run into problems from escalated drain due to battery voltage drop.  This is especially true for deep cycle rechargeable batteries left in an installation, where draining more than 60% could also harm the battery.  &lt;br /&gt;
&lt;br /&gt;
Then, for lead-acid batteries, a typical battery is tested from full to complete drain over 20 hours by the manufacturer to obtain the advertised amp-hour rating.  Draining a battery at a faster rate than this will result in even more reduction in capacity, by 10% or even more.  This due to [http://en.wikipedia.org/wiki/Peukert%27s_law Peukert&#039;s Law].&lt;br /&gt;
&lt;br /&gt;
There are plenty of [http://www.google.ca/search?&amp;amp;q=battery+calculator battery calculators] around the Internet which take most or all of these additional factors into account when recommending an amp-hour rating.  For longer-term installations, the solar power online community has some excellent resources.&lt;br /&gt;
&lt;br /&gt;
====Setting up Multiple Batteries====&lt;br /&gt;
You can hook up multiple batteries in series to get more voltage at the same amperage.  The amperage is additive.  For example, you can hook up two single-wide 6 V lantern batteries in series to produce 12 V.  Or two 12 V batteries in series to produce 24 volts.  This system would still only have the amp hours of &#039;&#039;one&#039;&#039; of the lantern batteries, because you will be essentially using them both at once: &lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_series.png|250px]]&lt;br /&gt;
&lt;br /&gt;
The upside down triangle (ground) is explained above in a [[#Ground|section of its own]].&lt;br /&gt;
&lt;br /&gt;
Or, you can hook up multiple batteries in parallel to get more amperage at the same voltage.  For example, you could hook up two 12 V deep cycle batteries in parallel to provide more amperage at 12 V, which is like having a deeper reservoir of power for your device to use:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
====Heat====&lt;br /&gt;
*all batteries have some sort of internal resistance&lt;br /&gt;
*can be found on the battery&#039;s data sheet&lt;br /&gt;
*the more power you pull from the battery the more heat is going to build up as a consequence of the internal resistance.&lt;br /&gt;
*larger internal resistances will cause heat to build up faster.&lt;br /&gt;
*when charging a battery you are not just limited to the power in the battery.  nothing stops you from dumping energy into the battery past the point where it is fully charged&lt;br /&gt;
**this is why charging batteries is a bit of a tricky business.&lt;br /&gt;
**many batteries come with custom chargers that have control systems to prevent this type of overcharging.&lt;br /&gt;
&lt;br /&gt;
====Weight====&lt;br /&gt;
Finally, weight matters - a car battery is much heavier than a lantern battery.  Batteries vary widely by weight per amperage.  Lithium batteries are usually very light for their power, followed by alkaline, followed by lead acid.  This may not seem important at first, but if you are building a mobile robot it is worth calculating in the work of carting around a battery.  You may find that, for the length of time you want it to run, your battery requires some system redesign.&lt;br /&gt;
&lt;br /&gt;
==Selecting Cables==&lt;br /&gt;
&lt;br /&gt;
===USB Cables===&lt;br /&gt;
&lt;br /&gt;
In general, use the shortest cables possible.  There are many reasons for this [[#Emissions and Wires|described above]], but as a summary:&lt;br /&gt;
&lt;br /&gt;
; Long cables reduce the voltage that reaches the Phidget.&lt;br /&gt;
: This happens in both directions.  So, for every unit cable length added, the voltage decreases by twice the electrical resistance of that length of cable. With especially long cables the Phidget may drop below its 4.6 volt threshold and simply never turn on.&lt;br /&gt;
&lt;br /&gt;
; Long cables increase the width of your circuit.  &lt;br /&gt;
:All circuits act as emitting antennas for the resonance frequency of the circuit structure.  The longer the wires in the circuit, the lower the frequency, and the higher chance that it will be emissions that will interfere with your data and system.&lt;br /&gt;
&lt;br /&gt;
; Longer cables have more length exposed to external interfering emissions.&lt;br /&gt;
&lt;br /&gt;
Also, use thick cables that are built to specification.  Some USB cables with thinner wiring have higher electrical resistance.  This can be equal to what a much longer wire would have, and thus create a similar voltage drop where the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
====Options for longer cables====&lt;br /&gt;
The maximum length for a USB cable is 5m.  This is laid out in the USB specifications.  Often times however a system requires more reach.  In this case there are a few options available to you.  You can use what is known as an active extension cable or USB extender.  These cables act like extension cables and add power to the line so that the signal can travel further.  A second option is to use a Cat5 extender.  These extenders are 2 USB dongles that connect on either end of your system.  You join them up with Cat5 cable.  This allows you to run over much longer distances than USB traditionally allows.&lt;br /&gt;
&lt;br /&gt;
===Power Cables===&lt;br /&gt;
&lt;br /&gt;
There are &amp;quot;DC Wire Table&amp;quot; references on the Internet which describe how to pick a wire appropriate for your voltage and amperage.  When selecting AC wires, you will probably be using pre-made extension cords.  Cords add interference resonance length to your circuit, just like USB cables do as [[#USB Cables|described above]].  A long extension cord can create huge electromagnetic interference for your circuit and other systems in the area when first plugged in.&lt;br /&gt;
&lt;br /&gt;
Also as with the USB cables above, cut the cables to the shortest length possible.  This is again both for voltage drop reasons and frequency emission reasons.&lt;br /&gt;
&lt;br /&gt;
===Hubs===&lt;br /&gt;
&lt;br /&gt;
Avoid hubs where possible.  Unpowered hubs are good for reading data from memory keys, but not for powering many external devices.  If you must use a hub, buy a powered one.&lt;br /&gt;
&lt;br /&gt;
===Sensor and Motor Wiring===&lt;br /&gt;
All Phidgets sensor class devices (products whose part numbers start with 11 such as the 1129) use a 3 channel ribbon cable for power and data transmission.  Similarly, all our motors and load cells use multichannel wire interfaces.  As mentioned previously, USB spec limits cables to 5m, this is not the case for these wires.  The biggest concerns are electromagnetic interference (EMI) and voltage drop.  In general you should be able to run these wires over significant distances (30m or more) with the load cells in particular having very long range.  If EMI starts causing issues you can always use ferrite beads on the cable near the sensor or motor and the controller to reduce noise.&lt;br /&gt;
&lt;br /&gt;
===Cable Gauges for Terminal Blocks===&lt;br /&gt;
&lt;br /&gt;
Many Phidgets products feature green terminal blocks that use screws to hold wires in place, making it easy to take apart and rebuild connections in your project. The size of the terminal block determines the gauge of wire you should use.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Terminal Block Size and Wire Gauge&#039;&#039;&#039;&lt;br /&gt;
! Terminal Block Width (mm/port)&lt;br /&gt;
! Recommended Wire Gauge (AWG)&lt;br /&gt;
|-&lt;br /&gt;
| 3.81&lt;br /&gt;
| 14 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 5.0&lt;br /&gt;
| 12 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 9.5&lt;br /&gt;
| 10 to 26&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The gauge of cables and wires is measured in AWG, which is the American Wire Gauge standard. The following table lists the properties of wire gauges commonly used with Phidgets:&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;American Wire Gauge Sizes&#039;&#039;&#039;&lt;br /&gt;
! AWG Size&lt;br /&gt;
! Diameter (mm)&lt;br /&gt;
! Area (mm²)&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| 2.588&lt;br /&gt;
| 5.26&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| 2.305&lt;br /&gt;
| 4.17&lt;br /&gt;
|-&lt;br /&gt;
| 12&lt;br /&gt;
| 2.053&lt;br /&gt;
| 3.31&lt;br /&gt;
|-&lt;br /&gt;
| 13&lt;br /&gt;
| 1.828&lt;br /&gt;
| 2.62&lt;br /&gt;
|-&lt;br /&gt;
| 14&lt;br /&gt;
| 1.628&lt;br /&gt;
| 2.08&lt;br /&gt;
|-&lt;br /&gt;
| 15&lt;br /&gt;
| 1.450&lt;br /&gt;
| 1.65&lt;br /&gt;
|-&lt;br /&gt;
| 16&lt;br /&gt;
| 1.291&lt;br /&gt;
| 1.31&lt;br /&gt;
|-&lt;br /&gt;
| 17&lt;br /&gt;
| 1.150&lt;br /&gt;
| 1.04&lt;br /&gt;
|-&lt;br /&gt;
| 18&lt;br /&gt;
| 1.024&lt;br /&gt;
| 0.823&lt;br /&gt;
|-&lt;br /&gt;
| 19&lt;br /&gt;
| 0.912&lt;br /&gt;
| 0.653&lt;br /&gt;
|-&lt;br /&gt;
| 20&lt;br /&gt;
| 0.812&lt;br /&gt;
| 0.518&lt;br /&gt;
|-&lt;br /&gt;
| 21&lt;br /&gt;
| 0.723&lt;br /&gt;
| 0.410&lt;br /&gt;
|-&lt;br /&gt;
| 22&lt;br /&gt;
| 0.644&lt;br /&gt;
| 0.326&lt;br /&gt;
|-&lt;br /&gt;
| 23&lt;br /&gt;
| 0.573&lt;br /&gt;
| 0.258&lt;br /&gt;
|-&lt;br /&gt;
| 24&lt;br /&gt;
| 0.511&lt;br /&gt;
| 0.205&lt;br /&gt;
|-&lt;br /&gt;
| 25&lt;br /&gt;
| 0.455&lt;br /&gt;
| 0.162&lt;br /&gt;
|-&lt;br /&gt;
| 26&lt;br /&gt;
| 0.405&lt;br /&gt;
| 0.129&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Hooking Up The Pieces==&lt;br /&gt;
&lt;br /&gt;
Here, things can be tricky.  You might think: just plug everything in and go!  But often it is not that simple.  Many Phidgets require special care when hooking up.  We encourage a process where you apply the concepts in this Primer, through analysis, to your system.  So, we don&#039;t explicitly list the boards most commonly affected until the [[#Affected Products|end of this Primer]].&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;categories&#039;&#039; of the boards which require special attention within a complex system are:&lt;br /&gt;
&lt;br /&gt;
# Phidgets with more than one power source, and&lt;br /&gt;
# Phidgets needing precise measuring or control of an external power source&lt;br /&gt;
&lt;br /&gt;
If you are already thinking about your boards in your head and trying to figure out whether they fit into one category or another, you&#039;re on the right track!  The list of [[#Affected Products|commonly affected boards]] are only the common ones... with a sufficiently complex system, you could conceivably create problems with &#039;&#039;any&#039;&#039; boards.&lt;br /&gt;
&lt;br /&gt;
Both types of projects require a full understanding of [[#The Basics|electrical basics]].  Using those concepts, below we first describe problems that arise when hooking up different power sources, and extend that into using the solution to give more precise measurement and control.  &lt;br /&gt;
&lt;br /&gt;
===Shared Grounds===&lt;br /&gt;
&lt;br /&gt;
Shared grounds can occur in Phidgets that handle two different power sources.  Recognizing the sharing of a ground is not always easy.  We show what it is, how it can be possible, and why it creates problems by starting with the most basic Phidget system.  The simplest setup for a Phidget is to use the [[#Ground|ground]] of the computer it gets data and power from over a USB port:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_simple_case.png]]&lt;br /&gt;
&lt;br /&gt;
In this case, there is only one relative ground, and it is the PC ground, which is ground #1 in the image.  The PC ground determines what is considered 0 volts for all signals on the Phidget.  When you add different power sources or sinks in the system, you are pulling the system relative to the PC ground.  &lt;br /&gt;
&lt;br /&gt;
=====One Powered Phidget=====&lt;br /&gt;
&lt;br /&gt;
The next most complicated system is one Phidget that handles two power sources.  Let us say you have a motor controller, which takes power from USB, and which also takes power from a second power source.  Although the second power source is usually just a wall plug, the simpler case for thinking about ground is actually a battery.  A battery creates a second &#039;&#039;relative&#039;&#039; ground.  Through the Phidget, relative ground #1 (from the PC) and #2 (from the battery) actually become the same ground:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_wall_power.png]]&lt;br /&gt;
&lt;br /&gt;
This is the first reason why systems with powered Phidgets have to carefully manage ground.  If ground #1 and ground #2 are different with respect to each other (see the static shock analogy in the [[#Ground|ground section]] above), then whatever circuitry along the red dashed arrow must deal with the initial static shock.  In this case it would be the circuitry of the Phidget.  In the case of a battery, after the initial equalizing shock the battery will be whatever relative voltage the PC ground needs it to be.  Hence a battery relative ground can &#039;float&#039;.&lt;br /&gt;
&lt;br /&gt;
If ground #2 comes from the wall, on the other hand, the ground does not &#039;float&#039; and instead is always absolute 0 volts Earth ground.  With the PC giving the power, this is not a problem in practice because the PC can also float (as with a laptop), or it uses Earth ground.  But if you were using a different and more powerful USB power supply instead of a PC, and then connected it to the absolute Earth ground through the Phidget, the Phidget would bear the brunt of any ground equalization that would occur.  If neither the new ground nor the old ground float, and the power supplies were powerful enough, this would eventually destroy the Phidget.  In this case, you would want to use isolation, as described in [[#How To Fix This|How To Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Multiple Powered Phidgets=====&lt;br /&gt;
&lt;br /&gt;
A worse case comes in when you are using two powered Phidgets and one external power source.  Again, say you are using a battery as the external power source.  It would be tempting to simply wire both grounds from the Phidgets to the ground on the battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_phidget.png]]&lt;br /&gt;
&lt;br /&gt;
Although this looks benign, you have actually created a new circuit.  The circuit is a second path, via ground, for the current to return to the voltage source.  This is also known as a &#039;&#039;&#039;ground loop&#039;&#039;&#039;. The path we intuitively think of the current returning by is  &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;, but the sharing of grounds has created a new path through the motherboard, &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_paths.png]]&lt;br /&gt;
&lt;br /&gt;
All current gets &#039;pumped&#039; in a loop by voltage, and so it will use all return paths available to it, assuming all paths are equally easy (electrically) to use.  This extends the pipe analogy, where water will flow in every path that exists.  So, if your battery (or other power source with ground #2) is quite powerful, you can actually harm your motherboard within your PC (or at least your USB bus ground), because &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039; runs through the motherboard circuitry on the way back to the voltage source.&lt;br /&gt;
&lt;br /&gt;
This problem does &#039;&#039;not&#039;&#039; apply to using a different power source between a black power plug and for the green control terminal block on, say, a [[DC Motor and Controller Primer|DC motor controller]].  Although the grounds are connected, and they run across a part of a Phidget board, creating a ground loop does not actually run through any circuitry if only these types of boards are used.  If you have a complex system with other types of boards and therefore circuitry between black plug power port and green terminal block connections, draw out your system carefully to identify the loops.&lt;br /&gt;
&lt;br /&gt;
Ground loops can be fixed by one of the ways described in [[#How To Fix This|How to Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Single Board Computer And Powered Hub=====&lt;br /&gt;
&lt;br /&gt;
When combining one externally powered Phidget and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] or the [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]] on the same external power source, you still may inadvertently create a ground loop as described above in [[#Multiple Powered Phidgets|the multiple powered Phidgets section]].  If they share a true [[#Ground|Earth ground]], this is not a problem.  But if the ground is from a battery, or uninterruptible power supply, etc. then you should carefully draw out your system circuit and examine it for ground loops.&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
Once you are aware of shared grounds in your system, you have two options.  &lt;br /&gt;
&lt;br /&gt;
One, for ground loop problems in simple systems (two Phidgets), you could make the normal return path (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;) the most electrically desirable path.  This is best for simple systems where you have a lot of control over all of the ground wires within your system.  For the ground wires leading directly from the Phidget to the external power supply (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;), lower the resistance in the wire as much as possible.  You can do this by keeping the wires short, and using a thick (large gague) wire for the hookups.  &lt;br /&gt;
&lt;br /&gt;
Although this solution works, sometimes you do not have much choice on how long your ground return wires can be, because the location of your power supply and and Phidgets are set by your system design.  If you cannot be totally sure that the direct ground path is the shortest and most electrically desirable path, it is best to use the second option: a &#039;&#039;&#039;USB Isolator&#039;&#039;&#039; such as the [[Product - 3060 - USB Isolator|Phidget 3060]].  This isolator is like any other USB isolator - it can be used on a Phidget system, as well as any system that needs ground isolation.&lt;br /&gt;
&lt;br /&gt;
You need isolators for every USB cable in your system, less one.  If you have two USB connections, you need one isolator; three USB connections, two isolators, and so on.  The one USB connection can remain non-isolated because a single ground connection cannot form a loop.  However, if you are concerned about connecting the grounds as described in the [[#One Powered Phidget|single connected Phidget section above]], use a USB isolator on every cable.&lt;br /&gt;
&lt;br /&gt;
===Precise Voltage Control===&lt;br /&gt;
&lt;br /&gt;
Precise voltage (or other system) control and measurement is related to the concept of [[#Shared Ground|shared ground above]].  But here, you want to keep grounds separate not only to prevent ground loops, but also to make your system more sensitive to what it will control or measure.&lt;br /&gt;
&lt;br /&gt;
For example, we make Phidgets that can create power precisely, or that can take it in and measure it.  One such product is the 1002, which outputs a precise analog voltage with which to control an analog system.  Now that you know about [[#Ground|relative ground]], however, you would be right to expect that you do not want to combine the ground in the PC and the ground in the system.&lt;br /&gt;
&lt;br /&gt;
Even if you don&#039;t care about system sensitivity, you can still create [[#Multiple Powered Phidgets|ground loops]] in a system with multiple of these types of Phidgets.  In addition, if you are using the Phidget to control a large, powerful system, even a single Phidget can receive damage from connecting two powerful power sources meeting across it, also as [[#One Powered Phidget|described earlier]].&lt;br /&gt;
&lt;br /&gt;
But above and beyond the powered Phidget problems, there is another reason to separate (isolate) the electrical grounds in your system.  The reason is: to make your system control more precise.  For example, with the 1002, if you are trying to control an external system with an Phidget output voltage, that output voltage should be relative to the &#039;&#039;system you are trying to control&#039;&#039;, not relative to the PC.  Rather than forcing the grounds - and therefore the relative voltages - to be equal to each other, you can provide more precise control by isolating the grounds and working with the relative voltage of the controlled system on its own terms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Schematic-type image of a ground isolated analog out on a 1002&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
The solution to all of these problems in precise voltage control systems is to use USB isolation, even for a single Phidget.  The [[Product - 3060 - USB Isolator|Phidget 3060]] is one such isolator.  It inserts along the USB connection between your PC and the Phidget, and it separates the Phidget (and controlled system) ground from the PC ground.  This fixes ground loops, separates relative voltage mis-matches, and isolates the control system for better precision.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Image of 1002 and Isolator connected, with lines superimposed on the image to show non-copper connection in isolator&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Affected Products==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure whether a certain concept applies to your Phidget within a complex system, the best way to figure this out is by doing some mental (or pencil and paper) simulation.  Draw the inputs and outputs for the entire board, and label them with voltage, list their required amperage (or watts), and draw connections (such as ground connections) through any circuitry.  &lt;br /&gt;
&lt;br /&gt;
With a technique like this, it is easy to see that some products - such as the [[Product - 1049 - PhidgetSpatial 0/0/3|Phidget Spatial]] - are simply not complex at all. Although you could conceivably create problems (such as by using separate power supplies instead of using USB power and connecting the grounds incorrectly, or by using really long wires), this would be an exceptional case.  &lt;br /&gt;
&lt;br /&gt;
Other Phidgets can be more easily used incorrectly without realizing it.  These are often devices that are simple in some systems and yet complex in others.  Your primary defense against designing unreliable systems is to draw the system out and identifying any problems using the concepts in this primer. To help you, however, you can generally think of two classes of Phidgets which usually need careful handling when they are part of complex systems:&lt;br /&gt;
# Phidgets with more than one power source, (these can be subject to the [[#Shared Grounds|multiple power source problems]] described above)&lt;br /&gt;
# Phidgets needing precise measuring of an external power source (these can be subject to the [[#Shared Grounds|multiple power source problems]] &#039;&#039;and&#039;&#039; [[#Precise Voltage Control|precise voltage control]] problems)&lt;br /&gt;
&lt;br /&gt;
Expanded into individual products, the Phidgets which are most often affected are.....&lt;br /&gt;
&lt;br /&gt;
# These Phidgets use a second type of external power:&lt;br /&gt;
#* Motor controllers &lt;br /&gt;
#**[[DC Motor and Controller Primer|DC controllers]] &lt;br /&gt;
#**[[Stepper Motor and Controller Primer|Stepper controllers]]&lt;br /&gt;
#**{{LinksNeeded|Servo controllers|[[Servo Motor and Controller Primer|Servo controllers]]}}&lt;br /&gt;
#* Pure relay boards &lt;br /&gt;
#**[[Solid State Relay Primer|Solid state relay boards]]&lt;br /&gt;
#**[[Mechanical Relay Primer|Mechanical relay boards]]&lt;br /&gt;
#* Interface kits with relays &lt;br /&gt;
#**[[Product - 1017 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
#**[[Product - 1014 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
#* Powered Digital Output Interface Kits &lt;br /&gt;
#** [[Product - 1012 - PhidgetInterfaceKit 0/16/16]]&lt;br /&gt;
#* Interface Kits with Powered Hubs&lt;br /&gt;
#** The [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]&lt;br /&gt;
#** [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]]&lt;br /&gt;
# And these Phidgets may have a need to be sensitive to external power:&lt;br /&gt;
#* [[Temperature Sensor Primer|Thermocouple]] control&lt;br /&gt;
#* Analog Output ([[Product - 1002 - PhidgetAnalog 4-Output]])&lt;br /&gt;
#* Frequency Counter ([[Product - 1054 - PhidgetFrequencyCounter]])&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
&lt;br /&gt;
This page should have helped you to: &lt;br /&gt;
*Choose a power supply from either the [[#Wall Power|wall]] or a [[#Battery Power|battery]]&lt;br /&gt;
*Properly [[#Ground|ground]] and/or [[#How To Fix This|isolate]] that power supply from looping through other circuitry&lt;br /&gt;
*Also use [[#How To Fix This|isolation]] to make your control or measurement system more precise&lt;br /&gt;
*Keep your cables short and thick to reduce electromagnetic emissions and limit voltage drop&lt;br /&gt;
*Be more aware of system-wide power problems in general, and use drawing and analysis of systems to identify problems&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
===Memory Effect===&lt;br /&gt;
Memory effect is an effect observed in NiCd batteries that causes them to hold less charge.  It pertains to the specific situation in which NiCd batteries lose their maximum capacity if they are repeatedly recharged without being fully discharged.  The battery appears to remember the smaller capacity.  The term is often misused in cases where other batteries seem to hold less charge than originally, however this is most likely due to age and use.  This phenomenon is unique NiCd batteries.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20725</id>
		<title>Solid State Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20725"/>
		<updated>2012-06-29T21:41:39Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:SSR.jpg]]&lt;br /&gt;
| [[Image:3052.jpg|200px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR, so named because of its thick shape and black color. They are specifically designed to switch either AC loads or DC loads, but never both.]]&lt;br /&gt;
&lt;br /&gt;
Solid state relays (SSRs) turn on or off the power being supplied to other devices, in a similar fashion as a physical [[Switch Primer|switch]]. However, instead of being switched by human interaction like a physical switch, SSRs are switched electronically.&lt;br /&gt;
With SSRs, you can control high-current devices such as lights or appliances with low-current signals, like a standard DC signal from a [[Digital Output Primer|Digital Output]]. Most SSRs will switch on with a voltage of 3V or higher. This makes them perfect for use with Phidget [[Interface Kits]], or any device with a digital output. &lt;br /&gt;
&lt;br /&gt;
SSRs perform the same job as [[Mechanical Relay Primer|Mechanical Relays]], but have the following advantages:&lt;br /&gt;
* SSRs produce less electromagnetic interference than mechanical relays during operation. This is mostly due to the absence of a phenomenon called [[Mechanical Relay Primer#Arcing, Interference, and Sticking|contact arcing]] only present in mechanical relays, where the physical contacts of the relay tend to spark internally while switching. The reduced interference can also be attributed to the fact that SSRs do not use electromagnets to switch.&lt;br /&gt;
* The switch contacts of a mechanical relay will eventually wear down from arcing.  An SSR will have a longer life because its internals are purely digital.  Properly used, they will last for millions of cycles.&lt;br /&gt;
* SSRs turn on and off faster than mechanical relays (≈1ms compared to ≈10ms).&lt;br /&gt;
* SSRs are less susceptible to physical vibrations than mechanical relays.&lt;br /&gt;
* Since the switch inside an SSR isn&#039;t a mechanical switch, it does not suffer from [[Switch Primer#Bounce|contact bounce]] and operates silently.&lt;br /&gt;
&lt;br /&gt;
However, compared to Mechanical Relays, SSRs: &lt;br /&gt;
* Are more expensive.&lt;br /&gt;
* Will dissipate more energy in the form of heat (1-2% of the energy intended to power the load).&lt;br /&gt;
&lt;br /&gt;
==How SSRs Work==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR_Internals.png|thumb|A conceptual diagram of the insides of an SSR.]]&lt;br /&gt;
&lt;br /&gt;
The control inputs are connected internally to an LED, which shines across an air gap to light sensors.  &lt;br /&gt;
The light sensor is connected to the transistors which open or close, supplying the relay&#039;s load with power. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;closed&#039;&#039;&#039;, current can flow freely through the relay, causing the load and power supply to be connected. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;open&#039;&#039;&#039;, almost all current is blocked, causing the load to become disconnected from the power supply. &lt;br /&gt;
The pairing of an LED with light sensors is called an optocoupler, and is a common technique to link two parts of a circuit without a direct electrical connection. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling an SSR is no more complicated than turning an LED on and off. Switch it on, switch it off, it is that easy (see the [[Digital Output Primer|Digital Output Primer]], or our [{{SERVER}}/products.php?product_id=1031 specific LED controller] for more).  &lt;br /&gt;
&lt;br /&gt;
The ability of an SSR to switch a load is very similar to a [[Mechanical Relay Primer|mechanical relay]] or simple switch. &lt;br /&gt;
By turning the digital output controlling the relay on and off, you control whether or not the load is connected to its power supply.&lt;br /&gt;
&lt;br /&gt;
The challenge is to pick an appropriate type of SSR for your application. There is no single SSR perfect for all applications. To choose an SSR for your particular application, please follow the [[#Choosing an SSR|Choosing an SSR]] section.&lt;br /&gt;
&lt;br /&gt;
===Safety===&lt;br /&gt;
&lt;br /&gt;
Since relays switch high currents and voltages, standard precautions apply.  Make sure you never touch the terminals while the relay is powered. If your SSR came with a plastic cover, use it.  Even when the SSR is switched off, a very small amount of current will flow.&lt;br /&gt;
&lt;br /&gt;
When an SSR fails, it most often fails permanently closed. This is because when the transistor inside fails due to excessive current or heat, it will usually short out, allowing current to pass through unimpeded. &lt;br /&gt;
This means that as long as the power supply remains on, the load will be powered, possibly creating a fire or safety hazard.&lt;br /&gt;
&lt;br /&gt;
==Choosing an SSR==&lt;br /&gt;
&lt;br /&gt;
===Identify your voltage===&lt;br /&gt;
&lt;br /&gt;
First, determine whether you need to switch AC or DC voltage. The electrical grid, and thus your wall outlet, runs AC, whereas batteries and most small power supplies are DC.  &lt;br /&gt;
&lt;br /&gt;
Next, determine the maximum number of volts you will be switching.  If you are switching DC, particularly with batteries, assume your voltage is at least 25% more than what your battery is rated for.  Even larger fluctuations occur on AC, but AC SSRs are designed to handle these surges.  Typical AC voltage from a wall socket in North America is 110VAC, whereas in Europe it is usually 220VAC. If you are switching AC voltage from a wall socket, check which standard your country uses, and use that number as your voltage.&lt;br /&gt;
&lt;br /&gt;
===Identify your current===&lt;br /&gt;
&lt;br /&gt;
The current drawn by your load when turned on affects how large of an SSR you need, and how hot it will be when it is in use.  If you know how much current, on average, your load draws, this is what we call &#039;&#039;&#039;Average Load Current&#039;&#039;&#039;.  If you don&#039;t know the average current, but you know the wattage (power rating) of your load, you can calculate Average Load Current by:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Average Load Current} =\frac{\text{Watts}}{\text{Operating Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, you need to know the current drawn by your load when it is first turned on.  Many loads demand a huge inrush of current when the load is first turned on. This places a significant amount of stress on the electronics inside the SSR.  If you&#039;ve ever noticed the lights dimming in the house for a second when the furnace starts up, this is caused by the fan motor starting up. In the same way that it takes a lot of force to move a heavy object from rest, it initially takes a lot of current to power up a fan or incandescent bulb. It&#039;s very difficult to measure the &#039;&#039;&#039;Surge Current&#039;&#039;&#039; itself, so we use a multiplier based on your device type.  Surge Current is also referred to as &#039;&#039;&#039;inrush current&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Surge Current Multiplier&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Multiplier&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Motors || 6x&lt;br /&gt;
|-&lt;br /&gt;
| LEDs || 1x&lt;br /&gt;
|-&lt;br /&gt;
| Complex Electronics i.e., Motor Controllers, Phidgets || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures   (AC Only) || 10x&lt;br /&gt;
|-&lt;br /&gt;
| Transformers || 20x             &lt;br /&gt;
|-&lt;br /&gt;
| Heaters || 1x&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Multiply your Average Load Current by the multiplier for your device type to calculate the Surge Current.&lt;br /&gt;
&lt;br /&gt;
===I need to switch AC===&lt;br /&gt;
&lt;br /&gt;
Most AC applications will be switching 110 to 240 Volt power coming from the grid.  If that&#039;s you, go to the [[#Mains Voltage (110 to 240V AC)|Mains Voltage (110 to 240V AC)]] section.&lt;br /&gt;
&lt;br /&gt;
We also cover low voltage AC applications - 28 VAC (Volts AC) or less. For more information, visit the [[#AC/DC SSRs|AC/DC SSRs]] section.&lt;br /&gt;
&lt;br /&gt;
===I need to switch DC===&lt;br /&gt;
&lt;br /&gt;
If you only need to switch a small amount of current - 9 Amps or less, consider our compact, cost effective [[#AC/DC SSRs|AC/DC SSRs]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch more than 9 Amps, you need a serious [[#DC SSRs|DC SSR]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch up to 16 small loads of 2 Amps or less, you can use the [[Open Collector Digital Output Primer|open collector digital outputs]] on a [[1012_2 - PhidgetInterfaceKit 0/16/16|1012 PhidgetInterfaceKit 0/16/16]], which can be wired to behave similarly to relays.&lt;br /&gt;
&lt;br /&gt;
==I need Gradual Dimming==&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
==Mains Voltage (110 to 240V AC)==&lt;br /&gt;
&lt;br /&gt;
We sell AC SSRs for 120 VAC or 240 VAC operation. If you are unsure what voltages you could eventually need to switch, the 240 VAC relays can be used to switch 120 VAC with no problems.  Please note we are very conservative in how we rate SSRs - our 120 VAC relays are rated by the manufacturer for 240 VAC, and the 240 VAC for 480 VAC.  We strongly recommend against using them to the manufacturer rated voltage.  To understand why, read the [[#AC SSR Protection|AC SSR Protection]] section.&lt;br /&gt;
&lt;br /&gt;
===Load Type - Inductive vs. Resistive===&lt;br /&gt;
&lt;br /&gt;
[[Image:zero cross.png|right|thumb|300px|This graph shows the difference between zero-cross and random turn-on. The blue line represents the oscillating voltage of an AC load, and the shaded areas represent the sections when the relay is turned on and letting current pass through. As you can see, the random turn-on SSR immediately opens when activated, while the zero-cross turn-on SSR waits until the voltage crosses zero before opening.]]&lt;br /&gt;
&lt;br /&gt;
If your load is inductive, you need to choose a &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; relay.  If your load is resistive, choose a &#039;&#039;&#039;Zero Crossing&#039;&#039;&#039; relay.&lt;br /&gt;
&lt;br /&gt;
Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples.  A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat.  An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.  There is no such thing as a perfectly resistive load - but a load has to be very inductive to cause the zero crossing SSRs to malfunction.&lt;br /&gt;
&lt;br /&gt;
SSRs are designed to either turn on immediately (&#039;&#039;&#039;Random Turn On&#039;&#039;&#039;), or wait until the next &#039;alternation&#039; of the voltage (&#039;&#039;&#039;Zero Crossing&#039;&#039;&#039;).  Zero Crossing SSRs create less electromagnetic &#039;noise&#039; when they turn on.  They are best used with resistive loads - Zero Crossing SSRs are not able to turn off some inductive loads.  It&#039;s very difficult to determine which inductive loads will create problems - well beyond the scope of this document.  If your load is inductive, we recommend buying the &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; SSRs.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+ &#039;&#039;&#039;Inductive and Resistive Loads&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Load Type&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs   || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures || Inductive or Resistive &amp;lt;font size=4&amp;gt;&#039;&#039;&#039;*&#039;&#039;&#039;&amp;lt;/font&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Motors                     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Transformers               || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Heaters                    || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Computer / Electronics     || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| AC/DC power supplies (brick heavy type)     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
|AC/DC Power supplies (lightweight switchers) || Resistive&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size=4&amp;gt;&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;&amp;lt;/font&amp;gt; &#039;&#039;For fluorescent light fixtures, older units (magnetic ballast) may be inductive, and newer units are often resistive (electronic ballast).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Choosing your AC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, and your load type (inductive or resistive), you can create a short list of relays whose &lt;br /&gt;
* &#039;&#039;&#039;Maximum Load Voltage&#039;&#039;&#039; are greater than or equal to your operating voltage, &lt;br /&gt;
* &#039;&#039;&#039;Maximum Surge Current&#039;&#039;&#039; are greater than or equal to your surge current, and &lt;br /&gt;
* &#039;&#039;&#039;Load type&#039;&#039;&#039; matches what you chose for random turn on/zero crossing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +ac_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3953_0 || HFS34/D-240A20PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 8   || 15  || 20  || 255 || SCR&lt;br /&gt;
|-&lt;br /&gt;
| 3954_0 || HFS34/D-240A80PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 10  || 20  || 50  || 800 || SCR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current with no heatsink.&lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===AC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:MOV.jpg|thumb|An MOV, which comes packaged with our AC &amp;quot;Hockey Puck&amp;quot; relays. ]]&lt;br /&gt;
&lt;br /&gt;
Your AC SSR from Phidgets comes with a circular disc with two legs (pictured). This is a Metal Oxide Varistor (MOV) and should be installed across the load (larger) terminals of your SSR.  MOVs are the classic surge protector - an inexpensive component that absorbs high voltage spikes.  High voltage spikes are caused by inductive loads when they are turned off, and also happen very often on the electrical grid, as nearby devices are operated.  Even if your load is resistive, use an MOV to protect the SSR.&lt;br /&gt;
&lt;br /&gt;
Matching an MOV to an SSR is not easy - this is why we include an MOV with your SSR.  If an MOV is chosen for too low of a voltage spike, it will wear out quickly.  If it is chosen for too high of a voltage spike, it will not protect the SSR adequately.  To balance SSR protection against MOV lifetime, we have found it necessary to use SSRs built for 240 VAC in 120 VAC applications, and SSRs built for 480 VAC in 240 VAC applications.  If you must operate our AC SSRs on higher voltages than we recommend, do not use the included MOV.&lt;br /&gt;
&lt;br /&gt;
As MOVs wear out from use, they will become more sensitive to common voltage spikes, causing them to wear out quicker.  When they entirely fail, they will become a short circuit, potentially creating a fire hazard.  The MOV included with your SSR has a fuse built in which will disable the MOV when it becomes a hazard. To be on the safe side, avoid mounting your SSR near any flammable material.&lt;br /&gt;
&lt;br /&gt;
===Proportional Control SSR===&lt;br /&gt;
&lt;br /&gt;
Proportional Control Relays (often simply called &amp;quot;Control Relays&amp;quot;) are SSRs you can use to control the amount of power to the load.  Rather than reduce the voltage, or somehow limit the current - which would be very expensive solutions, the Proportional SSR reduces power by turning the load on/off quickly, feeding full power in short pulses.  &lt;br /&gt;
&lt;br /&gt;
Proportional SSRs are controlled by a variable voltage - as the control voltage increases, more power is available to the load.  Our PhidgetAnalog product can be used to control Proportional SSRs, since an [[Analog Output Primer|analog output]] can output various amounts of voltage, as opposed to a digital output, which only has two states- high and low.  We don&#039;t sell Proportional SSRs - but they can be purchased from [http://www.digikey.com Digikey], where they are called AC Linear Controlled SSRs.&lt;br /&gt;
&lt;br /&gt;
A quick and dirty solution for dimming with Phidgets is to use an {{LinksNeeded|RC Servo Motor|[[Servo Motor and Controller Primer|RC Servo Motor]]}} with a PhidgetAdvancedServo controller to rotate the knob on a light dimmer.  From software, the RC Servo Motor is rotated to the desired position, cranking the knob as it turns. While this may seem like a roundabout way of achieving proportional control, dimmers tend to be much less expensive because they are less specialized and are manufactured in greater quantity.&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:AC SSR Load.png|right|thumb|300px|Schematic of an AC SSR switching a generic load. A metal oxide varistor is added across the load to protect the SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring up an AC circuit, particularly for long term installation, you may find it helpful to buy a book on residential wiring from your local hardware store.  There are many wiring conventions (and often legal codes) which will help you plan your project, and the legal codes are often a great source of wisdom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DC SSRs (0 to 50V DC)==&lt;br /&gt;
&lt;br /&gt;
We sell DC SSRs for that switch a maximum load of 50 volts. If you are unsure what voltages you could be switching in the future, higher voltage DC SSRs can be used to switch lower voltages.  Common engineering practice would be to purchase an SSR rated for 50-100% higher voltage than the voltage you plan to be switching.  For instance, if you are switching 24V, a 50V SSR is reasonable.&lt;br /&gt;
&lt;br /&gt;
===Choosing your DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +dc_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3950_0 || HFS33/D-30D50M     || DC    || N/A            || 3-32VDC || 30	     || 18  || 50  || 50  || 120  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3951_0 || HFS33/D-50D80M     || DC    || N/A            || 3-32VDC || 50           || 20  || 40  || 80  || 200  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3952_0 || HFS33/D-30D100M    || DC    || N/A            || 3-32VDC || 30           || 25  || 50  || 100 || 240  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a Heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current without a heatsink. SSRs rated for a larger load than the load you&#039;re using will be more efficient (meaning less energy lost in the form of heat) than an SSR that&#039;s being operated at its maximum load. &lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===DC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:Diode.jpg|thumb| A diode, included with our DC &amp;quot;hockey puck&amp;quot; SSRs. The cathode is marked with a line. The blue symbol shows circuit diagram equivalent of the diode.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:relaymotor.jpg|thumb| A DC SSR switching an electric motor. The 1018 Phidget InterfaceKit controls the SSR using its digital outputs. A diode is shown installed across the motor, and a fuse is hooked up between the power supply and the rest of the circuit.]]&lt;br /&gt;
&lt;br /&gt;
Your DC SSR from Phidgets comes with a diode. This diode should be installed across your load, with the Cathode installed towards the positive terminal of the power supply (as shown in the diagram).  &lt;br /&gt;
&lt;br /&gt;
If the diode is installed backwards, as soon as the SSR is turned on, the load will be shorted out, likely destroying the diode, or the SSR, or your power supply.&lt;br /&gt;
A fuse protecting your power supply is always a good idea. You can place the fuse in between the positive terminal of the power supply and the positive terminal of the load side of the SSR. &lt;br /&gt;
&lt;br /&gt;
The diode protects the SSR from powerful residual currents after the SSR is turned off.  While your load is being driven, inductance builds up magnetic fields around the wiring. &lt;br /&gt;
Every load is inductive to some degree, and when the SSR turns off, the magnetic fields will ram current against the now open SSR, easily damaging it.  The diode allows these currents to recirculate in the load until they have lost their energy. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:DC SSR Load.png|right|thumb|300px|Schematic of an DC SSR switching a generic load, which is protected by a diode connected in parallel. The circuit is protected by a fuse in series after the power supply.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a DC SSR allows them to be placed within a circuit just like a switch.  Since it is isolated, you don&#039;t have to worry about grounding or voltage offsets. &lt;br /&gt;
&lt;br /&gt;
With a DC SSR, always make sure the positive load terminal (labeled +) is facing towards the positive terminal of the power supply. If the load terminals are reversed, your load will immediately turn on. There is a diode inside of the SSR that allows current to flow freely through it when the SSR is connected incorrectly. This feature is included because this sort of wiring mistake would destroy the transistor in the DC SSR otherwise.&lt;br /&gt;
&lt;br /&gt;
The DC SSR can be installed on either side of the load, and it will work properly, but there is an advantage to installing the SSR between the power supply and the load.  If the load is connected to the power supply, it will always have a potentially dangerous voltage on it, even when it is not operating.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==AC/DC SSRs (0 to 40V DC / 0 to 28V AC)==&lt;br /&gt;
&lt;br /&gt;
[[Image:AC_DC_SSR.png|thumb|A small, versatile AC/DC SSR mounted on a Phidgets board for easy pin access.]]&lt;br /&gt;
&lt;br /&gt;
Our AC/DC SSRs are built on a small PCB, making them physically smaller than the large &amp;quot;hockey puck&amp;quot; SSRs, and less expensive.  They are limited to lower currents, and cannot be mounted on a heatsink.  &lt;br /&gt;
&lt;br /&gt;
We sell AC/DC SSRs that can switch up to 40 Volts DC or 28 Volts AC.  This is indicated on the SSR Product pages under the Maximum Load Voltage specification.  There is no lower limit on the voltages that the AC/DC SSRs can switch.  If your voltage is close - be conservative.  For instance, a 36 Volt system built from 3 Lead Acid batteries can reach 45 volts when charging.&lt;br /&gt;
&lt;br /&gt;
===Picking your AC/DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +versatile_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3052_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 2.5 || N/A || N/A || 5    || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3053_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 9   || N/A || N/A || ???  || MOSFET&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you are interested in minimum cost, you will likely choose the cheapest option that meets these criteria.  If you are interested in high efficiency operation and less heat generation, consider buying an SSR with higher current rating.&lt;br /&gt;
&lt;br /&gt;
Your AC/DC SSR from Phidgets has built in protection from static electricity, and dangerous residual currents  after the SSR is turned off.  If the load you are switching is powered by a DC source, installing a diode across the load will offer even more protection.  Refer to the [[#DC SSR Protection|DC SSR Protection]] section for more information.&lt;br /&gt;
&lt;br /&gt;
To learn more about SSRs in general, visit the [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC/DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:Versatile SSR DC Load.png|thumb|A versatile AC/DC SSR switching a DC load. The load terminals are bidirectional, so it doesn&#039;t matter which way you hook them up. The optional diode can be added to help protect the SSR when switching DC loads.]]&lt;br /&gt;
[[Image:Versatile SSR AC Load.png|thumb|A versatile AC/DC SSR switching an AC load.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a AC/DC SSR allows them to be placed within a circuit just like a switch.  Circuits without electrical isolation require a lot more care - proper grounding, careful consideration of voltage offsets.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using heatsinks with Hockey Puck SSRs==&lt;br /&gt;
&lt;br /&gt;
[[Image:3950_0 Accessories Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR with plastic cover (left), a thermal pad (right). All hockey puck SSRs sold at Phidgets come with both of these accessories plus a diode or varistor to protect the SSR.]]&lt;br /&gt;
[[Image:3955_0 Functional Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR mounted on a [[3955]] heatsink by two screws. The thermal pad is pressed between the SSR and the heatsink.]]&lt;br /&gt;
&lt;br /&gt;
SSRs will only achieve their promise of reliability and long life if they are kept cool.  Cool is relative, of course, but a good rule of thumb is to keep the metal base of the SSR at less than 85°C (185°F).  A [[Thermocouple Primer|thermocouple]] can be used to precisely measure the temperature of the metal base.&lt;br /&gt;
&lt;br /&gt;
Excess heat usually comes from too much current and too little heatsinking.  A lot of heat can also be generated by frequently turning the relay on and off.  If your relay is operated for brief periods of time, you may not need as large of a heatsink - provided the relay is never accidentally left on for extended periods.  Unless space is a concern, it&#039;s better to err on the side of caution.&lt;br /&gt;
&lt;br /&gt;
Before buying a heatsink, consider if you actually need it.  If your application is running at room temperature, and your average current is less than the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; specification of your SSR, then you don&#039;t need a heatsink.  Alternatively, if your project has a large metal chassis that the SSR can bolt to, this can be used as your heatsink.&lt;br /&gt;
&lt;br /&gt;
Each SSR suitable for use with heatsinks will include a specification of how much current it can switch with each heatsink we sell.  This specification assumes a reasonable airflow over the heatsink, and that the flowing air is at room temperature.  Our SSRs have a sheet of metal underneath, where the heat is concentrated - this is also where the heat is measured to tell if the SSR is too hot.  Phidgets includes a grey thermal pad with our Hockey Puck SSRs (see pictured). You place this pad under an SSR when mounting it on a heatsink, or on large metal surfaces that can dissipate heat.  The pad performs the same function as thermal grease - it helps conduct heat between the base of the SSR and the heatsink. If you prefer to use thermal grease, you can use it instead of the pad.  Our heatsinks include screws for mounting SSRs. Use a good size screwdriver when tightening the SSR down on the heatsink to ensure good conduction.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Product Name&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Dimensions (mm)&lt;br /&gt;
! Thermal Resistance (C/W)&lt;br /&gt;
|-&lt;br /&gt;
| 3955_0 || Small Heatsink for SSR || HF92B-80 || 50x50x80 || 2.4&lt;br /&gt;
|-&lt;br /&gt;
| 3956_0 || Large Heatsink for SSR || HF92B-150A || 55x142x150 || 0.6&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hooking up wires to the Hockey Puck SSR==&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_mov.jpg|thumb|An AC SSR with the wires attached normally and an MOV installed across the load side.]]&lt;br /&gt;
[[Image:lugs.jpg|thumb|TRM6 wiring lugs connected to a DC SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring your load to the SSR, the wire is looped clockwise around the terminal, so when the screw is tightened down, it will draw the wire in tighter.  We recommend using wires up to 10 AWG in size - any larger, and the screws will not have enough thread left to tighten down, and they will strip.  Larger wires can be attached using a wiring lug.  The lug is clamped under the SSR screw, and the wire attaches to the lug.&lt;br /&gt;
&lt;br /&gt;
Loose wire connections can generate a lot of heat - use a large enough screwdriver when clamping down the load wires to ensure that the screws are on tight enough.&lt;br /&gt;
&lt;br /&gt;
For the current ratings of various wires sizes, please see [[Page on Wire Sizes]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Did you know?==&lt;br /&gt;
&lt;br /&gt;
* Mains Voltage &#039;&#039;&#039;AC SSRs&#039;&#039;&#039; cannot switch DC. They will never turn the load off.  AC SSRs turn off twice per AC Cycle, when the current changes direction and is momentarily zero. For example, AC is 60 Hz in North America, so the AC SSR has 120 opportunities per second to turn off (the SSR will only &#039;&#039;&#039;stay&#039;&#039;&#039; off if the control signal is low).  If the SSR is operating from DC, the current will flow continuously, and the load will not turn off, even when the control input is off.&lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; turns off automatically every time the load current reaches zero. It will turn back on almost immediately as long as the signal controlling the SSR is high. An AC SSR will actually have a low, non-zero current value that it regards as &#039;zero&#039;. This specification is usually called &amp;quot;Minimum Load Current&amp;quot; in the data sheet. If your load requires less than this minimum current, your SSR will never turn on, or will not reliably turn on. The simplest solution to this problem is to connect another load in parallel with the first, increasing the Current required by the load.&lt;br /&gt;
&lt;br /&gt;
* SSR Manufacturers have started adding a simple circuit inside &#039;&#039;&#039;AC SSRs&#039;&#039;&#039;, across the load terminals, called a snubber.  The snubber absorbs very fast electrical changes that could normally cause an &#039;&#039;&#039;AC SSR&#039;&#039;&#039; to turn on accidentally. When the AC SSR is turned on, there is little voltage difference between the terminals, so the snubber has very little effect.  When the AC SSR is turned off, the snubber is actively protecting the SSR - but at a cost, as it allows a small current through the SSR, which is wasted.  &lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; uses bipolar transistors - an old technology that has been replaced by CMOS transistors in modern digital circuits.  Bipolar transistors are still superior for handling high voltages.  Bipolar transistors, and the more complex transistors built from them, will lose a constant voltage as current flows through them.  The collection of transistors in your SSR will lose about 1.7 volts - so on a 120 VAC system, you will lose about 1.5% to the SSR.  This energy converts to heat inside the SSR, and the heating from these transistors is the reason SSRs often need heatsinks.&lt;br /&gt;
&lt;br /&gt;
* SSRs, and semiconductors in general, usually fail as a short circuit. A short circuit is a circuit whose internals have been damaged such that current can flow through it freely.  This means your load will probably turn on permanently (until you disconnect the power source) - make sure this doesn&#039;t cause a safety hazard.  For instance, Sauna Heaters have a simple thermally-triggered mechanical shutdown to protect them if control electronics fails.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;DC SSRs&#039;&#039;&#039; (at least the units we sell) use Metal Oxide Semiconductor Field Effect Transistors (MOSFETs). MOSFETs do not lose a constant voltage - instead, when they turn on, they act as a very slight restriction to the flow of current - a resistor.  At low currents, the slight restriction wastes very little power, giving high efficiency and often not requiring a heatsink.  This efficiency is lost as the current increases - a doubling of current quadruples the production of heat.  &lt;br /&gt;
&lt;br /&gt;
* Normally, a MOSFET can only block current in one direction - as soon as the voltage reverses, the current flows through a diode run in parallel to the MOSFET.  If a MOSFET were used to switch AC, the load would be turned on half the time.  A common solution is to use two MOSFETs back to back - which is what we do with our &#039;&#039;&#039;AC/DC SSRs&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20724</id>
		<title>Electricity Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20724"/>
		<updated>2012-06-29T21:40:32Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Design of reliable systems is really, really hard.  The main challenge is the design of reliable building blocks - i.e. circuit and board layouts - from which to create your system.  Phidgets does the majority of this work for you.  And, once you have reliable building blocks, designing a reliable system from them is much easier.  &lt;br /&gt;
&lt;br /&gt;
However, you can still make an unreliable system out of Phidgets.  In fact, if you are building a more complex system than the common examples we show through our documentation, and you have limited experience in complex electrical design, you will probably - and unintentionally - introduce design flaws that will make your system unreliable.&lt;br /&gt;
&lt;br /&gt;
There are two reasons why you should read this primer:&lt;br /&gt;
# You want to build a complex system, more complex than we illustrate in our documentation.  To succeed, you need to understand concepts.&lt;br /&gt;
# You understand how to make your system work, and you want to ensure it is well designed for maximum reliability and/or precision.&lt;br /&gt;
&lt;br /&gt;
==The Basics==&lt;br /&gt;
&lt;br /&gt;
To understand our discussion of potential problems and their solutions below, you&#039;ll need to be familiar with the basics.  For this page, &#039;being familiar&#039; means more than simply having heard of voltage, amperage, and power.  You will need to have a working, conceptual model in your head, so that you can apply that model to your own system and examine it for problems.  This section is all about giving the tools to build that mental model.&lt;br /&gt;
&lt;br /&gt;
First, some terminology.  We introduce it by analogy.  If a circuit is a water system,&lt;br /&gt;
* The &#039;&#039;&#039;voltage&#039;&#039;&#039; is the &#039;&#039;pressure&#039;&#039; in the system&lt;br /&gt;
* The &#039;&#039;&#039;power supply&#039;&#039;&#039; is the &#039;&#039;pump&#039;&#039; creating the pressure&lt;br /&gt;
* The &#039;&#039;&#039;amperage&#039;&#039;&#039;, also known as current, is the amount of &#039;&#039;flow&#039;&#039;&lt;br /&gt;
* The &#039;&#039;&#039;load&#039;&#039;&#039; is the &#039;&#039;faucet&#039;&#039; - adjusting your load will adjust the flow&lt;br /&gt;
* The &#039;&#039;&#039;resistance&#039;&#039;&#039; is an attribute of the load - how tight or loose the faucet is&lt;br /&gt;
* The &#039;&#039;&#039;ground&#039;&#039;&#039; is the return path from load to pump.&lt;br /&gt;
&lt;br /&gt;
The basic concepts for all of these terms are presented below.&lt;br /&gt;
 &lt;br /&gt;
===Load===&lt;br /&gt;
&lt;br /&gt;
We start with the load, because the load is the purpose of your entire system.  &lt;br /&gt;
&lt;br /&gt;
In simple, USB-only Phidget systems, the load is the Phidget itself.  The USB port is ready to provide power, but it does not (and cannot) until a load is applied (i.e. the Phidget is attached) and the circuit is completed.  &lt;br /&gt;
&lt;br /&gt;
Without a load that connects in a loop, it is like attaching a closed pipe to your pump.  Initially, water will fill the pipe, and pressurize it, but once the pipe fills the system as a whole will do nothing more.  To allow the pump to drive the load, and the flow to supply the load, we need to have a completed circuit, like this:&lt;br /&gt;
 &lt;br /&gt;
[[Image:elec_flow.png|150px]]&lt;br /&gt;
&lt;br /&gt;
The load and the pump must &#039;&#039;&#039;match&#039;&#039;&#039;.  If the load lets too much flow through, the pump will work too hard and burn itself out.  This is what happens when you short circuit a power supply.  The load is then simply a wire, which basically opens the flood gates and drains your power supply pump.  The load must not let too much flow through, which it does by &#039;&#039;&#039;resistance&#039;&#039;&#039;. Likewise, the pump cannot push too hard on the load, or the load will break.  This is discussed in-depth as part of [[#Voltage and Amperage|Voltage and Amperage]] below.&lt;br /&gt;
&lt;br /&gt;
===Voltage and Amperage===&lt;br /&gt;
&lt;br /&gt;
Within the flow concept [[#Load|above]], voltage is pressure.  Specifically, it is the &#039;&#039;difference&#039;&#039; in pressure between the flow and the return.  Voltage is measured in volts, and is denoted by &#039;&#039;&#039;V&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Amperage - also known as current - is the flow, or the amount of water that moves.  At the pump, the amount of current out and the amount of current in are equal.  The pressure might vary widely (highly pressurized pipes out, low pressure pipes back) but the &#039;&#039;amount&#039;&#039; of current is always the same.  Amperage is measured in Amps, and is denoted by &#039;&#039;&#039;A&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To match a pump to a load, the voltage and amperage of the power (supply) and load (sink) must line up.  We discuss picking a power supply - whether [[#Wall Power|wall mains]], or [[#Battery Power|batteries]] - in the [[#Power Needs|Power Needs section]] farther along in the document, but we need a few more concepts before we get there.&lt;br /&gt;
&lt;br /&gt;
Power supplies - whether wall power or batteries - are usually rated based on voltage and amperage.  Voltage is the specification to be the most careful with for circuits.  Too much voltage is the same as overpressurizing your pipes - they will burst.  In the case of electronics, you device will break.  &lt;br /&gt;
&lt;br /&gt;
This can be counterintuitive - in reference to safety (for humans) around electronics, you may have heard &amp;quot;It is not the voltage that will kill you, it is the amperage&amp;quot;.  Because of this, it may be tempting to think that too high of an amperage will harm your device, but this is not true.  Our hearts are very susceptible to amperage but not voltage, hence amperage is considered dangerous for us whereas voltage is not.  But a circuit is not like a human body - in a circuit trying to handle a power supply it is the voltage that matters most.  &lt;br /&gt;
&lt;br /&gt;
====Set Voltage (No Control)====&lt;br /&gt;
&lt;br /&gt;
Most loads do no power regulation of their own.  They simply take the voltage given to them and do useful things with it.  You can tell that a pre-designed load (like a Phidget) falls into this category because it gives its voltage need &#039;&#039;as an exact value&#039;&#039;.  For example, most Phdigets use exactly 5 V of USB power.  These loads will also tell you their amperage, which is a flow need that must be met or exceeded.  A load will only use as much amperage as it needs.&lt;br /&gt;
&lt;br /&gt;
====Controlled Power====&lt;br /&gt;
&lt;br /&gt;
Some loads change the voltage or current they receive.  This can be with the intent to either (a) keep a constant amount of power flowing from a draining power source like batteries, or (b) to modify a common power source (i.e. 12 V at 1 A) into an uncommon power source (i.e. 1 V at 12 A).  This process is called &#039;&#039;&#039;regulation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can tell that a pre-designed load (like a Phidget) falls into this &amp;quot;power-regulated device&amp;quot; category because it gives its voltage need &#039;&#039;as a range&#039;&#039;. For example, the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer (SBC)] can take 6 V to 15 V.  &lt;br /&gt;
&lt;br /&gt;
To understand how this works, take the example of a flywheel.  Flywheels are designed to be heavy and to take work in order to get them spinning at speed.  But once you have them spinning, you can extract that work later at a more consistent rate:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flywheel.png]]&lt;br /&gt;
&lt;br /&gt;
Flywheels can either make amperage or voltage be the more consistent blue line over time.  The most common one in Phidgets is for stable amperage.  Regulated amperage is also how LED lights can stay consistently bright for any length of time when using batteries.  Stable voltage design is usually applied when the voltage is too low to begin with (such as any device that runs on a single AA battery), and the flywheel must amplify and stabilize it over time.&lt;br /&gt;
&lt;br /&gt;
For those readers trying to envision how this works electrically, in practice the flywheel is an inductor (or, a transformer utilizing its inductor properties).  For both voltage and amperage regulation, one way relief valves (diodes) must be added. And, in amperage regulation a reservoir (capacitor) must be added to offset the current drop by pulling &#039;&#039;more&#039;&#039; amperage as a battery drains.  Then, a controller is needed to measure and then correspondingly enable and disable the flywheel system as the voltage or amperage drops from the supply.  &lt;br /&gt;
&lt;br /&gt;
But with those details in place, the inductor (and capacitor, in the case of amperage regulation) can effectively take the variety of voltages from, say, a draining battery, and still allow the board to run.  Some devices even do this naturally.  For example, motors often can take a variety of voltages because their construction (i.e. wire wrapping) naturally creates inductance.&lt;br /&gt;
&lt;br /&gt;
These regulated systems often list the power they need directly, using a type of power rating called &#039;&#039;&#039;watts&#039;&#039;&#039;.  Watts are voltage and amperage together (i.e. power):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Amperage} =\frac{\text{Watts}}{\text{Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Watts can be a handy way to describe flow and pressure together for these regulated devices.  Rather than separating voltage and amperage like the unregulated devices do (i.e. this load needs exactly 12 V, or this load will draw exactly 2 A), the unit of watts will allow different value combinations of volts and amps as long as the wattage remains the same.  For example, a 12 watt device with a voltage range of 5 to 12 volts can run on 6 V at 2 A, or 12 V at 1 A.  Either will work.  Amperage for all values in the device&#039;s range of 5 to 12 V can be found with the equation above.  Because of this, watts are often preferred when trying to match a power supply to a regulated load.&lt;br /&gt;
&lt;br /&gt;
===Ground===&lt;br /&gt;
&lt;br /&gt;
All circuits have a &#039;&#039;&#039;ground&#039;&#039;&#039;.  This is simply the return pipe to the pump.  In a circuit, it is denoted by an upside-down triangle:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground.png]]&lt;br /&gt;
&lt;br /&gt;
When drawing a circuit diagram, the symbol is placed on the wires that return to the pump:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flow_ground.png|170px]]&lt;br /&gt;
&lt;br /&gt;
This electric ground provides a voltage reference throughout the circuit.  Ground is always &#039;&#039;&#039;0&#039;&#039;&#039; volts as far as the circuit is concerned. (Remember, voltage is the &#039;&#039;difference&#039;&#039; between the flow and return pipes at the pump.)  Ground is important because it provides a reference from which all the parts of the circuit can speak the same &amp;quot;voltage language&amp;quot; to each other, which matters a lot when a certain voltage means &amp;quot;1&amp;quot; and a certain voltage means &amp;quot;0&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
There is only one &#039;&#039;&#039;absolute&#039;&#039;&#039; ground, and that is the Earth, which is taken to be 0 volts as an absolute value.  Circuits not well-grounded to the Earth (of which there are many - your cell phone, car, etc) operate at a &#039;&#039;&#039;relative&#039;&#039;&#039; voltage.  The upside-down triangle above denotes a &#039;&#039;relative&#039;&#039; ground.&lt;br /&gt;
&lt;br /&gt;
With relative voltage, only the difference between local ground and the local high voltage matters.  For example, a cell phone might operate as a 3 volt device, which means relative to its ground it always operates between 0 and 3 volts.  But if that cell phone were compared carefully to Earth ground, its absolute voltage could be, say, between 10 and 13 volts.  Until comparison, the device doesn&#039;t &amp;quot;feel&amp;quot; charged.  This is the same as how you don&#039;t &amp;quot;feel&amp;quot; charged after skidding your feet in socks across a carpeted floor.  But, when you &amp;quot;compare&amp;quot; yourself to Earth ground by touching some well-grounded metal, you receive a static electricity shock.&lt;br /&gt;
&lt;br /&gt;
The same thing can happen when you combine two different power supplies, as we discuss [[#Projects With Different Power Sources|below]].&lt;br /&gt;
&lt;br /&gt;
===Power===&lt;br /&gt;
&lt;br /&gt;
There can be different types of pumps, and at this point we should supplant our heart symbol with some actual power supply pump symbols.  For example, this is the symbol for a direct current (DC) battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
The + end is on the out flow, and the - end is on the return (ground).  Batteries are usually listed with their voltages.  This is because the resistance of the load will determine how much amperage is drawn, but too much voltage and you will harm your load.&lt;br /&gt;
&lt;br /&gt;
This is the symbol for alternating current (AC) that you would get directly from the wall:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_wall_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
Again, this is listed using voltage for the same reasons as DC.  A relative ground symbol is still used on the return line here.  AC devices can still operate on relative voltage if they do not use Earth ground (the third prong on a wall plug in North America).  This is how some loads have AC cords with only two prongs - they operate on a relative voltage and relative ground.  And relative AC voltage, having significantly more voltage (pressure) behind it, can really hit a device hard when two power supplies meet across it.&lt;br /&gt;
&lt;br /&gt;
This connecting of multiple power supplies is quite a complex subject, and is described further in both [[#Power Needs|picking different power supplies]] and [[#One Powered Phidget|connecting different power supplies]] later on in this Primer.&lt;br /&gt;
&lt;br /&gt;
===Emissions and Wires===&lt;br /&gt;
&lt;br /&gt;
To talk about emissions, it is worth speaking more precisely about what a load is.  The typical, simple Phidget setup is receiving 5 V direct current (DC) from the computer over the USB port.  Let&#039;s model this as coming from a battery so that we can examine all parts of the system.  From the point of view of the battery, the Phidget load is not just the green board with the circuitry on it.  The load &#039;&#039;also&#039;&#039; includes the power cable (i.e. two wires in the USB cable), and anything else on the path out or back from the circuitry to the battery itself:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
This is important because the wires play a role in the voltage that eventually makes it to the Phidget.  This is true all the time, even when the Phidget is attached to a computer instead of a battery.  All wires have some resistance, and so they are, in a way, in and of themselves circuits.    Therefore, because of their resistance, the wires &#039;use&#039; some of the 5 V heading out to the Phidget circuit board.  This is discussed more below, but essentially longer cables have more resistance and at some point the voltage will drop so much over the length that the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
To conceptually separate the wires from the Phidget in terms of the load, we can now start drawing the wires themselves in our circuit diagram, instead of the curved concept arrows indicating flow and return:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wires.png|200px]]&lt;br /&gt;
&lt;br /&gt;
When talking about the 5V relative ground in this system, we are in fact talking about the ground &#039;&#039;right at the battery&#039;&#039; so we move the ground symbol to the battery itself.&lt;br /&gt;
&lt;br /&gt;
Then, the resistance on these wires creates a possible problem - the emission of electromagnetic radiation as the wires naturally drop the voltage:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_emissions.png|200px]]&lt;br /&gt;
&lt;br /&gt;
These emissions are at a set frequency determined by the length of the wire:&lt;br /&gt;
* Long wires create low frequencies (harmful interference)&lt;br /&gt;
* Short wires create high frequencies (less harmful interference)&lt;br /&gt;
&lt;br /&gt;
This can be minimized by having the flow and return wires be the same length and sit right next to each other.  This way, the emissions somewhat cancel each other out from the flow and return going in opposite directions.  This is partially how USB cables minimize emissions.&lt;br /&gt;
&lt;br /&gt;
So, the way you design your connections (i.e. the resistance and placement of your wire) will have a direct affect on:&lt;br /&gt;
# The voltage that reaches the Phidget&lt;br /&gt;
# The emissions that your system produces&lt;br /&gt;
&lt;br /&gt;
With all this talk of emissions, you might be tempted to try to shield parts or all of your system from emissions that either your system or external systems create.  &lt;br /&gt;
&lt;br /&gt;
Keep in mind that shielding is actually really hard to do correctly.  Especially when grounding your shielding, with ad-hoc design you have a high chance of having an interfering signal (that has traveled out to the shield and traveled back via ground) creating a larger problem than not having a shield at all.  Rather than shielding, it is easier to simply keep your cables short and with as low a resistance as possible throughout your system to minimize your emissions in the first place.&lt;br /&gt;
&lt;br /&gt;
Identification of and solutions to these (and other more complex) problems are discussed in detail in the [[#Selecting Cables|section on choosing cables]] and the [[#Hooking Up The Pieces|section on connecting the pieces]] below.&lt;br /&gt;
&lt;br /&gt;
===Multiple Loads===&lt;br /&gt;
&lt;br /&gt;
The easiest way to hook up multiple Phidgets is in parallel, where the voltage stays the same but they share the amperage.  Here the DC supply is two USB ports, each at 5 V and 0.5 A:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
However, the length of your wires comes into play again, because the voltage that actually reaches the Phidgets above is somewhat less than 5 V.  So if your wires are long, or mismatched, the voltage may not match and will give you strange results.  The voltage is both affected on the way out, and on the way back.  Assuming the wires are the same length:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wire_drop.png|350px]]&lt;br /&gt;
&lt;br /&gt;
In this way, you can create difficult-to-debug problems within a complex system, where one Phidget works but others mysteriously fail.&lt;br /&gt;
&lt;br /&gt;
==Power Needs==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve understood the basics, it is time to actually talk about decisions and design.  This section will help you choose a power supply for your Phidget.  Let&#039;s say you want to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] off of a battery.  Or you want to run a motor controller with a power supply you bought from the hobby store.  What do you need to buy?  Will one you already have work?  It is worth it to spend a moment with pencil and paper to work through this section and identify your power needs.&lt;br /&gt;
&lt;br /&gt;
As described [[#Voltage and Amperage|earlier]], voltage is pressure. Too much pressure behind your faucet, and the water mains or faucet will break.  Likewise, if you have too much voltage from a power supply, your circuit will break.  You should choose a supply with voltage that &#039;&#039;matches the range the Phidget can accept&#039;&#039;.  The voltage cannot be over the maximum (otherwise, like pressure in a pipe, the pipe will burst), and the voltage cannot be under the minimum (otherwise, like pressure in a pipe, no flow will occur).  Also, generally, a device (like a motor controller) will perform better at its maximum rated voltage if a range is available.&lt;br /&gt;
&lt;br /&gt;
But the faucet doesn&#039;t care whether there is a big reservoir or small reservoir feeding the system, as long as the pressure is managed.  Likewise, you can choose a power supply with more amperage than you need (a big reservoir to draw from) as long as the voltage matches.  In the same way that a faucet restricts water by design, loads draw and allow only the amperage that they need. However, the amperage cannot be less than the Phidget needs.  In that case, you will either overextend (and break) your power supply, or the circuit simply will not turn on at all.&lt;br /&gt;
&lt;br /&gt;
The specification [[#Device List|for your specific device]] will list its power needs. For most devices, the external power supply needs will simply be listed in voltage and amperage.  USB power is 5V at up to 500 mA (0.5 Amps).  Most Phidgets will draw less than this - if you need precision, you can check the specification for your particular Phidget.  And, if it is an Interface Kit, you can add the draw of each analog sensor and digital in/out from their specifications.&lt;br /&gt;
&lt;br /&gt;
However, some Phidgets (e.g. motors, and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]) do not have a straight amperage and voltage specification.  Instead, their power draw will be listed in watts, for which you [[#Voltage and Amperage|saw a relation earlier]] to convert to the values you need.&lt;br /&gt;
&lt;br /&gt;
===Wall Power===&lt;br /&gt;
&lt;br /&gt;
Wall power sources usually take the alternating current (AC) from the wall and convert it into a direct current (DC).  These power supplies often take your familiar two-or-three prong wall connector and put power out via a barrel plug-type connector.  AC power (typically 110 or 240 volts, depending where you live in the world) goes in the typical wall plug, and DC power (typically 5 to 24 volts) comes out the barrel plug.  Most power supplies of this type list the conversion explicitly, such as: 110-240 Volts to 12 Volts at 2 Amps.  You&#039;ll want to match your Phidget&#039;s needs against the 12 Volts at 2 Amps. &lt;br /&gt;
&lt;br /&gt;
*The voltage must match exactly&lt;br /&gt;
**If the Phidget takes a range of voltages, the supply must fall within the range&lt;br /&gt;
*The amperage can be equal to or greater than the Phidget needs&lt;br /&gt;
&lt;br /&gt;
A wall power supply is essentially an inexhaustible supply of current, so you don&#039;t need to worry about it running out like you would with batteries.&lt;br /&gt;
&lt;br /&gt;
===Battery Power===&lt;br /&gt;
&lt;br /&gt;
If you intend to use a battery bank (even of only one battery) to power your Phidget, you probably want to know what type of battery to purchase.  &lt;br /&gt;
&lt;br /&gt;
====Battery Chemistries====&lt;br /&gt;
The first thing that sets batteries apart is the type of materials used in their construction.  The following table shows several of the more common battery chemistries as well as the voltage per cell they produce and the specific energy of the chemistry.  &lt;br /&gt;
&lt;br /&gt;
{| border = 1&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Chemistry&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Nominal Cell Voltage&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Specific Energy (MJ/kg)&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Primary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| Alkaline||1.5||0.4||These are the most common form of battery.  Many commercially available AA and AAA batteries are alkaline. &lt;br /&gt;
|-&lt;br /&gt;
| Lithium (LiMnO2)||3||0.83-1.01||These are used in high drain devices or devices with a long shelf life as they have a very low self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Silver-oxide||1.55||0.47||Only used in small button cells as these are quite expensive.&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Secondary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| NiCd||1.2||0.14||Older technology, suffers from [[Electricity Primer#Memory Effect|memory effect]].  Capable of very high discharge rates with no ill effects.  Moderate self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Lead-acid||2.1||0.14||Not particularly good with high discharge rate.  Moderate rate of self discharge.  &lt;br /&gt;
|-&lt;br /&gt;
| NiMH||1.2||0.36||Very heavy.  Good performance in high drain devices.  Very high energy density naturally, at the cost of a high self discharge rate.  Newer versions are able to get rid of some of the self discharge though they suffer ~25% lower energy densities as a result.  &lt;br /&gt;
|-&lt;br /&gt;
| Lithium Ion||3.6||0.46||Expensive to produce but very high energy density.  Very low self discharge rate.  Safety hazard as short circuiting can yield explosive or fiery results. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Choosing a Battery====&lt;br /&gt;
Batteries are chosen first by their voltage (V).  Match the voltage exactly to the voltage the Phidget needs.  Over or under this value, you could harm the board or have it simply fail to turn on.&lt;br /&gt;
&lt;br /&gt;
Next, choose a battery that has adequate amperage to feed your device for the time you need. The lifespan of the battery will usually be listed in Amp-Hours (or Ah).  For example, a double wide 12 V lantern battery will have usually around 7-8 amp hours.  This means if you drew one amp from it for seven to eight hours, the battery would be totally drained.  Or you could draw two amps from it and drain it in 3.5-4 hours.  This does not mean however, that you can draw 36A for 15 minutes.  It is important to understand that there is a limit at which more power simply cannot be drawn from the battery.  Effectively, high drain devices will decrease the rated Ah.  The amount  differs from battery to battery so to be sure it is recommended to check the data sheets for the battery you are using.  If the battery did not come with a data sheet they can usually be found on the manufacturers website.  The data sheets should have a graph that shows the relationship between current draw (usually in mA) and capacity (Ah or mAh).  Another useful thing that can be gathered from the datasheets is the batteries response to temperature.  Batteries tend to not work as well in cold environments, most manufacturers will provide graphs of how the batteries lifespans will shorten at different temperatures.  This is often very significant, causing the battery to last a fraction of its normal lifespan at temperatures below -10&amp;amp;deg;C.&lt;br /&gt;
&lt;br /&gt;
Finding the amperage or voltage sometimes needs to be done indirectly by using a specification of watts.  The relationship between amperage, voltage, and watts is given above in the [[#Voltage and Amperage|voltage and amperage section]].&lt;br /&gt;
&lt;br /&gt;
For an example, let us say you want to use battery power to run the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer].  The specifications say that it uses 1.2 watts as a base value.  The specifications also say that it can take 12 V DC power.  If we choose to use a 12 V battery, at 1.2 watts it will use 0.1 amps according to the equation [[#Voltage and Amperage|shown earlier]].  Going by amp-hours alone, if our battery is a double-wide lantern type 12 V battery, with 7 amp hours, with 0.1 amp draw it will last 70 hours, or almost three days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Maximum Running Days} =\frac{\text{Battery Amp Hours}}{\text{Device Amps} * \text{24}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, to estimate &#039;&#039;average&#039;&#039; running time (rather than maximum running time possible), amp-hours cannot be used so directly.  Over time, batteries decrease in voltage as their power is used up.  Practically speaking, this means one of two things for your load.  For loads that do not regulate voltage or current, the amperage will also decrease over time.  The classic example is an LED light source that grows dimmer and dimmer as the batteries are used up.&lt;br /&gt;
&lt;br /&gt;
You should usually only count on about 60% of the stated amp hour rating to apply before expecting to run into problems from escalated drain due to battery voltage drop.  This is especially true for deep cycle rechargeable batteries left in an installation, where draining more than 60% could also harm the battery.  &lt;br /&gt;
&lt;br /&gt;
Then, for lead-acid batteries, a typical battery is tested from full to complete drain over 20 hours by the manufacturer to obtain the advertised amp-hour rating.  Draining a battery at a faster rate than this will result in even more reduction in capacity, by 10% or even more.  This due to [http://en.wikipedia.org/wiki/Peukert%27s_law Peukert&#039;s Law].&lt;br /&gt;
&lt;br /&gt;
There are plenty of [http://www.google.ca/search?&amp;amp;q=battery+calculator battery calculators] around the Internet which take most or all of these additional factors into account when recommending an amp-hour rating.  For longer-term installations, the solar power online community has some excellent resources.&lt;br /&gt;
&lt;br /&gt;
====Setting up Multiple Batteries====&lt;br /&gt;
You can hook up multiple batteries in series to get more voltage at the same amperage.  The amperage is additive.  For example, you can hook up two single-wide 6 V lantern batteries in series to produce 12 V.  Or two 12 V batteries in series to produce 24 volts.  This system would still only have the amp hours of &#039;&#039;one&#039;&#039; of the lantern batteries, because you will be essentially using them both at once: &lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_series.png|250px]]&lt;br /&gt;
&lt;br /&gt;
The upside down triangle (ground) is explained above in a [[#Ground|section of its own]].&lt;br /&gt;
&lt;br /&gt;
Or, you can hook up multiple batteries in parallel to get more amperage at the same voltage.  For example, you could hook up two 12 V deep cycle batteries in parallel to provide more amperage at 12 V, which is like having a deeper reservoir of power for your device to use:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
====Heat====&lt;br /&gt;
*all batteries have some sort of internal resistance&lt;br /&gt;
*can be found on the battery&#039;s data sheet&lt;br /&gt;
*the more power you pull from the battery the more heat is going to build up as a consequence of the internal resistance.&lt;br /&gt;
*larger internal resistances will cause heat to build up faster.&lt;br /&gt;
*when charging a battery you are not just limited to the power in the battery.  nothing stops you from dumping energy into the battery past the point where it is fully charged&lt;br /&gt;
**this is why charging batteries is a bit of a tricky business.&lt;br /&gt;
**many batteries come with custom chargers that have control systems to prevent this type of overcharging.&lt;br /&gt;
&lt;br /&gt;
====Weight====&lt;br /&gt;
Finally, weight matters - a car battery is much heavier than a lantern battery.  Batteries vary widely by weight per amperage.  Lithium batteries are usually very light for their power, followed by alkaline, followed by lead acid.  This may not seem important at first, but if you are building a mobile robot it is worth calculating in the work of carting around a battery.  You may find that, for the length of time you want it to run, your battery requires some system redesign.&lt;br /&gt;
&lt;br /&gt;
==Selecting Cables==&lt;br /&gt;
&lt;br /&gt;
===USB Cables===&lt;br /&gt;
&lt;br /&gt;
In general, use the shortest cables possible.  There are many reasons for this [[#Emissions and Wires|described above]], but as a summary:&lt;br /&gt;
&lt;br /&gt;
; Long cables reduce the voltage that reaches the Phidget.&lt;br /&gt;
: This happens in both directions.  So, for every unit cable length added, the voltage decreases by twice the electrical resistance of that length of cable. With especially long cables the Phidget may drop below its 4.6 volt threshold and simply never turn on.&lt;br /&gt;
&lt;br /&gt;
; Long cables increase the width of your circuit.  &lt;br /&gt;
:All circuits act as emitting antennas for the resonance frequency of the circuit structure.  The longer the wires in the circuit, the lower the frequency, and the higher chance that it will be emissions that will interfere with your data and system.&lt;br /&gt;
&lt;br /&gt;
; Longer cables have more length exposed to external interfering emissions.&lt;br /&gt;
&lt;br /&gt;
Also, use thick cables that are built to specification.  Some USB cables with thinner wiring have higher electrical resistance.  This can be equal to what a much longer wire would have, and thus create a similar voltage drop where the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
====Options for longer cables====&lt;br /&gt;
The maximum length for a USB cable is 5m.  This is laid out in the USB specifications.  Often times however a system requires more reach.  In this case there are a few options available to you.  You can use what is known as an active extension cable or USB extender.  These cables act like extension cables and add power to the line so that the signal can travel further.  A second option is to use a Cat5 extender.  These extenders are 2 USB dongles that connect on either end of your system.  You join them up with Cat5 cable.  This allows you to run over much longer distances than USB traditionally allows.&lt;br /&gt;
&lt;br /&gt;
===Power Cables===&lt;br /&gt;
&lt;br /&gt;
There are &amp;quot;DC Wire Table&amp;quot; references on the Internet which describe how to pick a wire appropriate for your voltage and amperage.  When selecting AC wires, you will probably be using pre-made extension cords.  Cords add interference resonance length to your circuit, just like USB cables do as [[#USB Cables|described above]].  A long extension cord can create huge electromagnetic interference for your circuit and other systems in the area when first plugged in.&lt;br /&gt;
&lt;br /&gt;
Also as with the USB cables above, cut the cables to the shortest length possible.  This is again both for voltage drop reasons and frequency emission reasons.&lt;br /&gt;
&lt;br /&gt;
===Hubs===&lt;br /&gt;
&lt;br /&gt;
Avoid hubs where possible.  Unpowered hubs are good for reading data from memory keys, but not for powering many external devices.  If you must use a hub, buy a powered one.&lt;br /&gt;
&lt;br /&gt;
===Sensor and Motor Wiring===&lt;br /&gt;
All Phidgets sensor class devices (products whose part numbers start with 11 such as the 1129) use a 3 channel ribbon cable for power and data transmission.  Similarly, all our motors and load cells use multichannel wire interfaces.  As mentioned previously, USB spec limits cables to 5m, this is not the case for these wires.  The biggest concerns are electromagnetic interference (EMI) and voltage drop.  In general you should be able to run these wires over significant distances (30m or more) with the load cells in particular having very long range.  If EMI starts causing issues you can always use ferrite beads on the cable near the sensor or motor and the controller to reduce noise.&lt;br /&gt;
&lt;br /&gt;
===Cable Gauges for Terminal Blocks===&lt;br /&gt;
&lt;br /&gt;
Many Phidgets products feature green terminal blocks that use screws to hold wires in place, making it easy to take apart and rebuild connections in your project. The size of the terminal block determines the gauge of wire you should use.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Terminal Block Size and Wire Gauge&#039;&#039;&#039;&lt;br /&gt;
! Terminal Block Width (mm/port)&lt;br /&gt;
! Recommended Wire Gauge (AWG)&lt;br /&gt;
|-&lt;br /&gt;
| 3.81&lt;br /&gt;
| 14 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 5.0&lt;br /&gt;
| 12 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 9.5&lt;br /&gt;
| 10 to 26&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The gauge of cables and wires is measured in AWG, which is the American Wire Gauge standard. The following table lists the properties of wire gauges commonly used with Phidgets:&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;American Wire Gauge Sizes&#039;&#039;&#039;&lt;br /&gt;
! AWG Size&lt;br /&gt;
! Diameter (mm)&lt;br /&gt;
! Area (mm²)&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| 2.588&lt;br /&gt;
| 5.26&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| 2.305&lt;br /&gt;
| 4.17&lt;br /&gt;
|-&lt;br /&gt;
| 12&lt;br /&gt;
| 2.053&lt;br /&gt;
| 3.31&lt;br /&gt;
|-&lt;br /&gt;
| 13&lt;br /&gt;
| 1.828&lt;br /&gt;
| 2.62&lt;br /&gt;
|-&lt;br /&gt;
| 14&lt;br /&gt;
| 1.628&lt;br /&gt;
| 2.08&lt;br /&gt;
|-&lt;br /&gt;
| 15&lt;br /&gt;
| 1.450&lt;br /&gt;
| 1.65&lt;br /&gt;
|-&lt;br /&gt;
| 16&lt;br /&gt;
| 1.291&lt;br /&gt;
| 1.31&lt;br /&gt;
|-&lt;br /&gt;
| 17&lt;br /&gt;
| 1.150&lt;br /&gt;
| 1.04&lt;br /&gt;
|-&lt;br /&gt;
| 18&lt;br /&gt;
| 1.024&lt;br /&gt;
| 0.823&lt;br /&gt;
|-&lt;br /&gt;
| 19&lt;br /&gt;
| 0.912&lt;br /&gt;
| 0.653&lt;br /&gt;
|-&lt;br /&gt;
| 20&lt;br /&gt;
| 0.812&lt;br /&gt;
| 0.518&lt;br /&gt;
|-&lt;br /&gt;
| 21&lt;br /&gt;
| 0.723&lt;br /&gt;
| 0.410&lt;br /&gt;
|-&lt;br /&gt;
| 22&lt;br /&gt;
| 0.644&lt;br /&gt;
| 0.326&lt;br /&gt;
|-&lt;br /&gt;
| 23&lt;br /&gt;
| 0.573&lt;br /&gt;
| 0.258&lt;br /&gt;
|-&lt;br /&gt;
| 24&lt;br /&gt;
| 0.511&lt;br /&gt;
| 0.205&lt;br /&gt;
|-&lt;br /&gt;
| 25&lt;br /&gt;
| 0.455&lt;br /&gt;
| 0.162&lt;br /&gt;
|-&lt;br /&gt;
| 26&lt;br /&gt;
| 0.405&lt;br /&gt;
| 0.129&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Hooking Up The Pieces==&lt;br /&gt;
&lt;br /&gt;
Here, things can be tricky.  You might think: just plug everything in and go!  But often it is not that simple.  Many Phidgets require special care when hooking up.  We encourage a process where you apply the concepts in this Primer, through analysis, to your system.  So, we don&#039;t explicitly list the boards most commonly affected until the [[#Affected Products|end of this Primer]].&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;categories&#039;&#039; of the boards which require special attention within a complex system are:&lt;br /&gt;
&lt;br /&gt;
# Phidgets with more than one power source, and&lt;br /&gt;
# Phidgets needing precise measuring or control of an external power source&lt;br /&gt;
&lt;br /&gt;
If you are already thinking about your boards in your head and trying to figure out whether they fit into one category or another, you&#039;re on the right track!  The list of [[#Affected Products|commonly affected boards]] are only the common ones... with a sufficiently complex system, you could conceivably create problems with &#039;&#039;any&#039;&#039; boards.&lt;br /&gt;
&lt;br /&gt;
Both types of projects require a full understanding of [[#The Basics|electrical basics]].  Using those concepts, below we first describe problems that arise when hooking up different power sources, and extend that into using the solution to give more precise measurement and control.  &lt;br /&gt;
&lt;br /&gt;
===Shared Grounds===&lt;br /&gt;
&lt;br /&gt;
Shared grounds can occur in Phidgets that handle two different power sources.  Recognizing the sharing of a ground is not always easy.  We show what it is, how it can be possible, and why it creates problems by starting with the most basic Phidget system.  The simplest setup for a Phidget is to use the [[#Ground|ground]] of the computer it gets data and power from over a USB port:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_simple_case.png]]&lt;br /&gt;
&lt;br /&gt;
In this case, there is only one relative ground, and it is the PC ground, which is ground #1 in the image.  The PC ground determines what is considered 0 volts for all signals on the Phidget.  When you add different power sources or sinks in the system, you are pulling the system relative to the PC ground.  &lt;br /&gt;
&lt;br /&gt;
=====One Powered Phidget=====&lt;br /&gt;
&lt;br /&gt;
The next most complicated system is one Phidget that handles two power sources.  Let us say you have a motor controller, which takes power from USB, and which also takes power from a second power source.  Although the second power source is usually just a wall plug, the simpler case for thinking about ground is actually a battery.  A battery creates a second &#039;&#039;relative&#039;&#039; ground.  Through the Phidget, relative ground #1 (from the PC) and #2 (from the battery) actually become the same ground:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_wall_power.png]]&lt;br /&gt;
&lt;br /&gt;
This is the first reason why systems with powered Phidgets have to carefully manage ground.  If ground #1 and ground #2 are different with respect to each other (see the static shock analogy in the [[#Ground|ground section]] above), then whatever circuitry along the red dashed arrow must deal with the initial static shock.  In this case it would be the circuitry of the Phidget.  In the case of a battery, after the initial equalizing shock the battery will be whatever relative voltage the PC ground needs it to be.  Hence a battery relative ground can &#039;float&#039;.&lt;br /&gt;
&lt;br /&gt;
If ground #2 comes from the wall, on the other hand, the ground does not &#039;float&#039; and instead is always absolute 0 volts Earth ground.  With the PC giving the power, this is not a problem in practice because the PC can also float (as with a laptop), or it uses Earth ground.  But if you were using a different and more powerful USB power supply instead of a PC, and then connected it to the absolute Earth ground through the Phidget, the Phidget would bear the brunt of any ground equalization that would occur.  If neither the new ground nor the old ground float, and the power supplies were powerful enough, this would eventually destroy the Phidget.  In this case, you would want to use isolation, as described in [[#How To Fix This|How To Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Multiple Powered Phidgets=====&lt;br /&gt;
&lt;br /&gt;
A worse case comes in when you are using two powered Phidgets and one external power source.  Again, say you are using a battery as the external power source.  It would be tempting to simply wire both grounds from the Phidgets to the ground on the battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_phidget.png]]&lt;br /&gt;
&lt;br /&gt;
Although this looks benign, you have actually created a new circuit.  The circuit is a second path, via ground, for the current to return to the voltage source.  This is also known as a &#039;&#039;&#039;ground loop&#039;&#039;&#039;. The path we intuitively think of the current returning by is  &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;, but the sharing of grounds has created a new path through the motherboard, &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_paths.png]]&lt;br /&gt;
&lt;br /&gt;
All current gets &#039;pumped&#039; in a loop by voltage, and so it will use all return paths available to it, assuming all paths are equally easy (electrically) to use.  This extends the pipe analogy, where water will flow in every path that exists.  So, if your battery (or other power source with ground #2) is quite powerful, you can actually harm your motherboard within your PC (or at least your USB bus ground), because &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039; runs through the motherboard circuitry on the way back to the voltage source.&lt;br /&gt;
&lt;br /&gt;
This problem does &#039;&#039;not&#039;&#039; apply to using a different power source between a black power plug and for the green control terminal block on, say, a [[DC Motor and Controller Primer|DC motor controller]].  Although the grounds are connected, and they run across a part of a Phidget board, creating a ground loop does not actually run through any circuitry if only these types of boards are used.  If you have a complex system with other types of boards and therefore circuitry between black plug power port and green terminal block connections, draw out your system carefully to identify the loops.&lt;br /&gt;
&lt;br /&gt;
Ground loops can be fixed by one of the ways described in [[#How To Fix This|How to Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Single Board Computer And Powered Hub=====&lt;br /&gt;
&lt;br /&gt;
When combining one externally powered Phidget and the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer] or the [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]] on the same external power source, you still may inadvertently create a ground loop as described above in [[#Multiple Powered Phidgets|the multiple powered Phidgets section]].  If they share a true [[#Ground|Earth ground]], this is not a problem.  But if the ground is from a battery, or uninterruptible power supply, etc. then you should carefully draw out your system circuit and examine it for ground loops.&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
Once you are aware of shared grounds in your system, you have two options.  &lt;br /&gt;
&lt;br /&gt;
One, for ground loop problems in simple systems (two Phidgets), you could make the normal return path (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;) the most electrically desirable path.  This is best for simple systems where you have a lot of control over all of the ground wires within your system.  For the ground wires leading directly from the Phidget to the external power supply (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;), lower the resistance in the wire as much as possible.  You can do this by keeping the wires short, and using a thick (large gague) wire for the hookups.  &lt;br /&gt;
&lt;br /&gt;
Although this solution works, sometimes you do not have much choice on how long your ground return wires can be, because the location of your power supply and and Phidgets are set by your system design.  If you cannot be totally sure that the direct ground path is the shortest and most electrically desirable path, it is best to use the second option: a &#039;&#039;&#039;USB Isolator&#039;&#039;&#039; such as the [[Product - 3060 - USB Isolator|Phidget 3060]].  This isolator is like any other USB isolator - it can be used on a Phidget system, as well as any system that needs ground isolation.&lt;br /&gt;
&lt;br /&gt;
You need isolators for every USB cable in your system, less one.  If you have two USB connections, you need one isolator; three USB connections, two isolators, and so on.  The one USB connection can remain non-isolated because a single ground connection cannot form a loop.  However, if you are concerned about connecting the grounds as described in the [[#One Powered Phidget|single connected Phidget section above]], use a USB isolator on every cable.&lt;br /&gt;
&lt;br /&gt;
===Precise Voltage Control===&lt;br /&gt;
&lt;br /&gt;
Precise voltage (or other system) control and measurement is related to the concept of [[#Shared Ground|shared ground above]].  But here, you want to keep grounds separate not only to prevent ground loops, but also to make your system more sensitive to what it will control or measure.&lt;br /&gt;
&lt;br /&gt;
For example, we make Phidgets that can create power precisely, or that can take it in and measure it.  One such product is the 1002, which outputs a precise analog voltage with which to control an analog system.  Now that you know about [[#Ground|relative ground]], however, you would be right to expect that you do not want to combine the ground in the PC and the ground in the system.&lt;br /&gt;
&lt;br /&gt;
Even if you don&#039;t care about system sensitivity, you can still create [[#Multiple Powered Phidgets|ground loops]] in a system with multiple of these types of Phidgets.  In addition, if you are using the Phidget to control a large, powerful system, even a single Phidget can receive damage from connecting two powerful power sources meeting across it, also as [[#One Powered Phidget|described earlier]].&lt;br /&gt;
&lt;br /&gt;
But above and beyond the powered Phidget problems, there is another reason to separate (isolate) the electrical grounds in your system.  The reason is: to make your system control more precise.  For example, with the 1002, if you are trying to control an external system with an Phidget output voltage, that output voltage should be relative to the &#039;&#039;system you are trying to control&#039;&#039;, not relative to the PC.  Rather than forcing the grounds - and therefore the relative voltages - to be equal to each other, you can provide more precise control by isolating the grounds and working with the relative voltage of the controlled system on its own terms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Schematic-type image of a ground isolated analog out on a 1002&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
The solution to all of these problems in precise voltage control systems is to use USB isolation, even for a single Phidget.  The [[Product - 3060 - USB Isolator|Phidget 3060]] is one such isolator.  It inserts along the USB connection between your PC and the Phidget, and it separates the Phidget (and controlled system) ground from the PC ground.  This fixes ground loops, separates relative voltage mis-matches, and isolates the control system for better precision.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Image of 1002 and Isolator connected, with lines superimposed on the image to show non-copper connection in isolator&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Affected Products==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure whether a certain concept applies to your Phidget within a complex system, the best way to figure this out is by doing some mental (or pencil and paper) simulation.  Draw the inputs and outputs for the entire board, and label them with voltage, list their required amperage (or watts), and draw connections (such as ground connections) through any circuitry.  &lt;br /&gt;
&lt;br /&gt;
With a technique like this, it is easy to see that some products - such as the [[Product - 1049 - PhidgetSpatial 0/0/3|Phidget Spatial]] - are simply not complex at all. Although you could conceivably create problems (such as by using separate power supplies instead of using USB power and connecting the grounds incorrectly, or by using really long wires), this would be an exceptional case.  &lt;br /&gt;
&lt;br /&gt;
Other Phidgets can be more easily used incorrectly without realizing it.  These are often devices that are simple in some systems and yet complex in others.  Your primary defense against designing unreliable systems is to draw the system out and identifying any problems using the concepts in this primer. To help you, however, you can generally think of two classes of Phidgets which usually need careful handling when they are part of complex systems:&lt;br /&gt;
# Phidgets with more than one power source, (these can be subject to the [[#Shared Grounds|multiple power source problems]] described above)&lt;br /&gt;
# Phidgets needing precise measuring of an external power source (these can be subject to the [[#Shared Grounds|multiple power source problems]] &#039;&#039;and&#039;&#039; [[#Precise Voltage Control|precise voltage control]] problems)&lt;br /&gt;
&lt;br /&gt;
Expanded into individual products, the Phidgets which are most often affected are.....&lt;br /&gt;
&lt;br /&gt;
# These Phidgets use a second type of external power:&lt;br /&gt;
#* Motor controllers &lt;br /&gt;
#**[[DC Motor and Controller Primer|DC controllers]] &lt;br /&gt;
#**[[Stepper Motor and Controller Primer|Stepper controllers]]&lt;br /&gt;
#**[[Servo Motor and Controller Primer|Servo controllers]]&lt;br /&gt;
#* Pure relay boards &lt;br /&gt;
#**[[Solid State Relay Primer|Solid state relay boards]]&lt;br /&gt;
#**[[Mechanical Relay Primer|Mechanical relay boards]]&lt;br /&gt;
#* Interface kits with relays &lt;br /&gt;
#**[[Product - 1017 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
#**[[Product - 1014 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
#* Powered Digital Output Interface Kits &lt;br /&gt;
#** [[Product - 1012 - PhidgetInterfaceKit 0/16/16]]&lt;br /&gt;
#* Interface Kits with Powered Hubs&lt;br /&gt;
#** The [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer]&lt;br /&gt;
#** [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]]&lt;br /&gt;
# And these Phidgets may have a need to be sensitive to external power:&lt;br /&gt;
#* [[Temperature Sensor Primer|Thermocouple]] control&lt;br /&gt;
#* Analog Output ([[Product - 1002 - PhidgetAnalog 4-Output]])&lt;br /&gt;
#* Frequency Counter ([[Product - 1054 - PhidgetFrequencyCounter]])&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
&lt;br /&gt;
This page should have helped you to: &lt;br /&gt;
*Choose a power supply from either the [[#Wall Power|wall]] or a [[#Battery Power|battery]]&lt;br /&gt;
*Properly [[#Ground|ground]] and/or [[#How To Fix This|isolate]] that power supply from looping through other circuitry&lt;br /&gt;
*Also use [[#How To Fix This|isolation]] to make your control or measurement system more precise&lt;br /&gt;
*Keep your cables short and thick to reduce electromagnetic emissions and limit voltage drop&lt;br /&gt;
*Be more aware of system-wide power problems in general, and use drawing and analysis of systems to identify problems&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
===Memory Effect===&lt;br /&gt;
Memory effect is an effect observed in NiCd batteries that causes them to hold less charge.  It pertains to the specific situation in which NiCd batteries lose their maximum capacity if they are repeatedly recharged without being fully discharged.  The battery appears to remember the smaller capacity.  The term is often misused in cases where other batteries seem to hold less charge than originally, however this is most likely due to age and use.  This phenomenon is unique NiCd batteries.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Linux&amp;diff=20723</id>
		<title>OS - Linux</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Linux&amp;diff=20723"/>
		<updated>2012-06-29T21:39:24Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:icon-Linux.png|64x64px|link=OS - Linux]]|On Linux, Phidgets can be either plugged directly into a USB Port or run over a network using the [[#WebService | WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
 &lt;br /&gt;
You need kernel &#039;&#039;&#039;version 2.6&#039;&#039;&#039; (released in 2003) or later.&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
Linux has complete support for all Phidgets and their software APIs; the only thing it lacks when compared to Windows and Mac OSX is a graphical user interface.  We walk you through all steps for download,  installation, checking, and starting to write code below.  &lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the downloads:&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Libraries for Linux]&lt;br /&gt;
*[{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Phidget Generic C Examples]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetwebservice.tar.gz Phidget WebService for Linux]&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#linux Software license]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with Linux==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
To install the libraries, follow these steps:&lt;br /&gt;
&lt;br /&gt;
#Download {{Code|libusb-0.1}} and its development libraries.  &lt;br /&gt;
#*Note that libusb may be already on your system, but the development libraries probably aren&#039;t.&lt;br /&gt;
#*Try {{Code|apt-cache search libusb}} in a terminal to find current installable packages from your source list&lt;br /&gt;
#*Or install [http://www.libusb.org/ from source], which includes the libusb development libraries by default&lt;br /&gt;
#Unpack and install the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Libraries]&lt;br /&gt;
#*From the main unpacked libraries directory, run:&lt;br /&gt;
#*:{{Code|./configure}}&lt;br /&gt;
#*:{{Code|make}}&lt;br /&gt;
#*:{{Code|sudo make install}}&lt;br /&gt;
#*This will compile phidget21.h and place the library into your gcc path&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Although these libraries are written in C, the additional libraries for Python, Java, and most other Phidget-supported languages depend on them.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
To confirm the libraries were installed and work correctly, you can check both the hardware and software sides of the interface.  It is worth checking the software side first, because if it works then you know the hardware side is also okay.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
To confirm that the libraries were installed correctly and can be used in code, you can use the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Phidget Generic C Examples].&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm correct installation will be to compile and run the {{Code|HelloWorld}} C example, included in the examples download.  This does not involve writing any C code, but it does involve compiling the example and running it, which is a quick process as we show below.  If you feel more comfortable running the {{Code|HelloWorld}} example for your specific language, you can skip below and pick your language, but keep in mind that any problems could be with the C library installation and not necessarily with your language.&lt;br /&gt;
&lt;br /&gt;
To compile and run the basic C example for checking your installation:&lt;br /&gt;
&lt;br /&gt;
1. Unpack the Phidget Generic C Examples&amp;lt;br&amp;gt;&lt;br /&gt;
2. Open a terminal (often Ctrl-Alt-T) and go to the directory where the examples are unpacked&amp;lt;br&amp;gt;&lt;br /&gt;
3. Compile the {{Code|HelloWorld.c}} example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 gcc HelloWorld.c -o HelloWorld -lphidget21&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
4. Run the {{Code|HelloWorld}} example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 sudo ./HelloWorld&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
(The sudo is needed for USB access for now, see the [[#Setting udev Rules|Setting udev Rules]] section for how to change this)&lt;br /&gt;
&lt;br /&gt;
The {{Code|-lphidget21}} will look in the standard library location for your Linux distribution (usually {{Code|/usr/lib/}}) for the Phidget 21 library file.  Generally, libraries to be linked on Linux through {{Code|gcc}} have a naming convention.  For example, {{Code|-lphidget21}} looks for the binary files &#039;&#039;&#039;{{Code|libphidget21.a}}&#039;&#039;&#039; and &#039;&#039;&#039;{{Code|libphidget21.so}}&#039;&#039;&#039; in the library location.  These files are automatically put in the library location during the {{Code|make install}} step of [[#Installing | installing the libraries]].&lt;br /&gt;
&lt;br /&gt;
The HelloWorld program will simply print out basic information for any device you plug in, and print a message upon unplugging the device.  For example, starting the program, plugging in an Interface Kit Phidget, unplugging the Interface Kit, and pressing Enter displays:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $ sudo ./HelloWorld &lt;br /&gt;
   &lt;br /&gt;
 Opening...&lt;br /&gt;
 Press Enter to end&lt;br /&gt;
&lt;br /&gt;
 Hello to Device Phidget InterfaceKit 8/8/8, Serial Number: 37299&lt;br /&gt;
 Goodbye Device Phidget InterfaceKit 8/8/8, Serial Number: 37299&lt;br /&gt;
&lt;br /&gt;
 Closing...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
If the out-of-the-box examples do not work, make sure the Phidget is seen by your USB interface.  To check this, you can use the kernel log reader {{Code|dmesg}}.  Pipe the output of {{Code|dmesg}} into the utility {{Code|tail}} to read the last ten lines of the log:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $&amp;gt; dmesg | tail&lt;br /&gt;
 ....(9 lines)....&lt;br /&gt;
 [24344.013638] usb 2-1.2: new low speed USB device number 5 using ehci_hcd&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The number between the [ ] is the system time in seconds since the last boot up, so you can tell whether the event was recent or not.  (This will also tell you the interrupt type of Phidget that is registered by the USB interface, see the [[#Common Problems and Solutions | common problems section below]] for more information on what this means.)&lt;br /&gt;
&lt;br /&gt;
The Phidget should both connect and disconnect properly, so unplugging it should result in an additional line at the tail:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $&amp;gt; dmesg | tail&lt;br /&gt;
 ....(8 lines)....&lt;br /&gt;
 [24344.013638] usb 2-1.2: new low speed USB device number 5 using ehci_hcd&lt;br /&gt;
 [25094.809328] usb 2-1.2: USB disconnect, device number 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t see similar lines to these at the tail of your kernel log, take a look at the [[#Troubleshooting|troubleshooting]] section below, as well as the &#039;&#039;&#039;Communications&#039;&#039;&#039; section of our [[General Troubleshooting#Communications Troubleshooting|general troubleshooting page]].&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the examples &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your computer can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* No other programs, drivers, or processes are using that USB port in software&lt;br /&gt;
* You are running the example program as root (or your udev rules have been set properly)&lt;br /&gt;
* You are using libusb 0.1 (not 1.0 or later)&lt;br /&gt;
* You have compiled versions of libphidget21.a and libphidget21.so in your system library location (usually {{Code|/usr/lib}})&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| quick downloads section]] to download them)&lt;br /&gt;
* Your Linux kernel version is 2.6 or later (type {{Code|uname -r}} in a terminal to get your kernel version)&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic libraries installed, you can pick your language and begin programming!  &lt;br /&gt;
&lt;br /&gt;
If you are not using the [[#WebService | webservice]] (discussed below) to control a Phidget over a network, your next step will be to delve into the use of your specific language.  Each page has its own set of specific libraries, code examples, and setup instructions.  &lt;br /&gt;
&lt;br /&gt;
On Linux, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Java | Java]]&lt;br /&gt;
*[[Language - Python | Python]]&lt;br /&gt;
*[[Language - Ruby | Ruby]]&lt;br /&gt;
*[[Language - C Sharp | C#]] (Using [[Language - C Sharp#Mono|Mono]])&lt;br /&gt;
*[[Language - Flash AS3 | Flash AS3]]&lt;br /&gt;
&lt;br /&gt;
You can also use these languages, but they do not support [[General Phidget Programming#Event Driven Code | event driven code]], and must use [[General Phidget Programming#Logic Code | logic code]] only:&lt;br /&gt;
&lt;br /&gt;
*[[Language - MATLAB|MATLAB]]&lt;br /&gt;
*[[Language - Simulink|Simulink]]&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network.&amp;lt;br&amp;gt;This section helps you install, check, and use the WebService on Linux, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
===Installing the WebService===&lt;br /&gt;
&lt;br /&gt;
To install the webservice, you must first have the [[#Installing|Phidget libraries installed]].  Then, follow these steps:&lt;br /&gt;
&lt;br /&gt;
#Download &#039;&#039;&#039;avahi&#039;&#039;&#039; and its development libraries (mdnsresponder/bonjour is also an option, see the [[#WebService with mDNSResponder|webservice with mDNSResponder]] section)&lt;br /&gt;
#*Try {{Code|apt-cache search avahi}} in a terminal to find current packages&lt;br /&gt;
#*Often, this is installed in a default system, you may already have it&lt;br /&gt;
#Unpack and install the [{{SERVER}}/downloads/libraries/phidgetwebservice.tar.gz Phidgets WebService] source code tarball for Linux&lt;br /&gt;
#*From the unpacked WebService source code directory, run:&lt;br /&gt;
#*:{{Code|./configure}}&lt;br /&gt;
#*:{{Code|make}}&lt;br /&gt;
#*:{{Code|sudo make install}}&lt;br /&gt;
#*This will compile the executable {{Code|phidgetwebservice21}} and place it into {{Code|/usr/bin/phidgetwebservice21}}&lt;br /&gt;
&lt;br /&gt;
====WebService with BSD====&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;BSD&#039;&#039;&#039;, the webservice has been found to work (BSD 8+) but requires a special configuration at the {{Code|./configure}} step:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 ./configure LIBS=/usr/lib/libphidget21.so CFLAGS=-pthread&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then {{Code|make}} and {{Code|sudo make install}} are the same.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The {{Code|LIBS}} argument may not be necessary, but sometimes BSD has trouble finding the library install location.  The {{Code|CFLAGS}} argument is needed because BSD needs explicit linking for using threads.&lt;br /&gt;
&lt;br /&gt;
====WebService with mDNSResponder====&lt;br /&gt;
&lt;br /&gt;
To use &#039;&#039;&#039;mdnsresponder&#039;&#039;&#039; instead of avahi, change the configure script to be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 ./configure --enable-zeroconf=bonjour&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(To see all options, use {{Code|./configure --help}} like you would any configure script)&lt;br /&gt;
&lt;br /&gt;
===Setting Up the WebService===&lt;br /&gt;
&lt;br /&gt;
To set up and use the webservice, it helps to have [[#Setting udev Rules|set your udev rules]].  Otherwise, you must run the webservice as root.&lt;br /&gt;
&lt;br /&gt;
You can get command line help with {{Code|phidgetwebservice21}} by using the {{Code|-h}} option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
$ phidgetwebservice21 -h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
&#039;phidgetwebservice21&#039; is a Phidget and Dictionary server from Phidgets Inc. See www.phidgets.com for more information.&lt;br /&gt;
Usage: phidgetwebservice21 [OPTION]&lt;br /&gt;
All parameters are optional. The default parameters are: port=5001, ServerName=(Computer Name) and no password&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
  -p      Port&lt;br /&gt;
  -n      Server Name&lt;br /&gt;
  -P      Password&lt;br /&gt;
  -v      Debug mode&lt;br /&gt;
  -h      Display this help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see this help regardless of whether the webservice was correctly hooked in to avahi.  In fact, you will see it even if you explicitly disabled mDNS in the {{Code|./configure}} step at compile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  ./configure --disable-zeroconf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(To see all options, use {{Code|./configure --help}} like you would any configure script)&lt;br /&gt;
&lt;br /&gt;
To find the defaults used by {{Code|phidget21webservice}}, the command line is the fastest way to learn the default server name and IP address of your computer:&lt;br /&gt;
*For the default server name, use {{Code|hostname}} on the command line.&lt;br /&gt;
*For your IP address, use {{Code|ifconfig -a}} on the command line.&lt;br /&gt;
**A line in the return text, under your main internet connection (usually {{Code|eth0}}) will say something like {{Code|inet addr:192.168.3.178}}, which is your IP.&lt;br /&gt;
&lt;br /&gt;
Using a server name to connect would not be an option without avahi or some other mDNS service; in this case you would only have the option to use an IP address.&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
To use a Phidget over the webservice, you&#039;ll want to:&lt;br /&gt;
* Obtain code you can use to open a Phidget remotely&lt;br /&gt;
* Start the webservice on the computer that directly connects to the Phidget&lt;br /&gt;
* Run your program on the remote computer that will control the Phidget over the network&lt;br /&gt;
&lt;br /&gt;
The easiest way to test these steps on Linux is simply to set up the webservice and run the Phidget program on the same computer, using the loopback interface.  Later, you can replace one of the two ends with a different computer and/or operating system.&lt;br /&gt;
&lt;br /&gt;
To quickly create code to run remotely, in our examples we include commented out lines with openRemote() function calls of different types.  In the C example for your device, find the line that says:&lt;br /&gt;
&lt;br /&gt;
{{Code|CPhidget_open((CPhidgetHandle) device, -1)}}&lt;br /&gt;
&lt;br /&gt;
and change it to be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 int serial_number = 37299&lt;br /&gt;
 CPhidget_openRemoteIP ((CPhidgetHandle) device, serial_number, &amp;quot;127.0.0.1&amp;quot;, 5001, NULL)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except that you should replace &#039;&#039;&#039;37299&#039;&#039;&#039; with the serial number of your Phidget, which you can obtain from either the Phidget board itself, or from when you [[#Checking|ran the HelloWorld example code]].  The IP address &amp;quot;127.0.0.1&amp;quot; simply loops back to the same computer, and 5001 is the default port as found from using {{Code|phidget21webservice -h}} in [[#Setting Up the WebService|the Setting Up the WebService]] section.  The NULL is used to not specify a password.&lt;br /&gt;
&lt;br /&gt;
Save the changed example under a different filename.  In the walkthrough here, we are using the {{Code|InterfaceKit.c}} example, and we rename it to be {{Code|InterfaceKitRemote.c}}&lt;br /&gt;
&lt;br /&gt;
Compile your new C file. In our {{Code|InterfaceKitRemote.c}} case, this would be by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 gcc InterfaceKitRemote.c -o InterfaceKitRemote -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Start two terminals to run this test, usually opened via Ctrl-Alt-T.  Your [[#Setting udev Rules|udev rules]] need to be set up or you should use sudo for every command.  First, start the webservice in Terminal #1:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_start.png]]&lt;br /&gt;
&lt;br /&gt;
This will broadcast any Phidget events, and receive any Phidget requests, both over the network.&lt;br /&gt;
&lt;br /&gt;
2. Start the InterfaceKitRemote program that you just compiled which will open the remote Phidget.  In this case, it is {{Code|InterfaceKitRemote}}:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_step2.png]]&lt;br /&gt;
&lt;br /&gt;
3. Now, plug in the Phidget!  The {{Code|phidget21webservice}} program captures the attach and other events and sends them out over the network (in the background in Terminal #1) and the Phidget software objected opened with openRemote in Terminal #2 receives them:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_step3.png]]&lt;br /&gt;
&lt;br /&gt;
4. You can confirm that the webservice was indeed behind this exchange by killing the webservice process while still allowing the remote program to run:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_step4.png]]&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
In addition to enabling [[General Phidget Programming#Logging|logging]] in your Phidget code, you can get additional debugging information from the WebService itself.  This additional debugging is enabled via a re-compile of the webservice.  From the webservice source code directory, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 make clean&lt;br /&gt;
&lt;br /&gt;
 ./configure --enable-debug&lt;br /&gt;
&lt;br /&gt;
 make&lt;br /&gt;
&lt;br /&gt;
 sudo make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you suspect multicast DNS (mDNS) may be the problem, you can:&lt;br /&gt;
* Try compiling the webservice with mDNSResponder, as described in [[#Installing the WebService|Installing the WebService]], or &lt;br /&gt;
* Try compiling the webservice completely without mDNS, as described in [[#Setting Up the WebService|Setting Up the WebService]]&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Setting udev Rules===&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to be using {{Code|sudo}} to run Phidget programs (including the webservice) forever, you will want to create a {{Code|udev}} rule to allow yourself access to the Phidget when you are not root.&lt;br /&gt;
&lt;br /&gt;
Udev has an easy way to set the owner and permissions of the USB interface of the Phidget - it finds all devices that match a given set of rules, and applies new traits to them.  But you need to give udev something to match in order to apply the new settings.  Here, we will tell udev to match the vendor code for Phidgets, Inc.  You can get the vendor code in hex by using {{Code|lsusb}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 $&amp;gt; lsusb&lt;br /&gt;
 ....Information about other devices...&lt;br /&gt;
 Bus 002 Device 013: ID 06c2:0045 Phidgets Inc. (formerly GLAB) PhidgetInterface Kit 8-8-8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two numbers separated by a colon are the codes for &#039;&#039;&#039;vendor:product&#039;&#039;&#039;.  Since we want to set up the rule so that all Phidgets, no matter what product, can be used without root privileges, we use the vendor code, which is &#039;&#039;&#039;06c2&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The rules for udev are kept in files in {{Code|/etc/udev/rules.d/}} and are traditionally grouped into order of running (10 runs before 20, 30, etc) and device type (cd, network, etc).  There should be one or more files in there already - if this is your first time editing udev rules take a look at them to see the syntax to use:&lt;br /&gt;
* Commas separate each pair with == or =&lt;br /&gt;
* One rule on each line, no line breaks&lt;br /&gt;
* Quotes around the value to be matched or changed&lt;br /&gt;
* Comments can be added on lines starting with #&lt;br /&gt;
&lt;br /&gt;
Strictly speaking, the files run in lexical order (i.e. the order they&#039;re listed when you use {{Code|ls}}).  A device can match many rules, and all will apply (if possible).  If conflicting rules are found, the first rule found is followed.&lt;br /&gt;
&lt;br /&gt;
To make sure the Phidget udev rules are found first, we can create a file {{Code|10-persistent-usb.rules}} (all udev rule files need to end with {{Code|.rules}}) and add one line to it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 SUBSYSTEM==&amp;quot;usb&amp;quot;, ATTRS{idVendor}==&amp;quot;06c2&amp;quot;, MODE=&amp;quot;0666&amp;quot;, OWNER=&amp;quot;user&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure to replace {{Code|user}} with your user name.  You probably recognize the &#039;&#039;&#039;06c2&#039;&#039;&#039; from the vendor discussion above.  We have added the match on {{Code|SUBSYSTEM}} to search first within usb (within a possibly big database).  The {{Code|MODE}} sets read and write privileges for everyone to the device, and {{Code|OWNER}} sets the owner to be you.&lt;br /&gt;
&lt;br /&gt;
Save the {{Code|10-persistent-usb.rules}} in {{Code|/etc/udev/rules.d/}} and then change its permissions so it can be read by all:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo chmod a+r /etc/udev/rules.d/10-persistent-usb.rules&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The udev rule is now set, and it just has to get read in.  The reading of the rules is goverened by a daemon, {{Code|udevd}}, which you can manage via the program {{Code|udevadm}}.  The {{Code|udevadm}} man page is quite extensive for all sorts of uses of {{Code|udevadm}} while you are testing this or other udev rules.  To re-read and implement the rules without having to reset the daemon or reset the computer, you can use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo udevadm control --reload-rules&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, if you performed all of these steps with the Phidget plugged in to your computer, you will need to unplug and plug the Phidget back in before trying to use usb access without root privileges.&lt;br /&gt;
&lt;br /&gt;
===Starting the WebService at Boot===&lt;br /&gt;
&lt;br /&gt;
If you are tired of starting the webservice on the command line all the time, you can have the webservice start when your system starts, every time.&lt;br /&gt;
&lt;br /&gt;
====User Space====&lt;br /&gt;
&lt;br /&gt;
If you are running a standard Linux machine with an X-server (Unity, KDE) the easiest way to do this is to have the Phidget WebService start when your x server starts.&lt;br /&gt;
&lt;br /&gt;
In this case, the webservice will be running in user space, so your [[#Setting udev Rules|udev rules need to be set up]] for the your user permissions to be able to access the USB ports using libusb.&lt;br /&gt;
&lt;br /&gt;
Within the X-windowing system, there is usually some sort of {{Code|System &amp;amp;rarr; Settings/Preferences &amp;amp;rarr; Startup}} that you can choose to add programs that start when a user session starts.  On Ubuntu you can use Unity to find programs listing &amp;quot;startup&amp;quot; in their names to accomplish the same thing.  This will eventually lead you to a graphical tool like this to simply add the {{Code|/usr/bin/phidgetwebservice21}} program:&lt;br /&gt;
&lt;br /&gt;
[[Image:linux_ws_boot.png|400px]]&lt;br /&gt;
&lt;br /&gt;
====As A Service====&lt;br /&gt;
&lt;br /&gt;
You would want to set the boot start of {{Code|phidgetwebservice21}} to be a service if you are running a server, or a headless machine.  It is handy any time you need the webservice to be started as a booted, respawning service with a presence in different run levels and for all users.&lt;br /&gt;
&lt;br /&gt;
A service is essentially a program that hangs out in the background, waiting to be used by some incoming task.  When the service is needed, the service forks a program to handle that need.  Most services that run on your Linux computer already have the ability to fork themselves.  &lt;br /&gt;
&lt;br /&gt;
The webservice, however, is just a binary on Linux - {{Code|phidgetwebservice21}} - and so we need a program that handles the forking for us.  For this, we use the {{Code|start-stop-daemon}} program to spawn a standalone process for us, or kill it, based on our service-like start, stop, and restart commands.&lt;br /&gt;
&lt;br /&gt;
To do this, we need:&lt;br /&gt;
# A script that tells the boot process how to start and handle the webservice (i.e. by using {{Code|start-stop-daemon}})&lt;br /&gt;
# A link from that script to the boot list&lt;br /&gt;
# An initialization file for the script&lt;br /&gt;
&lt;br /&gt;
First, the script.  We will walk through Debian here, both because it is such a common distribution and because it is the distribution that our [{{SERVER}}products.php?product_id=1072 Single Board Computer] runs.  But {{Code|init}} is surprisingly diverse on Linux, including everything from a different boot order, to different initialization programs and structure, and even different runlevels.  &lt;br /&gt;
&lt;br /&gt;
On Debian (including Ubuntu), the initialization script covers:&lt;br /&gt;
* Runlevels that the service should be present on&lt;br /&gt;
* Dependencies of the service&lt;br /&gt;
* Name of the service and other informative data&lt;br /&gt;
* The location of the PIDFILE, which stores the process ID (pid) for later dealing with a spawned instance&lt;br /&gt;
* Any configuration file locations&lt;br /&gt;
* What to do when the service is given instructions to &#039;&#039;&#039;start&#039;&#039;&#039;, &#039;&#039;&#039;stop&#039;&#039;&#039;, or &#039;&#039;&#039;reload&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The Debian script we use to start the webservice on the [{{SERVER}}products.php?product_id=1072 Single Board Computer]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight line start=&amp;quot;1&amp;quot; lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
### BEGIN INIT INFO&lt;br /&gt;
# Provides:          phidgetwebservice&lt;br /&gt;
# Required-Start:    $network $remote_fs&lt;br /&gt;
# Required-Stop:     $network $remote_fs&lt;br /&gt;
# Should-Start:      avahi&lt;br /&gt;
# Should-Stop:       avahi&lt;br /&gt;
# Default-Start:     2 3 4 5&lt;br /&gt;
# Default-Stop:      0 1 6&lt;br /&gt;
# Short-Description: Phidget WebService&lt;br /&gt;
# Description:       Phidget WebService for controlling Phidgets over the network.&lt;br /&gt;
### END INIT INFO&lt;br /&gt;
&lt;br /&gt;
DESC=&amp;quot;Phidget WebService&amp;quot;&lt;br /&gt;
NAME=phidgetwebservice&lt;br /&gt;
BIN=phidgetwebservice21&lt;br /&gt;
DAEMON=/usr/bin/$BIN&lt;br /&gt;
PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
CFG=/etc/default/$NAME&lt;br /&gt;
&lt;br /&gt;
# Gracefully exit if the package has been removed.&lt;br /&gt;
test -x $DAEMON || exit 0&lt;br /&gt;
&lt;br /&gt;
# load config&lt;br /&gt;
pws_port=&amp;quot;5001&amp;quot;&lt;br /&gt;
pws_serverid=&amp;quot;&amp;quot;&lt;br /&gt;
pws_password=&amp;quot;&amp;quot;&lt;br /&gt;
[ -f $CFG ] &amp;amp;&amp;amp; . $CFG&lt;br /&gt;
&lt;br /&gt;
start() {&lt;br /&gt;
	[ -z &amp;quot;$pws_port&amp;quot; ] || OPTIONS=&amp;quot;-p $pws_port &amp;quot;&lt;br /&gt;
	[ -z &amp;quot;$pws_password&amp;quot; ] || OPTIONS=&amp;quot;$OPTIONS-P $pws_password &amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if [ -z &amp;quot;$pws_serverid&amp;quot; ]; then&lt;br /&gt;
		OPTIONS=&amp;quot;$OPTIONS -n $( hostname )&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		OPTIONS=&amp;quot;$OPTIONS -n $pws_serverid&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
	&lt;br /&gt;
	echo -n &amp;quot;Starting $DESC: &amp;quot;&lt;br /&gt;
	start-stop-daemon -S -b -q -p $PIDFILE -m -x $DAEMON -- $OPTIONS &amp;amp;&amp;amp; echo &amp;quot;OK&amp;quot; || echo &amp;quot;ALREADY RUNNING&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop() {&lt;br /&gt;
	echo -n &amp;quot;Stopping $DESC: &amp;quot;&lt;br /&gt;
	start-stop-daemon -K -q -p $PIDFILE -x $DAEMON &amp;amp;&amp;amp; echo &amp;quot;OK&amp;quot; || echo &amp;quot;NOT RUNNING&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
	start&lt;br /&gt;
	;;&lt;br /&gt;
  stop)&lt;br /&gt;
	stop&lt;br /&gt;
	;;&lt;br /&gt;
  restart|force-reload)&lt;br /&gt;
	stop&lt;br /&gt;
	sleep 1&lt;br /&gt;
	start&lt;br /&gt;
	;;&lt;br /&gt;
  *)&lt;br /&gt;
	echo &amp;quot;Usage: $0 {start|stop|restart}&amp;quot;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the script into a file called {{Code|phidgetwebservice}}, and use {{Code|chmod 755}} to make it executable.&lt;br /&gt;
&lt;br /&gt;
Also on Debian, startup service scripts should go in {{Code|/etc/init.d}}, and then put within the appropriate runlevel-numbered folder - by symbolic link.  There is a handy tool to do this for you, called {{Code|insserv}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo insserv -d phidgetwebservice&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The {{Code|insserv}} program is the program that makes use of the {{Code|### BEGIN INIT INFO...### END INIT INFO}} that appears at the top of the {{Code|phidgetwebservice}} script.  Use {{Code|man insserv}} for more information.  The {{Code|insserv}} tool handles the mess of finding the right runlevel folders (i.e. the {{Code|rc.d}} numbered folders) and making the appropriate links. You can see what links would be updated by running {{Code|insserv}} with the {{Code|-n}} option, for a dry run.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; When you run {{Code|insserv}}, all of the dependencies for the boot order are re-written.  This means that all of the initialization scripts in {{Code|/etc/init.d}} are re-examined.  So, you&#039;ll probably get a lot of output when you run the command.&lt;br /&gt;
&lt;br /&gt;
Then, you can check that {{Code|phidgetwebservice}} is on the service list with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 service --status-all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And you can start it right now without rebooting like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:linux_system_service_start.png]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|service}} command has many options to start and stop services like the phidgetwebservice, try {{Code|man service}} for more information.&lt;br /&gt;
&lt;br /&gt;
At this point, you can follow the client instructions on [[#Using the WebService|using the webservice]] to create a loopback test for the new webservice service that should now be running.&lt;br /&gt;
&lt;br /&gt;
The final piece, for future configuration changes, is that the {{Code|/etc/init.d}} script looks for the file {{Code|/etc/default/phidgetwebservice}} upon starting up.  The file is expected to contain the port, server ID, and password for the server side of the webservice.  These are also set in the {{Code|phidgetwebservice}} script in {{Code|init.d}}, as you can see from reading the code above, but if you want to change them a lot, you can edit the configuration file rather than changing the {{Code|phidgetwebservice}} script and re-installing by {{Code|insserv}} every time.  The configuration file in {{Code|/etc/default/}} should contain the same syntax as that used in the script source above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 pws_port=&amp;quot;5001&amp;quot;&lt;br /&gt;
 pws_serverid=&amp;quot;&amp;quot;&lt;br /&gt;
 pws_password=&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-Compiling with a Custom Toolchain===&lt;br /&gt;
&lt;br /&gt;
This would allow you to have the Phidget libraries compiled to include in code for an embedded device.  When developing for an embedded device, you will often write code for it on your &#039;normal&#039; computer, and then build the code to binary with a different target than the processor in your computer.  Many microcontrollers do not have the ability to run a full operating system, and hence cannot compile code natively.  &lt;br /&gt;
&lt;br /&gt;
The collection of tools used to create binary code for a separate system is called a &#039;&#039;toolchain&#039;&#039;.  Compiling the Phidget libraries specifically for an embedded system, and placing them into the path for writing code on top of the libraries is like adding another link in this chain.&lt;br /&gt;
&lt;br /&gt;
You can use the typical {{Code|./configure}} setup for custom build targets:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./configure --prefix=toolchain_location --build=this_system --host=target_system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the Phidget libraries, the {{Code|./configure}} tool works this way as well. You&#039;d use this in the [[#Installing|install the libraries section]] setup. For example, let&#039;s say you&#039;re building the libraries to develop code for the [{{SERVER}}products.php?product_id=1072 Single Board Computer] as a target.  Your system is a standard Linux system (i686-pc-linux-gnu) and the target system for the SBC is {{Code|arm-linux-gnueabi}}.  For this target, you&#039;ll need the base of the GNU embedded Debian chain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo apt-get install gcc-arm-linux-gnueabi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, download the Phidget libraries [[#Quick Downloads|above]] and unpack them into a folder {{Code|phidget_libraries}}.  If {{Code|/usr/arm-linux-gnueabi}} is the location of your ARM toolchain (downloaded above in {{Code|gcc-arm-linux-gnueabi}}), type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 ~/phidget_libraries $&amp;gt; ./configure --prefix=/usr/arm-linux-gnueabi --build=i686-pc-linux-gnu --host=arm-linux-gnueabi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Linux on Non-Standard Systems===&lt;br /&gt;
&lt;br /&gt;
We occasionally get requests to use Phidgets on Linux systems other than a standard laptop or desktop.  One example is the new Raspberry Pi system.  Often these systems include USB ports, so the combination makes sense.&lt;br /&gt;
&lt;br /&gt;
Our libraries are installed by building from source, and their main dependency is the {{Code|libusb-dev}} library, so if you can get gcc on your machine (or set up a cross compiler for it) and you can also install the libusb-0.1 development headers, you can probably get Phidgets to work.  Of course, we don&#039;t offer much support for these systems, so - depending on your system - expect to spend some raw time getting it up and going.  &lt;br /&gt;
&lt;br /&gt;
If you&#039;re new to the embedded computer thing, keep in mind that for these super basic systems, once you&#039;ve gotten a power supply, and storage, and put the kernel you want on it, and then spent a couple of days of time getting things working, and  more time getting your drivers going, costs add up pretty quickly.  If you want a compact system that works right out of the box (and which can use all of our analog sensors in addition to our USB Phidgets), check out our [{{SERVER}}products.php?product_id=1072 Single Board Computer].   Our SBC:&lt;br /&gt;
* Has many more USB ports than super-stripped devices, and also has digital and analog ports &lt;br /&gt;
* Includes a power supply and can run on batteries easily&lt;br /&gt;
* Has a nice amount of RAM, a decent embedded processor, and built-in onboard storage (we&#039;ve run R, GRASS, and X11 on it)&lt;br /&gt;
* Includes installed Debian, working Phidget drivers, and [[Phidget WebService|networked Phidget drivers]] from the moment it ships &lt;br /&gt;
* Has access to the full Debian repository including Python, Mono .NET, Ruby, and gcc&lt;br /&gt;
* Has a kernel development kit with patch file and instructions for adding new drivers (bluetooth, wireless, and so on)&lt;br /&gt;
* Comes with very in-depth documentation and technical support by phone and email &lt;br /&gt;
* Etc, etc.&lt;br /&gt;
The [[Phidget WebService|networked support]] in particular allows it to work with your cell phone and more.  &lt;br /&gt;
&lt;br /&gt;
But if you really do want a raw hobbyist system to tinker with, go for it!  We&#039;re all nerds here - we&#039;ve been there too and we certainly understand!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Low Speed Phidgets (Max of 8)|Linux will only schedule one low-speed interrupt transfer per millisecond.}}&lt;br /&gt;
&lt;br /&gt;
You can find out the type of your Phidget by attaching it and then running &amp;lt;code&amp;gt;&amp;lt;font size=3&amp;gt;dmesg | tail&amp;lt;/font&amp;gt;&amp;lt;/code&amp;gt;, which will display the type of Phidget from your kernel logs, as described above in the [[#Hardware|hardware section]]. The practical consequence of this is if your system has many low speed Phidgets attached, they will each be throttled down.  Low speed Phidgets require an interrupt transfer as often as every 8 milliseconds.  A Linux system could only have up to 8 of these Phidgets attached.&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Sample Overrun Error|The data read from a program, or the first packet on the WebService, can give a sample overrun error (EEPHIDGET_OVERRUN).}}&lt;br /&gt;
&lt;br /&gt;
Linux only polls data from the analog inputs on Phidgets when you ask it to.  So there is some delay between when you open the device and when it actually attaches when data from those inputs are accumulating...and overrunning the buffer.  This is simply in the nature of how Linux polls USB - we recommend catching (but ignoring) this one-time initial error.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20722</id>
		<title>Mechanical Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20722"/>
		<updated>2012-06-29T21:38:34Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* How it works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[File:1017.jpg|link=]]&lt;br /&gt;
| [[File:3051.jpg|250px|link=]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are devices that can turn on or turn off the power supplied to another device, like a switch. However, instead of having a person flip the switch, mechanical relays switch when provided with a small amount of power. This allows high-power circuits to be controlled by low-power devices. &lt;br /&gt;
&lt;br /&gt;
They perform the same function as [[Solid State Relay Primer|Solid State Relays]], except they are less expensive and have a shorter lifespan.&lt;br /&gt;
You can use them to control [[LED Primer|LEDs]], heaters, appliances, and generally any powered device as long as the power you&#039;re switching falls within the limits of the relay you&#039;re using.&lt;br /&gt;
&lt;br /&gt;
Phidgets sells boards with multiple relays on them, making it easy to control many separate circuits with your computer. Some boards plug straight into your USB port, while others are designed to connect to another device, such as an Interface Kit, or any device with enough [[Digital Output Primer|Digital Outputs]].&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay.jpg|thumb|link=|300px|&#039;&#039;&#039;Mechanical Relay&#039;&#039;&#039;&amp;lt;br /&amp;gt;The switching arm and contacts of a [[#Single Pole, Double Throw (SPDT)|SPDT]] mechanical relay.]]&lt;br /&gt;
&lt;br /&gt;
Mechanical relays use an electromagnetic coil to open or close the circuit. When current runs through the input and energizes the coil, it creates a small magnetic field which either pulls the arm of the switch away from the other contact of the switch, or pushes it down to close the switch depending on the how the switch is made. A relay also serves as an isolator, because the control (input) and load (output) ends of the relay are not electrically connected. This allows you to protect the device you&#039;re using to control the relay from power surges in your application. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling a mechanical relay is as easy as turning on an LED or light bulb. By simply supplying enough power to energize the electromagnetic coil, you will be able to control a mechanical relay. A normal digital output will not be powerful enough without external components as described in the [[Digital Output Primer#Controlling a Relay with a N-Channel MOSFET| relay section of the Digital Output Primer]]. A Phidgets device with open collector digital outputs, (the ones you have to [{{SERVER}}/products.php?product_id=1012 provide power to]{{LinksNeeded||[[Digital Output Primer]]}}), on the other hand, will be able to control a relay on its own. &lt;br /&gt;
Relays are often used in large quantities to turn multiple devices on and off in a particular order or timing. For example, a popular trend has been to hook up many strands of Christmas lights to multiple relays and a control system in order to make them flash in rhythm with specific music.&lt;br /&gt;
&lt;br /&gt;
Relays are designed to be controlled by a particular voltage applied to the coil.  If you buy a relay product from Phidgets with integrated electronics, this is taken care of for you- you&#039;ll be able to switch the relays via USB or with any Phidgets device with enough [[Digital Output Primer|Digital Outputs]] (see table below), depending on which relay board you buy.  If you are integrating your own relay, you&#039;ll want to keep an eye on the specifications. The relay coil is also specified for a particular current.  For example, a 5V relay might require 70mA.  If you connect this relay to a very weak source of 5V, like a digital output, the output will not be able to provide 70mA, and there will not be enough current to switch the relay.&lt;br /&gt;
&lt;br /&gt;
(table: +mechanical_relay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Mechanical Relays&#039;&#039;&#039;&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Connects to&lt;br /&gt;
! etc...&lt;br /&gt;
|-&lt;br /&gt;
| 1014_2 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 1017_1 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 3051_1 || Digital Output || ...&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The load side of the relay also requires a minimum current. This minimum load current (also called &amp;quot;wetting current&amp;quot;) is a requirement because the electricity needs to conduct through an oxide layer that has formed on the contacts of the relay. If the minimum load current requirement of your relay is too high, you won&#039;t be able to use it to switch a signal (such as the data line on an analog sensor), you&#039;ll only be able to switch power to a circuit. If you&#039;re using a relay to switch a signal, [[#Contact Bounce|contact bounce]] might also be a problem.&lt;br /&gt;
&lt;br /&gt;
====Switching Speed and High-Frequency Switching====&lt;br /&gt;
&lt;br /&gt;
Even though they use moving mechanical parts, mechanical relays switch very quickly. The amount of time it takes for current to begin flowing through the circuit from when the relay&#039;s input is activated is in the order of tens of milliseconds. For extremely time-sensitive applications that need to minimize switching delay, [[Solid State Relay Primer|Solid State Relays]] can switch as quickly as 1ms. &lt;br /&gt;
&lt;br /&gt;
You should be careful when using mechanical relays in applications that require very frequent switching. Typically, mechanical relays can only manage one contact every few seconds- any quicker and they may begin to overheat.&lt;br /&gt;
&lt;br /&gt;
==Choosing a Relay==&lt;br /&gt;
&lt;br /&gt;
Since mechanical relays are nothing more than a controllable switch, they support both AC and DC loads. &lt;br /&gt;
&lt;br /&gt;
The major deciding factor in choosing a mechanical relay is the amount of current it&#039;s capable of switching.&lt;br /&gt;
For example, the most current you can switch with the largest mechanical relay we sell is 5A DC or 10A AC. &lt;br /&gt;
If the load you&#039;re switching consumes more current than our mechanical relays can handle, take a look at our [[Solid State Relay Primer|Solid State Relays]].&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
&lt;br /&gt;
One of the major characteristics of a mechanical relay is the design of the switch inside. A switch can generally be defined by the number of &#039;&#039;&#039;poles&#039;&#039;&#039; and &#039;&#039;&#039;throws&#039;&#039;&#039; it has. The number of &amp;quot;poles&amp;quot; refers to the number of individual circuits the switch controls. The number of &amp;quot;throws&amp;quot; refers to the number of positions the switch arm can occupy. &lt;br /&gt;
&lt;br /&gt;
[[File:Switch_types.jpg|border|300px|link=]]&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Single Throw (SPST)====&lt;br /&gt;
&lt;br /&gt;
This is a simple switch with only one path for the current to follow. The relay is either designed to be &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039;. If it is normally open, the arm of the switch is held away from the contact with a spring when the relay is off and the electromagnet pulls the arm to make contact and close the switch when the relay is turned on. If it is normally closed, the arm of the switch is held to the contact when the relay is off, and the electromagnet pulls the arm away when the relay is turned on.&lt;br /&gt;
&lt;br /&gt;
While the decision to use a normally opened or normally closed relay may seem arbitrary at first, it is actually very important for certain applications. If you choose a normally closed relay, it means your load will remain powered as long as the relay coil is &#039;&#039;&#039;not&#039;&#039;&#039; powered. If some other part of your system fails, causing your relay to lose power, your load will remain powered even though it should not be. For loads that are potentially dangerous when left on (such as a heater, or a high-power load) it is best to use a normally open relay, so that in the event of a system failure, the load will remain off. On the other hand, circuits that are designed to be powered most of the time but temporarily interrupted will use less power if they use a normally closed relay. An example of this type of circuit is the radio in a car: When the engine is started, the radio circuit is momentarily switched off because the engine needs a large amount of battery power to start.&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Double Throw (SPDT)====&lt;br /&gt;
&lt;br /&gt;
[[File:relay2loads.png|thumb|link=|300px|&#039;&#039;&#039;Toggle Between Two Loads&#039;&#039;&#039;&amp;lt;br /&amp;gt;By connecting the power supply to the common terminal, and connecting a different load to the other two terminals, a relay with a SPDT switch can be used to toggle power between the two loads.&amp;lt;br /&amp;gt;[[Media:relay2loads.png|Full-size Image]]]]&lt;br /&gt;
&lt;br /&gt;
This switch has two paths for the current to follow. This type of relay is useful if you want to toggle power between two different loads, as pictured. You can also use a SPDT relay as a single pole, single throw switch, and it can function as &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039; depending on which pins (common and normally open, or common and normally closed) you connect the load to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Double Pole, Single Throw (DPST)====&lt;br /&gt;
&lt;br /&gt;
This switch functions like two SPST switches, but both switches are controlled by one coil. This type of switch is useful for keeping two loads on separate circuits while still being able to have them turn on and off in unison. &lt;br /&gt;
&lt;br /&gt;
====Double Pole, Double Throw (DPDT)====&lt;br /&gt;
&lt;br /&gt;
This switch functions the same as a SPDT switch, except there are two of them, but are both controlled by a single input on the relay. You can use this type of switch to simultaneously control two separate circuits.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
===Contact Bounce===&lt;br /&gt;
&lt;br /&gt;
As with any mechanical switch, relays are susceptible to [[Switch Primer#Bounce|contact bounce]]. This means that when the switch closes, the arm can bounce on the contact, causing the load&#039;s power to flicker slightly. This usually only matters when the application is triggered by pulses in the power signal, or for applications where meaningful data is being switched instead of power. For example, a circuit designed to increment a counter every time power is applied to its input could incorrectly interpret a bouncing relay contact as multiple switch events. Or, a circuit that uses a relay to switch an audio signal between two different paths will experience some static noise when switching if there is significant contact bounce. Check the [[Switch Primer|switch primer]] for information on how to deal with switch contact bounce. It&#039;s worth mentioning that [[Solid State Relay Primer|Solid State Relays]] don&#039;t suffer from contact bounce, because they operate without using moving mechanical parts.&lt;br /&gt;
&lt;br /&gt;
===Arcing, Interference, and Sticking===&lt;br /&gt;
&lt;br /&gt;
[[File:contact_arc.jpg|border|link=]]&lt;br /&gt;
&lt;br /&gt;
When a mechanical relay opens or closes, for the moment that the arm of the switch is very close (but not connected) to the contact, the electric current can arc through the air between the contacts.&lt;br /&gt;
This arc can cause interference with nearby electrical instruments and sensors. For example, if an unshielded cable carrying an audio signal is travelling past some relays whose contacts are arcing when they switch, the audio would contain bursts of static noise. &lt;br /&gt;
&lt;br /&gt;
This arcing can also heat up the contacts of the switch enough that they can slowly degrade away until the relay no longer functions. They could also weld together, causing the relay to stay on permanently, which means your load will be powered constantly. If this imposes safety concerns, you should install a fail-safe of some kind. For example, some sauna heaters are turned on with a mechanical relay. In the event of a relay failure, the sauna heater will remain on and continue heating the room beyond the intended temperature. However, a simple mechanical temperature sensor is installed which cuts power to the heater if the room goes beyond a certain temperature. &lt;br /&gt;
&lt;br /&gt;
Some relays are encased in a clear plastic enclosure (sometimes called &amp;quot;ice cube&amp;quot; relays), so the switch contacts can be easily inspected. By inspecting the contacts periodically, you could tell when the relay is getting near the end of its life.&lt;br /&gt;
&lt;br /&gt;
===Prolonging Relay Lifespan===&lt;br /&gt;
&lt;br /&gt;
In order to prolong the lifespan of your relay, avoid switching loads of higher voltage or current than the relay is built for, and avoid highly inductive loads, which worsen the effects of contact arcing. Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples. A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat. An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.&lt;br /&gt;
&lt;br /&gt;
Additionally,  you should avoid switching at or near the relay&#039;s maximum frequency if possible. You can think of a mechanical relay&#039;s lifespan in terms of number times switched rather than the amount of time it&#039;s used for. A relay that doesn&#039;t need to be switched very often can last a long time. If your application requires constant switching over long periods of time, it might be more cost-effective to use a [[Solid State Relay Primer|Solid State Relay]].&lt;br /&gt;
&lt;br /&gt;
====Arc Suppression ====&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay_diode.jpg|link=|thumb|300px|&#039;&#039;&#039;DC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching a DC load. An optional diode and fuse are used to protect the relay and prevent hardware damaged caused by improper wiring.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_diode.jpg|Full-sized Image]]]]&lt;br /&gt;
[[File:Mechanical_relay_mov.jpg|link=|thumb|300px|&#039;&#039;&#039;AC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching an AC load. An optional MOV or Transil diode is placed in parallel to protect the relay from voltage spikes.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_mov.jpg|Full-Sized Image]]]]&lt;br /&gt;
The main cause of failure for mechanical relays is electricity arcing across the contacts during switching. To lengthen the lifespan of your relay, you can add various circuit elements that mitigate arcing.&lt;br /&gt;
&lt;br /&gt;
For DC powered applications, one simple method of mitigating the effects of contact arcing is to place a feedback diode across the load, as pictured. This will allow some of the residual electricity in the circuit to recirculate through the load instead of contributing to the arc that forms when the switch makes the transition from closed to open. You can buy a suitable diode from any electronics distributor, like this [http://parts.digikey.com/1/parts/1850825-diode-std-rec-10a-100v-r-6-10a02-t.html Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For AC powered applications, you can put a Metal Oxide Varistor (MOV) across the load terminals of the relay in order to protect it from voltage spikes. An MOV will not remove the entire arc, but it will be helpful in circuits up to several hundred volts. You can buy an MOV from any electronics distributor, like this [http://parts.digikey.com/1/parts/714083-varistor-thermal-200v-10ka-20mm-tmov20rp200e.html MOV] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For low-voltage AC applications, a bi-directional transient voltage suppression diode (&amp;quot;transil diode&amp;quot;) that is rated for higher than the AC voltage of the circuit can be placed across the relay terminals in order to protect it from voltage spikes. You can buy one from any electronics distributor, like this [http://parts.digikey.com/1/parts/718140-transil-600w-47v-bidir-do-15-p6ke47carl.html Transil Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are inexpensive and simple devices that allow AC or DC circuits to be switched on and off using a small amount of power.&lt;br /&gt;
They come in a variety of switch formats, enabling the user to build some very clever control into a circuit. Phidgets Inc. sells boards with multiple relays that can be connected directly to USB, so they can be controlled by your program. &lt;br /&gt;
&lt;br /&gt;
Contact arcing and switch bounce can be an obstacle for some applications, but both are common problems and can be worked around fairly easily. &lt;br /&gt;
Mechanical relays don&#039;t last as long as solid state relays, but if you take care of them, they can be a good cost-effective alternative.&lt;br /&gt;
&lt;br /&gt;
==Products in this Category==&lt;br /&gt;
&lt;br /&gt;
* [[1014_2 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
* [[1017_1 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
* [[3051_1 - Dual Relay Board]]&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
* SPST - either normally open or normally closed. Simple on/off switch.&lt;br /&gt;
* SPDT - 3 pins, has both a NO and NC pin and can function like a SPST switch of either type, or can be used to toggle power between two different loads. &lt;br /&gt;
* DPDT - Same as SPDT but there are two controlled by the same relay input. Useful for controlling 2 seperate circuits in a synchronized manner. &lt;br /&gt;
* Potential selection criteria for specific switching circuits.&lt;br /&gt;
&lt;br /&gt;
===Contact Arcing===&lt;br /&gt;
* As the switch moves from the &amp;quot;on&amp;quot; position to the &amp;quot;off&amp;quot; position (and vice-versa) there is a moment when the arm of the switch in close enough to the contact that electricity will arc through the air, creating lots of heat and possibly damaging the contact. (Diagram would be useful)&lt;br /&gt;
* Arcing can lead to sticking, where the switch welds itself closed. If your relay is always on, it might be stuck. &lt;br /&gt;
* Arcing will be more severe with higher power loads or highly inductive loads. &lt;br /&gt;
* Arcing is expected, but can be mitigated by:&lt;br /&gt;
** For DC, feedback diode across load&lt;br /&gt;
** For AC, Snubber circuit or&lt;br /&gt;
** MOV or&lt;br /&gt;
** TVS&lt;br /&gt;
&lt;br /&gt;
===Switching Speed===&lt;br /&gt;
* Lifespan of relay is measured in number of contacts, not time in use. Faster switching -&amp;gt; shorter life.&lt;br /&gt;
* Switching is audible - you can hear the switching, which might be annoying / undesirable, or it might be good as a confirmation the system is operating.&lt;br /&gt;
* Switching speed is limited by heating in the contacts - the arcing generates heat, and switching high loads faster than the rated switching speed will cause the relay to overheat.&lt;br /&gt;
&lt;br /&gt;
===Operating Time===&lt;br /&gt;
* Time it takes for the arm of the switch to connect with the contact after being activated&lt;br /&gt;
* If 10ms is too slow, look at SSRs&lt;br /&gt;
&lt;br /&gt;
===Control Voltage===&lt;br /&gt;
* Can be controlled via digital output&lt;br /&gt;
* Relay offers isolation between load circuit and control circuit&lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Voltage===&lt;br /&gt;
* Secondary selection criteria. &lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Current===&lt;br /&gt;
* Main selection criteria.&lt;br /&gt;
* If they need to switch more than 5A DC, or 10A AC, go to SSRs&lt;br /&gt;
* Inductive loads- does the same multiplier apply as for SSRs? &lt;br /&gt;
&lt;br /&gt;
===Minimum Switching Current===&lt;br /&gt;
* A certain amount of current is needed on the LOAD side of a relay. &lt;br /&gt;
* Oxide films build up on the contacts, so this minimum is required to conduct through them.&lt;br /&gt;
* This spec determines whether or not the relay can switch a signal instead of power.&lt;br /&gt;
** If you are switching a signal rather than power, contact bounce could be a problem.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20721</id>
		<title>Mechanical Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20721"/>
		<updated>2012-06-29T21:37:17Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Basic Use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[File:1017.jpg|link=]]&lt;br /&gt;
| [[File:3051.jpg|250px|link=]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are devices that can turn on or turn off the power supplied to another device, like a switch. However, instead of having a person flip the switch, mechanical relays switch when provided with a small amount of power. This allows high-power circuits to be controlled by low-power devices. &lt;br /&gt;
&lt;br /&gt;
They perform the same function as [[Solid State Relay Primer|Solid State Relays]], except they are less expensive and have a shorter lifespan.&lt;br /&gt;
You can use them to control [[LED Primer|LEDs]], heaters, appliances, and generally any powered device as long as the power you&#039;re switching falls within the limits of the relay you&#039;re using.&lt;br /&gt;
&lt;br /&gt;
Phidgets sells boards with multiple relays on them, making it easy to control many separate circuits with your computer. Some boards plug straight into your USB port, while others are designed to connect to another device, such as an Interface Kit, or any device with enough [[Digital Output Primer|Digital Outputs]].&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay.jpg|thumb|link=|300px|&#039;&#039;&#039;Mechanical Relay&#039;&#039;&#039;&amp;lt;br /&amp;gt;The switching arm and contacts of a [[#Single Pole, Double Throw (SPDT)|SPDT]] mechanical relay.]]&lt;br /&gt;
&lt;br /&gt;
Mechanical relays use an electromagnetic coil to open or close the circuit. When current runs through the input and energizes the coil, it creates a small magnetic field which either pulls the arm of the switch away from the other contact of the switch, or pushes it down to close the switch depending on the how the switch is made. A relay also serves as an isolator, because the control (input) and load (output) ends of the relay are not electrically connected. This allows you to protect the device you&#039;re using to control the relay from power surges in your application. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling a mechanical relay is as easy as turning on an LED or light bulb. By simply supplying enough power to energize the electromagnetic coil, you will be able to control a mechanical relay. A normal digital output will not be powerful enough without external components as described in the [[Digital Output Primer#Controlling a Relay with a N-Channel MOSFET| relay section of the Digital Output Primer]]. A Phidgets device with {{LinksNeeded|open collector digital outputs, (the ones you have to [{{SERVER}}/products.php?product_id=1012 provide power to]|[[Digital Output Primer]]}}, on the other hand, will be able to control a relay on its own. &lt;br /&gt;
Relays are often used in large quantities to turn multiple devices on and off in a particular order or timing. For example, a popular trend has been to hook up many strands of Christmas lights to multiple relays and a control system in order to make them flash in rhythm with specific music.&lt;br /&gt;
&lt;br /&gt;
Relays are designed to be controlled by a particular voltage applied to the coil.  If you buy a relay product from Phidgets with integrated electronics, this is taken care of for you- you&#039;ll be able to switch the relays via USB or with any Phidgets device with enough [[Digital Output Primer|Digital Outputs]] (see table below), depending on which relay board you buy.  If you are integrating your own relay, you&#039;ll want to keep an eye on the specifications. The relay coil is also specified for a particular current.  For example, a 5V relay might require 70mA.  If you connect this relay to a very weak source of 5V, like a digital output, the output will not be able to provide 70mA, and there will not be enough current to switch the relay.&lt;br /&gt;
&lt;br /&gt;
(table: +mechanical_relay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Mechanical Relays&#039;&#039;&#039;&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Connects to&lt;br /&gt;
! etc...&lt;br /&gt;
|-&lt;br /&gt;
| 1014_2 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 1017_1 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 3051_1 || Digital Output || ...&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The load side of the relay also requires a minimum current. This minimum load current (also called &amp;quot;wetting current&amp;quot;) is a requirement because the electricity needs to conduct through an oxide layer that has formed on the contacts of the relay. If the minimum load current requirement of your relay is too high, you won&#039;t be able to use it to switch a signal (such as the data line on an analog sensor), you&#039;ll only be able to switch power to a circuit. If you&#039;re using a relay to switch a signal, [[#Contact Bounce|contact bounce]] might also be a problem.&lt;br /&gt;
&lt;br /&gt;
====Switching Speed and High-Frequency Switching====&lt;br /&gt;
&lt;br /&gt;
Even though they use moving mechanical parts, mechanical relays switch very quickly. The amount of time it takes for current to begin flowing through the circuit from when the relay&#039;s input is activated is in the order of tens of milliseconds. For extremely time-sensitive applications that need to minimize switching delay, [[Solid State Relay Primer|Solid State Relays]] can switch as quickly as 1ms. &lt;br /&gt;
&lt;br /&gt;
You should be careful when using mechanical relays in applications that require very frequent switching. Typically, mechanical relays can only manage one contact every few seconds- any quicker and they may begin to overheat.&lt;br /&gt;
&lt;br /&gt;
==Choosing a Relay==&lt;br /&gt;
&lt;br /&gt;
Since mechanical relays are nothing more than a controllable switch, they support both AC and DC loads. &lt;br /&gt;
&lt;br /&gt;
The major deciding factor in choosing a mechanical relay is the amount of current it&#039;s capable of switching.&lt;br /&gt;
For example, the most current you can switch with the largest mechanical relay we sell is 5A DC or 10A AC. &lt;br /&gt;
If the load you&#039;re switching consumes more current than our mechanical relays can handle, take a look at our [[Solid State Relay Primer|Solid State Relays]].&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
&lt;br /&gt;
One of the major characteristics of a mechanical relay is the design of the switch inside. A switch can generally be defined by the number of &#039;&#039;&#039;poles&#039;&#039;&#039; and &#039;&#039;&#039;throws&#039;&#039;&#039; it has. The number of &amp;quot;poles&amp;quot; refers to the number of individual circuits the switch controls. The number of &amp;quot;throws&amp;quot; refers to the number of positions the switch arm can occupy. &lt;br /&gt;
&lt;br /&gt;
[[File:Switch_types.jpg|border|300px|link=]]&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Single Throw (SPST)====&lt;br /&gt;
&lt;br /&gt;
This is a simple switch with only one path for the current to follow. The relay is either designed to be &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039;. If it is normally open, the arm of the switch is held away from the contact with a spring when the relay is off and the electromagnet pulls the arm to make contact and close the switch when the relay is turned on. If it is normally closed, the arm of the switch is held to the contact when the relay is off, and the electromagnet pulls the arm away when the relay is turned on.&lt;br /&gt;
&lt;br /&gt;
While the decision to use a normally opened or normally closed relay may seem arbitrary at first, it is actually very important for certain applications. If you choose a normally closed relay, it means your load will remain powered as long as the relay coil is &#039;&#039;&#039;not&#039;&#039;&#039; powered. If some other part of your system fails, causing your relay to lose power, your load will remain powered even though it should not be. For loads that are potentially dangerous when left on (such as a heater, or a high-power load) it is best to use a normally open relay, so that in the event of a system failure, the load will remain off. On the other hand, circuits that are designed to be powered most of the time but temporarily interrupted will use less power if they use a normally closed relay. An example of this type of circuit is the radio in a car: When the engine is started, the radio circuit is momentarily switched off because the engine needs a large amount of battery power to start.&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Double Throw (SPDT)====&lt;br /&gt;
&lt;br /&gt;
[[File:relay2loads.png|thumb|link=|300px|&#039;&#039;&#039;Toggle Between Two Loads&#039;&#039;&#039;&amp;lt;br /&amp;gt;By connecting the power supply to the common terminal, and connecting a different load to the other two terminals, a relay with a SPDT switch can be used to toggle power between the two loads.&amp;lt;br /&amp;gt;[[Media:relay2loads.png|Full-size Image]]]]&lt;br /&gt;
&lt;br /&gt;
This switch has two paths for the current to follow. This type of relay is useful if you want to toggle power between two different loads, as pictured. You can also use a SPDT relay as a single pole, single throw switch, and it can function as &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039; depending on which pins (common and normally open, or common and normally closed) you connect the load to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Double Pole, Single Throw (DPST)====&lt;br /&gt;
&lt;br /&gt;
This switch functions like two SPST switches, but both switches are controlled by one coil. This type of switch is useful for keeping two loads on separate circuits while still being able to have them turn on and off in unison. &lt;br /&gt;
&lt;br /&gt;
====Double Pole, Double Throw (DPDT)====&lt;br /&gt;
&lt;br /&gt;
This switch functions the same as a SPDT switch, except there are two of them, but are both controlled by a single input on the relay. You can use this type of switch to simultaneously control two separate circuits.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
===Contact Bounce===&lt;br /&gt;
&lt;br /&gt;
As with any mechanical switch, relays are susceptible to [[Switch Primer#Bounce|contact bounce]]. This means that when the switch closes, the arm can bounce on the contact, causing the load&#039;s power to flicker slightly. This usually only matters when the application is triggered by pulses in the power signal, or for applications where meaningful data is being switched instead of power. For example, a circuit designed to increment a counter every time power is applied to its input could incorrectly interpret a bouncing relay contact as multiple switch events. Or, a circuit that uses a relay to switch an audio signal between two different paths will experience some static noise when switching if there is significant contact bounce. Check the [[Switch Primer|switch primer]] for information on how to deal with switch contact bounce. It&#039;s worth mentioning that [[Solid State Relay Primer|Solid State Relays]] don&#039;t suffer from contact bounce, because they operate without using moving mechanical parts.&lt;br /&gt;
&lt;br /&gt;
===Arcing, Interference, and Sticking===&lt;br /&gt;
&lt;br /&gt;
[[File:contact_arc.jpg|border|link=]]&lt;br /&gt;
&lt;br /&gt;
When a mechanical relay opens or closes, for the moment that the arm of the switch is very close (but not connected) to the contact, the electric current can arc through the air between the contacts.&lt;br /&gt;
This arc can cause interference with nearby electrical instruments and sensors. For example, if an unshielded cable carrying an audio signal is travelling past some relays whose contacts are arcing when they switch, the audio would contain bursts of static noise. &lt;br /&gt;
&lt;br /&gt;
This arcing can also heat up the contacts of the switch enough that they can slowly degrade away until the relay no longer functions. They could also weld together, causing the relay to stay on permanently, which means your load will be powered constantly. If this imposes safety concerns, you should install a fail-safe of some kind. For example, some sauna heaters are turned on with a mechanical relay. In the event of a relay failure, the sauna heater will remain on and continue heating the room beyond the intended temperature. However, a simple mechanical temperature sensor is installed which cuts power to the heater if the room goes beyond a certain temperature. &lt;br /&gt;
&lt;br /&gt;
Some relays are encased in a clear plastic enclosure (sometimes called &amp;quot;ice cube&amp;quot; relays), so the switch contacts can be easily inspected. By inspecting the contacts periodically, you could tell when the relay is getting near the end of its life.&lt;br /&gt;
&lt;br /&gt;
===Prolonging Relay Lifespan===&lt;br /&gt;
&lt;br /&gt;
In order to prolong the lifespan of your relay, avoid switching loads of higher voltage or current than the relay is built for, and avoid highly inductive loads, which worsen the effects of contact arcing. Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples. A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat. An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.&lt;br /&gt;
&lt;br /&gt;
Additionally,  you should avoid switching at or near the relay&#039;s maximum frequency if possible. You can think of a mechanical relay&#039;s lifespan in terms of number times switched rather than the amount of time it&#039;s used for. A relay that doesn&#039;t need to be switched very often can last a long time. If your application requires constant switching over long periods of time, it might be more cost-effective to use a [[Solid State Relay Primer|Solid State Relay]].&lt;br /&gt;
&lt;br /&gt;
====Arc Suppression ====&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay_diode.jpg|link=|thumb|300px|&#039;&#039;&#039;DC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching a DC load. An optional diode and fuse are used to protect the relay and prevent hardware damaged caused by improper wiring.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_diode.jpg|Full-sized Image]]]]&lt;br /&gt;
[[File:Mechanical_relay_mov.jpg|link=|thumb|300px|&#039;&#039;&#039;AC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching an AC load. An optional MOV or Transil diode is placed in parallel to protect the relay from voltage spikes.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_mov.jpg|Full-Sized Image]]]]&lt;br /&gt;
The main cause of failure for mechanical relays is electricity arcing across the contacts during switching. To lengthen the lifespan of your relay, you can add various circuit elements that mitigate arcing.&lt;br /&gt;
&lt;br /&gt;
For DC powered applications, one simple method of mitigating the effects of contact arcing is to place a feedback diode across the load, as pictured. This will allow some of the residual electricity in the circuit to recirculate through the load instead of contributing to the arc that forms when the switch makes the transition from closed to open. You can buy a suitable diode from any electronics distributor, like this [http://parts.digikey.com/1/parts/1850825-diode-std-rec-10a-100v-r-6-10a02-t.html Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For AC powered applications, you can put a Metal Oxide Varistor (MOV) across the load terminals of the relay in order to protect it from voltage spikes. An MOV will not remove the entire arc, but it will be helpful in circuits up to several hundred volts. You can buy an MOV from any electronics distributor, like this [http://parts.digikey.com/1/parts/714083-varistor-thermal-200v-10ka-20mm-tmov20rp200e.html MOV] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For low-voltage AC applications, a bi-directional transient voltage suppression diode (&amp;quot;transil diode&amp;quot;) that is rated for higher than the AC voltage of the circuit can be placed across the relay terminals in order to protect it from voltage spikes. You can buy one from any electronics distributor, like this [http://parts.digikey.com/1/parts/718140-transil-600w-47v-bidir-do-15-p6ke47carl.html Transil Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are inexpensive and simple devices that allow AC or DC circuits to be switched on and off using a small amount of power.&lt;br /&gt;
They come in a variety of switch formats, enabling the user to build some very clever control into a circuit. Phidgets Inc. sells boards with multiple relays that can be connected directly to USB, so they can be controlled by your program. &lt;br /&gt;
&lt;br /&gt;
Contact arcing and switch bounce can be an obstacle for some applications, but both are common problems and can be worked around fairly easily. &lt;br /&gt;
Mechanical relays don&#039;t last as long as solid state relays, but if you take care of them, they can be a good cost-effective alternative.&lt;br /&gt;
&lt;br /&gt;
==Products in this Category==&lt;br /&gt;
&lt;br /&gt;
* [[1014_2 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
* [[1017_1 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
* [[3051_1 - Dual Relay Board]]&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
* SPST - either normally open or normally closed. Simple on/off switch.&lt;br /&gt;
* SPDT - 3 pins, has both a NO and NC pin and can function like a SPST switch of either type, or can be used to toggle power between two different loads. &lt;br /&gt;
* DPDT - Same as SPDT but there are two controlled by the same relay input. Useful for controlling 2 seperate circuits in a synchronized manner. &lt;br /&gt;
* Potential selection criteria for specific switching circuits.&lt;br /&gt;
&lt;br /&gt;
===Contact Arcing===&lt;br /&gt;
* As the switch moves from the &amp;quot;on&amp;quot; position to the &amp;quot;off&amp;quot; position (and vice-versa) there is a moment when the arm of the switch in close enough to the contact that electricity will arc through the air, creating lots of heat and possibly damaging the contact. (Diagram would be useful)&lt;br /&gt;
* Arcing can lead to sticking, where the switch welds itself closed. If your relay is always on, it might be stuck. &lt;br /&gt;
* Arcing will be more severe with higher power loads or highly inductive loads. &lt;br /&gt;
* Arcing is expected, but can be mitigated by:&lt;br /&gt;
** For DC, feedback diode across load&lt;br /&gt;
** For AC, Snubber circuit or&lt;br /&gt;
** MOV or&lt;br /&gt;
** TVS&lt;br /&gt;
&lt;br /&gt;
===Switching Speed===&lt;br /&gt;
* Lifespan of relay is measured in number of contacts, not time in use. Faster switching -&amp;gt; shorter life.&lt;br /&gt;
* Switching is audible - you can hear the switching, which might be annoying / undesirable, or it might be good as a confirmation the system is operating.&lt;br /&gt;
* Switching speed is limited by heating in the contacts - the arcing generates heat, and switching high loads faster than the rated switching speed will cause the relay to overheat.&lt;br /&gt;
&lt;br /&gt;
===Operating Time===&lt;br /&gt;
* Time it takes for the arm of the switch to connect with the contact after being activated&lt;br /&gt;
* If 10ms is too slow, look at SSRs&lt;br /&gt;
&lt;br /&gt;
===Control Voltage===&lt;br /&gt;
* Can be controlled via digital output&lt;br /&gt;
* Relay offers isolation between load circuit and control circuit&lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Voltage===&lt;br /&gt;
* Secondary selection criteria. &lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Current===&lt;br /&gt;
* Main selection criteria.&lt;br /&gt;
* If they need to switch more than 5A DC, or 10A AC, go to SSRs&lt;br /&gt;
* Inductive loads- does the same multiplier apply as for SSRs? &lt;br /&gt;
&lt;br /&gt;
===Minimum Switching Current===&lt;br /&gt;
* A certain amount of current is needed on the LOAD side of a relay. &lt;br /&gt;
* Oxide films build up on the contacts, so this minimum is required to conduct through them.&lt;br /&gt;
* This spec determines whether or not the relay can switch a signal instead of power.&lt;br /&gt;
** If you are switching a signal rather than power, contact bounce could be a problem.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20720</id>
		<title>Mechanical Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20720"/>
		<updated>2012-06-29T21:36:45Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* How it works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[File:1017.jpg|link=]]&lt;br /&gt;
| [[File:3051.jpg|250px|link=]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are devices that can turn on or turn off the power supplied to another device, like a switch. However, instead of having a person flip the switch, mechanical relays switch when provided with a small amount of power. This allows high-power circuits to be controlled by low-power devices. &lt;br /&gt;
&lt;br /&gt;
They perform the same function as [[Solid State Relay Primer|Solid State Relays]], except they are less expensive and have a shorter lifespan.&lt;br /&gt;
You can use them to control [[LED Primer|LEDs]], heaters, appliances, and generally any powered device as long as the power you&#039;re switching falls within the limits of the relay you&#039;re using.&lt;br /&gt;
&lt;br /&gt;
Phidgets sells boards with multiple relays on them, making it easy to control many separate circuits with your computer. Some boards plug straight into your USB port, while others are designed to connect to another device, such as an Interface Kit, or any device with enough [[Digital Output Primer|Digital Outputs]].&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay.jpg|thumb|link=|300px|&#039;&#039;&#039;Mechanical Relay&#039;&#039;&#039;&amp;lt;br /&amp;gt;The switching arm and contacts of a [[#Single Pole, Double Throw (SPDT)|SPDT]] mechanical relay.]]&lt;br /&gt;
&lt;br /&gt;
Mechanical relays use an electromagnetic coil to open or close the circuit. When current runs through the input and energizes the coil, it creates a small magnetic field which either pulls the arm of the switch away from the other contact of the switch, or pushes it down to close the switch depending on the how the switch is made. A relay also serves as an isolator, because the control (input) and load (output) ends of the relay are not electrically connected. This allows you to protect the device you&#039;re using to control the relay from power surges in your application. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling a mechanical relay is as easy as turning on an LED or light bulb. By simply supplying enough power to energize the electromagnetic coil, you will be able to control a mechanical relay. A normal digital output will not be powerful enough without external components as described in the [[Digital Output Primer#Controlling a Relay with a N-Channel MOSFET| relay section of the Digital Output Primer]]. A Phidgets device with {{LinksNeeded|open collector digital outputs, (the ones you have to [{{SERVER}}/products.php?product_id=1012 provide power to]|[[Open Collector Digital Output Primer|Open Collector Digital Outputs]]}}, on the other hand, will be able to control a relay on its own. &lt;br /&gt;
Relays are often used in large quantities to turn multiple devices on and off in a particular order or timing. For example, a popular trend has been to hook up many strands of Christmas lights to multiple relays and a control system in order to make them flash in rhythm with specific music.&lt;br /&gt;
&lt;br /&gt;
Relays are designed to be controlled by a particular voltage applied to the coil.  If you buy a relay product from Phidgets with integrated electronics, this is taken care of for you- you&#039;ll be able to switch the relays via USB or with any Phidgets device with enough [[Digital Output Primer|Digital Outputs]] (see table below), depending on which relay board you buy.  If you are integrating your own relay, you&#039;ll want to keep an eye on the specifications. The relay coil is also specified for a particular current.  For example, a 5V relay might require 70mA.  If you connect this relay to a very weak source of 5V, like a digital output, the output will not be able to provide 70mA, and there will not be enough current to switch the relay.&lt;br /&gt;
&lt;br /&gt;
(table: +mechanical_relay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Mechanical Relays&#039;&#039;&#039;&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Connects to&lt;br /&gt;
! etc...&lt;br /&gt;
|-&lt;br /&gt;
| 1014_2 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 1017_1 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 3051_1 || Digital Output || ...&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The load side of the relay also requires a minimum current. This minimum load current (also called &amp;quot;wetting current&amp;quot;) is a requirement because the electricity needs to conduct through an oxide layer that has formed on the contacts of the relay. If the minimum load current requirement of your relay is too high, you won&#039;t be able to use it to switch a signal (such as the data line on an analog sensor), you&#039;ll only be able to switch power to a circuit. If you&#039;re using a relay to switch a signal, [[#Contact Bounce|contact bounce]] might also be a problem.&lt;br /&gt;
&lt;br /&gt;
====Switching Speed and High-Frequency Switching====&lt;br /&gt;
&lt;br /&gt;
Even though they use moving mechanical parts, mechanical relays switch very quickly. The amount of time it takes for current to begin flowing through the circuit from when the relay&#039;s input is activated is in the order of tens of milliseconds. For extremely time-sensitive applications that need to minimize switching delay, [[Solid State Relay Primer|Solid State Relays]] can switch as quickly as 1ms. &lt;br /&gt;
&lt;br /&gt;
You should be careful when using mechanical relays in applications that require very frequent switching. Typically, mechanical relays can only manage one contact every few seconds- any quicker and they may begin to overheat.&lt;br /&gt;
&lt;br /&gt;
==Choosing a Relay==&lt;br /&gt;
&lt;br /&gt;
Since mechanical relays are nothing more than a controllable switch, they support both AC and DC loads. &lt;br /&gt;
&lt;br /&gt;
The major deciding factor in choosing a mechanical relay is the amount of current it&#039;s capable of switching.&lt;br /&gt;
For example, the most current you can switch with the largest mechanical relay we sell is 5A DC or 10A AC. &lt;br /&gt;
If the load you&#039;re switching consumes more current than our mechanical relays can handle, take a look at our [[Solid State Relay Primer|Solid State Relays]].&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
&lt;br /&gt;
One of the major characteristics of a mechanical relay is the design of the switch inside. A switch can generally be defined by the number of &#039;&#039;&#039;poles&#039;&#039;&#039; and &#039;&#039;&#039;throws&#039;&#039;&#039; it has. The number of &amp;quot;poles&amp;quot; refers to the number of individual circuits the switch controls. The number of &amp;quot;throws&amp;quot; refers to the number of positions the switch arm can occupy. &lt;br /&gt;
&lt;br /&gt;
[[File:Switch_types.jpg|border|300px|link=]]&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Single Throw (SPST)====&lt;br /&gt;
&lt;br /&gt;
This is a simple switch with only one path for the current to follow. The relay is either designed to be &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039;. If it is normally open, the arm of the switch is held away from the contact with a spring when the relay is off and the electromagnet pulls the arm to make contact and close the switch when the relay is turned on. If it is normally closed, the arm of the switch is held to the contact when the relay is off, and the electromagnet pulls the arm away when the relay is turned on.&lt;br /&gt;
&lt;br /&gt;
While the decision to use a normally opened or normally closed relay may seem arbitrary at first, it is actually very important for certain applications. If you choose a normally closed relay, it means your load will remain powered as long as the relay coil is &#039;&#039;&#039;not&#039;&#039;&#039; powered. If some other part of your system fails, causing your relay to lose power, your load will remain powered even though it should not be. For loads that are potentially dangerous when left on (such as a heater, or a high-power load) it is best to use a normally open relay, so that in the event of a system failure, the load will remain off. On the other hand, circuits that are designed to be powered most of the time but temporarily interrupted will use less power if they use a normally closed relay. An example of this type of circuit is the radio in a car: When the engine is started, the radio circuit is momentarily switched off because the engine needs a large amount of battery power to start.&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Double Throw (SPDT)====&lt;br /&gt;
&lt;br /&gt;
[[File:relay2loads.png|thumb|link=|300px|&#039;&#039;&#039;Toggle Between Two Loads&#039;&#039;&#039;&amp;lt;br /&amp;gt;By connecting the power supply to the common terminal, and connecting a different load to the other two terminals, a relay with a SPDT switch can be used to toggle power between the two loads.&amp;lt;br /&amp;gt;[[Media:relay2loads.png|Full-size Image]]]]&lt;br /&gt;
&lt;br /&gt;
This switch has two paths for the current to follow. This type of relay is useful if you want to toggle power between two different loads, as pictured. You can also use a SPDT relay as a single pole, single throw switch, and it can function as &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039; depending on which pins (common and normally open, or common and normally closed) you connect the load to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Double Pole, Single Throw (DPST)====&lt;br /&gt;
&lt;br /&gt;
This switch functions like two SPST switches, but both switches are controlled by one coil. This type of switch is useful for keeping two loads on separate circuits while still being able to have them turn on and off in unison. &lt;br /&gt;
&lt;br /&gt;
====Double Pole, Double Throw (DPDT)====&lt;br /&gt;
&lt;br /&gt;
This switch functions the same as a SPDT switch, except there are two of them, but are both controlled by a single input on the relay. You can use this type of switch to simultaneously control two separate circuits.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
===Contact Bounce===&lt;br /&gt;
&lt;br /&gt;
As with any mechanical switch, relays are susceptible to [[Switch Primer#Bounce|contact bounce]]. This means that when the switch closes, the arm can bounce on the contact, causing the load&#039;s power to flicker slightly. This usually only matters when the application is triggered by pulses in the power signal, or for applications where meaningful data is being switched instead of power. For example, a circuit designed to increment a counter every time power is applied to its input could incorrectly interpret a bouncing relay contact as multiple switch events. Or, a circuit that uses a relay to switch an audio signal between two different paths will experience some static noise when switching if there is significant contact bounce. Check the [[Switch Primer|switch primer]] for information on how to deal with switch contact bounce. It&#039;s worth mentioning that [[Solid State Relay Primer|Solid State Relays]] don&#039;t suffer from contact bounce, because they operate without using moving mechanical parts.&lt;br /&gt;
&lt;br /&gt;
===Arcing, Interference, and Sticking===&lt;br /&gt;
&lt;br /&gt;
[[File:contact_arc.jpg|border|link=]]&lt;br /&gt;
&lt;br /&gt;
When a mechanical relay opens or closes, for the moment that the arm of the switch is very close (but not connected) to the contact, the electric current can arc through the air between the contacts.&lt;br /&gt;
This arc can cause interference with nearby electrical instruments and sensors. For example, if an unshielded cable carrying an audio signal is travelling past some relays whose contacts are arcing when they switch, the audio would contain bursts of static noise. &lt;br /&gt;
&lt;br /&gt;
This arcing can also heat up the contacts of the switch enough that they can slowly degrade away until the relay no longer functions. They could also weld together, causing the relay to stay on permanently, which means your load will be powered constantly. If this imposes safety concerns, you should install a fail-safe of some kind. For example, some sauna heaters are turned on with a mechanical relay. In the event of a relay failure, the sauna heater will remain on and continue heating the room beyond the intended temperature. However, a simple mechanical temperature sensor is installed which cuts power to the heater if the room goes beyond a certain temperature. &lt;br /&gt;
&lt;br /&gt;
Some relays are encased in a clear plastic enclosure (sometimes called &amp;quot;ice cube&amp;quot; relays), so the switch contacts can be easily inspected. By inspecting the contacts periodically, you could tell when the relay is getting near the end of its life.&lt;br /&gt;
&lt;br /&gt;
===Prolonging Relay Lifespan===&lt;br /&gt;
&lt;br /&gt;
In order to prolong the lifespan of your relay, avoid switching loads of higher voltage or current than the relay is built for, and avoid highly inductive loads, which worsen the effects of contact arcing. Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples. A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat. An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.&lt;br /&gt;
&lt;br /&gt;
Additionally,  you should avoid switching at or near the relay&#039;s maximum frequency if possible. You can think of a mechanical relay&#039;s lifespan in terms of number times switched rather than the amount of time it&#039;s used for. A relay that doesn&#039;t need to be switched very often can last a long time. If your application requires constant switching over long periods of time, it might be more cost-effective to use a [[Solid State Relay Primer|Solid State Relay]].&lt;br /&gt;
&lt;br /&gt;
====Arc Suppression ====&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay_diode.jpg|link=|thumb|300px|&#039;&#039;&#039;DC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching a DC load. An optional diode and fuse are used to protect the relay and prevent hardware damaged caused by improper wiring.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_diode.jpg|Full-sized Image]]]]&lt;br /&gt;
[[File:Mechanical_relay_mov.jpg|link=|thumb|300px|&#039;&#039;&#039;AC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching an AC load. An optional MOV or Transil diode is placed in parallel to protect the relay from voltage spikes.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_mov.jpg|Full-Sized Image]]]]&lt;br /&gt;
The main cause of failure for mechanical relays is electricity arcing across the contacts during switching. To lengthen the lifespan of your relay, you can add various circuit elements that mitigate arcing.&lt;br /&gt;
&lt;br /&gt;
For DC powered applications, one simple method of mitigating the effects of contact arcing is to place a feedback diode across the load, as pictured. This will allow some of the residual electricity in the circuit to recirculate through the load instead of contributing to the arc that forms when the switch makes the transition from closed to open. You can buy a suitable diode from any electronics distributor, like this [http://parts.digikey.com/1/parts/1850825-diode-std-rec-10a-100v-r-6-10a02-t.html Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For AC powered applications, you can put a Metal Oxide Varistor (MOV) across the load terminals of the relay in order to protect it from voltage spikes. An MOV will not remove the entire arc, but it will be helpful in circuits up to several hundred volts. You can buy an MOV from any electronics distributor, like this [http://parts.digikey.com/1/parts/714083-varistor-thermal-200v-10ka-20mm-tmov20rp200e.html MOV] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For low-voltage AC applications, a bi-directional transient voltage suppression diode (&amp;quot;transil diode&amp;quot;) that is rated for higher than the AC voltage of the circuit can be placed across the relay terminals in order to protect it from voltage spikes. You can buy one from any electronics distributor, like this [http://parts.digikey.com/1/parts/718140-transil-600w-47v-bidir-do-15-p6ke47carl.html Transil Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are inexpensive and simple devices that allow AC or DC circuits to be switched on and off using a small amount of power.&lt;br /&gt;
They come in a variety of switch formats, enabling the user to build some very clever control into a circuit. Phidgets Inc. sells boards with multiple relays that can be connected directly to USB, so they can be controlled by your program. &lt;br /&gt;
&lt;br /&gt;
Contact arcing and switch bounce can be an obstacle for some applications, but both are common problems and can be worked around fairly easily. &lt;br /&gt;
Mechanical relays don&#039;t last as long as solid state relays, but if you take care of them, they can be a good cost-effective alternative.&lt;br /&gt;
&lt;br /&gt;
==Products in this Category==&lt;br /&gt;
&lt;br /&gt;
* [[1014_2 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
* [[1017_1 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
* [[3051_1 - Dual Relay Board]]&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
* SPST - either normally open or normally closed. Simple on/off switch.&lt;br /&gt;
* SPDT - 3 pins, has both a NO and NC pin and can function like a SPST switch of either type, or can be used to toggle power between two different loads. &lt;br /&gt;
* DPDT - Same as SPDT but there are two controlled by the same relay input. Useful for controlling 2 seperate circuits in a synchronized manner. &lt;br /&gt;
* Potential selection criteria for specific switching circuits.&lt;br /&gt;
&lt;br /&gt;
===Contact Arcing===&lt;br /&gt;
* As the switch moves from the &amp;quot;on&amp;quot; position to the &amp;quot;off&amp;quot; position (and vice-versa) there is a moment when the arm of the switch in close enough to the contact that electricity will arc through the air, creating lots of heat and possibly damaging the contact. (Diagram would be useful)&lt;br /&gt;
* Arcing can lead to sticking, where the switch welds itself closed. If your relay is always on, it might be stuck. &lt;br /&gt;
* Arcing will be more severe with higher power loads or highly inductive loads. &lt;br /&gt;
* Arcing is expected, but can be mitigated by:&lt;br /&gt;
** For DC, feedback diode across load&lt;br /&gt;
** For AC, Snubber circuit or&lt;br /&gt;
** MOV or&lt;br /&gt;
** TVS&lt;br /&gt;
&lt;br /&gt;
===Switching Speed===&lt;br /&gt;
* Lifespan of relay is measured in number of contacts, not time in use. Faster switching -&amp;gt; shorter life.&lt;br /&gt;
* Switching is audible - you can hear the switching, which might be annoying / undesirable, or it might be good as a confirmation the system is operating.&lt;br /&gt;
* Switching speed is limited by heating in the contacts - the arcing generates heat, and switching high loads faster than the rated switching speed will cause the relay to overheat.&lt;br /&gt;
&lt;br /&gt;
===Operating Time===&lt;br /&gt;
* Time it takes for the arm of the switch to connect with the contact after being activated&lt;br /&gt;
* If 10ms is too slow, look at SSRs&lt;br /&gt;
&lt;br /&gt;
===Control Voltage===&lt;br /&gt;
* Can be controlled via digital output&lt;br /&gt;
* Relay offers isolation between load circuit and control circuit&lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Voltage===&lt;br /&gt;
* Secondary selection criteria. &lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Current===&lt;br /&gt;
* Main selection criteria.&lt;br /&gt;
* If they need to switch more than 5A DC, or 10A AC, go to SSRs&lt;br /&gt;
* Inductive loads- does the same multiplier apply as for SSRs? &lt;br /&gt;
&lt;br /&gt;
===Minimum Switching Current===&lt;br /&gt;
* A certain amount of current is needed on the LOAD side of a relay. &lt;br /&gt;
* Oxide films build up on the contacts, so this minimum is required to conduct through them.&lt;br /&gt;
* This spec determines whether or not the relay can switch a signal instead of power.&lt;br /&gt;
** If you are switching a signal rather than power, contact bounce could be a problem.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20719</id>
		<title>Mechanical Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Mechanical_Relay_Guide&amp;diff=20719"/>
		<updated>2012-06-29T21:35:40Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[File:1017.jpg|link=]]&lt;br /&gt;
| [[File:3051.jpg|250px|link=]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are devices that can turn on or turn off the power supplied to another device, like a switch. However, instead of having a person flip the switch, mechanical relays switch when provided with a small amount of power. This allows high-power circuits to be controlled by low-power devices. &lt;br /&gt;
&lt;br /&gt;
They perform the same function as [[Solid State Relay Primer|Solid State Relays]], except they are less expensive and have a shorter lifespan.&lt;br /&gt;
You can use them to control [[LED Primer|LEDs]], heaters, appliances, and generally any powered device as long as the power you&#039;re switching falls within the limits of the relay you&#039;re using.&lt;br /&gt;
&lt;br /&gt;
Phidgets sells boards with multiple relays on them, making it easy to control many separate circuits with your computer. Some boards plug straight into your USB port, while others are designed to connect to another device, such as an Interface Kit, or any device with enough [[Digital Output Primer|Digital Outputs]].&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay.jpg|thumb|link=|300px|&#039;&#039;&#039;Mechanical Relay&#039;&#039;&#039;&amp;lt;br /&amp;gt;The switching arm and contacts of a [[#Single Pole, Double Throw (SPDT)|SPDT]] mechanical relay.]]&lt;br /&gt;
&lt;br /&gt;
Mechanical relays use an electromagnetic coil to open or close the circuit. When current runs through the input and energizes the coil, it creates a small magnetic field which either pulls the arm of the switch away from the other contact of the switch, or pushes it down to close the switch depending on the how the switch is made. A relay also serves as an isolator, because the control (input) and load (output) ends of the relay are not electrically connected. This allows you to protect the device you&#039;re using to control the relay from power surges in your application. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling a mechanical relay is as easy as turning on an LED or light bulb. By simply supplying enough power to energize the electromagnetic coil, you will be able to control a mechanical relay. A normal digital output will not be powerful enough without external components as described in the [[Digital Output Primer#Controlling a Relay with a N-Channel MOSFET| relay section of the Digital Output Primer]]. A Phidgets device with {{LinksNeeded|open collector digital outputs, the ones you have to provide power to|[[Open Collector Digital Output Primer|Open Collector Digital Outputs]]}}, on the other hand, will be able to control a relay on its own. &lt;br /&gt;
Relays are often used in large quantities to turn multiple devices on and off in a particular order or timing. For example, a popular trend has been to hook up many strands of Christmas lights to multiple relays and a control system in order to make them flash in rhythm with specific music.&lt;br /&gt;
&lt;br /&gt;
Relays are designed to be controlled by a particular voltage applied to the coil.  If you buy a relay product from Phidgets with integrated electronics, this is taken care of for you- you&#039;ll be able to switch the relays via USB or with any Phidgets device with enough [[Digital Output Primer|Digital Outputs]] (see table below), depending on which relay board you buy.  If you are integrating your own relay, you&#039;ll want to keep an eye on the specifications. The relay coil is also specified for a particular current.  For example, a 5V relay might require 70mA.  If you connect this relay to a very weak source of 5V, like a digital output, the output will not be able to provide 70mA, and there will not be enough current to switch the relay.&lt;br /&gt;
&lt;br /&gt;
(table: +mechanical_relay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Mechanical Relays&#039;&#039;&#039;&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Connects to&lt;br /&gt;
! etc...&lt;br /&gt;
|-&lt;br /&gt;
| 1014_2 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 1017_1 || USB || ...&lt;br /&gt;
|-&lt;br /&gt;
| 3051_1 || Digital Output || ...&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The load side of the relay also requires a minimum current. This minimum load current (also called &amp;quot;wetting current&amp;quot;) is a requirement because the electricity needs to conduct through an oxide layer that has formed on the contacts of the relay. If the minimum load current requirement of your relay is too high, you won&#039;t be able to use it to switch a signal (such as the data line on an analog sensor), you&#039;ll only be able to switch power to a circuit. If you&#039;re using a relay to switch a signal, [[#Contact Bounce|contact bounce]] might also be a problem.&lt;br /&gt;
&lt;br /&gt;
====Switching Speed and High-Frequency Switching====&lt;br /&gt;
&lt;br /&gt;
Even though they use moving mechanical parts, mechanical relays switch very quickly. The amount of time it takes for current to begin flowing through the circuit from when the relay&#039;s input is activated is in the order of tens of milliseconds. For extremely time-sensitive applications that need to minimize switching delay, [[Solid State Relay Primer|Solid State Relays]] can switch as quickly as 1ms. &lt;br /&gt;
&lt;br /&gt;
You should be careful when using mechanical relays in applications that require very frequent switching. Typically, mechanical relays can only manage one contact every few seconds- any quicker and they may begin to overheat.&lt;br /&gt;
&lt;br /&gt;
==Choosing a Relay==&lt;br /&gt;
&lt;br /&gt;
Since mechanical relays are nothing more than a controllable switch, they support both AC and DC loads. &lt;br /&gt;
&lt;br /&gt;
The major deciding factor in choosing a mechanical relay is the amount of current it&#039;s capable of switching.&lt;br /&gt;
For example, the most current you can switch with the largest mechanical relay we sell is 5A DC or 10A AC. &lt;br /&gt;
If the load you&#039;re switching consumes more current than our mechanical relays can handle, take a look at our [[Solid State Relay Primer|Solid State Relays]].&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
&lt;br /&gt;
One of the major characteristics of a mechanical relay is the design of the switch inside. A switch can generally be defined by the number of &#039;&#039;&#039;poles&#039;&#039;&#039; and &#039;&#039;&#039;throws&#039;&#039;&#039; it has. The number of &amp;quot;poles&amp;quot; refers to the number of individual circuits the switch controls. The number of &amp;quot;throws&amp;quot; refers to the number of positions the switch arm can occupy. &lt;br /&gt;
&lt;br /&gt;
[[File:Switch_types.jpg|border|300px|link=]]&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Single Throw (SPST)====&lt;br /&gt;
&lt;br /&gt;
This is a simple switch with only one path for the current to follow. The relay is either designed to be &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039;. If it is normally open, the arm of the switch is held away from the contact with a spring when the relay is off and the electromagnet pulls the arm to make contact and close the switch when the relay is turned on. If it is normally closed, the arm of the switch is held to the contact when the relay is off, and the electromagnet pulls the arm away when the relay is turned on.&lt;br /&gt;
&lt;br /&gt;
While the decision to use a normally opened or normally closed relay may seem arbitrary at first, it is actually very important for certain applications. If you choose a normally closed relay, it means your load will remain powered as long as the relay coil is &#039;&#039;&#039;not&#039;&#039;&#039; powered. If some other part of your system fails, causing your relay to lose power, your load will remain powered even though it should not be. For loads that are potentially dangerous when left on (such as a heater, or a high-power load) it is best to use a normally open relay, so that in the event of a system failure, the load will remain off. On the other hand, circuits that are designed to be powered most of the time but temporarily interrupted will use less power if they use a normally closed relay. An example of this type of circuit is the radio in a car: When the engine is started, the radio circuit is momentarily switched off because the engine needs a large amount of battery power to start.&lt;br /&gt;
&lt;br /&gt;
====Single Pole, Double Throw (SPDT)====&lt;br /&gt;
&lt;br /&gt;
[[File:relay2loads.png|thumb|link=|300px|&#039;&#039;&#039;Toggle Between Two Loads&#039;&#039;&#039;&amp;lt;br /&amp;gt;By connecting the power supply to the common terminal, and connecting a different load to the other two terminals, a relay with a SPDT switch can be used to toggle power between the two loads.&amp;lt;br /&amp;gt;[[Media:relay2loads.png|Full-size Image]]]]&lt;br /&gt;
&lt;br /&gt;
This switch has two paths for the current to follow. This type of relay is useful if you want to toggle power between two different loads, as pictured. You can also use a SPDT relay as a single pole, single throw switch, and it can function as &#039;&#039;&#039;normally open&#039;&#039;&#039; or &#039;&#039;&#039;normally closed&#039;&#039;&#039; depending on which pins (common and normally open, or common and normally closed) you connect the load to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Double Pole, Single Throw (DPST)====&lt;br /&gt;
&lt;br /&gt;
This switch functions like two SPST switches, but both switches are controlled by one coil. This type of switch is useful for keeping two loads on separate circuits while still being able to have them turn on and off in unison. &lt;br /&gt;
&lt;br /&gt;
====Double Pole, Double Throw (DPDT)====&lt;br /&gt;
&lt;br /&gt;
This switch functions the same as a SPDT switch, except there are two of them, but are both controlled by a single input on the relay. You can use this type of switch to simultaneously control two separate circuits.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
===Contact Bounce===&lt;br /&gt;
&lt;br /&gt;
As with any mechanical switch, relays are susceptible to [[Switch Primer#Bounce|contact bounce]]. This means that when the switch closes, the arm can bounce on the contact, causing the load&#039;s power to flicker slightly. This usually only matters when the application is triggered by pulses in the power signal, or for applications where meaningful data is being switched instead of power. For example, a circuit designed to increment a counter every time power is applied to its input could incorrectly interpret a bouncing relay contact as multiple switch events. Or, a circuit that uses a relay to switch an audio signal between two different paths will experience some static noise when switching if there is significant contact bounce. Check the [[Switch Primer|switch primer]] for information on how to deal with switch contact bounce. It&#039;s worth mentioning that [[Solid State Relay Primer|Solid State Relays]] don&#039;t suffer from contact bounce, because they operate without using moving mechanical parts.&lt;br /&gt;
&lt;br /&gt;
===Arcing, Interference, and Sticking===&lt;br /&gt;
&lt;br /&gt;
[[File:contact_arc.jpg|border|link=]]&lt;br /&gt;
&lt;br /&gt;
When a mechanical relay opens or closes, for the moment that the arm of the switch is very close (but not connected) to the contact, the electric current can arc through the air between the contacts.&lt;br /&gt;
This arc can cause interference with nearby electrical instruments and sensors. For example, if an unshielded cable carrying an audio signal is travelling past some relays whose contacts are arcing when they switch, the audio would contain bursts of static noise. &lt;br /&gt;
&lt;br /&gt;
This arcing can also heat up the contacts of the switch enough that they can slowly degrade away until the relay no longer functions. They could also weld together, causing the relay to stay on permanently, which means your load will be powered constantly. If this imposes safety concerns, you should install a fail-safe of some kind. For example, some sauna heaters are turned on with a mechanical relay. In the event of a relay failure, the sauna heater will remain on and continue heating the room beyond the intended temperature. However, a simple mechanical temperature sensor is installed which cuts power to the heater if the room goes beyond a certain temperature. &lt;br /&gt;
&lt;br /&gt;
Some relays are encased in a clear plastic enclosure (sometimes called &amp;quot;ice cube&amp;quot; relays), so the switch contacts can be easily inspected. By inspecting the contacts periodically, you could tell when the relay is getting near the end of its life.&lt;br /&gt;
&lt;br /&gt;
===Prolonging Relay Lifespan===&lt;br /&gt;
&lt;br /&gt;
In order to prolong the lifespan of your relay, avoid switching loads of higher voltage or current than the relay is built for, and avoid highly inductive loads, which worsen the effects of contact arcing. Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples. A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat. An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.&lt;br /&gt;
&lt;br /&gt;
Additionally,  you should avoid switching at or near the relay&#039;s maximum frequency if possible. You can think of a mechanical relay&#039;s lifespan in terms of number times switched rather than the amount of time it&#039;s used for. A relay that doesn&#039;t need to be switched very often can last a long time. If your application requires constant switching over long periods of time, it might be more cost-effective to use a [[Solid State Relay Primer|Solid State Relay]].&lt;br /&gt;
&lt;br /&gt;
====Arc Suppression ====&lt;br /&gt;
&lt;br /&gt;
[[File:Mechanical_relay_diode.jpg|link=|thumb|300px|&#039;&#039;&#039;DC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching a DC load. An optional diode and fuse are used to protect the relay and prevent hardware damaged caused by improper wiring.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_diode.jpg|Full-sized Image]]]]&lt;br /&gt;
[[File:Mechanical_relay_mov.jpg|link=|thumb|300px|&#039;&#039;&#039;AC Load Protection&#039;&#039;&#039;&amp;lt;br/&amp;gt;A diagram of a mechanical relay switching an AC load. An optional MOV or Transil diode is placed in parallel to protect the relay from voltage spikes.&amp;lt;br/&amp;gt;[[Media:Mechanical_relay_mov.jpg|Full-Sized Image]]]]&lt;br /&gt;
The main cause of failure for mechanical relays is electricity arcing across the contacts during switching. To lengthen the lifespan of your relay, you can add various circuit elements that mitigate arcing.&lt;br /&gt;
&lt;br /&gt;
For DC powered applications, one simple method of mitigating the effects of contact arcing is to place a feedback diode across the load, as pictured. This will allow some of the residual electricity in the circuit to recirculate through the load instead of contributing to the arc that forms when the switch makes the transition from closed to open. You can buy a suitable diode from any electronics distributor, like this [http://parts.digikey.com/1/parts/1850825-diode-std-rec-10a-100v-r-6-10a02-t.html Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For AC powered applications, you can put a Metal Oxide Varistor (MOV) across the load terminals of the relay in order to protect it from voltage spikes. An MOV will not remove the entire arc, but it will be helpful in circuits up to several hundred volts. You can buy an MOV from any electronics distributor, like this [http://parts.digikey.com/1/parts/714083-varistor-thermal-200v-10ka-20mm-tmov20rp200e.html MOV] from Digikey.&lt;br /&gt;
&lt;br /&gt;
For low-voltage AC applications, a bi-directional transient voltage suppression diode (&amp;quot;transil diode&amp;quot;) that is rated for higher than the AC voltage of the circuit can be placed across the relay terminals in order to protect it from voltage spikes. You can buy one from any electronics distributor, like this [http://parts.digikey.com/1/parts/718140-transil-600w-47v-bidir-do-15-p6ke47carl.html Transil Diode] from Digikey.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
Mechanical relays are inexpensive and simple devices that allow AC or DC circuits to be switched on and off using a small amount of power.&lt;br /&gt;
They come in a variety of switch formats, enabling the user to build some very clever control into a circuit. Phidgets Inc. sells boards with multiple relays that can be connected directly to USB, so they can be controlled by your program. &lt;br /&gt;
&lt;br /&gt;
Contact arcing and switch bounce can be an obstacle for some applications, but both are common problems and can be worked around fairly easily. &lt;br /&gt;
Mechanical relays don&#039;t last as long as solid state relays, but if you take care of them, they can be a good cost-effective alternative.&lt;br /&gt;
&lt;br /&gt;
==Products in this Category==&lt;br /&gt;
&lt;br /&gt;
* [[1014_2 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
* [[1017_1 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
* [[3051_1 - Dual Relay Board]]&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
&lt;br /&gt;
===Switch Type===&lt;br /&gt;
* SPST - either normally open or normally closed. Simple on/off switch.&lt;br /&gt;
* SPDT - 3 pins, has both a NO and NC pin and can function like a SPST switch of either type, or can be used to toggle power between two different loads. &lt;br /&gt;
* DPDT - Same as SPDT but there are two controlled by the same relay input. Useful for controlling 2 seperate circuits in a synchronized manner. &lt;br /&gt;
* Potential selection criteria for specific switching circuits.&lt;br /&gt;
&lt;br /&gt;
===Contact Arcing===&lt;br /&gt;
* As the switch moves from the &amp;quot;on&amp;quot; position to the &amp;quot;off&amp;quot; position (and vice-versa) there is a moment when the arm of the switch in close enough to the contact that electricity will arc through the air, creating lots of heat and possibly damaging the contact. (Diagram would be useful)&lt;br /&gt;
* Arcing can lead to sticking, where the switch welds itself closed. If your relay is always on, it might be stuck. &lt;br /&gt;
* Arcing will be more severe with higher power loads or highly inductive loads. &lt;br /&gt;
* Arcing is expected, but can be mitigated by:&lt;br /&gt;
** For DC, feedback diode across load&lt;br /&gt;
** For AC, Snubber circuit or&lt;br /&gt;
** MOV or&lt;br /&gt;
** TVS&lt;br /&gt;
&lt;br /&gt;
===Switching Speed===&lt;br /&gt;
* Lifespan of relay is measured in number of contacts, not time in use. Faster switching -&amp;gt; shorter life.&lt;br /&gt;
* Switching is audible - you can hear the switching, which might be annoying / undesirable, or it might be good as a confirmation the system is operating.&lt;br /&gt;
* Switching speed is limited by heating in the contacts - the arcing generates heat, and switching high loads faster than the rated switching speed will cause the relay to overheat.&lt;br /&gt;
&lt;br /&gt;
===Operating Time===&lt;br /&gt;
* Time it takes for the arm of the switch to connect with the contact after being activated&lt;br /&gt;
* If 10ms is too slow, look at SSRs&lt;br /&gt;
&lt;br /&gt;
===Control Voltage===&lt;br /&gt;
* Can be controlled via digital output&lt;br /&gt;
* Relay offers isolation between load circuit and control circuit&lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Voltage===&lt;br /&gt;
* Secondary selection criteria. &lt;br /&gt;
&lt;br /&gt;
===Maximum (AC/DC) Switching Current===&lt;br /&gt;
* Main selection criteria.&lt;br /&gt;
* If they need to switch more than 5A DC, or 10A AC, go to SSRs&lt;br /&gt;
* Inductive loads- does the same multiplier apply as for SSRs? &lt;br /&gt;
&lt;br /&gt;
===Minimum Switching Current===&lt;br /&gt;
* A certain amount of current is needed on the LOAD side of a relay. &lt;br /&gt;
* Oxide films build up on the contacts, so this minimum is required to conduct through them.&lt;br /&gt;
* This spec determines whether or not the relay can switch a signal instead of power.&lt;br /&gt;
** If you are switching a signal rather than power, contact bounce could be a problem.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=InterfaceKit_Digital_Outputs&amp;diff=20718</id>
		<title>InterfaceKit Digital Outputs</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=InterfaceKit_Digital_Outputs&amp;diff=20718"/>
		<updated>2012-06-29T21:33:47Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
{{HiddenNeeds|This should eventually include open collector digital outputs, and their differences}}&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Digital Outputs can be used to drive LEDs, solid state relays, and transistors (or anything that will accept a CMOS signal).&lt;br /&gt;
Digital outputs can be used to control devices that accept a +5V control signal.&lt;br /&gt;
With transistors and some electronics experience, other devices can be controlled, such as buzzers, lights, larger LEDs, relays.&lt;br /&gt;
&lt;br /&gt;
==Specifications and Features==&lt;br /&gt;
&lt;br /&gt;
[[Image:digital_output.jpg|right|thumb|A Phidgets digital output.]]&lt;br /&gt;
&lt;br /&gt;
The 250 ohm resistance is internal to the PhidgetInterfaceKit 8/8/8, and limits the current that can flow through the output. &lt;br /&gt;
This is intended to protect the device from being damaged if there is a short to ground or if an LED is used. &lt;br /&gt;
Ultimately this means the maximum current output of the digital outputs is 16mA.  In practice you should not try to draw 16mA from the outputs for extended periods of time though as this can lead to damaged components.  You should try to limit your current draw to less than 5mA though up to 10 would not cause any immediate concerns.&lt;br /&gt;
The output is intended to drive TTL or CMOS inputs; it is not designed to provide power to an external circuit.&lt;br /&gt;
&lt;br /&gt;
In practice the frequency at which these outputs can be switched is highly dependent on system properties such as OS, USB hardware, and cabling.  However, it is a good bet that the majority of systems will be able to achieve 1kHz.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Ground Protection===&lt;br /&gt;
Ground terminals on the InterfaceKit share a common ground with USB ground.  &lt;br /&gt;
Because they are not internally isolated, these terminals will expose the USB ground potential of the PC to which they are connected.  &lt;br /&gt;
Be sure you are completely familiar with any circuit you intend to connect to the InterfaceKit before it is connected.  &lt;br /&gt;
If a reverse voltage or dangerously high voltage is applied to the input or output terminals, damage to the Phidget or the PC may result.&lt;br /&gt;
&lt;br /&gt;
===5 Volt Terminal Block===&lt;br /&gt;
For users who need it, we provide 5V on the terminal block next to Digital Output 7.&lt;br /&gt;
&lt;br /&gt;
==Using the Digital Outputs==&lt;br /&gt;
Here are some circuit diagrams that illustrate how to connect various devices to the digital outputs on your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Driving an LED with the Digital Output===&lt;br /&gt;
&lt;br /&gt;
[[Image:LED_digital_output.jpg|right|thumb|Schematic for connecting to an LED.]]&lt;br /&gt;
&lt;br /&gt;
Connecting an LED to a digital output is simple. Wire the anode to a digital output labeled 0 to 7 on the Interface Kit, and the cathode to a supplied ground, labeled G.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a 3052 SSR Board with a Digital Output===&lt;br /&gt;
&lt;br /&gt;
[[Image:3052_digital_output.jpg|right|thumb|Schematic for connecting a 3052 board.]]&lt;br /&gt;
&lt;br /&gt;
Setting the digital output to true causes the output of the 3052 to turn on. &lt;br /&gt;
This can be used to control AC or DC devices. &lt;br /&gt;
&lt;br /&gt;
The load can also be switched with the 3052 on the high side.  &lt;br /&gt;
High side switching is helpful for powering more complicated circuitry that cannot tolerate having multiple grounds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Output with a MOSFET based SSR===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_output_ssr.jpg|right|thumb|Schematic for isolating a digital input with an SSR.]]&lt;br /&gt;
&lt;br /&gt;
It’s possible to wire up your own Solid State Relay to the digital output.  &lt;br /&gt;
MOSFET based SSRs have the advantage that they can be understood as being a simple switch.  &lt;br /&gt;
&lt;br /&gt;
There are many other types of SSRs that are more suitable for controlling higher power, higher voltage AC devices that can also be controlled in the same fashion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Output with an Optocoupler===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_output_optocoupler.jpg|right|thumb|Schematic for isolating a digital input with an optocoupler.]]&lt;br /&gt;
&lt;br /&gt;
In some applications, particularly where there is a lot of electrical noise (automotive), or where you want maximum protection of the circuitry (interactive installations, kiosks), electrical isolation buys you a huge margin of protection.&lt;br /&gt;
Driving the LED causes the output transistor to sink current.  &lt;br /&gt;
&lt;br /&gt;
The maximum current through the transistor will depend in part on the characteristics of the optocoupler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Controlling a Relay with a N-Channel MOSFET===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_nmos.jpg|right|thumb|Schematic for using a relay with an NMOS transistor.]]&lt;br /&gt;
&lt;br /&gt;
A inexpensive mosfet and flyback diode can be used to control larger loads - relays for example - directly from the digital output.&lt;br /&gt;
Be sure to use a Logic-Level MOSFET so that the +5V Digital Output is able to turn it on.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Controlling a Relay with a NPN Transistor===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_npn.jpg|right|thumb|Schematic for using a relay with an NPN transistor.]]&lt;br /&gt;
&lt;br /&gt;
This circuit is very similar to the N-channel mosfet - but you may already have NPN transistors on hand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a 3051 Dual Relay Board with one or two Digital Outputs===&lt;br /&gt;
&lt;br /&gt;
[[Image:3051_digital_outputs.jpg|right|thumb|Schematic for using a 3051 board.]]&lt;br /&gt;
&lt;br /&gt;
The 3051 Dual Relay Board is designed to be used with the PhidgetInterfaceKit 8/8/8.  &lt;br /&gt;
An Analog Input can be used to supply power to the relays, and one or two digital outputs used to control the relays.  &lt;br /&gt;
The 3051 is a good option if you need a couple relays in your project.&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Update Rate==&lt;br /&gt;
&lt;br /&gt;
Please check the specification for the maximum rate of sampling that the Digital input can measure.  This is often slower than your program can change it.  So, if you change the output one way and then flip it back immediately in your code, the interface kit may not register the change.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20716</id>
		<title>Solid State Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20716"/>
		<updated>2012-06-29T21:31:45Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* How SSRs Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:SSR.jpg]]&lt;br /&gt;
| [[Image:3052.jpg|200px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR, so named because of its thick shape and black color. They are specifically designed to switch either AC loads or DC loads, but never both.]]&lt;br /&gt;
&lt;br /&gt;
Solid state relays (SSRs) turn on or off the power being supplied to other devices, in a similar fashion as a physical [[Switch Primer|switch]]. However, instead of being switched by human interaction like a physical switch, SSRs are switched electronically.&lt;br /&gt;
With SSRs, you can control high-current devices such as lights or appliances with low-current signals, like a standard DC signal from a [[Digital Output Primer|Digital Output]]. Most SSRs will switch on with a voltage of 3V or higher. This makes them perfect for use with Phidget [[Interface Kits]], or any device with a digital output. &lt;br /&gt;
&lt;br /&gt;
SSRs perform the same job as [[Mechanical Relay Primer|Mechanical Relays]], but have the following advantages:&lt;br /&gt;
* SSRs produce less electromagnetic interference than mechanical relays during operation. This is mostly due to the absence of a phenomenon called [[Mechanical Relay Primer#Arcing, Interference, and Sticking|contact arcing]] only present in mechanical relays, where the physical contacts of the relay tend to spark internally while switching. The reduced interference can also be attributed to the fact that SSRs do not use electromagnets to switch.&lt;br /&gt;
* The switch contacts of a mechanical relay will eventually wear down from arcing.  An SSR will have a longer life because its internals are purely digital.  Properly used, they will last for millions of cycles.&lt;br /&gt;
* SSRs turn on and off faster than mechanical relays (≈1ms compared to ≈10ms).&lt;br /&gt;
* SSRs are less susceptible to physical vibrations than mechanical relays.&lt;br /&gt;
* Since the switch inside an SSR isn&#039;t a mechanical switch, it does not suffer from [[Switch Primer#Bounce|contact bounce]] and operates silently.&lt;br /&gt;
&lt;br /&gt;
However, compared to Mechanical Relays, SSRs: &lt;br /&gt;
* Are more expensive.&lt;br /&gt;
* Will dissipate more energy in the form of heat (1-2% of the energy intended to power the load).&lt;br /&gt;
&lt;br /&gt;
==How SSRs Work==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR_Internals.png|thumb|A conceptual diagram of the insides of an SSR.]]&lt;br /&gt;
&lt;br /&gt;
The control inputs are connected internally to an LED, which shines across an air gap to light sensors.  &lt;br /&gt;
The light sensor is connected to the transistors which open or close, supplying the relay&#039;s load with power. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;closed&#039;&#039;&#039;, current can flow freely through the relay, causing the load and power supply to be connected. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;open&#039;&#039;&#039;, almost all current is blocked, causing the load to become disconnected from the power supply. &lt;br /&gt;
The pairing of an LED with light sensors is called an optocoupler, and is a common technique to link two parts of a circuit without a direct electrical connection. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling an SSR is no more complicated than turning an LED on and off. Switch it on, switch it off, it is that easy (see the [[Digital Output Primer|Digital Output Primer]], or our [{{SERVER}}/products.php?product_id=1031 specific LED controller] for more).  &lt;br /&gt;
&lt;br /&gt;
The ability of an SSR to switch a load is very similar to a [[Mechanical Relay Primer|mechanical relay]] or simple switch. &lt;br /&gt;
By turning the digital output controlling the relay on and off, you control whether or not the load is connected to its power supply.&lt;br /&gt;
&lt;br /&gt;
The challenge is to pick an appropriate type of SSR for your application. There is no single SSR perfect for all applications. To choose an SSR for your particular application, please follow the [[#Choosing an SSR|Choosing an SSR]] section.&lt;br /&gt;
&lt;br /&gt;
===Safety===&lt;br /&gt;
&lt;br /&gt;
Since relays switch high currents and voltages, standard precautions apply.  Make sure you never touch the terminals while the relay is powered. If your SSR came with a plastic cover, use it.  Even when the SSR is switched off, a very small amount of current will flow.&lt;br /&gt;
&lt;br /&gt;
When an SSR fails, it most often fails permanently closed. This is because when the transistor inside fails due to excessive current or heat, it will usually short out, allowing current to pass through unimpeded. &lt;br /&gt;
This means that as long as the power supply remains on, the load will be powered, possibly creating a fire or safety hazard.&lt;br /&gt;
&lt;br /&gt;
==Choosing an SSR==&lt;br /&gt;
&lt;br /&gt;
===Identify your voltage===&lt;br /&gt;
&lt;br /&gt;
First, determine whether you need to switch AC or DC voltage. The electrical grid, and thus your wall outlet, runs AC, whereas batteries and most small power supplies are DC.  &lt;br /&gt;
&lt;br /&gt;
Next, determine the maximum number of volts you will be switching.  If you are switching DC, particularly with batteries, assume your voltage is at least 25% more than what your battery is rated for.  Even larger fluctuations occur on AC, but AC SSRs are designed to handle these surges.  Typical AC voltage from a wall socket in North America is 110VAC, whereas in Europe it is usually 220VAC. If you are switching AC voltage from a wall socket, check which standard your country uses, and use that number as your voltage.&lt;br /&gt;
&lt;br /&gt;
===Identify your current===&lt;br /&gt;
&lt;br /&gt;
The current drawn by your load when turned on affects how large of an SSR you need, and how hot it will be when it is in use.  If you know how much current, on average, your load draws, this is what we call &#039;&#039;&#039;Average Load Current&#039;&#039;&#039;.  If you don&#039;t know the average current, but you know the wattage (power rating) of your load, you can calculate Average Load Current by:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Average Load Current} =\frac{\text{Watts}}{\text{Operating Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, you need to know the current drawn by your load when it is first turned on.  Many loads demand a huge inrush of current when the load is first turned on. This places a significant amount of stress on the electronics inside the SSR.  If you&#039;ve ever noticed the lights dimming in the house for a second when the furnace starts up, this is caused by the fan motor starting up. In the same way that it takes a lot of force to move a heavy object from rest, it initially takes a lot of current to power up a fan or incandescent bulb. It&#039;s very difficult to measure the &#039;&#039;&#039;Surge Current&#039;&#039;&#039; itself, so we use a multiplier based on your device type.  Surge Current is also referred to as &#039;&#039;&#039;inrush current&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Surge Current Multiplier&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Multiplier&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Motors || 6x&lt;br /&gt;
|-&lt;br /&gt;
| LEDs || 1x&lt;br /&gt;
|-&lt;br /&gt;
| Complex Electronics i.e., Motor Controllers, Phidgets || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures   (AC Only) || 10x&lt;br /&gt;
|-&lt;br /&gt;
| Transformers || 20x             &lt;br /&gt;
|-&lt;br /&gt;
| Heaters || 1x&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Multiply your Average Load Current by the multiplier for your device type to calculate the Surge Current.&lt;br /&gt;
&lt;br /&gt;
===I need to switch AC===&lt;br /&gt;
&lt;br /&gt;
Most AC applications will be switching 110 to 240 Volt power coming from the grid.  If that&#039;s you, go to the [[#Mains Voltage (110 to 240V AC)|Mains Voltage (110 to 240V AC)]] section.&lt;br /&gt;
&lt;br /&gt;
We also cover low voltage AC applications - 28 VAC (Volts AC) or less. For more information, visit the [[#AC/DC SSRs|AC/DC SSRs]] section.&lt;br /&gt;
&lt;br /&gt;
===I need to switch DC===&lt;br /&gt;
&lt;br /&gt;
If you only need to switch a small amount of current - 9 Amps or less, consider our compact, cost effective [[#AC/DC SSRs|AC/DC SSRs]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch more than 9 Amps, you need a serious [[#DC SSRs|DC SSR]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch up to 16 small loads of 2 Amps or less, you can use the [[Open Collector Digital Output Primer|open collector digital outputs]] on a [[1012_2 - PhidgetInterfaceKit 0/16/16|1012 PhidgetInterfaceKit 0/16/16]], which can be wired to behave similarly to relays.&lt;br /&gt;
&lt;br /&gt;
==I need Gradual Dimming==&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
==Mains Voltage (110 to 240V AC)==&lt;br /&gt;
&lt;br /&gt;
We sell AC SSRs for 120 VAC or 240 VAC operation. If you are unsure what voltages you could eventually need to switch, the 240 VAC relays can be used to switch 120 VAC with no problems.  Please note we are very conservative in how we rate SSRs - our 120 VAC relays are rated by the manufacturer for 240 VAC, and the 240 VAC for 480 VAC.  We strongly recommend against using them to the manufacturer rated voltage.  To understand why, read the [[#AC SSR Protection|AC SSR Protection]] section.&lt;br /&gt;
&lt;br /&gt;
===Load Type - Inductive vs. Resistive===&lt;br /&gt;
&lt;br /&gt;
[[Image:zero cross.png|right|thumb|300px|This graph shows the difference between zero-cross and random turn-on. The blue line represents the oscillating voltage of an AC load, and the shaded areas represent the sections when the relay is turned on and letting current pass through. As you can see, the random turn-on SSR immediately opens when activated, while the zero-cross turn-on SSR waits until the voltage crosses zero before opening.]]&lt;br /&gt;
&lt;br /&gt;
If your load is inductive, you need to choose a &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; relay.  If your load is resistive, choose a &#039;&#039;&#039;Zero Crossing&#039;&#039;&#039; relay.&lt;br /&gt;
&lt;br /&gt;
Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples.  A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat.  An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.  There is no such thing as a perfectly resistive load - but a load has to be very inductive to cause the zero crossing SSRs to malfunction.&lt;br /&gt;
&lt;br /&gt;
SSRs are designed to either turn on immediately (&#039;&#039;&#039;Random Turn On&#039;&#039;&#039;), or wait until the next &#039;alternation&#039; of the voltage (&#039;&#039;&#039;Zero Crossing&#039;&#039;&#039;).  Zero Crossing SSRs create less electromagnetic &#039;noise&#039; when they turn on.  They are best used with resistive loads - Zero Crossing SSRs are not able to turn off some inductive loads.  It&#039;s very difficult to determine which inductive loads will create problems - well beyond the scope of this document.  If your load is inductive, we recommend buying the &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; SSRs.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+ &#039;&#039;&#039;Inductive and Resistive Loads&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Load Type&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs   || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures || Inductive or Resistive &amp;lt;font size=4&amp;gt;&#039;&#039;&#039;*&#039;&#039;&#039;&amp;lt;/font&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Motors                     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Transformers               || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Heaters                    || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Computer / Electronics     || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| AC/DC power supplies (brick heavy type)     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
|AC/DC Power supplies (lightweight switchers) || Resistive&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size=4&amp;gt;&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;&amp;lt;/font&amp;gt; &#039;&#039;For fluorescent light fixtures, older units (magnetic ballast) may be inductive, and newer units are often resistive (electronic ballast).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Choosing your AC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, and your load type (inductive or resistive), you can create a short list of relays whose &lt;br /&gt;
* &#039;&#039;&#039;Maximum Load Voltage&#039;&#039;&#039; are greater than or equal to your operating voltage, &lt;br /&gt;
* &#039;&#039;&#039;Maximum Surge Current&#039;&#039;&#039; are greater than or equal to your surge current, and &lt;br /&gt;
* &#039;&#039;&#039;Load type&#039;&#039;&#039; matches what you chose for random turn on/zero crossing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +ac_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3953_0 || HFS34/D-240A20PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 8   || 15  || 20  || 255 || SCR&lt;br /&gt;
|-&lt;br /&gt;
| 3954_0 || HFS34/D-240A80PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 10  || 20  || 50  || 800 || SCR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current with no heatsink.&lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===AC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:MOV.jpg|thumb|An MOV, which comes packaged with our AC &amp;quot;Hockey Puck&amp;quot; relays. ]]&lt;br /&gt;
&lt;br /&gt;
Your AC SSR from Phidgets comes with a circular disc with two legs (pictured). This is a Metal Oxide Varistor (MOV) and should be installed across the load (larger) terminals of your SSR.  MOVs are the classic surge protector - an inexpensive component that absorbs high voltage spikes.  High voltage spikes are caused by inductive loads when they are turned off, and also happen very often on the electrical grid, as nearby devices are operated.  Even if your load is resistive, use an MOV to protect the SSR.&lt;br /&gt;
&lt;br /&gt;
Matching an MOV to an SSR is not easy - this is why we include an MOV with your SSR.  If an MOV is chosen for too low of a voltage spike, it will wear out quickly.  If it is chosen for too high of a voltage spike, it will not protect the SSR adequately.  To balance SSR protection against MOV lifetime, we have found it necessary to use SSRs built for 240 VAC in 120 VAC applications, and SSRs built for 480 VAC in 240 VAC applications.  If you must operate our AC SSRs on higher voltages than we recommend, do not use the included MOV.&lt;br /&gt;
&lt;br /&gt;
As MOVs wear out from use, they will become more sensitive to common voltage spikes, causing them to wear out quicker.  When they entirely fail, they will become a short circuit, potentially creating a fire hazard.  The MOV included with your SSR has a fuse built in which will disable the MOV when it becomes a hazard. To be on the safe side, avoid mounting your SSR near any flammable material.&lt;br /&gt;
&lt;br /&gt;
===Proportional Control SSR===&lt;br /&gt;
&lt;br /&gt;
Proportional Control Relays (often simply called &amp;quot;Control Relays&amp;quot;) are SSRs you can use to control the amount of power to the load.  Rather than reduce the voltage, or somehow limit the current - which would be very expensive solutions, the Proportional SSR reduces power by turning the load on/off quickly, feeding full power in short pulses.  &lt;br /&gt;
&lt;br /&gt;
Proportional SSRs are controlled by a variable voltage - as the control voltage increases, more power is available to the load.  Our PhidgetAnalog product can be used to control Proportional SSRs, since an [[Analog Output Primer|analog output]] can output various amounts of voltage, as opposed to a digital output, which only has two states- high and low.  We don&#039;t sell Proportional SSRs - but they can be purchased from [http://www.digikey.com Digikey], where they are called AC Linear Controlled SSRs.&lt;br /&gt;
&lt;br /&gt;
A quick and dirty solution for dimming with Phidgets is to use an [[Servo Motor and Controller Primer|RC Servo Motor]] with a PhidgetAdvancedServo controller to rotate the knob on a light dimmer.  From software, the RC Servo Motor is rotated to the desired position, cranking the knob as it turns. While this may seem like a roundabout way of achieving proportional control, dimmers tend to be much less expensive because they are less specialized and are manufactured in greater quantity.&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:AC SSR Load.png|right|thumb|300px|Schematic of an AC SSR switching a generic load. A metal oxide varistor is added across the load to protect the SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring up an AC circuit, particularly for long term installation, you may find it helpful to buy a book on residential wiring from your local hardware store.  There are many wiring conventions (and often legal codes) which will help you plan your project, and the legal codes are often a great source of wisdom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DC SSRs (0 to 50V DC)==&lt;br /&gt;
&lt;br /&gt;
We sell DC SSRs for that switch a maximum load of 50 volts. If you are unsure what voltages you could be switching in the future, higher voltage DC SSRs can be used to switch lower voltages.  Common engineering practice would be to purchase an SSR rated for 50-100% higher voltage than the voltage you plan to be switching.  For instance, if you are switching 24V, a 50V SSR is reasonable.&lt;br /&gt;
&lt;br /&gt;
===Choosing your DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +dc_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3950_0 || HFS33/D-30D50M     || DC    || N/A            || 3-32VDC || 30	     || 18  || 50  || 50  || 120  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3951_0 || HFS33/D-50D80M     || DC    || N/A            || 3-32VDC || 50           || 20  || 40  || 80  || 200  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3952_0 || HFS33/D-30D100M    || DC    || N/A            || 3-32VDC || 30           || 25  || 50  || 100 || 240  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a Heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current without a heatsink. SSRs rated for a larger load than the load you&#039;re using will be more efficient (meaning less energy lost in the form of heat) than an SSR that&#039;s being operated at its maximum load. &lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===DC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:Diode.jpg|thumb| A diode, included with our DC &amp;quot;hockey puck&amp;quot; SSRs. The cathode is marked with a line. The blue symbol shows circuit diagram equivalent of the diode.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:relaymotor.jpg|thumb| A DC SSR switching an electric motor. The 1018 Phidget InterfaceKit controls the SSR using its digital outputs. A diode is shown installed across the motor, and a fuse is hooked up between the power supply and the rest of the circuit.]]&lt;br /&gt;
&lt;br /&gt;
Your DC SSR from Phidgets comes with a diode. This diode should be installed across your load, with the Cathode installed towards the positive terminal of the power supply (as shown in the diagram).  &lt;br /&gt;
&lt;br /&gt;
If the diode is installed backwards, as soon as the SSR is turned on, the load will be shorted out, likely destroying the diode, or the SSR, or your power supply.&lt;br /&gt;
A fuse protecting your power supply is always a good idea. You can place the fuse in between the positive terminal of the power supply and the positive terminal of the load side of the SSR. &lt;br /&gt;
&lt;br /&gt;
The diode protects the SSR from powerful residual currents after the SSR is turned off.  While your load is being driven, inductance builds up magnetic fields around the wiring. &lt;br /&gt;
Every load is inductive to some degree, and when the SSR turns off, the magnetic fields will ram current against the now open SSR, easily damaging it.  The diode allows these currents to recirculate in the load until they have lost their energy. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:DC SSR Load.png|right|thumb|300px|Schematic of an DC SSR switching a generic load, which is protected by a diode connected in parallel. The circuit is protected by a fuse in series after the power supply.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a DC SSR allows them to be placed within a circuit just like a switch.  Since it is isolated, you don&#039;t have to worry about grounding or voltage offsets. &lt;br /&gt;
&lt;br /&gt;
With a DC SSR, always make sure the positive load terminal (labeled +) is facing towards the positive terminal of the power supply. If the load terminals are reversed, your load will immediately turn on. There is a diode inside of the SSR that allows current to flow freely through it when the SSR is connected incorrectly. This feature is included because this sort of wiring mistake would destroy the transistor in the DC SSR otherwise.&lt;br /&gt;
&lt;br /&gt;
The DC SSR can be installed on either side of the load, and it will work properly, but there is an advantage to installing the SSR between the power supply and the load.  If the load is connected to the power supply, it will always have a potentially dangerous voltage on it, even when it is not operating.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==AC/DC SSRs (0 to 40V DC / 0 to 28V AC)==&lt;br /&gt;
&lt;br /&gt;
[[Image:AC_DC_SSR.png|thumb|A small, versatile AC/DC SSR mounted on a Phidgets board for easy pin access.]]&lt;br /&gt;
&lt;br /&gt;
Our AC/DC SSRs are built on a small PCB, making them physically smaller than the large &amp;quot;hockey puck&amp;quot; SSRs, and less expensive.  They are limited to lower currents, and cannot be mounted on a heatsink.  &lt;br /&gt;
&lt;br /&gt;
We sell AC/DC SSRs that can switch up to 40 Volts DC or 28 Volts AC.  This is indicated on the SSR Product pages under the Maximum Load Voltage specification.  There is no lower limit on the voltages that the AC/DC SSRs can switch.  If your voltage is close - be conservative.  For instance, a 36 Volt system built from 3 Lead Acid batteries can reach 45 volts when charging.&lt;br /&gt;
&lt;br /&gt;
===Picking your AC/DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +versatile_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3052_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 2.5 || N/A || N/A || 5    || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3053_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 9   || N/A || N/A || ???  || MOSFET&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you are interested in minimum cost, you will likely choose the cheapest option that meets these criteria.  If you are interested in high efficiency operation and less heat generation, consider buying an SSR with higher current rating.&lt;br /&gt;
&lt;br /&gt;
Your AC/DC SSR from Phidgets has built in protection from static electricity, and dangerous residual currents  after the SSR is turned off.  If the load you are switching is powered by a DC source, installing a diode across the load will offer even more protection.  Refer to the [[#DC SSR Protection|DC SSR Protection]] section for more information.&lt;br /&gt;
&lt;br /&gt;
To learn more about SSRs in general, visit the [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC/DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:Versatile SSR DC Load.png|thumb|A versatile AC/DC SSR switching a DC load. The load terminals are bidirectional, so it doesn&#039;t matter which way you hook them up. The optional diode can be added to help protect the SSR when switching DC loads.]]&lt;br /&gt;
[[Image:Versatile SSR AC Load.png|thumb|A versatile AC/DC SSR switching an AC load.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a AC/DC SSR allows them to be placed within a circuit just like a switch.  Circuits without electrical isolation require a lot more care - proper grounding, careful consideration of voltage offsets.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using heatsinks with Hockey Puck SSRs==&lt;br /&gt;
&lt;br /&gt;
[[Image:3950_0 Accessories Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR with plastic cover (left), a thermal pad (right). All hockey puck SSRs sold at Phidgets come with both of these accessories plus a diode or varistor to protect the SSR.]]&lt;br /&gt;
[[Image:3955_0 Functional Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR mounted on a [[3955]] heatsink by two screws. The thermal pad is pressed between the SSR and the heatsink.]]&lt;br /&gt;
&lt;br /&gt;
SSRs will only achieve their promise of reliability and long life if they are kept cool.  Cool is relative, of course, but a good rule of thumb is to keep the metal base of the SSR at less than 85°C (185°F).  A [[Thermocouple Primer|thermocouple]] can be used to precisely measure the temperature of the metal base.&lt;br /&gt;
&lt;br /&gt;
Excess heat usually comes from too much current and too little heatsinking.  A lot of heat can also be generated by frequently turning the relay on and off.  If your relay is operated for brief periods of time, you may not need as large of a heatsink - provided the relay is never accidentally left on for extended periods.  Unless space is a concern, it&#039;s better to err on the side of caution.&lt;br /&gt;
&lt;br /&gt;
Before buying a heatsink, consider if you actually need it.  If your application is running at room temperature, and your average current is less than the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; specification of your SSR, then you don&#039;t need a heatsink.  Alternatively, if your project has a large metal chassis that the SSR can bolt to, this can be used as your heatsink.&lt;br /&gt;
&lt;br /&gt;
Each SSR suitable for use with heatsinks will include a specification of how much current it can switch with each heatsink we sell.  This specification assumes a reasonable airflow over the heatsink, and that the flowing air is at room temperature.  Our SSRs have a sheet of metal underneath, where the heat is concentrated - this is also where the heat is measured to tell if the SSR is too hot.  Phidgets includes a grey thermal pad with our Hockey Puck SSRs (see pictured). You place this pad under an SSR when mounting it on a heatsink, or on large metal surfaces that can dissipate heat.  The pad performs the same function as thermal grease - it helps conduct heat between the base of the SSR and the heatsink. If you prefer to use thermal grease, you can use it instead of the pad.  Our heatsinks include screws for mounting SSRs. Use a good size screwdriver when tightening the SSR down on the heatsink to ensure good conduction.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Product Name&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Dimensions (mm)&lt;br /&gt;
! Thermal Resistance (C/W)&lt;br /&gt;
|-&lt;br /&gt;
| 3955_0 || Small Heatsink for SSR || HF92B-80 || 50x50x80 || 2.4&lt;br /&gt;
|-&lt;br /&gt;
| 3956_0 || Large Heatsink for SSR || HF92B-150A || 55x142x150 || 0.6&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hooking up wires to the Hockey Puck SSR==&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_mov.jpg|thumb|An AC SSR with the wires attached normally and an MOV installed across the load side.]]&lt;br /&gt;
[[Image:lugs.jpg|thumb|TRM6 wiring lugs connected to a DC SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring your load to the SSR, the wire is looped clockwise around the terminal, so when the screw is tightened down, it will draw the wire in tighter.  We recommend using wires up to 10 AWG in size - any larger, and the screws will not have enough thread left to tighten down, and they will strip.  Larger wires can be attached using a wiring lug.  The lug is clamped under the SSR screw, and the wire attaches to the lug.&lt;br /&gt;
&lt;br /&gt;
Loose wire connections can generate a lot of heat - use a large enough screwdriver when clamping down the load wires to ensure that the screws are on tight enough.&lt;br /&gt;
&lt;br /&gt;
For the current ratings of various wires sizes, please see [[Page on Wire Sizes]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Did you know?==&lt;br /&gt;
&lt;br /&gt;
* Mains Voltage &#039;&#039;&#039;AC SSRs&#039;&#039;&#039; cannot switch DC. They will never turn the load off.  AC SSRs turn off twice per AC Cycle, when the current changes direction and is momentarily zero. For example, AC is 60 Hz in North America, so the AC SSR has 120 opportunities per second to turn off (the SSR will only &#039;&#039;&#039;stay&#039;&#039;&#039; off if the control signal is low).  If the SSR is operating from DC, the current will flow continuously, and the load will not turn off, even when the control input is off.&lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; turns off automatically every time the load current reaches zero. It will turn back on almost immediately as long as the signal controlling the SSR is high. An AC SSR will actually have a low, non-zero current value that it regards as &#039;zero&#039;. This specification is usually called &amp;quot;Minimum Load Current&amp;quot; in the data sheet. If your load requires less than this minimum current, your SSR will never turn on, or will not reliably turn on. The simplest solution to this problem is to connect another load in parallel with the first, increasing the Current required by the load.&lt;br /&gt;
&lt;br /&gt;
* SSR Manufacturers have started adding a simple circuit inside &#039;&#039;&#039;AC SSRs&#039;&#039;&#039;, across the load terminals, called a snubber.  The snubber absorbs very fast electrical changes that could normally cause an &#039;&#039;&#039;AC SSR&#039;&#039;&#039; to turn on accidentally. When the AC SSR is turned on, there is little voltage difference between the terminals, so the snubber has very little effect.  When the AC SSR is turned off, the snubber is actively protecting the SSR - but at a cost, as it allows a small current through the SSR, which is wasted.  &lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; uses bipolar transistors - an old technology that has been replaced by CMOS transistors in modern digital circuits.  Bipolar transistors are still superior for handling high voltages.  Bipolar transistors, and the more complex transistors built from them, will lose a constant voltage as current flows through them.  The collection of transistors in your SSR will lose about 1.7 volts - so on a 120 VAC system, you will lose about 1.5% to the SSR.  This energy converts to heat inside the SSR, and the heating from these transistors is the reason SSRs often need heatsinks.&lt;br /&gt;
&lt;br /&gt;
* SSRs, and semiconductors in general, usually fail as a short circuit. A short circuit is a circuit whose internals have been damaged such that current can flow through it freely.  This means your load will probably turn on permanently (until you disconnect the power source) - make sure this doesn&#039;t cause a safety hazard.  For instance, Sauna Heaters have a simple thermally-triggered mechanical shutdown to protect them if control electronics fails.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;DC SSRs&#039;&#039;&#039; (at least the units we sell) use Metal Oxide Semiconductor Field Effect Transistors (MOSFETs). MOSFETs do not lose a constant voltage - instead, when they turn on, they act as a very slight restriction to the flow of current - a resistor.  At low currents, the slight restriction wastes very little power, giving high efficiency and often not requiring a heatsink.  This efficiency is lost as the current increases - a doubling of current quadruples the production of heat.  &lt;br /&gt;
&lt;br /&gt;
* Normally, a MOSFET can only block current in one direction - as soon as the voltage reverses, the current flows through a diode run in parallel to the MOSFET.  If a MOSFET were used to switch AC, the load would be turned on half the time.  A common solution is to use two MOSFETs back to back - which is what we do with our &#039;&#039;&#039;AC/DC SSRs&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20715</id>
		<title>Solid State Relay Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Solid_State_Relay_Guide&amp;diff=20715"/>
		<updated>2012-06-29T21:31:29Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* How SSRs Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:SSR.jpg]]&lt;br /&gt;
| [[Image:3052.jpg|200px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR, so named because of its thick shape and black color. They are specifically designed to switch either AC loads or DC loads, but never both.]]&lt;br /&gt;
&lt;br /&gt;
Solid state relays (SSRs) turn on or off the power being supplied to other devices, in a similar fashion as a physical [[Switch Primer|switch]]. However, instead of being switched by human interaction like a physical switch, SSRs are switched electronically.&lt;br /&gt;
With SSRs, you can control high-current devices such as lights or appliances with low-current signals, like a standard DC signal from a [[Digital Output Primer|Digital Output]]. Most SSRs will switch on with a voltage of 3V or higher. This makes them perfect for use with Phidget [[Interface Kits]], or any device with a digital output. &lt;br /&gt;
&lt;br /&gt;
SSRs perform the same job as [[Mechanical Relay Primer|Mechanical Relays]], but have the following advantages:&lt;br /&gt;
* SSRs produce less electromagnetic interference than mechanical relays during operation. This is mostly due to the absence of a phenomenon called [[Mechanical Relay Primer#Arcing, Interference, and Sticking|contact arcing]] only present in mechanical relays, where the physical contacts of the relay tend to spark internally while switching. The reduced interference can also be attributed to the fact that SSRs do not use electromagnets to switch.&lt;br /&gt;
* The switch contacts of a mechanical relay will eventually wear down from arcing.  An SSR will have a longer life because its internals are purely digital.  Properly used, they will last for millions of cycles.&lt;br /&gt;
* SSRs turn on and off faster than mechanical relays (≈1ms compared to ≈10ms).&lt;br /&gt;
* SSRs are less susceptible to physical vibrations than mechanical relays.&lt;br /&gt;
* Since the switch inside an SSR isn&#039;t a mechanical switch, it does not suffer from [[Switch Primer#Bounce|contact bounce]] and operates silently.&lt;br /&gt;
&lt;br /&gt;
However, compared to Mechanical Relays, SSRs: &lt;br /&gt;
* Are more expensive.&lt;br /&gt;
* Will dissipate more energy in the form of heat (1-2% of the energy intended to power the load).&lt;br /&gt;
&lt;br /&gt;
==How SSRs Work==&lt;br /&gt;
&lt;br /&gt;
[[Image:SSR_Internals.png|thumb|A conceptual diagram of the insides of an SSR.]]&lt;br /&gt;
&lt;br /&gt;
The control inputs are connected internally to an LED, which shines across an air gap to light sensors.  &lt;br /&gt;
The light sensor is connected to the transistors which open or close, supplying the relay&#039;s load with power. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;closed&#039;&#039;&#039;, current can flow freely through the relay, causing the load and power supply to be connected. &lt;br /&gt;
When a transistor is &#039;&#039;&#039;open&#039;&#039;&#039;, almost all current is blocked, causing the load to become disconnected from the power supply. &lt;br /&gt;
The pairing of an LED with light sensors is called an optocoupler, and is a common technique to link two parts of a circuit without a direct electrical connection. &lt;br /&gt;
&lt;br /&gt;
===Basic Use===&lt;br /&gt;
&lt;br /&gt;
Controlling an SSR is no more complicated than turning an LED on and off. Switch it on, switch it off, it is that easy (see the [[Digital Output Primer|Digital Output primer]], or our [{{SERVER}}/products.php?product_id=1031 specific LED controller] for more).  &lt;br /&gt;
&lt;br /&gt;
The ability of an SSR to switch a load is very similar to a [[Mechanical Relay Primer|mechanical relay]] or simple switch. &lt;br /&gt;
By turning the digital output controlling the relay on and off, you control whether or not the load is connected to its power supply.&lt;br /&gt;
&lt;br /&gt;
The challenge is to pick an appropriate type of SSR for your application. There is no single SSR perfect for all applications. To choose an SSR for your particular application, please follow the [[#Choosing an SSR|Choosing an SSR]] section.&lt;br /&gt;
&lt;br /&gt;
===Safety===&lt;br /&gt;
&lt;br /&gt;
Since relays switch high currents and voltages, standard precautions apply.  Make sure you never touch the terminals while the relay is powered. If your SSR came with a plastic cover, use it.  Even when the SSR is switched off, a very small amount of current will flow.&lt;br /&gt;
&lt;br /&gt;
When an SSR fails, it most often fails permanently closed. This is because when the transistor inside fails due to excessive current or heat, it will usually short out, allowing current to pass through unimpeded. &lt;br /&gt;
This means that as long as the power supply remains on, the load will be powered, possibly creating a fire or safety hazard.&lt;br /&gt;
&lt;br /&gt;
==Choosing an SSR==&lt;br /&gt;
&lt;br /&gt;
===Identify your voltage===&lt;br /&gt;
&lt;br /&gt;
First, determine whether you need to switch AC or DC voltage. The electrical grid, and thus your wall outlet, runs AC, whereas batteries and most small power supplies are DC.  &lt;br /&gt;
&lt;br /&gt;
Next, determine the maximum number of volts you will be switching.  If you are switching DC, particularly with batteries, assume your voltage is at least 25% more than what your battery is rated for.  Even larger fluctuations occur on AC, but AC SSRs are designed to handle these surges.  Typical AC voltage from a wall socket in North America is 110VAC, whereas in Europe it is usually 220VAC. If you are switching AC voltage from a wall socket, check which standard your country uses, and use that number as your voltage.&lt;br /&gt;
&lt;br /&gt;
===Identify your current===&lt;br /&gt;
&lt;br /&gt;
The current drawn by your load when turned on affects how large of an SSR you need, and how hot it will be when it is in use.  If you know how much current, on average, your load draws, this is what we call &#039;&#039;&#039;Average Load Current&#039;&#039;&#039;.  If you don&#039;t know the average current, but you know the wattage (power rating) of your load, you can calculate Average Load Current by:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Average Load Current} =\frac{\text{Watts}}{\text{Operating Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, you need to know the current drawn by your load when it is first turned on.  Many loads demand a huge inrush of current when the load is first turned on. This places a significant amount of stress on the electronics inside the SSR.  If you&#039;ve ever noticed the lights dimming in the house for a second when the furnace starts up, this is caused by the fan motor starting up. In the same way that it takes a lot of force to move a heavy object from rest, it initially takes a lot of current to power up a fan or incandescent bulb. It&#039;s very difficult to measure the &#039;&#039;&#039;Surge Current&#039;&#039;&#039; itself, so we use a multiplier based on your device type.  Surge Current is also referred to as &#039;&#039;&#039;inrush current&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Surge Current Multiplier&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Multiplier&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Motors || 6x&lt;br /&gt;
|-&lt;br /&gt;
| LEDs || 1x&lt;br /&gt;
|-&lt;br /&gt;
| Complex Electronics i.e., Motor Controllers, Phidgets || 6x&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures   (AC Only) || 10x&lt;br /&gt;
|-&lt;br /&gt;
| Transformers || 20x             &lt;br /&gt;
|-&lt;br /&gt;
| Heaters || 1x&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Multiply your Average Load Current by the multiplier for your device type to calculate the Surge Current.&lt;br /&gt;
&lt;br /&gt;
===I need to switch AC===&lt;br /&gt;
&lt;br /&gt;
Most AC applications will be switching 110 to 240 Volt power coming from the grid.  If that&#039;s you, go to the [[#Mains Voltage (110 to 240V AC)|Mains Voltage (110 to 240V AC)]] section.&lt;br /&gt;
&lt;br /&gt;
We also cover low voltage AC applications - 28 VAC (Volts AC) or less. For more information, visit the [[#AC/DC SSRs|AC/DC SSRs]] section.&lt;br /&gt;
&lt;br /&gt;
===I need to switch DC===&lt;br /&gt;
&lt;br /&gt;
If you only need to switch a small amount of current - 9 Amps or less, consider our compact, cost effective [[#AC/DC SSRs|AC/DC SSRs]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch more than 9 Amps, you need a serious [[#DC SSRs|DC SSR]].&lt;br /&gt;
&lt;br /&gt;
If you need to switch up to 16 small loads of 2 Amps or less, you can use the [[Open Collector Digital Output Primer|open collector digital outputs]] on a [[1012_2 - PhidgetInterfaceKit 0/16/16|1012 PhidgetInterfaceKit 0/16/16]], which can be wired to behave similarly to relays.&lt;br /&gt;
&lt;br /&gt;
==I need Gradual Dimming==&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
==Mains Voltage (110 to 240V AC)==&lt;br /&gt;
&lt;br /&gt;
We sell AC SSRs for 120 VAC or 240 VAC operation. If you are unsure what voltages you could eventually need to switch, the 240 VAC relays can be used to switch 120 VAC with no problems.  Please note we are very conservative in how we rate SSRs - our 120 VAC relays are rated by the manufacturer for 240 VAC, and the 240 VAC for 480 VAC.  We strongly recommend against using them to the manufacturer rated voltage.  To understand why, read the [[#AC SSR Protection|AC SSR Protection]] section.&lt;br /&gt;
&lt;br /&gt;
===Load Type - Inductive vs. Resistive===&lt;br /&gt;
&lt;br /&gt;
[[Image:zero cross.png|right|thumb|300px|This graph shows the difference between zero-cross and random turn-on. The blue line represents the oscillating voltage of an AC load, and the shaded areas represent the sections when the relay is turned on and letting current pass through. As you can see, the random turn-on SSR immediately opens when activated, while the zero-cross turn-on SSR waits until the voltage crosses zero before opening.]]&lt;br /&gt;
&lt;br /&gt;
If your load is inductive, you need to choose a &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; relay.  If your load is resistive, choose a &#039;&#039;&#039;Zero Crossing&#039;&#039;&#039; relay.&lt;br /&gt;
&lt;br /&gt;
Your Load will probably be inductive if it is built around a large coil of wire - motors and transformers are typical examples.  A load considered resistive may also have loops of wire - for instance, hair dryers, toasters, incandescent bulbs use twisted wire elements to generate the heat.  An inductive load will have thousands of loops of wire - it&#039;s a matter of scale.  There is no such thing as a perfectly resistive load - but a load has to be very inductive to cause the zero crossing SSRs to malfunction.&lt;br /&gt;
&lt;br /&gt;
SSRs are designed to either turn on immediately (&#039;&#039;&#039;Random Turn On&#039;&#039;&#039;), or wait until the next &#039;alternation&#039; of the voltage (&#039;&#039;&#039;Zero Crossing&#039;&#039;&#039;).  Zero Crossing SSRs create less electromagnetic &#039;noise&#039; when they turn on.  They are best used with resistive loads - Zero Crossing SSRs are not able to turn off some inductive loads.  It&#039;s very difficult to determine which inductive loads will create problems - well beyond the scope of this document.  If your load is inductive, we recommend buying the &#039;&#039;&#039;Random Turn On&#039;&#039;&#039; SSRs.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+ &#039;&#039;&#039;Inductive and Resistive Loads&#039;&#039;&#039;&lt;br /&gt;
! Application&lt;br /&gt;
! Load Type&lt;br /&gt;
|-&lt;br /&gt;
| Incandescent Light Bulbs   || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Fluorescent Light Fixtures || Inductive or Resistive &amp;lt;font size=4&amp;gt;&#039;&#039;&#039;*&#039;&#039;&#039;&amp;lt;/font&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Motors                     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Transformers               || Inductive&lt;br /&gt;
|-&lt;br /&gt;
| Heaters                    || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| Computer / Electronics     || Resistive&lt;br /&gt;
|-&lt;br /&gt;
| AC/DC power supplies (brick heavy type)     || Inductive&lt;br /&gt;
|-&lt;br /&gt;
|AC/DC Power supplies (lightweight switchers) || Resistive&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size=4&amp;gt;&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;&amp;lt;/font&amp;gt; &#039;&#039;For fluorescent light fixtures, older units (magnetic ballast) may be inductive, and newer units are often resistive (electronic ballast).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Choosing your AC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, and your load type (inductive or resistive), you can create a short list of relays whose &lt;br /&gt;
* &#039;&#039;&#039;Maximum Load Voltage&#039;&#039;&#039; are greater than or equal to your operating voltage, &lt;br /&gt;
* &#039;&#039;&#039;Maximum Surge Current&#039;&#039;&#039; are greater than or equal to your surge current, and &lt;br /&gt;
* &#039;&#039;&#039;Load type&#039;&#039;&#039; matches what you chose for random turn on/zero crossing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +ac_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3953_0 || HFS34/D-240A20PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 8   || 15  || 20  || 255 || SCR&lt;br /&gt;
|-&lt;br /&gt;
| 3954_0 || HFS34/D-240A80PS-Y || AC    || Random Turn-on || 3-32VDC || 120          || 10  || 20  || 50  || 800 || SCR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current with no heatsink.&lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
Instead of simply turning the load on/off, if you want to dim it gradually, you can use a proportional control SSR.  They are able to reduce the average power to the load gradually, in proportion to the strength of the input signal. For more information, you can visit the [[#Proportional Control SSR|Proportional Control SSR Section]].&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===AC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:MOV.jpg|thumb|An MOV, which comes packaged with our AC &amp;quot;Hockey Puck&amp;quot; relays. ]]&lt;br /&gt;
&lt;br /&gt;
Your AC SSR from Phidgets comes with a circular disc with two legs (pictured). This is a Metal Oxide Varistor (MOV) and should be installed across the load (larger) terminals of your SSR.  MOVs are the classic surge protector - an inexpensive component that absorbs high voltage spikes.  High voltage spikes are caused by inductive loads when they are turned off, and also happen very often on the electrical grid, as nearby devices are operated.  Even if your load is resistive, use an MOV to protect the SSR.&lt;br /&gt;
&lt;br /&gt;
Matching an MOV to an SSR is not easy - this is why we include an MOV with your SSR.  If an MOV is chosen for too low of a voltage spike, it will wear out quickly.  If it is chosen for too high of a voltage spike, it will not protect the SSR adequately.  To balance SSR protection against MOV lifetime, we have found it necessary to use SSRs built for 240 VAC in 120 VAC applications, and SSRs built for 480 VAC in 240 VAC applications.  If you must operate our AC SSRs on higher voltages than we recommend, do not use the included MOV.&lt;br /&gt;
&lt;br /&gt;
As MOVs wear out from use, they will become more sensitive to common voltage spikes, causing them to wear out quicker.  When they entirely fail, they will become a short circuit, potentially creating a fire hazard.  The MOV included with your SSR has a fuse built in which will disable the MOV when it becomes a hazard. To be on the safe side, avoid mounting your SSR near any flammable material.&lt;br /&gt;
&lt;br /&gt;
===Proportional Control SSR===&lt;br /&gt;
&lt;br /&gt;
Proportional Control Relays (often simply called &amp;quot;Control Relays&amp;quot;) are SSRs you can use to control the amount of power to the load.  Rather than reduce the voltage, or somehow limit the current - which would be very expensive solutions, the Proportional SSR reduces power by turning the load on/off quickly, feeding full power in short pulses.  &lt;br /&gt;
&lt;br /&gt;
Proportional SSRs are controlled by a variable voltage - as the control voltage increases, more power is available to the load.  Our PhidgetAnalog product can be used to control Proportional SSRs, since an [[Analog Output Primer|analog output]] can output various amounts of voltage, as opposed to a digital output, which only has two states- high and low.  We don&#039;t sell Proportional SSRs - but they can be purchased from [http://www.digikey.com Digikey], where they are called AC Linear Controlled SSRs.&lt;br /&gt;
&lt;br /&gt;
A quick and dirty solution for dimming with Phidgets is to use an [[Servo Motor and Controller Primer|RC Servo Motor]] with a PhidgetAdvancedServo controller to rotate the knob on a light dimmer.  From software, the RC Servo Motor is rotated to the desired position, cranking the knob as it turns. While this may seem like a roundabout way of achieving proportional control, dimmers tend to be much less expensive because they are less specialized and are manufactured in greater quantity.&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:AC SSR Load.png|right|thumb|300px|Schematic of an AC SSR switching a generic load. A metal oxide varistor is added across the load to protect the SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring up an AC circuit, particularly for long term installation, you may find it helpful to buy a book on residential wiring from your local hardware store.  There are many wiring conventions (and often legal codes) which will help you plan your project, and the legal codes are often a great source of wisdom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DC SSRs (0 to 50V DC)==&lt;br /&gt;
&lt;br /&gt;
We sell DC SSRs for that switch a maximum load of 50 volts. If you are unsure what voltages you could be switching in the future, higher voltage DC SSRs can be used to switch lower voltages.  Common engineering practice would be to purchase an SSR rated for 50-100% higher voltage than the voltage you plan to be switching.  For instance, if you are switching 24V, a 50V SSR is reasonable.&lt;br /&gt;
&lt;br /&gt;
===Choosing your DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +dc_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3950_0 || HFS33/D-30D50M     || DC    || N/A            || 3-32VDC || 30	     || 18  || 50  || 50  || 120  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3951_0 || HFS33/D-50D80M     || DC    || N/A            || 3-32VDC || 50           || 20  || 40  || 80  || 200  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3952_0 || HFS33/D-30D100M    || DC    || N/A            || 3-32VDC || 30           || 25  || 50  || 100 || 240  || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now compare the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; value for the SSRs on your list to your Average Load Current.  If your Average Load Current is greater, you may need a heatsink.  For selecting a heatsink, please consult [[#Picking a Heatsink|Picking a Heatsink]]. Alternatively, look at other SSRs on your list - there may be an SSR that can handle your average load current without a heatsink. SSRs rated for a larger load than the load you&#039;re using will be more efficient (meaning less energy lost in the form of heat) than an SSR that&#039;s being operated at its maximum load. &lt;br /&gt;
&lt;br /&gt;
At this point, you know the SSR you need.&lt;br /&gt;
&lt;br /&gt;
If you are interested in learning more about SSRs in general, check out our [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
===DC SSR Protection===&lt;br /&gt;
&lt;br /&gt;
[[Image:Diode.jpg|thumb| A diode, included with our DC &amp;quot;hockey puck&amp;quot; SSRs. The cathode is marked with a line. The blue symbol shows circuit diagram equivalent of the diode.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:relaymotor.jpg|thumb| A DC SSR switching an electric motor. The 1018 Phidget InterfaceKit controls the SSR using its digital outputs. A diode is shown installed across the motor, and a fuse is hooked up between the power supply and the rest of the circuit.]]&lt;br /&gt;
&lt;br /&gt;
Your DC SSR from Phidgets comes with a diode. This diode should be installed across your load, with the Cathode installed towards the positive terminal of the power supply (as shown in the diagram).  &lt;br /&gt;
&lt;br /&gt;
If the diode is installed backwards, as soon as the SSR is turned on, the load will be shorted out, likely destroying the diode, or the SSR, or your power supply.&lt;br /&gt;
A fuse protecting your power supply is always a good idea. You can place the fuse in between the positive terminal of the power supply and the positive terminal of the load side of the SSR. &lt;br /&gt;
&lt;br /&gt;
The diode protects the SSR from powerful residual currents after the SSR is turned off.  While your load is being driven, inductance builds up magnetic fields around the wiring. &lt;br /&gt;
Every load is inductive to some degree, and when the SSR turns off, the magnetic fields will ram current against the now open SSR, easily damaging it.  The diode allows these currents to recirculate in the load until they have lost their energy. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:DC SSR Load.png|right|thumb|300px|Schematic of an DC SSR switching a generic load, which is protected by a diode connected in parallel. The circuit is protected by a fuse in series after the power supply.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a DC SSR allows them to be placed within a circuit just like a switch.  Since it is isolated, you don&#039;t have to worry about grounding or voltage offsets. &lt;br /&gt;
&lt;br /&gt;
With a DC SSR, always make sure the positive load terminal (labeled +) is facing towards the positive terminal of the power supply. If the load terminals are reversed, your load will immediately turn on. There is a diode inside of the SSR that allows current to flow freely through it when the SSR is connected incorrectly. This feature is included because this sort of wiring mistake would destroy the transistor in the DC SSR otherwise.&lt;br /&gt;
&lt;br /&gt;
The DC SSR can be installed on either side of the load, and it will work properly, but there is an advantage to installing the SSR between the power supply and the load.  If the load is connected to the power supply, it will always have a potentially dangerous voltage on it, even when it is not operating.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==AC/DC SSRs (0 to 40V DC / 0 to 28V AC)==&lt;br /&gt;
&lt;br /&gt;
[[Image:AC_DC_SSR.png|thumb|A small, versatile AC/DC SSR mounted on a Phidgets board for easy pin access.]]&lt;br /&gt;
&lt;br /&gt;
Our AC/DC SSRs are built on a small PCB, making them physically smaller than the large &amp;quot;hockey puck&amp;quot; SSRs, and less expensive.  They are limited to lower currents, and cannot be mounted on a heatsink.  &lt;br /&gt;
&lt;br /&gt;
We sell AC/DC SSRs that can switch up to 40 Volts DC or 28 Volts AC.  This is indicated on the SSR Product pages under the Maximum Load Voltage specification.  There is no lower limit on the voltages that the AC/DC SSRs can switch.  If your voltage is close - be conservative.  For instance, a 36 Volt system built from 3 Lead Acid batteries can reach 45 volts when charging.&lt;br /&gt;
&lt;br /&gt;
===Picking your AC/DC SSR===&lt;br /&gt;
&lt;br /&gt;
Now that you have identified your Operating Voltage, Average and Surge Current, you can create a short list of relays whose &lt;br /&gt;
* Maximum Load Voltage are greater than or equal to your operating voltage, &lt;br /&gt;
* Maximum Surge Current are greater than or equal to your surge current, and &lt;br /&gt;
* Maximum Average Current is greater than or equal to your Average current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=green&amp;gt; &amp;lt; Table: +versatile_ssr &amp;gt; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Current Type&lt;br /&gt;
! Turn-on Type&lt;br /&gt;
! Control Voltage (V)&lt;br /&gt;
! Max. Load Voltage (V)&lt;br /&gt;
! Max. Load Current Without Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3955 Heatsink (A)&lt;br /&gt;
! Max. Load Current with 3956 Heatsink (A)&lt;br /&gt;
! Max. Surge Current (A)&lt;br /&gt;
! Output Type&lt;br /&gt;
|-&lt;br /&gt;
| 3052_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 2.5 || N/A || N/A || 5    || MOSFET&lt;br /&gt;
|-&lt;br /&gt;
| 3053_0 || N/A                || AC/DC || N/A            || ???     || 40DC or 28AC || 9   || N/A || N/A || ???  || MOSFET&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you are interested in minimum cost, you will likely choose the cheapest option that meets these criteria.  If you are interested in high efficiency operation and less heat generation, consider buying an SSR with higher current rating.&lt;br /&gt;
&lt;br /&gt;
Your AC/DC SSR from Phidgets has built in protection from static electricity, and dangerous residual currents  after the SSR is turned off.  If the load you are switching is powered by a DC source, installing a diode across the load will offer even more protection.  Refer to the [[#DC SSR Protection|DC SSR Protection]] section for more information.&lt;br /&gt;
&lt;br /&gt;
To learn more about SSRs in general, visit the [[#Did you know?|&amp;quot;Did you know?&amp;quot;]] section.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example circuits with AC/DC SSRs===&lt;br /&gt;
&lt;br /&gt;
[[Image:Versatile SSR DC Load.png|thumb|A versatile AC/DC SSR switching a DC load. The load terminals are bidirectional, so it doesn&#039;t matter which way you hook them up. The optional diode can be added to help protect the SSR when switching DC loads.]]&lt;br /&gt;
[[Image:Versatile SSR AC Load.png|thumb|A versatile AC/DC SSR switching an AC load.]]&lt;br /&gt;
&lt;br /&gt;
The electrical isolation built into a AC/DC SSR allows them to be placed within a circuit just like a switch.  Circuits without electrical isolation require a lot more care - proper grounding, careful consideration of voltage offsets.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using heatsinks with Hockey Puck SSRs==&lt;br /&gt;
&lt;br /&gt;
[[Image:3950_0 Accessories Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR with plastic cover (left), a thermal pad (right). All hockey puck SSRs sold at Phidgets come with both of these accessories plus a diode or varistor to protect the SSR.]]&lt;br /&gt;
[[Image:3955_0 Functional Web.jpg|thumb|A &amp;quot;hockey puck&amp;quot; SSR mounted on a [[3955]] heatsink by two screws. The thermal pad is pressed between the SSR and the heatsink.]]&lt;br /&gt;
&lt;br /&gt;
SSRs will only achieve their promise of reliability and long life if they are kept cool.  Cool is relative, of course, but a good rule of thumb is to keep the metal base of the SSR at less than 85°C (185°F).  A [[Thermocouple Primer|thermocouple]] can be used to precisely measure the temperature of the metal base.&lt;br /&gt;
&lt;br /&gt;
Excess heat usually comes from too much current and too little heatsinking.  A lot of heat can also be generated by frequently turning the relay on and off.  If your relay is operated for brief periods of time, you may not need as large of a heatsink - provided the relay is never accidentally left on for extended periods.  Unless space is a concern, it&#039;s better to err on the side of caution.&lt;br /&gt;
&lt;br /&gt;
Before buying a heatsink, consider if you actually need it.  If your application is running at room temperature, and your average current is less than the &#039;&#039;&#039;Max. Load Current without Heatsink&#039;&#039;&#039; specification of your SSR, then you don&#039;t need a heatsink.  Alternatively, if your project has a large metal chassis that the SSR can bolt to, this can be used as your heatsink.&lt;br /&gt;
&lt;br /&gt;
Each SSR suitable for use with heatsinks will include a specification of how much current it can switch with each heatsink we sell.  This specification assumes a reasonable airflow over the heatsink, and that the flowing air is at room temperature.  Our SSRs have a sheet of metal underneath, where the heat is concentrated - this is also where the heat is measured to tell if the SSR is too hot.  Phidgets includes a grey thermal pad with our Hockey Puck SSRs (see pictured). You place this pad under an SSR when mounting it on a heatsink, or on large metal surfaces that can dissipate heat.  The pad performs the same function as thermal grease - it helps conduct heat between the base of the SSR and the heatsink. If you prefer to use thermal grease, you can use it instead of the pad.  Our heatsinks include screws for mounting SSRs. Use a good size screwdriver when tightening the SSR down on the heatsink to ensure good conduction.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
! Phidgets Product #&lt;br /&gt;
! Product Name&lt;br /&gt;
! Manufacturer Part #&lt;br /&gt;
! Dimensions (mm)&lt;br /&gt;
! Thermal Resistance (C/W)&lt;br /&gt;
|-&lt;br /&gt;
| 3955_0 || Small Heatsink for SSR || HF92B-80 || 50x50x80 || 2.4&lt;br /&gt;
|-&lt;br /&gt;
| 3956_0 || Large Heatsink for SSR || HF92B-150A || 55x142x150 || 0.6&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hooking up wires to the Hockey Puck SSR==&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_mov.jpg|thumb|An AC SSR with the wires attached normally and an MOV installed across the load side.]]&lt;br /&gt;
[[Image:lugs.jpg|thumb|TRM6 wiring lugs connected to a DC SSR.]]&lt;br /&gt;
&lt;br /&gt;
When wiring your load to the SSR, the wire is looped clockwise around the terminal, so when the screw is tightened down, it will draw the wire in tighter.  We recommend using wires up to 10 AWG in size - any larger, and the screws will not have enough thread left to tighten down, and they will strip.  Larger wires can be attached using a wiring lug.  The lug is clamped under the SSR screw, and the wire attaches to the lug.&lt;br /&gt;
&lt;br /&gt;
Loose wire connections can generate a lot of heat - use a large enough screwdriver when clamping down the load wires to ensure that the screws are on tight enough.&lt;br /&gt;
&lt;br /&gt;
For the current ratings of various wires sizes, please see [[Page on Wire Sizes]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Did you know?==&lt;br /&gt;
&lt;br /&gt;
* Mains Voltage &#039;&#039;&#039;AC SSRs&#039;&#039;&#039; cannot switch DC. They will never turn the load off.  AC SSRs turn off twice per AC Cycle, when the current changes direction and is momentarily zero. For example, AC is 60 Hz in North America, so the AC SSR has 120 opportunities per second to turn off (the SSR will only &#039;&#039;&#039;stay&#039;&#039;&#039; off if the control signal is low).  If the SSR is operating from DC, the current will flow continuously, and the load will not turn off, even when the control input is off.&lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; turns off automatically every time the load current reaches zero. It will turn back on almost immediately as long as the signal controlling the SSR is high. An AC SSR will actually have a low, non-zero current value that it regards as &#039;zero&#039;. This specification is usually called &amp;quot;Minimum Load Current&amp;quot; in the data sheet. If your load requires less than this minimum current, your SSR will never turn on, or will not reliably turn on. The simplest solution to this problem is to connect another load in parallel with the first, increasing the Current required by the load.&lt;br /&gt;
&lt;br /&gt;
* SSR Manufacturers have started adding a simple circuit inside &#039;&#039;&#039;AC SSRs&#039;&#039;&#039;, across the load terminals, called a snubber.  The snubber absorbs very fast electrical changes that could normally cause an &#039;&#039;&#039;AC SSR&#039;&#039;&#039; to turn on accidentally. When the AC SSR is turned on, there is little voltage difference between the terminals, so the snubber has very little effect.  When the AC SSR is turned off, the snubber is actively protecting the SSR - but at a cost, as it allows a small current through the SSR, which is wasted.  &lt;br /&gt;
&lt;br /&gt;
* An &#039;&#039;&#039;AC SSR&#039;&#039;&#039; uses bipolar transistors - an old technology that has been replaced by CMOS transistors in modern digital circuits.  Bipolar transistors are still superior for handling high voltages.  Bipolar transistors, and the more complex transistors built from them, will lose a constant voltage as current flows through them.  The collection of transistors in your SSR will lose about 1.7 volts - so on a 120 VAC system, you will lose about 1.5% to the SSR.  This energy converts to heat inside the SSR, and the heating from these transistors is the reason SSRs often need heatsinks.&lt;br /&gt;
&lt;br /&gt;
* SSRs, and semiconductors in general, usually fail as a short circuit. A short circuit is a circuit whose internals have been damaged such that current can flow through it freely.  This means your load will probably turn on permanently (until you disconnect the power source) - make sure this doesn&#039;t cause a safety hazard.  For instance, Sauna Heaters have a simple thermally-triggered mechanical shutdown to protect them if control electronics fails.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;DC SSRs&#039;&#039;&#039; (at least the units we sell) use Metal Oxide Semiconductor Field Effect Transistors (MOSFETs). MOSFETs do not lose a constant voltage - instead, when they turn on, they act as a very slight restriction to the flow of current - a resistor.  At low currents, the slight restriction wastes very little power, giving high efficiency and often not requiring a heatsink.  This efficiency is lost as the current increases - a doubling of current quadruples the production of heat.  &lt;br /&gt;
&lt;br /&gt;
* Normally, a MOSFET can only block current in one direction - as soon as the voltage reverses, the current flows through a diode run in parallel to the MOSFET.  If a MOSFET were used to switch AC, the load would be turned on half the time.  A common solution is to use two MOSFETs back to back - which is what we do with our &#039;&#039;&#039;AC/DC SSRs&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Phidget_SBC&amp;diff=20714</id>
		<title>OS - Phidget SBC</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Phidget_SBC&amp;diff=20714"/>
		<updated>2012-06-29T20:42:26Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:icon-Linux.png|64x64px|link=OS - Linux]]|On the Single Board Computer (SBC), Phidgets can be either plugged directly into one of the USB ports or run over a network using the [[#WebService | WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
Unlike our other supported operating systems, the SBC &#039;&#039;&#039;does not require downloads&#039;&#039;&#039; unless you are doing something advanced like loading the firmware or developing your own kernel.  You will know if you need these downloads, otherwise, the SBC should work as described on the [[1072_-_Getting_Started|SBC2 Getting Started Guide]] right out of the box.&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetsbc2.bin SBC2 Firmware]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC2 Kernel Development Package] (How-to and patch file)&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#SBC2 License]&lt;br /&gt;
&lt;br /&gt;
Note that, instead of using the firmware to update your SBC, updates should normally be done via the System -&amp;gt; Packages page on your SBC2 web interface. It is rarely necessary to completely re-flash your device.&lt;br /&gt;
&lt;br /&gt;
==Getting Started with the Phidget SBC Debian Linux==&lt;br /&gt;
&lt;br /&gt;
The Single Board Computer (SBC) is a unique Phidget.  It is a computer with a Linux operating system.  It can compile code, save files, manage background jobs, host information over the web, and more.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If this is your first time&#039;&#039;&#039; using the Phidget SBC, you will want to start with the [[1072 - Getting Started | Getting Started Guide for the SBC]].  After that, here we will get you started on topics beyond those in the getting started guide, including how to write Phidget code to run on the SBC.  You &#039;&#039;&#039;do not need this page&#039;&#039;&#039; if you are simply using the SBC to broadcast data from Phidgets over the network - it does that automatically.  We describe how to verify and use this in the [[1072 - Getting Started | Getting Started Guide]].&lt;br /&gt;
&lt;br /&gt;
This page will show you how to:&lt;br /&gt;
* Install the ability to write and develop code on the SBC itself&lt;br /&gt;
* Use the command line for basic coding tasks&lt;br /&gt;
* Troubleshoot the SBC&#039;s network&lt;br /&gt;
It will also give additional specifications, which are useful for doing more advanced things with the SBC hardware and software.&lt;br /&gt;
&lt;br /&gt;
Before reading this page, you should have done the following via the Getting Started Guide:&lt;br /&gt;
* Set up networking on your SBC, via either Ethernet or wireless&lt;br /&gt;
* Set up an admin password&lt;br /&gt;
* Learned the IP address or link local address of the SBC&lt;br /&gt;
We will use this information in setting up the libraries and drivers to use the SBC for writing and running code.&lt;br /&gt;
&lt;br /&gt;
Conceivably, you could simply use the SBC like any Linux computer, and do all of your development and compiling of Phidget code on the SBC itself.  In practice this gets complicated as the SBC does not have a keyboard or screen.  So usually, you will want to develop your code an external computer and copy files and settings over to the SBC via a network.  This makes this Getting Started section unique, in that we show you how to set up both computers:&lt;br /&gt;
* Your [[#Getting Started - External Computer | External Development Computer]], usually your main desktop or laptop which will transfer files and settings to and from the SBC&lt;br /&gt;
* The [[#Getting Started - The SBC (Debian Linux) | SBC]] itself, which needs programming language libraries to use Phidgets.&lt;br /&gt;
&lt;br /&gt;
===Getting Started - External Computer===&lt;br /&gt;
&lt;br /&gt;
You have two ways to connect to the SBC from an external computer: via the [[#SBC Web Interface|SBC Web Interface]] and over the more powerful but complex [[#SSH | Secure Shell (SSH)]].&lt;br /&gt;
&lt;br /&gt;
====SBC Web Interface====&lt;br /&gt;
&lt;br /&gt;
You have already worked extensively with the web interface in the [[1072 0 - Getting Started | Getting Started Guide for the SBC]].  This was the tool within a web browser which was opened either via the Phidget control panel on Windows, or by simply entering the IP or link local address into an internet browser.  It allowed you to set the password, set up internet connectivity, and so on.  &lt;br /&gt;
&lt;br /&gt;
This section doesn&#039;t have more information on the interface; rather, it simply serves as a reminder that you have the web interface as an available tool.  Examples, including screenshots, are placed where appropriate in this document.  The web interface will probably stay your initial go-to way to connect to the SBC, especially for tasks that benefit from graphical interaction, like setting up wireless or using the webcam.&lt;br /&gt;
&lt;br /&gt;
====SSH====&lt;br /&gt;
&lt;br /&gt;
The most flexible way to transfer files and commands to and from the SBC is via a program called &#039;&#039;&#039;ssh&#039;&#039;&#039;.  The ssh program provides command line text access over a network into the SBC.  Using it, you can run programs and give the SBC commands.  The ssh program has a companion program called &#039;&#039;&#039;scp&#039;&#039;&#039; which can copy files back and forth.  If you are unfamiliar with ssh, you can think of it like the command line or a Mac terminal, but with a remote connection to a different computer.  It is a minimal yet effective way to interact with a remote computer.&lt;br /&gt;
&lt;br /&gt;
Before connecting over ssh, you will need:&lt;br /&gt;
* The &#039;&#039;&#039;IP address&#039;&#039;&#039; (such as 168.254.3.0) or &#039;&#039;&#039;link local address&#039;&#039;&#039; (such as phidgetsbc.local) of the SBC&lt;br /&gt;
* The &#039;&#039;&#039;admin password&#039;&#039;&#039; for the SBC&lt;br /&gt;
Both of these items can be found by following the steps in the [[1072 0 - Getting Started | Getting Started Guide for the SBC]].&lt;br /&gt;
&lt;br /&gt;
You will also need to enable SSH on the SBC side.  This can be done through the [[#SBC Web Interface| Web Interface]], under {{Code|Network &amp;amp;rarr; Settings}}, by changing the &#039;&#039;SSH Server&#039;&#039; radio button to &#039;&#039;Enabled&#039;&#039; and saving your changes:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_turn_on_ssh.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
=====SSH on Windows=====&lt;br /&gt;
&lt;br /&gt;
The ssh program is not installed on Windows by default.  But, there are a variety of SSH programs available for free. One simple and commonly used program is [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY], and it has the advantage that the executable doesn&#039;t need to install, it just runs.&lt;br /&gt;
&lt;br /&gt;
With PuTTY, when you first run the program it will ask you what to connect to.  Enter the IP address or link local address of the SBC, and then click the SSH radio button right below the address, which will change the port to 22.  Then click open, and you&#039;ll have an ssh connection to the SBC open in a terminal.  It will prompt you for a user name ({{Code|root}}) and password (the admin password).&lt;br /&gt;
&lt;br /&gt;
To copy files back and forth, there is an SCP component to PuTTY, called PSCP, which is available from the same [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY download page].  Use of PSCP will be similar with the address, username, and password, except that you will be transferring files instead of sending commands.&lt;br /&gt;
&lt;br /&gt;
=====SSH on Linux and Mac OS=====&lt;br /&gt;
&lt;br /&gt;
Linux and Mac OS already have ssh installed by default.  To run ssh simply open a terminal...&lt;br /&gt;
* {{Code|Ctrl-Alt-T}} on Linux &lt;br /&gt;
* {{Code|Applications &amp;amp;rarr; Utilities &amp;amp;rarr; Terminal}} on Mac OS &lt;br /&gt;
...and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
ssh root@phidgetsbc.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have re-named your SBC, include that name instead of the {{Code|phidgetsbc.local}} link address.  Or, you can use the SBC&#039;s IP address, e.g. something like {{Code|ssh root@168.254.3.0}}&lt;br /&gt;
&lt;br /&gt;
To copy files back and forth, the command follows the form of: {{Code|scp from to}}&lt;br /&gt;
&lt;br /&gt;
So, to copy a file {{Code|/root/data.txt}} from the SBC to your local machine, type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
scp root@phidgetsbc.local:/root/data.txt .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the use of the dot &#039;&#039;&#039;.&#039;&#039;&#039; to indicate that scp should put the file in the current local directory.   If you&#039;re not sure what folder the terminal is operating in type {{Code|pwd}} to print the working directory.  Terminals usually start by default in your home folder.&lt;br /&gt;
&lt;br /&gt;
===Getting Started - The SBC (Debian Linux)===&lt;br /&gt;
&lt;br /&gt;
The SBC runs Linux, which is a full operating system. It is stripped down compared to a full desktop release of Linux, but you can compile code on it, run programs, schedule tasks, create and manage files, run a web server, and much, much more.&lt;br /&gt;
&lt;br /&gt;
At this point you have connected to the SBC via the [[#SBC Web Interface|web interface]], and probably also through [[#SSH|SSH]].  This section will help you install libraries and drivers that you probably want - i.e. support for C, Java, and Python.  After this section, you&#039;ll be well into the depths of using the SBC as a computer, and so you&#039;ll probably want to keep the [[#Using SBC Linux|Using SBC Linux section]] open for reference while you work if you are not already familiar with Linux.&lt;br /&gt;
&lt;br /&gt;
The SBC comes with the following Phidget functionality installed:&lt;br /&gt;
* The Phidget C libraries {{Code|libphidget21.so}}&lt;br /&gt;
* The Phidget [[#WebService | WebService]]&lt;br /&gt;
(If you are simply curious what these are and how they get installed, we describe the process on the [[OS - Linux | general Linux page]].)&lt;br /&gt;
&lt;br /&gt;
But to compile C programs, or run Java programs, or use Python, you will need to install these languages onto the SBC.  &lt;br /&gt;
&lt;br /&gt;
Before installing anything on the SBC, however, (even via a button on the web interface) make sure that the &#039;&#039;Include full Debian Package Repository&#039;&#039; option is checked in the web interface under {{Code|System &amp;amp;rarr; Packages}}.&lt;br /&gt;
&lt;br /&gt;
====Installing C/C++ and Java====&lt;br /&gt;
&lt;br /&gt;
The simplest way to install C/C++  and Java on the SBC is via the web interface.  There is a button under {{Code|System &amp;amp;rarr; Packages}} to install C support (including {{Code|gcc}}) and another button to install Java support:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_packages_web.png|link-|alt=]]&lt;br /&gt;
&lt;br /&gt;
Now you&#039;re ready to begin programming.  We have programming pages for both [[Language - C/C++|C/C++]] and for [[Language - Java|Java]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].  &lt;br /&gt;
&lt;br /&gt;
If you want to avoid using the [[#SSH|SSH]] interface on the SBC entirely, and you want to write your program in Java and run it continuously from boot (which is the only option if you want to avoid [[#SSH|SSH]]), we have a [[#Program in Java with the Web Interface|very in-depth section]] on that topic.&lt;br /&gt;
&lt;br /&gt;
====Installing Python====&lt;br /&gt;
&lt;br /&gt;
Installing Python has two steps.  First, you&#039;ll need to install the basic ability to run python, and then you&#039;ll need to install the Phidget Python module.  Both steps (and both options) require that you issue the relevant commands through an [[#SSH|SSH terminal]].&lt;br /&gt;
&lt;br /&gt;
=====Basic Python=====&lt;br /&gt;
&lt;br /&gt;
The base Python functionality can be downloaded and installed in one step with [[#apt|apt]] (i.e. in a terminal, type):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install python&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will give you Python, and now you just have to install the Phidget Python module to gain Phidget functionality.&lt;br /&gt;
&lt;br /&gt;
=====Install Phidget Python Method 1: Use a USB Key=====&lt;br /&gt;
&lt;br /&gt;
Copy the [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Python Libraries] onto a USB key.  Unpack the zip file into a folder on the USB key.  Insert the key into the SBC.&lt;br /&gt;
&lt;br /&gt;
You will have to figure out where the USB key (and the Phidget Python library folder) is now located.  We describe how in the general [[#Using USB Data Keys | Using USB Data Keys]] section.&lt;br /&gt;
&lt;br /&gt;
After you know the place where the USB key is mounted, in a terminal go to that directory (e.g. type {{Code|cd /media/usb0/}}), enter the unpacked Phidget Python Library folder, and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, you&#039;re ready to begin writing Python code for the SBC.  For more help on writing and using Python with Phidgets, we have an whole [[Language - Python | page on that topic]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].&lt;br /&gt;
&lt;br /&gt;
=====Install Phidget Python Method 2: Use the Internet=====&lt;br /&gt;
&lt;br /&gt;
Rather than using a USB key to transfer the file, the SBC can download it directly from the internet.  You will need {{Code|wget}} and {{Code|unzip}} installed, both of which are small:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install wget&lt;br /&gt;
apt-get install unzip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the web link address for the [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Python Libraries].&lt;br /&gt;
&lt;br /&gt;
In an SSH terminal to the SBC, type: {{Code|wget http://www.python_library_link}} where instead of http://www.python_library_link you insert the link you just copied. Copying into a terminal can usually be done via the right-click menu.&lt;br /&gt;
&lt;br /&gt;
This will download the Phidget python libraries to the folder you ran the {{Code|wget}} command in.  Unzip the downloaded file using the command {{Code|unzip file}}, where file is the filename from {{Code|wget}}. Or try typing {{Code|ls}} to list the names of a file in the directory, which should include the unzipped folder.  Enter the unzipped folder (e.g. use {{Code|cd}} to change directory), and install the Phidget Python libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, you&#039;re ready to begin writing Python code for the SBC.  For more help on writing and using Python with Phidgets, we have a whole [[Language - Python | page on that topic]].  Remember that if you&#039;re unfamiliar with Linux, we have help on using files and running programs automatically in the [[#Using SBC Linux|Using SBC Linux section]].&lt;br /&gt;
&lt;br /&gt;
====Installing Other Languages====&lt;br /&gt;
&lt;br /&gt;
You may also be able to program on the SBC using [[Language - Ruby|Ruby]] and [[Language - C Sharp|C# under Mono]], though we do not offer in-depth support for these languages on the SBC.  The installation procedures should more or less follow that of [[#Installing Python|installing python]] on the SBC, except you will be installing Ruby or Mono.  Performing package searches using [[#apt|apt cache search]] can help you find the relevant software.&lt;br /&gt;
&lt;br /&gt;
For C#, as of 2012 the {{Code|mono-complete}} package is broken on the Debian Squeeze repository.  Rather, you have to install the Mono runtime and Mono compiler separately.&lt;br /&gt;
&lt;br /&gt;
To install the runtime package (and its dependencies), use [[#apt|apt]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-runtime&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to install the C# compiler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-gmcs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or the Visual Basic compiler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install mono-vbnc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, the system and library packages do not link correctly for the version 2.0 of Mono.  If this is the case, your code will compile fine, but when you try to run it, you will get an error like:&lt;br /&gt;
&lt;br /&gt;
:{{Code|The assembly mscorlib.dll was not found or could not be loaded.}}&lt;br /&gt;
:{{Code|It should have been installed in the `/usr/lib/mono/1.0/mscorlib.dll&#039; directory.}}&lt;br /&gt;
&lt;br /&gt;
In this case, you need to install these two packages:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install libmono-corlib1.0-cil&lt;br /&gt;
apt-get install libmono-system1.0-cil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we found these packages to work by working through the tree structure.  As a general rule, you can find these dependencies by using install (here, {{Code|apt-get install mono-complete}}) to get a sense of the package tree structure.  This will possibly tell you that the packages are broken, but at the same time this will list the dependencies of the packages.  Trying to install individual dependencies will show you that although a root-package fails, the sub-packages will sometimes succeed, and install what you need.&lt;br /&gt;
&lt;br /&gt;
If you want to use a specific dll or library that is not available in this reduced version of mono, you can install mono complete by switching from Emdebian+Debian to just Debian.  To do this:&lt;br /&gt;
&lt;br /&gt;
In {{Code|/etc/apt/preferences}} make the following changes:&lt;br /&gt;
:{{Code|Package: *}}&lt;br /&gt;
:{{Code|&amp;lt;nowiki&amp;gt;Pin: release a=stable&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
:{{Code|Pin-Priority: 1010}}&lt;br /&gt;
	&lt;br /&gt;
In {{Code|/etc/apt/sources.list/mutistrap-debian.list}} remove the emdebian line.&lt;br /&gt;
&lt;br /&gt;
Apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get dist-upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many packages will be &#039;downgraded&#039; from the emdebian to debian versions.  Delete the {{Code|&amp;lt;nowiki&amp;gt;/etc/apt/preferences&amp;lt;/nowiki&amp;gt;}} file and install mono-complete:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install monodoc-http mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose monodoc-http explicitly, because otherwise the install fails on monodoc-browser.&lt;br /&gt;
&lt;br /&gt;
After this process, you can compile your C# Code.cs Phidget source file the same way as on a generic [[Language - C Sharp#Linux|Linux with Mono]] system.  Please refer to that page on how to obtain the *.dll Phidget resource file and compile your code.  On the SBC, however, because you are already running as root (the Super User), you do not need &#039;sudo&#039; and indeed the SBC will give you an error if you use it.  Instead, compiling and running will look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Code.cs -r:Phidget21.NET.dll&lt;br /&gt;
mono Code.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using SBC Linux==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve set up communication with the SBC, and installed whichever programming language support you need, you&#039;re probably ready for a short tour of useful tools on the SBC&#039;s version of Linux.&lt;br /&gt;
&lt;br /&gt;
First, you will by default be running on the SBC as &#039;&#039;&#039;root&#039;&#039;&#039;, which is the super-user.  For Linux users, this probably makes you nervous because you know you can overwrite important system files without the system asking for additional permission.  As a Windows or Mac OS user - although you may usually run your computer as an administrator - your familiar system usually prompts you to confirm before you do anything really dangerous, and this will &#039;&#039;&#039;not&#039;&#039;&#039; happen on the SBC as the root user.&lt;br /&gt;
&lt;br /&gt;
Next, there is no installed help on the SBC.  Help on Linux is usually called &#039;man pages&#039; which is short for &#039;the manual pages&#039;.  On a full Linux system, usually if you need help with any command you can type, for example, {{Code|man ls}} and it will give you help with the program [[#ls|ls]].  But these help pages take up significant space, and they are widely available online.  So, if you need more help with a certain command, you can always type {{Code|man command}} into your favourite search engine.&lt;br /&gt;
&lt;br /&gt;
Finally, the SBC has no windowing system.  For Linux users, this means no X-windows (Gnome, KDE, etc).  And as a Windows or Mac user, you can think of it as running all of your programs and commands through the terminal or DOS prompt command line.  The SBC provides all of the functionality of an operating system (e.g. process scheduling, file management, etc) but without any graphical interface.  The only exception is the [[#SBC Web Interface|web interface]], which gives graphical access to a limited part of what the SBC can do.&lt;br /&gt;
&lt;br /&gt;
===Some Useful Commands===&lt;br /&gt;
&lt;br /&gt;
If you are doing more with the SBC than simply running pre-written programs [[#Writing a Phidget Program|in Java to run continuously from boot]], you will be interacting with the SBC&#039;s Linux operating system over the command line by using [[#SSH|SSH]].  This section discusses useful programs already installed on the SBC, and how to run them on the command line.&lt;br /&gt;
&lt;br /&gt;
====ls====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ls&#039;&#039;&#039; program lists the contents of a directory.&lt;br /&gt;
&lt;br /&gt;
It will show both files and folders, but not files that start with a &amp;quot;.&amp;quot; (these are hidden files on Linux).&lt;br /&gt;
*If you also want to show hidden files, use {{Code|ls -a}}&lt;br /&gt;
*If you want more information, such as size and date modified, use {{Code|ls -l}}&lt;br /&gt;
*Commands can be combined, like {{Code|ls -al}}&lt;br /&gt;
&lt;br /&gt;
====cd====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;cd&#039;&#039;&#039; program changes to a new directory.&lt;br /&gt;
&lt;br /&gt;
For example, {{Code|cd /root}} changes into the directory at the base of the file tree called &#039;&#039;root&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
* Linux uses forward slashes&lt;br /&gt;
* The base of all directories is &amp;quot;/&amp;quot; (not &amp;quot;C:\&amp;quot;)&lt;br /&gt;
* The tilde symbol (~) is short for your home directory (i.e. when you are root, this is short for &amp;quot;/root&amp;quot;)&lt;br /&gt;
* The double dot &amp;quot;..&amp;quot; means move one directory higher (for example from {{Code|/root/data/}} to {{Code|/root/}})&lt;br /&gt;
&lt;br /&gt;
====pwd====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;pwd&#039;&#039;&#039; program prints the current directory you are working in.  (&#039;P&#039;rint &#039;W&#039;orking &#039;D&#039;irectory)&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
:{{Code|root@phidgetsbc:~# pwd}}&lt;br /&gt;
:{{Code|/root}}&lt;br /&gt;
&lt;br /&gt;
====cp, mv, and rm====&lt;br /&gt;
&lt;br /&gt;
These programs are copy (&#039;&#039;&#039;cp&#039;&#039;&#039;), move (&#039;&#039;&#039;mv&#039;&#039;&#039;), and remove (&#039;&#039;&#039;rm&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Copy copies a file from one location and pastes it to another.&lt;br /&gt;
&lt;br /&gt;
For example, if you have a file {{Code|data.txt}}, typing {{Code|cp data.txt data_backup.txt}} will put a copy of the file {{Code|data.txt}} into {{Code|data_backup.txt}}&lt;br /&gt;
&lt;br /&gt;
Move moves a file (this is also useful for renaming files) to a new destination.&lt;br /&gt;
&lt;br /&gt;
For example, if you have a file {{Code|data.txt}}, typing {{Code|mv data.txt data_backup.txt}} will put the contents of {{Code|data.txt}} into {{Code|data_backup.txt}}, and then will remove {{Code|data.txt}}.&lt;br /&gt;
&lt;br /&gt;
Remove deletes a file.&lt;br /&gt;
&lt;br /&gt;
For example, typing {{Code|rm data.txt}} will delete {{Code|data.txt}}.&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;&#039;rm&#039;&#039;&#039; is final.  Once you remove a file using {{Code|rm}}, it is gone forever.  There is no recycle bin, no temporary trash, nothing other than backups you may have personally created in the past!&lt;br /&gt;
&lt;br /&gt;
Directories can only be removed with {{Code|rmdir}}, and then only if they are empty.  If you want to remove a directory and all the files in it, use {{Code|rm -rf directory}} but be &#039;&#039;&#039;very, very careful&#039;&#039;&#039; with this command.  Trying to remove everything within a directory (e.g. {{Code|rm -rf *}}) is one of the most dangerous commands you can run on a Linux system, as running it from the wrong directory will result in Linux happily removing everything under that directory -- which could be your entire filesystem.&lt;br /&gt;
&lt;br /&gt;
====find====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;find&#039;&#039;&#039; program does what it says - it finds things.  &lt;br /&gt;
&lt;br /&gt;
Unfortunately for the casual user, the find program is very flexible and powerful, and thus not especially intuitive to use.  But, here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;15px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! SSH Command&lt;br /&gt;
! What it Does&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|find folder -name file.txt}}&lt;br /&gt;
| Looks for all files in a folder (/ for root - or all - folders) with a certain name (* for wildcard)&lt;br /&gt;
| {{Code|find / -name *.jpg}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|find folder -mtime +X}}&lt;br /&gt;
| Looks for all files in a folder modified less than X days ago&lt;br /&gt;
| {{Code|find /root -mtime +30}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====grep====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; program takes text input and searches for a term. &lt;br /&gt;
&lt;br /&gt;
For example, if you type {{Code|mount}} to view what devices are mounted (e.g. loaded) on your SBC, you will see:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may be a lot of information you don&#039;t need.  If you are only interested in a USB key attachment (as described in the [[#Using USB Data Keys|Using USB Data Keys]] section), you can use grep to filter that one response:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount | grep sda1&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====nano====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;nano&#039;&#039;&#039; program is a small text editor that you can use within an SSH terminal. &lt;br /&gt;
&lt;br /&gt;
Nano can be surprisingly useful for writing short lengths of code right on the SBC, so there is no need to transfer files and keep track of different file versions on different computers.&lt;br /&gt;
&lt;br /&gt;
Nano has all keyboard commands which are listed at the bottom of the screen at all times as a reminder (Ctrl-O to save, Ctrl-X to exit, these expand with a larger terminal window).  And, nano provides what is called &#039;syntax highlighting&#039;, which colours reserved keywords, comments, strings, and so on as appropriate to the programming language you are using.  Nano detects the programming language via the extension of the file ({{Code|.java}} for Java, {{Code|.c}} for C/C++, and {{Code|.py}} for Python).&lt;br /&gt;
&lt;br /&gt;
Typing {{Code|nano test.py}} on an SSH command line and then entering a few lines of Python into the new empty file results in:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_nano_python.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
====apt====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apt&#039;&#039;&#039; program allows you to install, uninstall, upgrade, and search software available for the SBC.&lt;br /&gt;
For a non-Linux user, the apt framework may be daunting at first, but it actually allows you to keep your system up to date and install and manage software quickly, easily, and for free.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Before installing anything on the SBC, make sure that the &#039;&#039;Include full Debian Package Repository&#039;&#039; option is checked in the web interface under {{Code|System &amp;amp;rarr; Packages}}.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;15px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! SSH Command&lt;br /&gt;
! What it Does&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|apt-cache search term}}&lt;br /&gt;
| Looks for all programs (packages) that have {{Code|term}} in the title or description&lt;br /&gt;
| {{Code|apt-cache search opencv}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|apt-cache show package}}&lt;br /&gt;
| Shows a lot of data about {{Code|package}} including size, version, etc&lt;br /&gt;
| {{Code|apt-cache show unzip}}&lt;br /&gt;
|- &lt;br /&gt;
| {{Code|apt-get update}}&lt;br /&gt;
| Gets the most recent listing of available software&lt;br /&gt;
| {{Code|apt-get update}}  (No options)&lt;br /&gt;
|-&lt;br /&gt;
| {{Code|apt-get install program}}&lt;br /&gt;
| Installs {{Code|program}} from the internet&lt;br /&gt;
| {{Code|apt-get install python}}&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====mount====&lt;br /&gt;
&lt;br /&gt;
The program {{Code|mount}} shows you all of the mounted devices on your SBC.  &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the non-Linux user, the concept of a device may be quite strange.  To give a short summary, everything on Linux that you can read or write is a file.  Webcams are files (i.e. you can &#039;read&#039; photos from them), USB keys are files, and each filesystem (tmp storage, the kernel portion, the main filesystem) are also themselves files.  These files specify what and how something can be written.  These are not necessarily linear, for example, you can see above that the USB key ({{Code|/media/usb0}} is mounted &#039;&#039;within&#039;&#039; the root file system {{Code|rootfs}} which is /.   &lt;br /&gt;
&lt;br /&gt;
So mount gives you an idea of what devices have been &#039;mounted&#039; for reading or writing, and how you can read and write to them.  More information on mount (and its various forms, like {{Code|umount}}) is available widely around the Internet.&lt;br /&gt;
&lt;br /&gt;
====which====&lt;br /&gt;
&lt;br /&gt;
The program {{Code|which}} tells you if and where a program is installed.&lt;br /&gt;
&lt;br /&gt;
For example, on a default SBC, typing {{Code|which python}} will return no results.  But after successfully [[#Installing Python | installing python]], it will return {{Code|/usr/bin/python}} as the location of the python program/binary/executable.&lt;br /&gt;
&lt;br /&gt;
===Some Useful Commands to Install===&lt;br /&gt;
&lt;br /&gt;
These are other programs you may find useful on the command line.  Although they are not on the SBC by default, these and other programs can usually be installed simply by using [[#apt|apt-get install]], with the exception of gcc.  For example, {{Code|apt-get install wget}} will download and install [[#wget|wget]].  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This section and the section on [[#Some Useful Commands|pre-installed commands]] can hardly cover all of the complexities and power of the Linux operating system.  There are many excellent tutorials online, and between them and using [[#apt|apt]] to find and install programs you should be able to learn a lot and perform any number of complex useful tasks.&lt;br /&gt;
&lt;br /&gt;
====gcc====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;gcc&#039;&#039;&#039; program is the C compiler for Linux.&lt;br /&gt;
&lt;br /&gt;
If you are an experienced C/C++ user on Mac or Linux, or if you&#039;ve already read our [[Language - C/C++ | C Language page]], you might think you need to install gcc via {{Code|apt-get}} to compile C code.  However, gcc is not in the package repository for the SBC, so {{Code|apt-get install gcc}} will fail.  Rather, to install gcc, you can do it via the web interface, as described in the [[#Installing C/C++ and Java|Installing C/C++ and Java]] section.&lt;br /&gt;
&lt;br /&gt;
After installing it via the SBC web interface, you can use {{Code|gcc}} normally.&lt;br /&gt;
&lt;br /&gt;
====less====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;less&#039;&#039;&#039; program displays the contents of a text or source code file.  When displaying the file, {{Code|less}} allows you to scroll up and down to read it.&lt;br /&gt;
&lt;br /&gt;
This is useful if you are writing your sensor readings to a data file, and you want to read the data file while it is being written by your main code.  If your data file is called {{Code|data.txt}}, you can type {{Code|less data.txt}} and see the lines in the file, and what they are.&lt;br /&gt;
&lt;br /&gt;
The {{Code|less}} program output can also be piped into another program.  For example, you can use {{Code|less}} and the word search program {{Code|grep}} to find lines within a file with a search term.  For instance, if you have a C source code file {{Code|Program.c}} on the SBC, and you want to see all the lines in {{Code|Program.c}} that contain a variable name {{Code|var}}, you can type: &lt;br /&gt;
:&amp;lt;code&amp;gt;less Program.c | grep var&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====wget====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;wget&#039;&#039;&#039; program allows you to get an online file (over http) and download it to the SBC.&lt;br /&gt;
&lt;br /&gt;
For example, to get the source file (HTML) from the Phidgets home page, you can type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
wget http://www.phidgets.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is most useful for downloading libraries, drivers, or anything (zip, tar, etc) you need from the web which is not available by [[#apt|using apt]].&lt;br /&gt;
&lt;br /&gt;
===Writing a Phidget Program===&lt;br /&gt;
&lt;br /&gt;
We provide two ways to write and upload a Phidget Program:&lt;br /&gt;
# The [[#SBC Web Interface|web interface]]:&lt;br /&gt;
#* This is useful for simple projects written in Java that you want to start only at boot&lt;br /&gt;
#* You can also use C projects, but they must be compiled off the SBC for an ARM processor&lt;br /&gt;
# Over [[#SSH|SSH]], which will allow you to write or transfer source code directly to and from the SBC&lt;br /&gt;
#* This is useful for all other projects, such as:&lt;br /&gt;
#** Projects that run at scheduled times (e.g. once per minute)&lt;br /&gt;
#** Projects that use languages other than Java or ARM-compiled C&lt;br /&gt;
Note that you can still run an [[#SSH|SSH]] project at boot, you just have to write and install a startup script.  This is a bit complex, but we do have an example that starts the program {{Code|phidgetwebservice21}} [[OS - Linux#As A Service|at boot using a script]].&lt;br /&gt;
&lt;br /&gt;
Once you know which method you&#039;d like to use, you can continue on to learn how to [[#Program in Java with the Web Interface|Program in Java with the Web Interface]], or how to [[#Program with SSH|Program with SSH]] using Java, C, or Python.  If you are actually typing in source code on the SBC, you&#039;ll find our [[#Developing Code on the SBC|developing code on the SBC section]] useful.&lt;br /&gt;
&lt;br /&gt;
====Program in Java with the Web Interface====&lt;br /&gt;
&lt;br /&gt;
To show how to write, compile, and install Java programs on the SBC, we&#039;ll use the [[Language - Java|Java Hello World]] example code.  You can download the HelloWorld example by downloading the whole [{{SERVER}}/downloads/examples/JavaJNI.zip Java example package].  Make sure you have [[#Installing C/C++ and Java|Java installed on the SBC]].&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to get the HelloWorld code running on the SBC.  On your external computer:&lt;br /&gt;
&lt;br /&gt;
1. Download the SBC version of the Phidget Java libraries ({{Code|phidget21.jar}}).  You can download this from the [[#SBC Web Interface|web interface]], on the page under {{Code|Projects &amp;amp;rarr; Projects}}, under the &#039;&#039;&#039;Notes&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
2. Place the SBC version of {{Code|phidget21.jar}} into a directory on your external computer.  This will be your working directory that you will use to compile the Java files.&lt;br /&gt;
&lt;br /&gt;
3. Also copy the {{Code|HelloWorld.java}} file into that working directory.&lt;br /&gt;
&lt;br /&gt;
4. Compile the {{Code|HelloWorld.java}} file from within that working directory.  From the command line prompt on Windows, this will be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
In a terminal on Linux or Mac OS, this will be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. You should now have three compiled class files: {{Code|HelloWorld.class}}, {{Code|HelloWorld$1.class}}, and {{Code|HelloWorld$2.class}}.  You don&#039;t need to try and run them, and if you do you may encounter an error because the SBC {{Code|phidget21.jar}} may be slightly different than the Phidget support you have installed on your external computer.&lt;br /&gt;
&lt;br /&gt;
Now we move onto the SBC:&lt;br /&gt;
&lt;br /&gt;
6. Create a new project on the SBC, in the web interface under {{Code|Projects &amp;amp;rarr; Projects}}.  Call it HelloWorld:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_create_project.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
7. On the next screen, you will be prompted to upload your files.  We will upload the three Java class files, and then click the {{Code|Start}} button:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_web_run_project.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
8. You&#039;ll note that as it runs, there are two links below the {{Code|Stop}} button: One called {{Code|stdout}}, which is &#039;&#039;Standard Output&#039;&#039;, and one called {{Code|stderr}}, which is &#039;&#039;Standard Error&#039;&#039;.  Usually, when you run a program on the command line, you see both standard out and standard error at the same time - i.e. you get all program output right there in your terminal or command prompt.  But when running a program in the background, Linux splits the output up into normal output and error output as this is very useful for debugging (i.e. you can check if standard error is empty).  &lt;br /&gt;
&lt;br /&gt;
Here, however, if you&#039;re not sure whether the program will run correctly, you should first check {{Code|stderr}} to see if any errors were generated, and then check {{Code|stdout}} to see if the output looks as expected.&lt;br /&gt;
&lt;br /&gt;
To write your own Java program, follow the same process but use your own source code instead of the {{Code|HelloWorld.java}} example.&lt;br /&gt;
&lt;br /&gt;
Now that you have a running program, we offer additional help on [[#Via the Web Interface|running a program automatically using the web interface]].&lt;br /&gt;
&lt;br /&gt;
====Program with SSH====&lt;br /&gt;
&lt;br /&gt;
Similarly to starting a program via the [[#Program in Java with the Web Interface|web interface]], we use the Phidget Java {{Code|HelloWorld}} example here.&lt;br /&gt;
&lt;br /&gt;
Make sure you have [[#Installing C/C++ and Java|Java installed on the SBC]].  To compile and run the {{Code|HelloWorld}} example:&lt;br /&gt;
&lt;br /&gt;
1. Open an [[#SSH|SSH terminal]] to the SBC&lt;br /&gt;
&lt;br /&gt;
2. Download the [{{SERVER}}/downloads/examples/JavaJNI.zip Phidget Java Examples] to the SBC, using [[#wget|wget]] (you may need to install {{Code|wget}} using [[#apt|apt]].)&lt;br /&gt;
&lt;br /&gt;
3. Unpack the examples using [[#unzip|unzip]] (you may need to install {{Code|unzip}} using [[#apt|apt]].)&lt;br /&gt;
&lt;br /&gt;
4. The location of {{Code|phidget21.jar}} on the SBC is {{Code|/usr/share/java/phidget21.jar}}.  Within the unzipped example directory, compile the {{Code|HelloWorld.java}} example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:/usr/share/java/phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. To run the {{Code|HelloWorld}} program, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:/usr/share/java/phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that you have a running program, you&#039;ll probably want to learn to [[#Running a Program Automatically|run this Java program automatically]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Permissions Note:&#039;&#039;&#039; If you&#039;re used to using Linux with Phidgets already, you&#039;ll probably notice that you don&#039;t need to switch into root using {{Code|sudo}} on the SBC in order to run programs.  This is because you already are running as root, not because the [[OS - Linux#Setting udev Rules|udev rules are set up]].  So if you set up another user, or [[#Via Cron|run a cron job]] as anything other than root or system, you&#039;ll need to add permission for the Phidget program to run in your [[OS - Linux#Setting udev Rules|udev rules]].&lt;br /&gt;
&lt;br /&gt;
====Developing Code on the SBC====&lt;br /&gt;
&lt;br /&gt;
When you&#039;re not just using pre-written source code, and you&#039;re writing code actually on the SBC itself, you&#039;ll probably want to use [[#nano|nano]].  Other terminal editors on the SBC include {{Code|vi}} which is already installed, and {{Code|emacs}}, which you can install using [[#apt|apt]].  Both {{Code|vi}} and {{Code|emacs}} are much more efficient for the experienced user, but they contain modes and keyboard shortcuts that can seem strange or almost hindering to the casual user.&lt;br /&gt;
&lt;br /&gt;
Regardless of which editor you choose to use, some of your keyboard habits may not transfer well.  For example, in the Linux command line, the command {{Code|Ctrl-C}} means &#039;&#039;stop the currently running program&#039;&#039;, (i.e. your open editor) not copy.  Within most SSH terminals, you can copy and paste using the right-mouse button, and on some terminals (and all native Linux terminals) you can copy by simply highlighting text, and you can paste it using the middle (scroll) mouse button.  On the other hand, if you write a program that hangs on the command line, {{Code|Ctrl-C}} can actually be useful to terminate it.&lt;br /&gt;
&lt;br /&gt;
Also {{Code|Ctrl-Z}} does not mean &#039;&#039;undo&#039;&#039;, rather it means &#039;&#039;run the current program in the background&#039;&#039;.  This is useful because running a program in an SSH terminal simply hangs your SSH input until the program is done.  So typing {{Code|Ctrl-Z}} while the program is running frees up the command line for more input.  But if you accidentally hit {{Code|Ctrl-Z}} while running an editor like [[#nano|nano]], the editor will immediately exit to the command line.  Don&#039;t worry though, it will not stop or lose your work.  You can bring it back up by using the {{Code|fg}} (e.g. &#039;foreground&#039;) command, like {{Code|fg nano}}, and this will automatically bring your nano process back to the front.&lt;br /&gt;
&lt;br /&gt;
===Running a Program Automatically===&lt;br /&gt;
&lt;br /&gt;
For testing your program, you will certainly want to run it via [[#SSH|SSH]] or via the {{Code|Start}} button on the project page on the web interface until you are quite sure it runs well.  However, eventually you will probably want the program to run without your input, either [[#Via the Web Interface|continuously, and starting at boot]], or via a task scheduled to [[#Via Cron|run to completion at certain times]].&lt;br /&gt;
&lt;br /&gt;
Both have their advantages and disadvantages.  Usually, you would want to use the continuous, from-boot methods for event driven code that has to handle a wide variety of user input that could occur at any time.  You would want to use the scheduled method when the SBC needs to perform a repeated task (e.g. reading sensor data) again and again.  The main difference is:&lt;br /&gt;
* With the continuous (boot) method you can have any Phidgets (including sensors, LEDs, input switches, etc) attached and giving events to your code all the time, and&lt;br /&gt;
* With the scheduled (cron) method you have much less of a chance to run into long-term memory management and instability problems with any code you write, because your program runs for only a short time before exiting and getting cleaned up.&lt;br /&gt;
&lt;br /&gt;
====Via the Web Interface====&lt;br /&gt;
&lt;br /&gt;
To use this method, you must have created the program you want to run as [[#Program in Java with the Web Interface | a Java or ARM-compiled C project in the web interface]].  If you would like to use another language, or another way of uploading your project, but you still want to start at boot and run continuously, you will need to use a [[#Via a Boot Script|boot script]].&lt;br /&gt;
&lt;br /&gt;
In the web interface, go to the {{Code|Projects}} tab, and click on the project you would like to run.  Near the bottom of the project page (the one with the {{Code|Start}} and {{Code|Stop}} buttons at the top), there will be a section called {{Code|Startup Settings}}.  You can see a screenshot of the whole project page, including these settings, in the [[#Program in Java with the Web Interface | web interface project section]].&lt;br /&gt;
&lt;br /&gt;
Select the {{Code|Enabled}} radio button.  The other defaults should be fine, unless you specifically know otherwise:&lt;br /&gt;
* For &#039;&#039;Boot Order&#039;&#039;, lower numbers boot first.  Booting later means more programs are available for use, booting earlier means other programs can use your program.  &lt;br /&gt;
* &#039;&#039;Run as a daemon&#039;&#039; starts the program as a daemon, which is a program that runs in the background.  Unless you have &#039;&#039;explicitly&#039;&#039; written your program as a daemon, leave this checked.  (If you don&#039;t know what a daemon is, don&#039;t worry, you haven&#039;t written one, so leave it checked.)  &#039;&#039;Un&#039;&#039;checking this when your program is a normal program will cause the SBC to hang while booting.&lt;br /&gt;
* The &#039;&#039;Executable or Class&#039;&#039; name should be automatically sensed to be your main Java class&lt;br /&gt;
* &#039;&#039;Arguments&#039;&#039; are any command line arguments you need, just as you would type them into the command line&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Your program must be very, very stable to run properly via the web interface.  Imagine your program running continuously for days, or months on end.  Any memory leaks, over time, will render your program (and the SBC) unusable until a reboot.  Counts or other variables that increase within your program and never reset may create a segmentation fault eventually.&lt;br /&gt;
&lt;br /&gt;
If, for stability purposes, you want your program to start, run for a little while, and then exit so that the SBC operating system can clean up the memory each time, you&#039;ll probably want to use [[#Via Cron|Cron]] to run your program instead.&lt;br /&gt;
&lt;br /&gt;
====Via Cron====&lt;br /&gt;
&lt;br /&gt;
Cron can automatically schedule programs - known as &#039;jobs&#039;, or &#039;cron jobs&#039; - at most once per minute.  Less often than that, it is very flexible, allowing you to run it on certain months, weekdays, hours, etc.  Cron simply reads a special file (your {{Code|crontab}}) and runs whatever programs are listed, with whatever timing they are listed with.  The cron program runs all the time in the background, making it what is known as a Linux &#039;&#039;daemon&#039;&#039;, but the programs it starts as jobs run only as long as they naturally would, and then they exit.&lt;br /&gt;
&lt;br /&gt;
If you need your program to run more often than once per minute, have the program schedule itself while still running.  For example, to run every five seconds, run a fast loop,  and sleep for five seconds. Do this twenty times and exit.  Then schedule this once per minute using cron, and your program will in essence run every five seconds.&lt;br /&gt;
&lt;br /&gt;
Setting up a cron job simply entails editing your {{Code|crontab}} file.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll probably want to specify your default editor to be [[#nano|nano]]. Otherwise it will default to {{Code|vi}} and you&#039;ll have to figure out {{Code|vi}} in order to add lines to your crontab:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
export EDITOR=nano&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to edit your crontab file, simply type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
crontab -e&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each line of the crontab file is one scheduled job.  Lines that start with a hash &amp;quot;#&amp;quot; are comments and are ignored.  There is an example line in the crontab, and a reminder line at the very end.  Essentially, each line should contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
minute hour dayOfMonth month dayOfWeek  command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
*{{Code|command}} is the program you want to run (with absolute path, and arguments)&lt;br /&gt;
** For example, {{Code|./myprogram argument1}} won&#039;t work, but {{Code|/root/code/myprogram argument1}} will&lt;br /&gt;
* Each time argument is either a number, a list of numbers separated by commas, or an asterisk&lt;br /&gt;
** For example, * * * * * means every minute for all days and months, 0,30 * * * * means every thirty minutes (i.e. at the top of the hour and at 30 minutes in) for all days and months&lt;br /&gt;
&lt;br /&gt;
If you already have jobs scheduled, you&#039;ll see them in the file that comes up.  You can edit, add, or delete.  &lt;br /&gt;
&lt;br /&gt;
After you save, you&#039;ll see a little message back in the terminal that says the new crontab file was installed, and it is now scheduled!  Cron always starts every boot, and so if you have edited and installed your crontab as above, the scheduling of your program will start properly even after a reboot of the SBC.  However, if you are having strange scheduling problems, you may want to familiarize yourself with the [[#Software Details|software details]] of how the SBC as a whole determines the current date and time.&lt;br /&gt;
&lt;br /&gt;
=====My Cron Job Doesn&#039;t Work!=====&lt;br /&gt;
&lt;br /&gt;
It is actually very common for a script or program to work on the command line but then &#039;&#039;not&#039;&#039; work as a cron job.  The most common reason for this, by far, is that you specify &#039;&#039;relative&#039;&#039; paths in your program to access files rather than &#039;&#039;absolute&#039;&#039; paths.  For example:&lt;br /&gt;
* {{Code|code/project.c}} is a relative path (bad for cron)&lt;br /&gt;
* {{Code|/root/code/project.c}} is an absolute path (good for cron)&lt;br /&gt;
The cron jobs are &#039;&#039;not&#039;&#039; executed from your home directory, or your code directory, so they will not be using the same location you may be using to test your code.  So always use absolute paths.&lt;br /&gt;
&lt;br /&gt;
Another common reason is you may be using environment variables or other settings that are true in a terminal but are &#039;&#039;not&#039;&#039; true by default in the raw system.  You can end up taking many things for granted in a shell, for example the shortcut &amp;quot;~&amp;quot; means home directory in a shell, but not by default in the raw system.  The things that get loaded for a shell (but which are not present in the raw system) are:&lt;br /&gt;
* The settings loaded by {{Code|/etc/profile}}&lt;br /&gt;
* Any settings in {{Code|~/.bashrc}}, which is nothing by default on the SBC&lt;br /&gt;
&lt;br /&gt;
On a full Linux operating system, you would use the logs written to by cron to find the error output and debug it.  On the SBC, however, cron does not write logs (otherwise, these logs would eat up the SBC memory very quickly even for routine jobs).  For short-term debugging, you can write output from your program to a file, and read that file afterwards to figure out what your program is doing.&lt;br /&gt;
&lt;br /&gt;
====Via a Boot Script====&lt;br /&gt;
&lt;br /&gt;
If you want to run your program constantly and for it to start at boot like the [[#Via the Web Interface|web interface would do]], you can install your program into the boot order using a script.  This is a somewhat involved process, and you should be familiar with shell programming in Linux.  For this process, we only offer a [[OS - Linux#As A Service|similar example]] which installs and runs the program {{Code|phidgetwebservice21}} within the boot sequence.&lt;br /&gt;
&lt;br /&gt;
===Using USB Data Keys===&lt;br /&gt;
&lt;br /&gt;
After plugging the USB key in, it won&#039;t just appear on your desktop, so to speak, so you&#039;ll need to figure out where you can read and write to it within the SSH directory structure.&lt;br /&gt;
&lt;br /&gt;
The web interface program can help with this.  After you plug a USB key in, it will show up under {{Code|Status &amp;amp;rarr; System}}.  Or, the USB key and all other attached devices can be seen at {{Code|Status &amp;amp;rarr; USB}}:&lt;br /&gt;
&lt;br /&gt;
[[File:sbc_mounted_devices.png|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, you can see that the USB key is located in {{Code|/media/usb0}}.&lt;br /&gt;
&lt;br /&gt;
Alternately, you can use the SSH command {{Code|mount}}, and the searching program {{Code|grep}} which will filter the response of {{Code|mount}} and only return the lines with your search term ({{Code|usb}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount | grep usb&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the USB key can be written to and read from using the {{Code|/media/usb0}} directory.  Copying a file to {{Code|/media/usb0}} will copy a file to the USB key.  The same goes for removing, renaming, opening files within your program, etc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Mount points like {{Code|/media/usb0}} should not be hard-coded into any of your programs.  (See the [[#Common Problems and Solutions | Common Problems and Solutions]] section for more information.)  If you need to obtain the mount point for a freshly mounted USB key within your code, have your code obtain the mount tables and search on the &#039;&#039;device&#039;&#039;  (e.g. {{Code|/dev/sda1}} or {{Code|/dev/sdb1}}) and obtain the corresponding mounted {{Code|/media/usbN}} location, where N is a number 0-9.&lt;br /&gt;
&lt;br /&gt;
===Saving and Retrieving Data===&lt;br /&gt;
&lt;br /&gt;
This section covers getting data on and off of the SBC.  There are two main methods of simply moving data on and off the SBC - via a [[#Via a USB Key|USB key]], and via [[#Over the Network (SCP)|copy over the network]] - and a third method for moving and installing data when it concerns [[#Backing Up Your Data|backing up lower level system data]].&lt;br /&gt;
&lt;br /&gt;
====Via a USB Key====&lt;br /&gt;
&lt;br /&gt;
After plugging in a USB data key, first you need to [[#Using USB Data Keys | find out the location]] where that data key was mounted.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say the location of the USB key is {{Code|/media/usb0/}}, and we want to copy the file {{Code|data.txt}} to the USB key.  Your SSH session might look something like this, using [[#ls|ls]] and [[#mount|mount]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# ls&lt;br /&gt;
data.txt&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
root@phidgetsbc:~# cp data.txt /media/usb0/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;cp&#039;&#039;&#039; program copies data from a source to a destination.  The syntax is {{Code|cp from to}}, where here we are copying from {{Code|data.txt}} to {{Code|/media/usb0/}}.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution:&#039;&#039;&#039; Even if there is no USB key mounted at {{Code|/media/usb0/}}, this use of {{Code|cp}} will still work &#039;&#039;with no errors&#039;&#039;!  This is because there is still a file called {{Code|/media/usb0/}}, there is just no USB key file system &#039;&#039;mounted&#039;&#039; to that point.  So be sure to run [[#mount|mount]] or use some other method of determining that there is, in fact, a USB data key attached and where it is mounted to.&lt;br /&gt;
&lt;br /&gt;
====Over the Network (SCP)====&lt;br /&gt;
&lt;br /&gt;
SCP is a command line program already installed on Linux and Mac OS, and downloadable for free on Windows.  We discuss it and give examples in the [[#SSH|SSH]] section, but remember it here when you&#039;re trying to get data on and off of the SBC.  With SSH or a terminal already open, you&#039;ll probably find it to be much faster and easier than dealing with a USB key.&lt;br /&gt;
&lt;br /&gt;
====Backing Up Your Data====&lt;br /&gt;
&lt;br /&gt;
For the web interface, you can save and restore all web interface settings under the {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore}} tab.&lt;br /&gt;
&lt;br /&gt;
To save the settings of what packages are installed for later re-installation, you can type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
dpkg --get-selections &amp;gt; installedPrograms.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then save the file {{Code|installedPrograms.txt}} externally.  If you have to completely wipe the SBC, you can just reinstall the whole list by moving the {{Code|installedPrograms.txt}} file back onto the SBC, and then typing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
dpkg –set-selections &amp;lt; installedPrograms.txt&lt;br /&gt;
apt-get dselect-upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also remember to externally save:&lt;br /&gt;
* Your {{Code|~/.bashrc}} settings file if you&#039;ve changed it&lt;br /&gt;
* Your {{Code|crontab}} file if [[#Via Cron|you&#039;ve edited it]]&lt;br /&gt;
* Any data files or code you&#039;ve created&lt;br /&gt;
&lt;br /&gt;
It is important to save these settings often, and at points where you know the system is running well.  It may be tempting to create a backup right before you [[#Recovery System|wipe the SBC and start from scratch]], but often the reason you are having problems then is some setting or change, and backing these up and reinstalling them will only reinstall the problem.&lt;br /&gt;
&lt;br /&gt;
To truly back the files up, you must copy them to an external computer or location using either a [[#Via a USB Key|USB Key]] or [[#Over the Network (SCP) | over the network]].  Then they can be copied back if needed later.&lt;br /&gt;
&lt;br /&gt;
If you are looking to restore data on an SBC that will not boot properly, you&#039;ll want to be in the [[#Partial Recovery|partial recovery]] portion of our Troubleshooting section.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
The SBC can be quite tricky to debug, because it is a complex and flexible computer.  Common problems and solutions include:&lt;br /&gt;
* You can&#039;t find the SBC on the network at all - refer to the [[#Initial Internet Setup|Initial Internet Setup]] section&lt;br /&gt;
* You have changed some setting or file such that the SBC doesn&#039;t run anymore, or doesn&#039;t run as expected - refer to the [[#Recovery|Recovery]] section&lt;br /&gt;
&lt;br /&gt;
If you are having trouble using Phidgets on the SBC, you should go through the [[OS - Linux#Troubleshooting | Troubleshooting section on the general Linux page]].  Some of the problems on the Linux page (such as library problems) are easier to fix by simply working through the [[#Recovery|Recovery]] section when they occur on the SBC.&lt;br /&gt;
&lt;br /&gt;
Namely, it often helps to simply perform a [[#Factory Reset|factory reset]] on the SBC (save your files and installed program list first, as [[#Backing Up Your Data|described here]]).  Sometimes you change a file or setting within the operating system when you are trying to get something up and running, and this unintentionally affects other programs too.  Performing a factory reset starts you with a clean slate.&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, or the information within this guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
===Initial Internet Setup===&lt;br /&gt;
&lt;br /&gt;
To set up the SBC, you almost always need a &#039;&#039;wired&#039;&#039; Ethernet connection with DHCP (Dynamic Host Configuration Protocol), and without a firewall.  This connection should be to a &#039;&#039;router&#039;&#039;, not directly plugged in to your computer.&lt;br /&gt;
&lt;br /&gt;
Even if you do not have this type of a connection at home, these types of connections are very common at both offices and universities.  On a Windows or Mac OS computer, you can bring up the Phidget Control Panel as described in the SBC&#039;s [[1072 0 - Getting Started|Getting Started Page]].  Failing this, or on a Linux computer, we discuss some alternate setup methods in this section.  Keep in mind that without a wired, open DHCP connection these setup methods can be difficult and fickle. &lt;br /&gt;
&lt;br /&gt;
====No Wired-Only Connection====&lt;br /&gt;
&lt;br /&gt;
Sometimes it can work to plug the SBC, using Ethernet, directly into an Ethernet port on your home wireless router.  Do not plug it directly into your computer!  (Although in some instances, a direct connection can be made to work on Linux, see the [[#No DHCP|No DHCP]] section below) &lt;br /&gt;
&lt;br /&gt;
This direct-router method is a very picky process, however, and can fail because:&lt;br /&gt;
* Some home and office routers place a firewall between wireless connections (clients) and wired connections (the local area network)&lt;br /&gt;
* Some home and office routers do not by default allow both Ethernet DHCP and wireless DHCP.&lt;br /&gt;
* Some routers and DHCP hubs only provide access to an internet connection, and do not provide local area network inter-connections (this is common on mobile device tethering hubs)&lt;br /&gt;
&lt;br /&gt;
Routers are quite complex, and even with admin privileges it can be a painstaking process to find all the right firewall settings to turn off in order to allow two computers on the network to talk to one another, rather than just connect to the internet.  This is why university or office networks are often ideal for the purpose of setting up the SBC, because these institutions depend on computers on a local network being able to talk together.  University libraries in particular can be a good source of wired DHCP connection ports.  &lt;br /&gt;
&lt;br /&gt;
Covering all of the different router configuration possibilities here, and how to change them to make the SBC work, is essentially impossible.  If you try using the SBC at home or at work, the SBC does not work on the first try when plugged directly into the router via Ethernet, and you want to make that connection work rather than seeking out an alternate for the initial setup, you should find documentation specific to your router (usually available online) and properly configure it.&lt;br /&gt;
&lt;br /&gt;
The good news is that if you can find an Ethernet DHCP connection &#039;&#039;just once&#039;&#039; for a short time, you can use that connection to configure the SBC to work on your home wireless network.  During that initial connection, you can enable wireless and set up as many wireless DHCP connections (with passwords) that you need.  Once wireless is enabled and set up, you can take the SBC home to your wireless router and the SBC will automatically seek out and connect to its remembered networks as they appear.  At that point, you can also use wireless like a normal internet, web interface, and SSH connection.&lt;br /&gt;
&lt;br /&gt;
====No Link Local Addressing====&lt;br /&gt;
&lt;br /&gt;
If you have a wired DHCP connection, no firewall, and no link local addressing (e.g. bonjour or avahi is not installed) then you will need access to the DHCP router logs.  From the router logs, you should see the connection (or attempted connection) by the SBC within the logs.  From that log entry, you should either be able to determine the IP address for the SBC, or see what happens when the router blocks access.  The IP address can be used in place of the link local address for both the web interface and for SSH.&lt;br /&gt;
&lt;br /&gt;
====No DHCP====&lt;br /&gt;
&lt;br /&gt;
The SBC will first try to use DHCP, but then it will revert to responding to a link local address under bonjour and avahi.  If you are depending on this, please wait &#039;&#039;&#039;at least three minutes&#039;&#039;&#039; after the SBC boots for the SBC to fail in obtaining a DHCP connection and properly revert to link local addressing.&lt;br /&gt;
&lt;br /&gt;
If you have a static IP setup, and want to use link local addressing rather than accessing the router logs, this should usually work by default on Windows and Mac OS (e.g. type the address such as {{Code|phidgetsbc.local}} into a web browser).  If it doesn&#039;t work automatically, there is not much you can do and you should seek out a wired DHCP connection elsewhere.&lt;br /&gt;
&lt;br /&gt;
On Linux, it also should work by default, but you have the additional option of explicitly adding routes that look within the default network settings for the SBC.  From a terminal (as root), type:&lt;br /&gt;
* {{Code|route add -net 169.254.0.0 netmask 255.255.0.0 dev eth0 metric 99}}&lt;br /&gt;
* {{Code|route add default dev eth0 metric 99}}&lt;br /&gt;
You can also compile and use the {{Code|phidgetsbclist.c}} example (use the provided Makefile, don&#039;t use gcc) in the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Linux Libraries] package, under the {{Code|examples}} folder.  This will allow you to see if the SBC is detected on the network at all.   Note that to use this option you must have the Phidget Libraries and the Phidget WebService installed on your Linux computer - in-depth instructions to do this are on the [[OS - Linux|main Linux page]].&lt;br /&gt;
&lt;br /&gt;
===Recovery System===&lt;br /&gt;
&lt;br /&gt;
You can either boot the SBC into recovery mode and attempt to recover files and settings, or you can completely wipe the SBC by performing a factory reset.  If the LEDs do not turn on normally (red on constantly, green on at first start, then off, then on when fully booted) then you&#039;ll want to read the [[#Hardware Issues|hardware issues]] section.&lt;br /&gt;
&lt;br /&gt;
====Partial Recovery====&lt;br /&gt;
&lt;br /&gt;
The recovery system can be entered in two ways:&lt;br /&gt;
# From the {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore}} web interface page.&lt;br /&gt;
# By holding down the reset button for 20+ seconds - until the green light has switched from flashing slowly to flashing quickly.&lt;br /&gt;
&lt;br /&gt;
The recovery system runs an [[#SSH|SSH]] server where the username and password both are {{Code|root}}.&lt;br /&gt;
&lt;br /&gt;
If the main filesystem has been damaged/misconfigured in such a way that it won’t boot, you may be able to fix the issue or recover important files before running a full factory reset. From an SSH connection to the recovery system, you can mount the main root filesystem with the following commands (assuming it’s not damaged):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
ubiattach /dev/ubi_ctrl -m 6&lt;br /&gt;
mount -t ubifs /dev/ubi0_0 /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Factory Reset====&lt;br /&gt;
&lt;br /&gt;
This restores the kernel and root filesystem from backup, overwriting any changes that may have been made and &#039;&#039;completely wiping the system&#039;&#039; to the state that it got shipped in. (You can save your files and installed program list first, as [[#Backing Up Your Data|described here]].)  This can be enacted one of two ways.&lt;br /&gt;
# Use the reset button:&lt;br /&gt;
##Enter the recovery mode by holding down the reset button for 20+ seconds as above (until fast flashing)&lt;br /&gt;
##Wait for a full boot (i.e. you can see it on the Phidget control panel, or can SSH with username and password as {{Code|root}})&lt;br /&gt;
##Hold down the reset button again, but this time for only 10 seconds (until slow flashing)&lt;br /&gt;
##Wait for the SBC to fully reset and reboot (at least three minutes) - the LED will turn off and on again when this occurs&lt;br /&gt;
##*Note that after a factory reboot the SSH server will be disabled&lt;br /&gt;
##*Also note that after a factory reboot the SBC creates new SSH keys, and reverts to the {{Code|phidgetsbc.local}} address&lt;br /&gt;
# Via the web interface, under {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore &amp;amp;rarr; Go button}}, where you can follow the instructions&lt;br /&gt;
&lt;br /&gt;
====Hardware Issues====&lt;br /&gt;
&lt;br /&gt;
The LEDs are an indicator of the hardware working properly.  The normal boot process is:&lt;br /&gt;
* Red LED: Turns on from moment of power being applied.&lt;br /&gt;
* Green LED: Turns on momentarily when power applied, then turns off momentarily, then turns on and stays on when booted.&lt;br /&gt;
&lt;br /&gt;
If the green status LED never turns on (or fails to turn on the second time), the boot process is failing somewhere.  This could be due to:&lt;br /&gt;
* A damaged OS - Try performing a [[#Factory Reset|Factory Reset]]&lt;br /&gt;
* If this fails, it is likely hardware damage (very difficult to diagnose, please [[Contact Us|contact us]])&lt;br /&gt;
&lt;br /&gt;
If neither LED turns on, hardware damage is even more likely.  Unless the path to the red LED is the one thing that has been damaged, the device is likely not receiving and using power.&lt;br /&gt;
* Try performing a [[#Factory Reset|Factory Reset]], and if that does not work please [[Contact Us|contact us]]&lt;br /&gt;
&lt;br /&gt;
=====USB Issues=====&lt;br /&gt;
&lt;br /&gt;
On the Phidget SBC2, there is a hardware issue that is unrelated to the LEDs.  It is a USB problem, and manifests in many ways:&lt;br /&gt;
* Strange behaviour when some devices but not others are plugged in to the SBC&lt;br /&gt;
* Strange behaviour with combinations of devices&lt;br /&gt;
* Failure (or intermittent failure) to see Phidgets on the USB hub, or USB keys on the hub&lt;br /&gt;
&lt;br /&gt;
This problem is fixable, either on your own or by sending your SBC back to Phidgets.  For an in-depth solution, see the [[SBC2_USB_Hub_Fix | SBC2 Hub Fix Page]].&lt;br /&gt;
&lt;br /&gt;
===Updating Your SBC===&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve owned your SBC for a while and want to update your packages, you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to &#039;&#039;update&#039;&#039; your software source list and then &#039;&#039;upgrade&#039;&#039; to the latest version of all installed software.  If you are used to Mac OS or Windows, note that this does not just update the non-kernel parts of the operating system, it updates every additional piece of software you have installed.&lt;br /&gt;
&lt;br /&gt;
To update the SBC software itself (e.g. the kernel), it is easiest to use the web interface, under {{Code|System &amp;amp;rarr; Backup &amp;amp; Restore &amp;amp;rarr; Go button}}, to enter a page that will give you the option to update.  You will need to have an update file on a USB key inserted into the SBC, of type:&lt;br /&gt;
* UBI Image (system_ubi.img), or &lt;br /&gt;
* Kernel image (uImage), or&lt;br /&gt;
* Phidget Upgrade package containing both UBI and Kernel images (phidgetsbc*.bin)&lt;br /&gt;
&lt;br /&gt;
These are either obtained from the Phidgets website, or are a custom kernel / filesystem that you can create yourself, if you are experienced.&lt;br /&gt;
&lt;br /&gt;
The reason why this information is in troubleshooting is that you should certainly [[#Backing Up Your Data|back up your system]] before trying this.  And, it is quite rare to need to upgrade the kernel or filesystem on the SBC, so something serious should be going on before you attempt it.  Try using the [[#Recovery System|recovery system]] first.&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic libraries installed, you can pick your language and begin programming!  &lt;br /&gt;
&lt;br /&gt;
If you are not using the [[#WebService | webservice]] to control a Phidget over a network, your next step will be to delve into the use of your specific language.  Each page has its own set of specific libraries, code examples, and setup instructions.  &lt;br /&gt;
&lt;br /&gt;
On SBC Linux, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Java | Java]]&lt;br /&gt;
*[[Language - Python | Python]]&lt;br /&gt;
&lt;br /&gt;
These languages may also run on the SBC, but we do not yet directly offer SBC support for them:&lt;br /&gt;
* [[Language - Ruby|Ruby]]&lt;br /&gt;
* [[Language - C Sharp|C#]] (using Mono)&lt;br /&gt;
&lt;br /&gt;
You can probably figure out how to install and use them by a combination of the language pages linked above, and the section on [[#Installing Other Languages|installing other languages on the SBC]].&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The SBC comes with the [[Phidget WebService]] installed, and the SBC automatically starts the WebService at boot.&lt;br /&gt;
&lt;br /&gt;
To practice using the WebService, and to learn more about it, we have hands-on examples on the [[OS - Linux|general Linux page]], starting in the [[OS - Linux#Using the WebService|using the WebService section]].&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Using a Different Wireless Adapter===&lt;br /&gt;
&lt;br /&gt;
The support for the wireless adaptor that Phidgets sells is written into the SBC kernel.  Hence, we do not support using other adaptors. &lt;br /&gt;
&lt;br /&gt;
However, Linux is very flexible, and it is possible (though not easy) to write a custom kernel for the SBC and add support for a new wireless adaptor.  We can&#039;t help you with this, but we do provide some basic guidelines for [[#Custom Kernel and Filesystem|building your own kernel]].&lt;br /&gt;
&lt;br /&gt;
===Using a Different Webcam===&lt;br /&gt;
&lt;br /&gt;
In addition to the webcam that Phidgets sells, you have the option to use many different webcams with the SBC.  There is a [http://www.ideasonboard.org/uvc/#devices long list] of compatible webcams.&lt;br /&gt;
&lt;br /&gt;
The common thread for these webcams is that they use UVC - the USB Video Class - drivers for Linux.  You can then use [[#mount|mount]] to find out what video device your webcam is mounted under.&lt;br /&gt;
&lt;br /&gt;
===Taking Pictures With the Webcam===&lt;br /&gt;
&lt;br /&gt;
Probably the most straightforward way to use a webcam for pictures rather than video is to use the {{Code|opencv}} library.  You can get it by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install libcv2.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there is no {{Code|libcv2.1}} package, you can perform {{Code|apt-cache search libcv}} to find the current version.&lt;br /&gt;
&lt;br /&gt;
The opencv libraries can also be used within Python, by installing the link between them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
apt-get install python-opencv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then taking pictures from within code becomes quite simple.  For example, in Python, taking and saving an image is four lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
import cv&lt;br /&gt;
&lt;br /&gt;
# The webcam is located at /dev/video0 &lt;br /&gt;
# OpenCV only needs the number after video&lt;br /&gt;
webcam = cv.CaptureFromCAM(0)&lt;br /&gt;
&lt;br /&gt;
frame = cv.QueryFrame(webcam)&lt;br /&gt;
&lt;br /&gt;
cv.SaveImage(&amp;quot;image.jpg&amp;quot;, frame)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the complete OpenCV documentation, see [http://opencv.willowgarage.com/documentation/index.html The OpenCV Reference], and specifically the section on [http://opencv.willowgarage.com/documentation/reading_and_writing_images_and_video.html Reading and Writing Images].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The SBC is probably not as powerful for image processing and transport when compared to your desktop computer.  Try running your image processing code on the SBC from an early point in development.  During those test runs, you can visit the first System page of the [[#SBC Web Interface|SBC Web Interface]] to check the processor and memory use.  For more information on processor power, check the specification for your SBC (on the product page on [{{SERVER}} our main website]) as well as our discussion of [[#Pushing Processor Limits|pushing processor limits]] below.&lt;br /&gt;
&lt;br /&gt;
===Checking System Logs===&lt;br /&gt;
&lt;br /&gt;
The SBC maintains two logs: a kernel log and a system log.  &lt;br /&gt;
&lt;br /&gt;
The kernel log is for low-level occurrences, such as devices attaching and leaving the USB hub, recording what drivers are being used, and so on.&lt;br /&gt;
&lt;br /&gt;
The system log (syslog) is for normal chatter from the operating system.  Any program with the right permissions can use it (though you need to know the method to write to it, information all around the Internet can help) and it contains everything from the Ethernet going up and down, to webserver requests, and so on.  If you don&#039;t run many programs or services on the SBC, the syslog will essentially be a mirror of the kernel log, because the kernel is the only thing talking.&lt;br /&gt;
&lt;br /&gt;
You can check these logs by using the web interface in the {{Code|System &amp;amp;rarr; Logs}} tab.&lt;br /&gt;
&lt;br /&gt;
Or you can perform more powerful filtering and displaying via an SSH terminal.  For example, {{Code|dmesg}} is the command to display the kernel log, and {{Code|tail}} prints the last ten lines of input.  So, if you are trying to see if you can get a device to be detected on USB, you can run &amp;lt;code&amp;gt;dmesg | tail&amp;lt;/code&amp;gt; to print the latest ten lines of kernel log data.&lt;br /&gt;
&lt;br /&gt;
The actual locations of the log files (for filtering and reading) are:&lt;br /&gt;
* {{Code|/var/log/syslog}} &lt;br /&gt;
* {{Code|/var/log/dmesg}}&lt;br /&gt;
But don&#039;t edit them directly!  Always follow the advice and procedures around the Internet on how to properly log items to syslog.&lt;br /&gt;
&lt;br /&gt;
===X Forwarding===&lt;br /&gt;
&lt;br /&gt;
Although most tasks can be done using the [[#SBC Web Interface|SBC Web Interface]] or [[#SSH|SSH]], you can also set up X11 forwarding on the SBC.  X11 is the window manager base, which provides a graphical windowing system on the SBC.  Although you probably won&#039;t connect directly to the X11 manager (i.e. by plugging a screen directly into the SBC), X11 also gives a user the ability to forward graphical windows over SSH.  You will need the following packages installed:&lt;br /&gt;
* {{Code|x11-common}}&lt;br /&gt;
* {{Code|xbase-clients}}&lt;br /&gt;
After installing, make sure that the line in {{Code|/etc/ssh/sshd_config}} has a line that says:&lt;br /&gt;
:{{Code|X11Forwarding yes}}&lt;br /&gt;
Then log out and log back into the SBC.  This second time you log in, use the {{Code|-X}} switch to turn on X forwarding for that connection:&lt;br /&gt;
:{{Code|ssh -X root@phidgetsbc.local}}&lt;br /&gt;
Then you should be able to run programs that launch a window, and it will launch remotely and appear on the computer you have the SSH connection from.&lt;br /&gt;
&lt;br /&gt;
===Pushing Processor Limits===&lt;br /&gt;
&lt;br /&gt;
The SBC, though more powerful than many embedded computers out there, is probably about as powerful as your smartphone.  If you hook up 1 ms Phidget sampling devices to all six of its USB ports, events and packets will probably get lost.  The exact data rates you can accomplish depend on:&lt;br /&gt;
* What else is running on the SBC&lt;br /&gt;
* How efficient your code is for external operations (like File I/O)&lt;br /&gt;
* Other minor details (e.g. the temperature of the SBC, etc)&lt;br /&gt;
&lt;br /&gt;
If you want to achieve data rates as fast as possible, try these tips:&lt;br /&gt;
* Program in C, not in an interpreted language (Python, Java, .NET)&lt;br /&gt;
* Perform file I/O as little as possible.  Locally cache data, manage your writing to a file in a separate thread, and use low-level write calls.&lt;br /&gt;
* Change the [[#Custom Kernel and Filesystem|filesystem]] to a faster, non-compressed file system.&lt;br /&gt;
** Alternatively, use a high-data-rate USB key.&lt;br /&gt;
* Keep other running processes to a minimum. &lt;br /&gt;
** If you are running code locally right on the SBC, turn off the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
===Custom Kernel and Filesystem===&lt;br /&gt;
&lt;br /&gt;
You can compile your own kernel and flash it to the board. It is left up to the user to configure an appropriate cross-compiler for kernel development. You may also be able to compile a new kernel on-board.  We have a kernel development kit, complete with patch file and README:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC Kernel Development Package]&lt;br /&gt;
&lt;br /&gt;
Compiling a new, custom kernel is somewhat complex.  If the SBC is your first experience with Linux, writing a custom kernel will be difficult.  However, it will probably also be very rewarding because you can put whatever you like into it.  We might be able to offer additional suggestions, but ultimately you&#039;re on your own here. &lt;br /&gt;
&lt;br /&gt;
You may be able to write a custom kernel right on the SBC, but the easiest way is to develop the kernel on an external computer.  And the easiest way to develop on an external computer is for that computer to also be Linux, even just in a Virtual Machine.  The time spent loading a copy of Linux into a virtual machine (such as VirtualBox, which is free) onto your computer will probably be less time than setting up a standard compiler on Windows to cross-compile.&lt;br /&gt;
&lt;br /&gt;
On your external Linux system, you will need:&lt;br /&gt;
* A cross-compiling toolchain for the ARM processor, which we briefly describe on the [[OS - Linux#Cross-Compiling with a Custom Toolchain | main Linux page]], and &lt;br /&gt;
* The [{{SERVER}}/downloads/libraries/phidgetsbc2-kerneldev.tar.gz SBC Kernel Development Package] from the Phidgets website.  &lt;br /&gt;
The kernel development kit has a brief README file which describes how to obtain the proper kernel and patch, configure, customize, and build it.&lt;br /&gt;
&lt;br /&gt;
We have an application guide in progress, which walks through building a custom kernel to add Bluetooth support to the SBC.  Please contact us if you would like more information.  Even if you are trying to add support for hardware other than a bluetooth modem, or wondering if support even exists in the kernel for your modem (3G, alternate wireless, etc) you will probably find the application guide helpful.  Follow it up to the point where you run the program {{Code|menuconfig}} (you don&#039;t need an SBC to do this), which will give you a menu of all drivers you can enable in the SBC kernel.&lt;br /&gt;
&lt;br /&gt;
After making your new kernel, you should have a uImage and modules target for your Makefile.  At this point you can transfer your kernel files onto the SBC, make their targets, and transfer them into the nand memory.  This involves erasing the old kernel, flashing the new kernel, installing the new kernel modules, and rebooting.  From the SBC, in the kernel directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make uImage; make modules&lt;br /&gt;
flash-eraseall /dev/mtd3&lt;br /&gt;
nandwrite -p /dev/mtd3 arch/arm/boot/uImage&lt;br /&gt;
make modules-install&lt;br /&gt;
reboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Custom kernels can also be flashed from the [[#Recovery System | Recovery System]].&lt;br /&gt;
&lt;br /&gt;
If you need to create a root filesystem image, the filesystem type is UBIFS, and the commands to create it are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mkfs.ubifs -m 2KiB -e 126KiB -c 4050 -r $ROOTFS/ system_ubifs.img&lt;br /&gt;
ubinize -o system_ubi.img -m 2KiB -p 128KiB -s 512 ubinize.cfg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where {{Code|ubinize.cfg}} contains:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
# Section header&lt;br /&gt;
[rootfs]		&lt;br /&gt;
# Volume mode (other option is static)&lt;br /&gt;
mode=ubi		&lt;br /&gt;
# Source image&lt;br /&gt;
image=system_ubifs.img	&lt;br /&gt;
# Volume ID in UBI image&lt;br /&gt;
vol_id=0		&lt;br /&gt;
# Volume size&lt;br /&gt;
vol_size=64128KiB&lt;br /&gt;
# Allow for dynamic resize&lt;br /&gt;
vol_type=dynamic	&lt;br /&gt;
# Volume name&lt;br /&gt;
vol_name=rootfs		&lt;br /&gt;
# Autoresize volume at first mount&lt;br /&gt;
vol_flags=autoresize&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You then flash ‘system_ubi.img’ (not ‘system_ubifs.img’) from the recovery system.&lt;br /&gt;
&lt;br /&gt;
Again, like the custom kernel creation, the need to create a custom root filesystem is essentially non-existent except for those advanced users who already know they need it... and furthermore, you are almost entirely on your own.&lt;br /&gt;
&lt;br /&gt;
==Software Details==&lt;br /&gt;
&lt;br /&gt;
For even more advanced uses of the SBC, it may help to know the gritty details of the SBC software system.&lt;br /&gt;
&lt;br /&gt;
;Operating System&lt;br /&gt;
:Debian/GNU Linux&lt;br /&gt;
:Kernel 2.6.X or higher (generally kept up to date with latest releases, use {{Code|uname -r}} to check the kernel version)&lt;br /&gt;
&lt;br /&gt;
;Main Filesystem (rootfs)&lt;br /&gt;
:UBIFS (a raw flash type of file system)&lt;br /&gt;
:Mounted in a 460 MB Nand partition (in Read/Write mode)&lt;br /&gt;
&lt;br /&gt;
;Kernel&lt;br /&gt;
:uImage format&lt;br /&gt;
:Has its own 3MiB partition on bare Nand&lt;br /&gt;
&lt;br /&gt;
;Web Interface Scripts and Configuration Data&lt;br /&gt;
:Located in {{Code|/etc/webif}}&lt;br /&gt;
:Modifying these scripts can be done; however, it is very easy to enter invalid data that could cause the system to behave unexpectedly or not boot.&lt;br /&gt;
&lt;br /&gt;
;User Applications uploaded through Web Interface&lt;br /&gt;
:Located in {{Code|/usr/userapps}}&lt;br /&gt;
&lt;br /&gt;
;Webcam Device Location&lt;br /&gt;
:{{Code|/dev/video0}}&lt;br /&gt;
:Numbers increase with more webcams&lt;br /&gt;
&lt;br /&gt;
;Date and Time&lt;br /&gt;
:Set using ntp (network time protocol) at boot&lt;br /&gt;
:The ntp daemon continues to run in the background and will periodically update the clock &lt;br /&gt;
:The network keeps the SBC very close to real time&lt;br /&gt;
:Also there is a real-time clock with battery backup which will preserve date/time across reboots, power removal&lt;br /&gt;
:The real-time clock is synced to system time during reboot/shutdown&lt;br /&gt;
:If power is unplugged suddenly, and the network not restored, the real-time clock may not have the correct time&lt;br /&gt;
&lt;br /&gt;
;Wireless Networking System&lt;br /&gt;
:Wireless adapter support for the wireless adapter that Phidgets sells is written into the kernel&lt;br /&gt;
:It supports WEP and WPA&lt;br /&gt;
:It is best configured through the configuration interface.&lt;br /&gt;
&lt;br /&gt;
;Nand Layout&lt;br /&gt;
:The board contains 512MiB on Nand. This nand is split into 7 partitions as follows:&lt;br /&gt;
:0: u-boot		 size: 256K		 Read Only&lt;br /&gt;
:1: u-boot_env		 size: 128K		 Read Only&lt;br /&gt;
:2: recovery_kernel	 size: 2M		 Read Only&lt;br /&gt;
:3: kernel		 size: 3M		 Writable&lt;br /&gt;
:4: flashfs	 	 size: ~3.625M	 	 Read Only&lt;br /&gt;
:5: recovery_fs		 size: ~ 43M		 Read Only&lt;br /&gt;
:6: rootfs		 size: ~ 460M		 Writable&lt;br /&gt;
: The final size of flashfs/recovery_fs/rootfs depends on the image size at production, and on the number/location of bad blocks in the NAND.&lt;br /&gt;
: &#039;&#039;&#039;Note&#039;&#039;&#039;: U-Boot and recovery kernel and filesystem cannot be written from Linux - this is a safety measure.&lt;br /&gt;
&lt;br /&gt;
;Boot Loader&lt;br /&gt;
:U-Boot is used for setting up the processor and booting Linux, and is only accessible via a serial connection. &lt;br /&gt;
:Normal users will not need to use or modify it.&lt;br /&gt;
:Be very careful when modifying the u-boot partition. If it is damaged or overwritten, it is difficult to fix.&lt;br /&gt;
:When using U-Boot, a prompt will appear via serial shortly after power on.  &lt;br /&gt;
:The environment variables will help you determine how to boot Linux on the SBC&lt;br /&gt;
:You can also refer to the [http://www.denx.de/wiki/DULG/Manual U-Boot documentation]&lt;br /&gt;
&lt;br /&gt;
;Boot Process&lt;br /&gt;
:From power on...&lt;br /&gt;
:1. Processor loads first 4 bytes from NAND into Steppingstone and runs it.&lt;br /&gt;
:2. Steppingstone sets up RAM, copies u-boot from NAND into RAM and runs U-Boot.&lt;br /&gt;
:3. U-Boot initializes the processor, sets GPIO state, etc., copies the linux kernel into RAM, sets up the kernel command line arguments, checks that the kernel image is valid, and boots it.&lt;br /&gt;
:4. Linux boots, bringing up USB, Networking, NAND, etc. and then mounts the rootfs NAND partition on /.&lt;br /&gt;
:5. init gets run as the parents of all processes, as uses the /etc/inittab script to bring up the system. This includes mounting other filesystems, settings the hostname, and running the scripts in /etc/init.d, among other things.&lt;br /&gt;
:6. inittab then turns the green LED on.&lt;br /&gt;
:7. inittab then sets up a getty on the first serial port, ready for interfacing using the debug board.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|USB Memory Key mounting|Sometimes USB Memory Keys mount at more than one location}}&lt;br /&gt;
&lt;br /&gt;
When you insert a memory key, the SBC will load it as a device (e.g. {{Code|/dev/sda1}}) and it will also &#039;&#039;mount&#039;&#039; the key for reading and writing within the {{Code|/media/}} directory.  The {{Code|/media/}} directory version will be called something like {{Code|usb0}}.  &lt;br /&gt;
At times, an inserted memory key will get mounted in more than one location.  You can observe if this occurs by checking the currently mounted devices with the command {{Code|mount}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# mount&lt;br /&gt;
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)&lt;br /&gt;
proc on /proc type proc (rw,noexec,nosuid,nodev)&lt;br /&gt;
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)&lt;br /&gt;
udev on /dev type tmpfs (rw,mode=0755)&lt;br /&gt;
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)&lt;br /&gt;
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)&lt;br /&gt;
rootfs on / type rootfs (rw)&lt;br /&gt;
procbususb on /proc/bus/usb type usbfs (rw)&lt;br /&gt;
/dev/sda1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
/dev/sda1 on /media/usb1 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will note that the same device ({{Code|/dev/sda1}}) is now mounted at &#039;&#039;both&#039;&#039; {{Code|/media/usb0}} and {{Code|/media/usb1}}.  To fix this problem as it occurs, you can use {{Code|umount}} (notice there is no letter &#039;n&#039;) to unmount the second instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@phidgetsbc:~# umount /media/usb1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In practice, this should not be a problem, because writing to or reading from either {{Code|usb0}} or {{Code|usb1}} will have the same effect on the memory key.  However, if you hard-code a media location into your program (i.e. expecting {{Code|/media/usb0}} to be the first USB key you insert and {{Code|/media/usb1}} to be the second key) your program will sometimes work and sometimes fail.  &lt;br /&gt;
&lt;br /&gt;
To get around this within code, find the mount point for each device as it appears.  The devices, such as {{Code|/dev/sda1}} will always refer to the actual memory key.  But, they cannot be written to directly without being mounted, so you will have to parse the mount table (what is returned from {{Code|mount}}) within your code to find the device and its corresponding mount point.&lt;br /&gt;
&lt;br /&gt;
This is a problem with the standard embedded Debian automount program, and we have no known fix.&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Perl Locale Errors on SSH|No Locales Installed}}&lt;br /&gt;
&lt;br /&gt;
By default, no locales are installed on the SBC.  If you use [[#apt|apt]] a lot to install and manage your software on the SBC, you will get messages like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
perl: warning: Setting locale failed.&lt;br /&gt;
perl: warning: Please check that your locale settings:&lt;br /&gt;
	LANGUAGE = (unset),&lt;br /&gt;
	LC_ALL = (unset),&lt;br /&gt;
	LANG = &amp;quot;en_CA.UTF-8&amp;quot;&lt;br /&gt;
    are supported and installed on your system.&lt;br /&gt;
perl: warning: Falling back to the standard locale (&amp;quot;C&amp;quot;).&lt;br /&gt;
locale: Cannot set LC_CTYPE to default locale: No such file or directory&lt;br /&gt;
locale: Cannot set LC_MESSAGES to default locale: No such file or directory&lt;br /&gt;
locale: Cannot set LC_ALL to default locale: No such file or directory&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To squelch these messages, you should install and reconfigure your locale like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt-get install locales&lt;br /&gt;
dpkg-reconfigure locales&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The last command will show you a long list from which you should pick your location, by language.  For example, en_CA is english_Canada.  Here in Calgary, we use en_CA.UTF-8 and so for the first question we would input locale &amp;quot;114&amp;quot; and for the second (system) question we would input {{Code|en_CA}} for the locale.&lt;br /&gt;
&lt;br /&gt;
This might give you a locale undefined error, in which case you can generate the locale (for us, again, it is en_CA):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
locale-gen en_CA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_macOS&amp;diff=20713</id>
		<title>OS - macOS</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_macOS&amp;diff=20713"/>
		<updated>2012-06-29T20:42:06Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:Icon-Mac-OS.png‎|64x64px|link=]]|On OS X, Phidgets can be either plugged directly into a USB Port or run over a network using the [[#WebService|WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
Phidgets are designed to run on &#039;&#039;&#039;OS X 10.4 Tiger or newer&#039;&#039;&#039;, and can run on PPC, 32-bit, and 64-bit systems.&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
If this is your first Phidget, we highly recommend working through the Getting Started guide for your specific Phidget device, which may be found on its product page on [{{SERVER}} our main website].  If you already have the Preference Pane Installed and know how to use it, then you&#039;ve already followed the guide and are ready to learn more about the workings behind the Preference Pane, the Phidget WebService, and more - all specific to OS X.&lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the drivers:&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}downloads/libraries/Phidget.dmg OS X Installer Download]&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#osx Software License]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with OS X==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
The Phidget installer will install the core Phidget files onto your system.&lt;br /&gt;
&lt;br /&gt;
To install the libraries, follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. Download the Phidget installer for your system:&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget.dmg OS X Installer]&lt;br /&gt;
&lt;br /&gt;
2. Open up the installer, and double click on {{Code|Phidgets.mpkg}} to install the libraries.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX Install 1.png|link=|alt=OS X Install]]&lt;br /&gt;
&lt;br /&gt;
3. Proceed through the wizard. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX Install 2.png|link=|alt=OS X Install]]&lt;br /&gt;
&lt;br /&gt;
4. Once the installation is complete, you are ready to program with Phidgets. To find out what files got installed, please see [[#Description of Installer files | Description of Installer files]] in the Appendix section.&lt;br /&gt;
&lt;br /&gt;
Proceed onto to the [[#Phidget Preference Pane | next]] section where the Phidget Preference Pane will be discussed.&lt;br /&gt;
&lt;br /&gt;
====Phidget Preference Pane====&lt;br /&gt;
&lt;br /&gt;
The Phidget Preference Pane is a tool to quickly determine whether your system is able to communicate with Phidgets, and also act as a debugging tool. &lt;br /&gt;
&lt;br /&gt;
Once the Phidget libraries are installed using the installer, open up the {{Code|System Preferences}} window.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX System Preferences.png|link=|alt=OS X System Preferences]]&lt;br /&gt;
&lt;br /&gt;
Click on the {{Code|Phidgets}} icon in the {{Code|Other}} section to bring up the Phidgets Preference Pane.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane General.png|link=|alt=OS X PreferencePane General]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|general}} tab shows the list of Phidgets currently physically attached to the computer. You can also view the currently installed Phidget library version. You can double click on a Phidget device to open up an example program for the device.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Example.png|link=|alt=OS X PreferencePane Example]]&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, the RFID example was opened. These examples are intended for demonstration and debugging purposes. If you have not yet already, please see the &#039;&#039;&#039;Getting Started&#039;&#039;&#039; guide for your device, which may be found on its product page on [{{SERVER}} our main website].  &lt;br /&gt;
&lt;br /&gt;
It is important to keep in mind that when an example Phidget application is opened from the Phidget Preference Pane or opened from any of your Phidget applications that you develop, it holds a lock on the Phidget. This prevents any other program from accessing the Phidget. Please ensure that this example application is closed(the Phidget Preference Pane can still be running) when you are running your own applications. &lt;br /&gt;
&lt;br /&gt;
The next tab is the {{Code|Web Service}} tab, which allows you to control Phidgets over a network. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Stopped.png|link=|alt=OS X PreferencePane WebService Stopped]]&lt;br /&gt;
&lt;br /&gt;
Here, you can start and stop the WebService. Details are provided in the [[#WebService | WebService]] section. This screen also tells you whether the Phidget WebService is currently running. &lt;br /&gt;
&lt;br /&gt;
The next tab is the {{Code|Labels}} tab. In this section, you can view the currently assigned labels of any Phidget attached to your computer. It is also possible to set the labels of Phidgets here too. You might want to set a label to a Phidget device because you can refer to it by its label as opposed to its serial number. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Labels Local.png|link=|alt=OS X PreferencePane WebService Labels Local]]&lt;br /&gt;
&lt;br /&gt;
You can also view the labels of any Phidget connected through the WebService&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Labels Remote.png|link=|alt=OS X PreferencePane WebService Labels Remote]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|Bonjour}} tab gives a list of all currently attached Phidgets that are connected to the WebService. You can also double click on the Phidget to connect to it over the network using one or more computers, but still use the Phidget on the computer it is directly connected to.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Bonjour.png|link=|alt=OS X PreferencePane Bonjour]]&lt;br /&gt;
&lt;br /&gt;
The last tab is the {{Code|PhidgetSBC}} tab, which displays the complete list of PhidgetSBCs connected to the network. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane PhidgetSBC.png|link=|alt=OS X PreferencePane PhidgetSBC]]&lt;br /&gt;
&lt;br /&gt;
You can double click on the PhidgetSBC to bring up the PhidgetSBC Administration Console log-in page in your default browser.&lt;br /&gt;
&lt;br /&gt;
[[File:PhidgetSBCAdminConsole.PNG|link=|alt=PhidgetSBC Admin Console]]&lt;br /&gt;
&lt;br /&gt;
The PhidgetSBC Administration Console is where you can go to configure the PhidgetSBC. For more details, please see the [[1072 - Getting Started | PhidgetSBC]] section.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
To confirm the libraries were installed and work correctly, you can check both the hardware and software components of the interface. It is worth checking the software side first, because if it works then you know the hardware side is also okay.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
If you have the Phidgets library installed on your system, you can verify that the software component is working by seeing if the Phidget device is listed in the General tab of the Phidget Preference Pane.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane General.png ‎|link=|alt=OS X Preference Pane General]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows that a PhidgetRFID and a PhidgetInterfaceKit are attached to the computer. If you see your Phidget in the list, you can continue to the [[#Programming Languages | programming languages]] section to learn more. If you are not able to see that the Phidget is in the list, there may be a hardware issue. Please see the [[#Hardware| hardware]] section for more details.&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
You can verify that your computer detects that the Phidget is plugged in through a USB connection by going to the OS X System Profiler. You can access the System Profiler by selecting {{Code|About This Mac}} under the Apple icon. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX About This Mac.png‎|link=|alt=OS X About This Mac]]&lt;br /&gt;
&lt;br /&gt;
The new window will open up.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX More Info.png|link=|alt=OS X More Info]]&lt;br /&gt;
&lt;br /&gt;
Select {{Code|More Info}}. The System Profiler will show up. In the USB section, you will be able to find all connected USB devices. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX USB Devices.png ‎|link=|alt=OS X Attached USB Devices]]&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, The PhidgetInterfaceKit and PhidgetRFID are connected to the USB ports. &lt;br /&gt;
&lt;br /&gt;
If you don&#039;t see the Phidget in the list, then take a look at the [[#Troubleshooting|troubleshooting]] section below, as well as the &#039;&#039;&#039;Communications&#039;&#039;&#039; section of our [[General Troubleshooting#Communications Troubleshooting|general troubleshooting page]].&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the example programs &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your computer can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* You are using OS X 10.4 or newer. &lt;br /&gt;
* No other programs, drivers, or processes are using that USB port in software&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| quick downloads section]] to download them)&lt;br /&gt;
&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
Phidgets’ philosophy is that you do not have to be an electrical engineer in order to do projects that use devices like sensors, motors, motor controllers, and interface boards. All you need to know is how to program.&lt;br /&gt;
&lt;br /&gt;
After you have installed the drivers above, you should pick a programming language, install libraries, and run the examples for that specific language. You can learn more about what is needed to program in a particular language by choosing the language of your preference below. If you need help choosing a language, please look at the [[Software Overview#Language Support |language comparison table]]. &lt;br /&gt;
&lt;br /&gt;
We recommend the following languages for OS X:&lt;br /&gt;
* [[Language - Applescript|AppleScript]]&lt;br /&gt;
* [[Language - C/C++|C/C++]]&lt;br /&gt;
* [[Language - C Sharp|C# (Using Mono)]]&lt;br /&gt;
* [[Language - Cocoa | Cocoa]]&lt;br /&gt;
* [[Language - Flash AS3 | Flash AS3]]&lt;br /&gt;
* [[Language - Flex AS3 | Flex AS3]]&lt;br /&gt;
* [[Language - LiveCode | LiveCode]]&lt;br /&gt;
* [[Language - Java | Java]]&lt;br /&gt;
* [[Language - Max/MSP|Max/MSP]]&lt;br /&gt;
* [[Language - Python | Python]]&lt;br /&gt;
* [[Language - Ruby|Ruby]]&lt;br /&gt;
&lt;br /&gt;
You can also use these languages, but they do not support [[General Phidget Programming#Event Driven Code | event driven code]], and must use [[General Phidget Programming#Logic Code | logic code]] only:&lt;br /&gt;
&lt;br /&gt;
*[[Language - MATLAB|MATLAB]]&lt;br /&gt;
*[[Language - Simulink|Simulink]]&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network.&lt;br /&gt;
&lt;br /&gt;
Drivers for the Phidget WebService on OS X are already included in the [[#Quick Downloads | Drivers]] above. If you see the Phidget Preference Pane in System Preferences, then you already have the WebService drivers installed.&lt;br /&gt;
&lt;br /&gt;
There are two ways that you can connect to a Phidget hosted on another computer. The first method is by using the IP address/host name and port of the host computer. The second method makes the use of [http://en.wikipedia.org/wiki/Multicast_DNS mDNS], which allows Phidgets to be found and opened on the network by a server id instead of an IP address/host name. When using a server id, both the client and server will need to be running an implementation of zero configuration networking. The Phidget WebService takes advantage of [http://www.apple.com/support/downloads/bonjourforwindows.html Bonjour] software, which is built-in to OS X. It is a tool developed by Apple to locate devices, such as Phidgets,  on a network.&lt;br /&gt;
&lt;br /&gt;
This section helps you install, check, and use the WebService on Windows, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
===Turning the WebService On and Off===&lt;br /&gt;
&lt;br /&gt;
There are two methods that can be used to turn the WebService on and off. The first method is through the Phidget Preference Pane. In the {{Code|WebService}} tab, you can start or stop the WebService. You can also choose to have the WebService start up automatically upon system boot up by selecting the {{Code|Start Automatically}} checkbox. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Stopped.png|link=|alt=OS X PreferencePane WebService]]&lt;br /&gt;
&lt;br /&gt;
The second method of turning the WebService on and off is through command line. After using our installer, the WebService utility is automatically installed in {{Code|/usr/bin/phidget21webservice}}. &lt;br /&gt;
&lt;br /&gt;
You can get command line help with {{Code|phidgetwebservice21}} using the -h option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21 -h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
&#039;phidgetwebservice21&#039; is a Phidget and Dictionary server from Phidgets Inc. See www.phidgets.com for more information.&lt;br /&gt;
Usage: phidgetwebservice21 [OPTION]&lt;br /&gt;
All parameters are optional. The default parameters are: port=5001, ServerName=(Computer Name) and no password&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
  -p      Port&lt;br /&gt;
  -n      Server Name&lt;br /&gt;
  -P      Password&lt;br /&gt;
  -v      Debug mode&lt;br /&gt;
  -h      Display this help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mapping out which command line options to which Phidget Preference Pane option is as follows:&lt;br /&gt;
&lt;br /&gt;
-p: {{Code|Port}} field&lt;br /&gt;
&lt;br /&gt;
-n: {{Code|ServerID}} field&lt;br /&gt;
&lt;br /&gt;
-P: {{Code|Password}} field&lt;br /&gt;
&lt;br /&gt;
-v: Not supported under the Phidget Preference Pane&lt;br /&gt;
&lt;br /&gt;
To find the defaults used by {{Code|phidget21webservice}}, the command line is the fastest way to learn the default server name and IP address of your computer:&lt;br /&gt;
*For the default server name, use {{Code|hostname}} on the command line.&lt;br /&gt;
*For your IP address, use {{Code|ifconfig -a}} on the command line.&lt;br /&gt;
**A line in the return text, under your main internet connection (usually {{Code|eth0}}) will say something like {{Code|inet addr:192.168.3.178}}, which is your IP.&lt;br /&gt;
&lt;br /&gt;
Here are some usage examples:&lt;br /&gt;
&lt;br /&gt;
To start the WebService with default parameters:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To start the WebService with a server name of {{Code|myServer}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21-n myServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To stop the WebService, simply close the command line window or press {{Code|Control}} and {{Code|c}} at the same time in the command line window.&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
To use a Phidget over the WebService, you&#039;ll want to:&lt;br /&gt;
* Have two different computers connected to the same network. We will call the computer that has the Phidget directly connected to the USB port the host. The client will be the computer that runs a Phidget application to connect to the Phidget attached to the host. Please note that if you only have a single computer, you can also connect to the Phidget over the WebService. The computer will simply act as both a host and client. This will allow you to bypass the [[General Phidget Programming # Details for Open() | one application per Phidget limitation]]. &lt;br /&gt;
&lt;br /&gt;
* Start the WebService on the computer that directly connects to the Phidget&lt;br /&gt;
* Run your program on the remote computer that will control the Phidget over the network&lt;br /&gt;
&lt;br /&gt;
The easiest way to test these steps on OS X is to set up the WebService and run the Phidget program on the client. Please follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. On the host, open up the Phidget Preference Pane and traverse to the {{Code|Web Service}} tab.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Stopped.png |link=|alt=OS X Preference Pane WebService]]&lt;br /&gt;
&lt;br /&gt;
2. Leave all fields the way they are, and click on {{Code|Start WebService}} to run the WebService.&lt;br /&gt;
&lt;br /&gt;
3. You can determine that the WebService is running by looking at the status on the right side.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Running.png|link=|alt=OS X PreferencePane WebService Running]]&lt;br /&gt;
&lt;br /&gt;
4. Ensure that the Phidget is plugged in to the host. &lt;br /&gt;
&lt;br /&gt;
5. On the client&#039;s Phidget Preference Pane, open up the {{Code|Bonjour}} tab. You will see the Phidget that is plugged into the host as one of the entries listed. Double click it to open the example application.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Bonjour.png ‎‎ |link=|alt=OS X PreferencePane Bonjour.png ‎]]&lt;br /&gt;
&lt;br /&gt;
6. The example application will open up, and you will be able to communicate with the Phidget over the WebService.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Example.png ‎ |link=|alt=OS X PreferencePane Example]]&lt;br /&gt;
&lt;br /&gt;
7. You can confirm that the WebService was indeed behind this exchange by terminating the WebService process while still allowing the remote program to run. On the host&#039;s Phidget Preference Pane, traverse to the {{Code|WebService}} tab. Hit {{Code|Stop WebService}} to terminate the WebService. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Running.png|link=|alt=OS X PreferencePane WebService Running]]&lt;br /&gt;
&lt;br /&gt;
8. Take a look at the example application on the client. Since the application can no longer connect to the WebService, there is nothing attached. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Example Stopped.png |link=|alt=OS X PreferencePane Example Stopped]]&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
In addition to enabling [[General Phidget Programming#Logging|logging]] in your Phidget code, you can get additional debugging information from the WebService itself.  This additional debugging can only be enabled from the command line approach to start the WebService. Debug information is enabled by specifying the {{Code|-v}} option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21 -v -n &amp;quot;myServer&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugging information will be shown as output in the command line console.&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Description of Installer files===&lt;br /&gt;
&lt;br /&gt;
Here is the list of files and their description for each file the installer puts onto your system. &lt;br /&gt;
===Description of Library files===&lt;br /&gt;
&lt;br /&gt;
This section will explain the files that were placed onto your system as part of the installation process.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.framework}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed into {{Code|/Library/Frameworks}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget.kext}}&amp;lt;/b&amp;gt; is the kernel extension.  It is placed into {{Code|/System/Library/Extensions}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|libphidget21.jnilib}}&amp;lt;/b&amp;gt; is the JNI library for Java.  It is placed into {{Code|/Library/Java/Extensions}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidgets.prefpane}}&amp;lt;/b&amp;gt; is the Phidgets Preference Pane.  It is placed into {{Code|/Library/PreferencePanes}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidgetwebservice21}}&amp;lt;/b&amp;gt; is the Phidget WebService.  It is placed into {{Code|/usr/bin}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetsOSA.app}}&amp;lt;/b&amp;gt; is the the Phidgets agent for AppleScript.  It is placed into {{Code|/Library/ScriptingAdditions}}.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
None, yet.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Windows&amp;diff=20712</id>
		<title>OS - Windows</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Windows&amp;diff=20712"/>
		<updated>2012-06-29T20:41:48Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:icon-Windows.png|64x64px|link=OS - Windows]]|Windows, Phidgets can be either plugged directly into a USB Port or run over a network using the [[#WebService | WebService]].&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
Phidgets are designed to run on &#039;&#039;&#039;Windows 2000 or newer&#039;&#039;&#039;, on both 32 and 64-bit systems.&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
If this is your first Phidget, we highly recommend working through the &#039;&#039;Getting Started&#039;&#039; guide for your specific Phidget device, which may be found on its product page on [{{SERVER}} main website]. If you already have the [[File:Ph.jpg]] icon in your task bar and know how to use it, then you&#039;ve already followed the guide and are ready to learn more about the control panel, the Phidget WebService, and more - all specific to Windows.&lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the drivers:&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget-x86.exe 32 Bit Installer Download]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget-x64.exe 64 Bit Installer Download]&lt;br /&gt;
&lt;br /&gt;
For special cases where you want to install the Phidget libraries without the installer, please see the [[#Advanced Uses | Advanced Uses]] section.&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget21 Libraries] (32-Bit and 64-Bit development files without an installer)&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#windows Software License]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with Windows==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
The Phidget installer requires that your system has .NET framework 2.0 or higher. The .NET framework can be downloaded from [http://www.microsoft.com/net Microsoft]. If you do not have the .NET framework 2.0 or later installed, you can still use Phidgets. However, you won&#039;t be able to use the installer, and will have to manually install the Phidget libraries. Please see the [[#Advanced Uses | Advanced Uses]] section.&lt;br /&gt;
&lt;br /&gt;
To install the libraries, follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. Download one of the Phidget installer for your system, depending on whether your system is 32 or 64-bit. &lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget-x86.exe 32-bit]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget-x64.exe 64-bit]&lt;br /&gt;
&lt;br /&gt;
2. Open up the installer, and proceed through the wizard. &lt;br /&gt;
&lt;br /&gt;
[[File:Windows Install.PNG|link=|alt=Windows Install]]&lt;br /&gt;
&lt;br /&gt;
Please note that by default, the installer places the [[#Description of Installer files | Phidget libraries]] in {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
&lt;br /&gt;
3. Once the installation is complete, you are ready to program with Phidgets. To find out what files got installed, please see [[#Description of Installer files | Description of Installer files]] in the Appendix section.&lt;br /&gt;
&lt;br /&gt;
Next, the Phidget Control Panel will be discussed.&lt;br /&gt;
&lt;br /&gt;
====Phidget Control Panel====&lt;br /&gt;
&lt;br /&gt;
The Phidget Control Panel is a tool to quickly determine whether your system is able to communicate with Phidgets, and also act as a debugging tool. &lt;br /&gt;
&lt;br /&gt;
Once the Phidget libraries are installed using the installer, you should see the [[File:Ph.jpg]] icon in the taskbar. Double click on it to bring up the Phidget Control Panel. If the icon does not appear, just find and open the Phidget Control Panel from the start menu.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel General.PNG|link=|alt=Windows Control Panel General]]&lt;br /&gt;
&lt;br /&gt;
The general tab shows the list of Phidgets currently physically attached to the computer. You can also view the currently installed Phidget library version, as well as having the checkbox option to choose whether the Phidget Control Panel is to be started up automatically once Windows boots up. You can double click on a Phidget device in the Phidget Control Panel to open up an example program for the device.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel Example.PNG|link=|alt=Windows Control Panel Example]]&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, the RFID example was opened. These examples are intended for demonstration and debugging purposes. If you have not yet already, please see the &#039;&#039;&#039;Getting Started&#039;&#039;&#039; guide for your device, which is found on its product page on [{{SERVER}} main website]. It is important to keep in mind that when an example Phidget application is opened from the Phidget Control Panel or opened from any of your Phidget applications that you develop, it holds a lock on the Phidget. This prevents any other program from accessing the Phidget. Please ensure that this example application is closed(the Phidget Control Panel can still be running) when you are running your own applications. &lt;br /&gt;
&lt;br /&gt;
The next tab is the {{Code|WebService}} tab, which allows you to control Phidgets over a network. There are four sub-tabs. The first sub-tab is the {{Code|Setup}} tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Setup Running.PNG|link=|alt=Windows Control Panel WebService Setup]]&lt;br /&gt;
&lt;br /&gt;
Here, you can start and stop the WebService. Details are provided in the [[#WebService | WebService]] section. You can also determine whether the Phidget WebService is currently running. There is also a check box that you can select to turn on verbose output, which will display useful troubleshooting information for the WebService.&lt;br /&gt;
&lt;br /&gt;
The next sub-tab is the {{Code|Output}} tab, which provides useful debugging information while you are using the WebService. This tab will only show up if the verbose output option is selected in the previous tab. &lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Output.PNG|link=|alt=Windows Control Panel WebService Output]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|Dictionary}} sub-tab comes next; it lists all the key-value pairs that gets created when the WebService runs. More information is provided in the [[General Phidget Programming#Using the Dictionary|Dictionary]] section of the [[General Phidget Programming|General Phidget Programming]] page. &lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Dictionary.PNG|link=|alt=Windows Control WebService Dictionary]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|Bonjour}} sub-tab gives a list of all currently attached Phidgets that are connected to the WebService. This tab will only appear if you have [http://www.apple.com/support/downloads/bonjourforwindows.html Bonjour] installed onto your system. You can also double click on the Phidget to connect to it over the network using one or more computers, but still use the Phidget on the computer it is directly connected to.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Bonjour.PNG|link=|alt=Windows Control Panel WebService Bonjour]]&lt;br /&gt;
&lt;br /&gt;
The last tab is the {{Code|PhidgetSBC}} tab, which displays the complete list of any PhidgetSBCs connected to the network. This tab will be enabled if you have [http://www.apple.com/support/downloads/bonjourforwindows.html Bonjour] installed onto your system.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService PhidgetSBC.PNG|link=|alt=Windows Control Panel WebService PhidgetSBC]]&lt;br /&gt;
&lt;br /&gt;
You can double click on the PhidgetSBC to bring up the PhidgetSBC Administration Console log-in page in your default browser.&lt;br /&gt;
&lt;br /&gt;
[[File:PhidgetSBCAdminConsole.PNG|link=|alt=PhidgetSBC Admin Console]]&lt;br /&gt;
&lt;br /&gt;
The PhidgetSBC Administration Console is where you can go to configure the PhidgetSBC. For more details, please see the [[1072 - Getting Started | PhidgetSBC]] section.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
To confirm the libraries were installed and work correctly, you can check both the hardware and software components of the interface. It is worth checking the software side first, because if it works then you know the hardware side is also okay.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
If you have the Phidgets library installed on your system, you can verify that the software side component is working by seeing if a Phidget device is listed in the {{Code|General}} tab of the Phidget Control Panel.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows_ControlPanel_General.PNG|link=|alt=Windows Control Panel General]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows that a PhidgetRFID and a PhidgetInterfaceKit are attached to the computer. If you see your Phidget in the list, you can continue to the [[#Programming Languages | programming languages]] section to learn more. If you are not able to see that the Phidget is in the list, there may be a hardware issue. Please see the [[#Hardware| hardware]] section for more details.&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
You can verify that your computer detects that the Phidget is plugged in through a USB connection by going to the Windows Device Manager. &lt;br /&gt;
On Windows XP, you can access the Device Manager by accessing the start menu, right clicking on {{Code|Computer}} and selecting {{Code|Properties}}. Next, select {{Code|Advanced System Settings}} to open up a new Window. Here, open up the {{Code|Hardware}} tab and select {{Code|Device Manager}}. The Device Manager window will open.  &lt;br /&gt;
&lt;br /&gt;
[[File:Windows7 DeviceManager.PNG|link=|alt=Windows Device Manager]]&lt;br /&gt;
&lt;br /&gt;
Under the {{Code|Human Interface Devices}} heading, you can view whether your computer detects that the Phidget is connected through the USB if it is in the list. There should be a {{Code|HID-compliant device}} and a {{Code|USB Input Device}} entry for every Phidget that is attached to the computer. Please note that there is currently no way of directly determining which entry belongs to which Phidget. A simple way of verifying which entry belongs to which Phidget is to simply connect or disconnect the Phidget from the USB port of the computer. The list will automatically refresh to show the updated list of all connected USB devices.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t see the Phidget in the list, then take a look at the [[#Troubleshooting|troubleshooting]] section below, as well as the &#039;&#039;&#039;Communications&#039;&#039;&#039; section of our [[General Troubleshooting#Communications Troubleshooting|general troubleshooting page]].&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the examples &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your computer can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* You are using Windows 2000 or newer. &lt;br /&gt;
* The Phidget Control Panel requires that you have .NET framework 2.0 or newer.&lt;br /&gt;
* No other programs, drivers, or processes are using that USB port in software. Some drivers or software will sometimes mistakenly claim Phidget devices when waiting on some hardware to be connected. Please see the section: [[#Issue: Some third party software prevents communications with Phidgets|third party software prevents communications with Phidgets]] for more information.&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| getting started section]] to download them)&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Phidgets’ philosophy is that you do not have to be an electrical engineer in order to do projects that use devices like sensors, motors, motor controllers, and interface boards. All you need to know is how to program.&lt;br /&gt;
&lt;br /&gt;
After you have installed the drivers above, you should pick a programming language, install libraries, and run the examples for that specific language. You can learn more about what is needed to program in a particular language by choosing the language of your preference below. If you need help choosing a language, please look at the [[Software Overview#Language Support |language comparison table]]. &lt;br /&gt;
&lt;br /&gt;
On Windows, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C Sharp|C#]]&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Flash AS3|Flash AS3]]&lt;br /&gt;
*[[Language - Java|Java]]&lt;br /&gt;
*[[Language - LabVIEW|LabView]]&lt;br /&gt;
*[[Language - Max/MSP|Max/MSP]]&lt;br /&gt;
*[[Language - Python|Python]]&lt;br /&gt;
*[[Language - Visual Basic .NET|Visual Basic .NET]]&lt;br /&gt;
*[[Language - Visual Basic 6.0|Visual Basic 6.0]]&lt;br /&gt;
&lt;br /&gt;
You can also use these languages, but they do not support [[General Phidget Programming#Event Driven Code | event driven code]], and must use [[General Phidget Programming#Logic Code | logic code]] only:&lt;br /&gt;
&lt;br /&gt;
*[[Language - MATLAB|MATLAB]]&lt;br /&gt;
*[[Language - Simulink|Simulink]]&lt;br /&gt;
&lt;br /&gt;
The following languages are also supported, but due to a lack of demand, the full API is not implemented. Please refer to the specific language for more information on what features are unsupported.&lt;br /&gt;
*[[Language - Adobe Director|Adobe Director]]&lt;br /&gt;
*[[Language - AutoIt|AutoIt]]&lt;br /&gt;
*[[Language - Delphi|Delphi]]&lt;br /&gt;
*[[Language - LiveCode|LiveCode]]&lt;br /&gt;
*[[Language - Visual Basic for Applications|Visual Basic for Applications]]&lt;br /&gt;
*[[Language - Visual Basic Script|Visual Basic Script]]&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network. For more information, please see the [[Phidget WebService|Phidget WebService]]  page.&lt;br /&gt;
&lt;br /&gt;
Drivers for the Phidget WebService on Windows are already included in the [[#Quick Downloads | Drivers]] above. If you have a [[File:Ph.jpg]] icon in your taskbar, you already have the WebService drivers installed.&lt;br /&gt;
&lt;br /&gt;
There are two ways that you can connect to a Phidget hosted on another computer. The first method is by using the IP address/host name and port of the host computer. The second method makes the use of [http://en.wikipedia.org/wiki/Multicast_DNS mDNS], which allows Phidgets to be found and opened on the network by a server id instead of an IP address/host name. When using a server id, both the client and server will need to be running an implementation of zero configuration networking. The Phidget WebService takes advantage of the [http://www.apple.com/support/downloads/bonjourforwindows.html Bonjour] software. It is a tool, developed by Apple to locate devices such as Phidgets, and printers. You will have to install Bonjour onto your system to use the second method.&lt;br /&gt;
&lt;br /&gt;
This section helps you install, check, and use the WebService on Windows, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
===Turning the WebService On and Off===&lt;br /&gt;
&lt;br /&gt;
There are two methods that can be used to turn the WebService on and off. The first method is through the Phidget Control Panel. In the {{Code|WebService}} tab, you can start, restart or stop the WebService. You can also choose to have the WebService start up automatically upon Windows boot up by selecting {{Code|Automatic}} as the {{Code|Startup Type}}. By leaving the {{Code|Startup Type}} as {{Code|Manual}}, you will have to manually turn the WebService on everytime you wish to use it. &lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Setup Stopped.PNG|link=|alt=Windows Control Panel WebService Setup]]&lt;br /&gt;
&lt;br /&gt;
The second method of turning the WebService on and off is through command line. If you used our installer, the WebService utility is automatically installed in {{Code|C:\Program Files\Phidgets\PhidgetWebservice21.exe}}. Otherwise, if you wish to manually install the {{Code|PhidgetWebservice21.exe}}, you can place it anywhere on your system, and navigate to it in command line.&lt;br /&gt;
&lt;br /&gt;
You can get command line help with {{Code|PhidgetWebservice21.exe}} using the {{Code|-h}} option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 PhidgetWebservice21 -h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
&#039;phidgetwebservice21&#039; is a Phidget and Dictionary server from Phidgets Inc. See www.phidgets.com for more information.&lt;br /&gt;
Usage: phidgetwebservice21 [OPTION]&lt;br /&gt;
All parameters are optional. The default parameters are: port=5001, ServerName=(Computer Name) and no password&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
  -p      Port&lt;br /&gt;
  -n      Server Name&lt;br /&gt;
  -P      Password&lt;br /&gt;
  -v      Debug mode&lt;br /&gt;
  -h      Display this help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mapping out which command line options to which Phidget Control Panel option is as follows:&lt;br /&gt;
&lt;br /&gt;
-p: {{Code|Port}} field&lt;br /&gt;
&lt;br /&gt;
-n: {{Code|ServerID}} field&lt;br /&gt;
&lt;br /&gt;
-P: {{Code|Password}} field&lt;br /&gt;
&lt;br /&gt;
-v: {{Code|Enable verbose output}} checkbox&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find the host name and IP address of  your computer, open up the command line prompt.&lt;br /&gt;
*For the default server name, type {{Code|hostname}}.&lt;br /&gt;
*For your IP address, type {{Code|ipconfig -all}}.&lt;br /&gt;
**A line in the return text, will say something like {{Code|192.168.2.198}}, which is your IP.&lt;br /&gt;
&lt;br /&gt;
Here are some usage examples.  The Windows command line is used. Traverse to the Phidget installation directory(by default, it is located in {{Code|C:\Program Files\Phidgets}}).&lt;br /&gt;
&lt;br /&gt;
To start the WebService with default parameters:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 PhidgetWebservice21.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To start the WebService with a server name of {{Code|myServer}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 PhidgetWebservice21.exe -n myServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To stop the WebService, simply close the command line window or press {{Code|Ctrl}} and {{Code|c}} at the same time in the command line window.&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
To use a Phidget over the WebService, you&#039;ll want to:&lt;br /&gt;
* Have two different computers connected to the same network. We will call the computer that has the Phidget directly connected to the USB port the host. The client will be the computer that runs a Phidget application to connect to the Phidget attached to the host. Please note that if you only have a single computer, you can also connect to the Phidget over the WebService. The computer will simply act as both a host and client. This will allow you to bypass the [[General Phidget Programming # Details for Open() | one application per Phidget limitation]]. &lt;br /&gt;
&lt;br /&gt;
* Start the WebService on the computer that directly connects to the Phidget&lt;br /&gt;
* Run your program on the remote computer that will control the Phidget over the network&lt;br /&gt;
&lt;br /&gt;
The easiest way to test these steps on Windows is [http://www.apple.com/support/downloads/bonjourforwindows.html download] and install Bonjour onto both the host and client. Next, we will set up the WebService and run the Phidget program on the client. Please follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. On the host, open up the Phidget Control Panel and traverse to the {{Code|Setup}} tab of the {{Code|WebService}} section.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Setup Stopped.PNG|link=|alt=Windows Control Panel WebService Setup Stopped]]&lt;br /&gt;
&lt;br /&gt;
2. Leave all fields the way they are, and click on {{Code|Start}} to run the WebService.&lt;br /&gt;
&lt;br /&gt;
3. You can determine that the WebService is running by looking at the WebService status at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Setup Running.PNG|link=|alt=Windows Control Panel WebService Setup Running]]&lt;br /&gt;
&lt;br /&gt;
4. Ensure that the Phidget is plugged in to the host. &lt;br /&gt;
&lt;br /&gt;
5. On the client&#039;s Phidget Control Panel, open up the {{Code|Bonjour}} tab in the {{Code|WebService}} section. You will see the Phidget that is plugged into the host as one of the entries listed. Double click it to open the example application.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Bonjour Running.PNG|link=|alt=Windows Control Panel WebService Bonjour]]&lt;br /&gt;
&lt;br /&gt;
6. The example application will open up, and you will be able to communicate with the Phidget over the WebService.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel Example.PNG|link=|alt=Windows Control Panel Example]]&lt;br /&gt;
&lt;br /&gt;
7. You can confirm that the WebService was indeed behind this exchange by terminating the WebService process while still allowing the remote program to run. On the host&#039;s Phidget Control Panel, traverse to the {{Code|Setup}} tab of the {{Code|WebService}} section. Hit {{Code|Stop}} to terminate the WebService. &lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Setup Running.PNG|link=|alt=Windows Control Panel WebService Setup Running]]&lt;br /&gt;
&lt;br /&gt;
8. Take a look at the example application on the client. Since the application can no longer connect to the WebService, the attached state of the Phidget is false. &lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Example Disconnected.PNG|link=|alt=Windows Control Panel WebService Example while WebService Stopped]]&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
In addition to enabling [[General Phidget Programming#Logging|logging]] in your Phidget code, you can get additional debugging information from the WebService itself.  This additional debugging can be enabled from the {{Code|Enable verbose output}} checkbox in the Phidget Control Panel.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Setup Running.PNG|link=|alt=Windows Control Panel WebService Setup]]&lt;br /&gt;
&lt;br /&gt;
The debugging information is shown in the {{Code|Output}} tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Windows ControlPanel WebService Output Running.PNG|link=|alt=Windows Control Panel WebService Output Running]]&lt;br /&gt;
&lt;br /&gt;
If you are using the command line approach to start the WebService, debug information is enabled by specifying the {{Code|-v}} option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 PhidgetWebservice21.exe -v -n &amp;quot;myServer&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugging information is shown command line output. This will prove useful when debugging WebService problems.&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Manual File Installation===&lt;br /&gt;
&lt;br /&gt;
The Phidget installer installs the most commonly used files onto your system. However, there may be special cases where you want to install the Phidget libraries without the installers. This section will describe the purpose of the most important files file and cover how to manually install and distribute the libraries with your code. You can get the files [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip here].&lt;br /&gt;
&lt;br /&gt;
====Description of Library files====&lt;br /&gt;
&lt;br /&gt;
Here is the list of files and their description for each file the installer puts onto your system. You don&#039;t need to know this if you&#039;re just using our installer, but if you are looking to distribute our libraries with your code (without your clients having to use our installer) this list will help you pick and choose what you need:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is also placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebservce]].&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWindowsService21.exe}}&amp;lt;/b&amp;gt; is a Windows service that controls {{Code|PhidgetWebService21.exe}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is an archive containing the Phidgets library, used by the [[Language -  Java | Java]] programming language.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidgets library for .NET framework 2.0 or greater. Any .NET language can be used, including [[Language - C Sharp | C#]]  , and [[Language - Visual Basic .NET | Visual Basic .NET]].&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidgets library for .NET framework 1.1. Any .NET language can be used, including [[Language - C Sharp | C#]]  , and [[Language - Visual Basic .NET | Visual Basic .NET]].  This version of the dll should &#039;&#039;only&#039;&#039; be used for .NET 1.1 applications, not .NET 2.0 applications.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21COM.dll}}&amp;lt;/b&amp;gt; is the Component Object Model(COM) library and provides your project access to the Phidget ActiveX objects. This libraries is used by the [[Language - Adobe Director|AdobeDirector]], [[Language - AutoIt|AutoIT]], [[Language - Delphi|Delphi]], [[Language -  Visual Basic 6.0|Visual Basic 6.0]], [[Language - Visual Basic for Applications|Visual Basic for Applications]], [[Language - Visual Basic Script|Visual Basic Script]].&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21Manager.exe}}&amp;lt;/b&amp;gt; is a tool to quickly determine whether your system is able to control Phidgets, and also act as a debugging tool. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Examples}} folder&amp;lt;/b&amp;gt; contain example applications that allows you to quickly see if your Phidget is properly configured.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|x86 folder}} folder&amp;lt;/b&amp;gt; contain the 32 bit versions of {{Code|phidget21.dll}}, {{Code|phidget21.lib}}, {{Code|Phidget21COM.dll}}. These folder will only appear on 64 bit installations and is useful if you want to code against the 32 bit libraries.&lt;br /&gt;
&lt;br /&gt;
=====Special Cases of Library Install=====&lt;br /&gt;
&lt;br /&gt;
Regardless of what language you will be using to program Phidgets, you will need the {{Code|phidget21.dll}} placed in the {{Code|C:\WINDOWS\system32}} directory. Additional files are needed for the language that you choose. Please refer to the documentation provided by your [[Software Overview#Language Support|language]] to determine what files are needed and the steps needed to install them onto your system.&lt;br /&gt;
&lt;br /&gt;
You can find the {{Code|phidget21.dll}} in the link below:&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget21 Libraries] (32-Bit and 64-Bit development files without an installer)&lt;br /&gt;
&lt;br /&gt;
{{Code|PhidgetWebService21.exe}} is also provided in the link above.&lt;br /&gt;
&lt;br /&gt;
===Windows in a Virtual Machine===&lt;br /&gt;
&lt;br /&gt;
Phidgets can also be used inside a virtual machine. Instructions for VMWare and VirtualBox are provided below. Virtual PC is not supported as USB Phidgets requires a virtual platform that supports HID USB Devices and since Virtual PC does not support HID USB devices, Phidgets may not be used.&lt;br /&gt;
&lt;br /&gt;
As always, please ensure that you have the latest Phidget [[#Quick Downloads | drivers]] installed on the virtual machine and that you are using the latest version of your virtual software. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;VMWare:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To enable USB Phidgets, select Virtual Machine -&amp;gt; Removable Devices -&amp;gt; and select the Phidget Input Device -&amp;gt; Connect. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;VirtualBox&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To enable USB Phidgets, VirtualBox Guest Additions(Devices -&amp;gt; Install Guest Additions) may need to be installed. Afterwards, click on Devices -&amp;gt; USB Devices and select the Phidget device to enable. The state should go from Busy to Captured. VirtualBox may bring up a new hardware wizard in the host operating system, which has to be installed. Please note that Phidgets with USB hubs (for example, the [{{SERVER}}/products.php?product_id=1019 1019 Interface Kit with 6-port hub]), are undetectable; Fortunately, Phidgets that are attached to such Phidgets are detectable.&lt;br /&gt;
&lt;br /&gt;
Note that Windows XP &amp;quot;mode&amp;quot; in Windows 7 does &#039;&#039;&#039;not&#039;&#039;&#039; support Phidgets.&lt;br /&gt;
&lt;br /&gt;
===Installing Without an Internet Connection===&lt;br /&gt;
When running the Phidgets installer it will check for other applications such as .NET.  Part of this requires an active internet connection.  The downside to this is that even if you have the applications installed already, if you do not have an internet connection you cannot complete the installation process.  There is a way around this however which involves extracting the Phidget21.msi out of the .exe installer.  To do this follow these steps:&lt;br /&gt;
&lt;br /&gt;
*Run the installer.&lt;br /&gt;
[[image:Msi-1.png|400px]]&lt;br /&gt;
*Once the installer has started up and you are at the first informational window, navigate to your {{Code|Local Disk\Users\&amp;quot;username&amp;quot;\AppData\Local\Temp}} folder.&lt;br /&gt;
*Look for the most recently modified folders.  The Phidgets one will not have an obvious title, most likely a seemingly random string of numbers and characters.  &lt;br /&gt;
[[image:Msi-2.png|500px]]&lt;br /&gt;
*In this folder you will find the Phidget21.msi.  This can be used to install the Phidgets libraries without needing an internet connection.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
===Issue: Projects are not working after a Phidget21 reinstall===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Solution: You need to reset your references and library paths.  When you reinstall the Phidgets drivers all of the old paths can get broken.  Make sure that you are including the right header files and that you have referenced the right libraries and that should fix the problem.&lt;br /&gt;
&lt;br /&gt;
===Issue: Some third party software prevents communications with Phidgets===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some drivers or software will sometimes mistakenly claim Phidget devices when waiting on some hardware to be connected. &lt;br /&gt;
This is caused by the drivers taking every HID (human interface device) on the USB bus, effectively stealing them from the Phidgets drivers.&lt;br /&gt;
When this happens, the device shows up in the Phidget Control Panel at start up but examples and programs are unable to make a connection to the Phidget. &lt;br /&gt;
This is known to occur with Logitech QuickCam, Force Feedback Mouse, Nike, Velleman K8055, and some SteelSeries drivers. &lt;br /&gt;
&lt;br /&gt;
Solution: Try shutting/uninstalling the offending driver/software down or kill its process in the task manager when using Phidgets.&lt;br /&gt;
&lt;br /&gt;
===Issue: A corrupt installation fails on uninstall or repair===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Solution: If the normal uninstall fails, or for whatever reason, you can choose to remove the Phidget drivers manually.&lt;br /&gt;
Please perform the following:&lt;br /&gt;
# Shut down any programs using the Phidget libraries, including the WebService and the Phidget Control Panel.&lt;br /&gt;
# Delete {{Code|C:\Program Files\Phidgets\}}&lt;br /&gt;
# Remove the Phidgets key from the Registry {{Code|[-HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services PhidgetWebService21]}}.&lt;br /&gt;
&lt;br /&gt;
In most cases this is enough to get the installer working again. If you need to remove all traces of the Phidgets libraries manually, perform the following additional steps:&lt;br /&gt;
&lt;br /&gt;
# Unregister the COM library: {{Code|regsvr32 /u &amp;quot;C:\Program Files\Phidgets\Phidget21COM.dll&amp;quot;}}.&lt;br /&gt;
# Remove {{Code|Phidget21.NET}} and {{Code|Policy.2.1.Phidget21.NET}} from {{Code|C:\Windows\Assembly\}}.&lt;br /&gt;
# Delete {{Code|C:\Documents and Settings\All Users\Application Data\Phidgets}} if you are  using WindowsXP or {{Code|C:\Users\All Users\Phidgets}} if you are using Windows Vista.&lt;br /&gt;
# Delete {{Code|C:\Windows\system32\phidget21.dll}}.&lt;br /&gt;
# Delete Phidgets from the start menu.&lt;br /&gt;
# Search for and remove keys mentioning Phidgets from the registry in the following locations:&lt;br /&gt;
#* {{Code|[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\]}}&lt;br /&gt;
#* {{Code|[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\]}}&lt;br /&gt;
#* {{Code|[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Phidgets Inc]}}&lt;br /&gt;
#* {{Code|[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\Phidget21Manager]}} &lt;br /&gt;
#* {{Code|[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\Global\]}}&lt;br /&gt;
# Reboot&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; You can go through the registry and purge any other keys mentioning Phidgets if you still have problems, but at this point you should be able to reinstall under most cases. There will also be keys relating to the installer, the .NET library and the COM library, but they should not interfere with anything.&lt;br /&gt;
&lt;br /&gt;
===Issue: Event data is sporadic/slow/clumped over the WebService===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Windows implements 200ms delayed ACKs for network traffic. When traffic is one-way only - as it is with event data, the data will all arrive in clumps every 200ms because of delayed ACKs. &lt;br /&gt;
&lt;br /&gt;
This can be a great drawback for applications which rely on low latency event data over the network. (source: http://support.microsoft.com/kb/214397)&lt;br /&gt;
&lt;br /&gt;
This delayed ACK behavior can be disabled in windows to decrease event latency as documented here: http://support.microsoft.com/kb/328890&lt;br /&gt;
&lt;br /&gt;
In the future, the Phidgets library may implement this differently, but so far we have been unable to match the performance achieved by disabling delayed ACK.&lt;br /&gt;
&lt;br /&gt;
===Issue: Windows XP &amp;quot;mode&amp;quot; in Windows 7 does not work with Phidgets===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039; (running XP in included XP mode)&lt;br /&gt;
&lt;br /&gt;
Although XP supports some USB devices, its overall device support is spotty.  If you need to run XP within a virtual machine, Phidgets work under both VMWare and VirtualBox - the two main virtual machine programs.  However, this means you will need to own a copy of Windows XP to install into the virtual machine.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Python&amp;diff=20711</id>
		<title>Language - Python</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Python&amp;diff=20711"/>
		<updated>2012-06-29T20:33:35Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Python.png|64x64px|link=|alt=Python]]|Python is an object oriented programming language developed by the [http://www.python.org/psf/summary/ Python Software Foundation], is powerful and easy to learn.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Python|the complete Phidget API, including events|all Phidget devices.|Windows, OS X and Linux. We provide instructions on how to set up your environment for [[#Command line | command line]], [[#IDLE | IDLE]], and [[#Eclipse with PyDev | Eclipse with PyDev]]|&lt;br /&gt;
&lt;br /&gt;
Only Python 2.5 or higher is supported.}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Python|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/PythonDoc.zip}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/PythonDoc/Phidgets.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/Python.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/PhidgetsPython.zip|Python|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Python==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library===&lt;br /&gt;
Python programs on Windows depend on the following. The installers in the [[#Libraries and Drivers | Quick Downloads]] section put only the {{Code|phidget21.dll}} into your system. You will need to manually put the Phidget Python Module into your system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget Python Module}}&amp;lt;/b&amp;gt; is the Phidget library for Python.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|setup.py}}&amp;lt;/b&amp;gt; is used to install the Phidget module into the standard location for third party Python modules. On typical Python environments, this setup will install the Phidget Python module in the {{Code|site-packages}} directory. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip {{Code|phidget21.dll}}] and refer to our [[OS - Windows|Windows page]] for manual installation instructions.&lt;br /&gt;
&lt;br /&gt;
The first thing you will have to do is to [[#Installing the Phidget Python Module |install the {{Code|Phidget Python Module}}]]. &lt;br /&gt;
Afterwards, Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each environment below.&lt;br /&gt;
&lt;br /&gt;
===Installing the Phidget Python Module===&lt;br /&gt;
&lt;br /&gt;
Please start by downloading [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Phidget Python Module]. After extracting the file, open up a command line terminal, traverse to the directory containing {{Code|setup.py}} and enter the following to install the Phidget Python module into the Python environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
Please ensure that the Phidget Python Module is [[#Installing the Phidget Python Module | installed]] onto your system.&lt;br /&gt;
&lt;br /&gt;
Next, download the [{{SERVER}}/downloads/examples/Python.zip examples] and unpack them into a folder.  While these examples were written in Python 3.0, they are also compatible with Python 2.5 (with a [[#All Operating Systems: The examples produces an error while running in a Python 2.5 environment. | minor modification]]). It is probably best to start with the HelloWorld program, which will work with any Phidget.  There is also an example file for your specific Phidget device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Now, open up a command line prompt and navigate to the directory of the example folder. &lt;br /&gt;
&lt;br /&gt;
Next, enter the following to run the example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python example.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the Python examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidgets Python libraries. Please see the [[#Use Our Examples| Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to reference to the Phidget Python library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you will also have to add a reference to your particular Phidget.  For example, you would include the following line for a PhidgetInterfaceKit:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [{{SERVER}}/downloads/examples/Python.zip examples] on how to add a reference to your particular Phidget.&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===IDLE===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Please ensure that the Phidget Python Module is [[#Installing the Phidget Python Module | installed]] onto your system. &lt;br /&gt;
&lt;br /&gt;
Next, download the [{{SERVER}}/downloads/examples/Python.zip examples] and unpack them into a folder.  While these examples were written in Python 3.0, they are also compatible with Python 2.5 (with a [[#All Operating Systems: The examples produces an error while running in a Python 2.5 environment. | minor modification]]). It is probably best to start with the HelloWorld program, which will work with any Phidget.  There is also an example file for your specific Phidget device.  {{FindYourDevice}}  Now, open the example in the IDLE editor.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Module.&lt;br /&gt;
&lt;br /&gt;
[[File:Python IDLE Run.PNG|link=|alt=Run?]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Python examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget Python library. Please see the [[#Use Our Examples 2| Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to reference to the Phidget Python library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you will also have to add a reference to your particular Phidget.  For example, you would include the following line for a PhidgetInterfaceKit:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [{{SERVER}}/downloads/examples/Python.zip examples] on how to add a reference to your particular Phidget.&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse with PyDev===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
1. Please ensure that the Phidget Python Module is [[#Installing the Phidget Python Module | installed]] onto your system. &lt;br /&gt;
&lt;br /&gt;
2. Next, download the [{{SERVER}}/downloads/examples/Python.zip examples] and unpack them into a folder.  While these examples were written in Python 3.0, they are also compatible with Python 2.5 (with a [[#All Operating Systems: The examples produces an error while running in a Python 2.5 environment. | minor modification]]). It is probably best to start with the HelloWorld program, which will work with any Phidget.  There is also an example file for your specific Phidget device.  {{FindYourDevice}}  You will need this example source code to be imported into your project later on.&lt;br /&gt;
&lt;br /&gt;
3. Next, a new project will need to be created. Generate a new PyDev project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. To import the example program into your project, right click the Project and select {{Code|Import}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Import File 1.PNG|link=|alt=Import File]]&lt;br /&gt;
&lt;br /&gt;
5. On the next screen, select {{Code|File System}} and proceed to the next screen.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Import File 2.PNG|link=|alt=Import File]]&lt;br /&gt;
&lt;br /&gt;
6. Browse to the directory where you extracted the examples into, and select the example you wish to open.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Import File 3.PNG|link=|alt=Import File]]&lt;br /&gt;
&lt;br /&gt;
7. The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Run.PNG|link=|alt=Run?]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Python examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget Python library. Please see the [[#Use Our Examples 3 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include a reference to the Phidget Python library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will also have to add a reference to your particular Phidget.  For example, you would include the following line for a PhidgetInterfaceKit:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [{{SERVER}}/downloads/examples/Python.zip examples] on how to add a reference to your particular Phidget.&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Python on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X]] page, which also describes the different Phidget files, their installed locations, and their roles....&lt;br /&gt;
&lt;br /&gt;
The next step is to install the Phidget Python module.  Download it here:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Phidget Python Module]&lt;br /&gt;
&lt;br /&gt;
Then, unpack the module and enter the root of the newly unzipped directory.  There will be a script in the base directory called {{Code|setup.py}}.  This is used the same way as most other distributed Python modules - from a command line type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will build the module and install the built python module files into your {{Code|site-packages}} directory.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
First, download the examples:&lt;br /&gt;
*[{{SERVER}}/downloads/examples/Python.zip Phidget Python Examples]&lt;br /&gt;
&lt;br /&gt;
Unpack them, and enter the root directory.  You will find examples specific to each Phidget device, as well as a {{Code|HelloWorld.py}} example.  The {{Code|HelloWorld.py}} code is probably the easiest example to run as it will work with any Phidget device.  Or you can use the example specific to your Phidget.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The Phidget examples were written in Python 3.0 and this tutorial assumes its use. However, they should still be compatible with Python 2.6. To run the examples using Python 2.5, you will need to modify the example code in the exception handling to read “except RuntimeError, e:”, instead of “except RuntimeError as e:”.&lt;br /&gt;
&lt;br /&gt;
If needed, make those changes to the {{Code|HelloWorld.py}} example or the one for your Phidget.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python HelloWorld.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Python code, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.py}}&#039;&#039;&#039; source code file, you must include a reference to the Phidget module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In addition, you should include the module functions for your specific device.  In the case of the Interface Kit, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, it would be the software object you found when running the examples above.  Then, you would run your Python code the same way as the examples.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided Python examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Python has excellent support on Linux.  &lt;br /&gt;
&lt;br /&gt;
The first step in using Python on Linux is to install the Phidget libraries.  These are the core Phidget libraries, written in C, which when compiled become part of the programming libraries available to your system.  Download, compile, and install from the links and instructions on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
The next step is to install the Phidget Python module.  Download it here:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/PhidgetsPython.zip Phidget Python Module]&lt;br /&gt;
&lt;br /&gt;
Then, unpack the module and enter the root of the newly unzipped directory.  There will be a script in the base directory called {{Code|setup.py}}.  This is used the same way as most other distributed Python modules - from a command line type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will build the module and install the built python module files into your {{Code|site-packages}} directory.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
First, download the examples:&lt;br /&gt;
*[{{SERVER}}/downloads/examples/Python.zip Phidget Python Examples]&lt;br /&gt;
&lt;br /&gt;
Unpack them, and enter the root directory.  You will find examples specific to each Phidget device, as well as a {{Code|HelloWorld.py}} example.  The {{Code|HelloWorld.py}} code is probably the easiest example to run as it will work with any Phidget device.  Or you can use the example specific to your Phidget.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The Phidget examples were written in Python 3.0 and this tutorial assumes its use. However, they should still be compatible with Python 2.6. To run the examples using Python 2.5, you will need to modify the example code in the exception handling to read “except RuntimeError, e:”, instead of “except RuntimeError as e:”.&lt;br /&gt;
&lt;br /&gt;
If needed, make those changes to the {{Code|HelloWorld.py}} example or the one for your Phidget.  &lt;br /&gt;
&lt;br /&gt;
Then, if you have not set up [[OS_-_Linux#Setting_udev_Rules|your udev rules for USB access]], you will need to run the Python example as &#039;&#039;&#039;root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo python HelloWorld.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Python code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.py}}&#039;&#039;&#039; source code file, you must include a reference to the Phidget module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In addition, you should include the module functions for your specific device.  In the case of the Interface Kit, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, it would be the software object you found when running the examples above.  Then, you would run your Python code the same way as the examples.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided Python examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Python code will be our Python API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Python|[{{SERVER}}/documentation/PythonDoc.zip Python API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Python, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass their function names to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in Python is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/PythonDoc.zip Python API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Python will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the Python syntax.  However, many additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a [{{SERVER}}/products.php?product_id=1018 Phidget Interface Kit] as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
# Create&lt;br /&gt;
try:&lt;br /&gt;
  device = InterfaceKit()	&lt;br /&gt;
except RuntimeError as e:&lt;br /&gt;
  print(&amp;quot;Runtime Error: %s&amp;quot; % e.message)&lt;br /&gt;
&lt;br /&gt;
# Open&lt;br /&gt;
try:&lt;br /&gt;
  device.openPhidget()&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
  print (“Phidget Exception %i: %s” % (e.code, e.detail))		&lt;br /&gt;
  exit(1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The variable {{Code|device}} is now a handle for the Phidget.  This example is &#039;&#039;specific to the Interface Kit&#039;&#039; because the call InterfaceKit() is used.  For another device, use the correspondingly named call in the Python API. &lt;br /&gt;
&lt;br /&gt;
The handle &#039;&#039;&#039;device&#039;&#039;&#039; is then used for all the Python function calls using the Phidget for its device-specific functions - in this case, Interface Kit specific functions.  Every type of Phidget also inherits functionality from the Phidget base class.&lt;br /&gt;
&lt;br /&gt;
Note that open() opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.  The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
Also note that you can catch exceptions thrown by the Phidget library as we did above when using the openPhidget() call.  In other words, this should probably be present around most of your Phidget calls, especially when you are learning how to use the Phidget and debugging your code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
try:&lt;br /&gt;
  # Your code goes here&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
  print (“Phidget Exception %i: %s” % (e.code, e.detail))		&lt;br /&gt;
  exit(1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget==== &lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached).  We can handle this simply by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
device.waitForAttach(10000)&lt;br /&gt;
print (&amp;quot;%d attached!&amp;quot; % (device.getSerialNum()))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sometimes, it makes more sense to handle the attachment via an event.  This would be in instances where the Phidget is being plugged and unplugged, and you want to handle these incidents.  Or, when you want to use event-driven programming because you have a GUI-driven program.  In these cases, an event-driven code snippet to handle the attachment might look something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
def AttachHandler(event):&lt;br /&gt;
    attachedDevice = event.device&lt;br /&gt;
    serialNumber = attachedDevice.getSerialNum()&lt;br /&gt;
    deviceName = attachedDevice.getDeviceName()&lt;br /&gt;
    print(&amp;quot;Hello to Device &amp;quot; + str(deviceName) + &amp;quot;, Serial Number: &amp;quot; + str(serialNumber))&lt;br /&gt;
&lt;br /&gt;
# Insert code for -creating- device here....&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    device.setOnAttachHandler(AttachHandler)&lt;br /&gt;
except PhidgetException as e: &lt;br /&gt;
    # Insert code for handling any exceptions&lt;br /&gt;
    # A common exception will occur if you do not create the device properly above&lt;br /&gt;
&lt;br /&gt;
# Insert code for -opening- device here....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
You can read data and interact with your Phidget both by polling it for its current state (or to set a state), or by catching events that trigger when the data changes.&lt;br /&gt;
&lt;br /&gt;
For our [{{SERVER}}/products.php?product_id=1018 | Phidget Interface Kit], the polling method of getting the current sensor state and setting an output state looks something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Get a data point from Analog Port 0&lt;br /&gt;
device.getSensorValue(0)&lt;br /&gt;
&lt;br /&gt;
# Set digital output port 0 to be on&lt;br /&gt;
device.setOutputState(0, 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To catch data changes via events, you would use something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def sensorChanged(e):&lt;br /&gt;
  print (“Sensor %i: %i” % (e.index, e.value))&lt;br /&gt;
  return 0&lt;br /&gt;
&lt;br /&gt;
# Insert code to create an Interface Kit called &#039;device&#039;&lt;br /&gt;
&lt;br /&gt;
# Hook our function above into the device object&lt;br /&gt;
device.setOnSensorChangeHandler(sensorChanged)&lt;br /&gt;
&lt;br /&gt;
# Insert code to open &#039;device&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, don’t forget to call closePhidget() to free any locks on the Phidget that the openPhidget() call put in place!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
&lt;br /&gt;
device.closePhidget()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [{{SERVER}}/documentation/PythonDoc.zip Python API]. You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [{{SERVER}} main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|OS X|My application hangs when using multiple devices in a single Python application.}}===&lt;br /&gt;
&lt;br /&gt;
A call to {{Code|open}} may hang indefinitely if multiple devices are being programmed in a single Python application. To circumvent this, allow the application to delay a short period between {{Code|open}} calls. For most environments, a 1.25 millisecond delay is enough. For example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
import time&lt;br /&gt;
...&lt;br /&gt;
interface_kit.openPhidget(94695)&lt;br /&gt;
time.sleep(0.00125)&lt;br /&gt;
rfid.openPhidget(33502)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The examples produce an error while running in a Python 2.5 environment.}}===&lt;br /&gt;
&lt;br /&gt;
Running the examples produces an error similar to the following:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
InterfaceKit-simple.py:33: Warning: &#039;as&#039; will become a reserved keyword in Python 2.6&lt;br /&gt;
  File &amp;quot;InterfaceKit-simple.py&amp;quot;, line 33&lt;br /&gt;
    except RuntimeError as e:&lt;br /&gt;
SyntaxError: invalid syntax&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example code in Python 2.5, all the lines containing:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
except RuntimeError as e:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
will need to be replaced with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
except Runtime, e:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then it should run.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_LabVIEW&amp;diff=20710</id>
		<title>Language - LabVIEW</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_LabVIEW&amp;diff=20710"/>
		<updated>2012-06-29T20:32:45Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-LabVIEW.png|64x64px|link=|alt=]]|LabVIEW, developed by [http://www.ni.com National Instruments] is dataflow programming language for data processing.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|LabVIEW|the complete Phidget API, including events|all Phidget devices.| Windows. A minimum version of LabVIEW  7.1.1 is required to use the Phidget LabVIEW 32 bit library. For the Phidget LabVIEW 64 bit library, a minimum version of LabVIEW 2009 is required. OS X and Linux are unsupported as the Labview/Phidgets combination has not been tested on those systems.|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|LabVIEW|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/LabVIEW_Manual.pdf PDF}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/LabVIEWDoc/index.html|HTML version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx866.zip| (32 bit Windows - same file as LabVIEW library)}}&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx64.zip| (64 bit Windows - same file as LabVIEW library)}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx86.zip|LabVIEW|(32 bit Windows - same file as LabVIEW Examples)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx64.zip|LabVIEW|(64 bit Windows - same file as LabVIEW Examples)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with LabVIEW==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
LabVIEW programs on Windows depend on the following two items, The installers in the [[#Libraries and Drivers|Quick Downloads]] section put only the {{Code|phidget21.dll}} into your system. You will need to manually put the Phidget LabVIEW library onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidgets LabVIEW library}}&amp;lt;/b&amp;gt; contains the Phidget library for LabVIEW. You need to place the library into your LabVIEW functions palette. Instructions are explained in the [[#Write Your Own Code | Write Your Own Code]] section.&lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [{{SERVER}}/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] and manually install it where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
We include instructions for LabVIEW 2011 on [[#Use Our Examples | using our examples]] and [[#Write Your Own Code | writing your own code]].&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the examples found in the [[#Example Code | Quick Downloads]] section and unpack them into a folder. Here, you will find the {{Code|examples}} folder, which contains {{Code|vi}} programs for all the devices. Each {{Code|vi}} example demonstrate the usage of a few of the device&#039;s properties. To get a broader understanding of the device, you should take a look at all the  {{Code|vi}} examples inside the directory for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
1. Inside the {{Code|examples}} folder, navigate to the directory for your device. &lt;br /&gt;
&lt;br /&gt;
2. Open up any {{Code|.vi}} of your choice in LabVIEW. In this section, the {{Code|Sensor to Output Example.vi}} of the PhidgetInterfaceKit examples will be used. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Front Panel.PNG|link=|alt=Front Panel]]&lt;br /&gt;
&lt;br /&gt;
You will see the front panel of the example. The front panel shows the user interface of the {{code|vi}} program.&lt;br /&gt;
&lt;br /&gt;
3. Next, let us take a look at the block diagram by navigating to {{Code|Window &amp;amp;rarr; Show Block  Diagram}}.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Block Diagram 1.PNG|link=|alt=Block Diagram]]&lt;br /&gt;
&lt;br /&gt;
The block diagram shows the logic of the application.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Block Diagram 2.PNG|link=|alt=Block Diagram]]&lt;br /&gt;
&lt;br /&gt;
4. The only thing left to do is to run the examples! Navigate to {{Code|Operate &amp;amp;rarr; Run}}.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Run 1.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
5. The application will run. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Run 2.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
You can determine that your device is connected to your application if you see the indicator for {{Code|attached}} turn green and the correct serial number is displayed. These features are available in most of the example {{Code|vis}} we provide.&lt;br /&gt;
 &lt;br /&gt;
6. When you are ready to terminate the application, click on the [[File:LabVIEW Win Stop.PNG|link=|alt=Stop]] button to release the hold on the device. Please keep in mind that the application may not terminate properly if you stop it by clicking on {{Code|Operate &amp;amp;rarr; Stop}}.&lt;br /&gt;
&lt;br /&gt;
Once you have the LabVIEW examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to add the Phidget LabVIEW library to your development environment. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Navigate to {{Code|Tools &amp;amp;rarr; Advanced &amp;amp;rarr; Edit Palette Set}} to modify the functions palette.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 1.PNG|link=|alt=Edit Function Palette]]&lt;br /&gt;
&lt;br /&gt;
2. The functions palette will show up. Right click an empty area, and select {{Code|Insert &amp;amp;rarr; Subpalette}}. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 2.PNG|link=|alt=Insert Function Palette]]&lt;br /&gt;
&lt;br /&gt;
3. Next, select {{Code|Link to a directory}}.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 3.PNG|link=|alt=Link to a library]]&lt;br /&gt;
&lt;br /&gt;
4. Make sure you have the Phidget LabVIEW library and examples in the [[#Libraries and Drivers| Quick Downloads]] section downloaded and extracted. After extracting, you will find the {{Code|Phidgets}} folder. In LabVIEW, browse to the {{Code|Phidgets}} folder, and select {{Code|Current Folder}}. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 4.PNG|link=|alt=Select Phidgets library]]&lt;br /&gt;
&lt;br /&gt;
This will load the Phidget LabVIEW library into the functions palette. You can find all the functions that pertain to Phidgets inside the {{Code|Phidgets}} palette. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 5.PNG|link=|alt=Phidgets LabVIEW Library]]&lt;br /&gt;
&lt;br /&gt;
5. Click on {{Code|Save Changes}} in the {{Code|Edit Controls and Functions Palette Set}} window. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 6.PNG|link=|alt=Save Function Palette]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Since LabVIEW is a graphical language, the best way to get the &#039;code snippets&#039; you need is to take them from our examples.  The best way to find what blocks exist and how to use them is probably to switch between the block diagram view and the GUI view between examples that apply to you.  This will allow you to use pieces from our examples to create your own LabVIEW application.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing LabVIEW code will be our LabVIEW API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in LabVIEW|[{{SERVER}}/documentation/LabVIEW_Manual.pdf API Manual]}}&lt;br /&gt;
&lt;br /&gt;
If you are really getting in to using Phidgets, you probably want our more general programming resources as well.  Although these are focused on the text-based languages that we support (C++, Java, etc), the concepts remain the same on how Phidgets are used within code.  Our [[General Phidget Programming]] page gives more information about:&lt;br /&gt;
* [[General Phidget Programming#Using Multiple Phidgets|Using Multiple Phidgets]] (or a Phidget [[General Phidget Programming#Creating a Software Object|other than the Interface Kit]])&lt;br /&gt;
* Catching [[General Phidget Programming#Exceptions and Errors|exceptions and errors]] and [[General Phidget Programming#Logging|using logging]]&lt;br /&gt;
* [[General Phidget Programming#Event Driven Code|Event catching]] versus [[General Phidget Programming#Logic Code|direct polling]]&lt;br /&gt;
* And more....&lt;br /&gt;
Of course, most of these concepts are covered using block flow within LabVIEW, but knowing the general order of operations can help you structure your code.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: Events can occasionally cause issues, especially when there are multiple of the same type of event===&lt;br /&gt;
In other words, if you open 2 Interface Kits and have a sensor change event for each one your system can behave unpredictably.  To solve this issue you have to stop using events and simply poll the device.  Events work similarly to polling in LabVIEW anyway and should not cause substantial performance changes to your application.&lt;br /&gt;
&lt;br /&gt;
Note that Phidgets do not always work cleanly in Labview.  Sometimes they do not appear, sometimes they work veeerrryyy slowly.  No known fixes yet, hopefully soon.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_LabVIEW&amp;diff=20709</id>
		<title>Language - LabVIEW</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_LabVIEW&amp;diff=20709"/>
		<updated>2012-06-29T20:32:30Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-LabVIEW.png|64x64px|link=|alt=]]|LabVIEW, developed by [http://www.ni.com National Instruments] is dataflow programming language for data processing.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|LabVIEW|the complete Phidget API, including events|all Phidget devices.| Windows. A minimum version of LabVIEW  7.1.1 is required to use the Phidget LabVIEW 32 bit library. For the Phidget LabVIEW 64 bit library, a minimum version of LabVIEW 2009 is required. OS X and Linux are unsupported as the Labview/Phidgets combination has not been tested on those systems.|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|LabVIEW|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/LabVIEW_Manual.pdf}}&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/web/LabVIEWDoc/index.html|HTML version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx866.zip| (32 bit Windows - same file as LabVIEW library)}}&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx64.zip| (64 bit Windows - same file as LabVIEW library)}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx86.zip|LabVIEW|(32 bit Windows - same file as LabVIEW Examples)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/examples/LabVIEWx64.zip|LabVIEW|(64 bit Windows - same file as LabVIEW Examples)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with LabVIEW==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
LabVIEW programs on Windows depend on the following two items, The installers in the [[#Libraries and Drivers|Quick Downloads]] section put only the {{Code|phidget21.dll}} into your system. You will need to manually put the Phidget LabVIEW library onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidgets LabVIEW library}}&amp;lt;/b&amp;gt; contains the Phidget library for LabVIEW. You need to place the library into your LabVIEW functions palette. Instructions are explained in the [[#Write Your Own Code | Write Your Own Code]] section.&lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [{{SERVER}}/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] and manually install it where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
We include instructions for LabVIEW 2011 on [[#Use Our Examples | using our examples]] and [[#Write Your Own Code | writing your own code]].&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the examples found in the [[#Example Code | Quick Downloads]] section and unpack them into a folder. Here, you will find the {{Code|examples}} folder, which contains {{Code|vi}} programs for all the devices. Each {{Code|vi}} example demonstrate the usage of a few of the device&#039;s properties. To get a broader understanding of the device, you should take a look at all the  {{Code|vi}} examples inside the directory for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
1. Inside the {{Code|examples}} folder, navigate to the directory for your device. &lt;br /&gt;
&lt;br /&gt;
2. Open up any {{Code|.vi}} of your choice in LabVIEW. In this section, the {{Code|Sensor to Output Example.vi}} of the PhidgetInterfaceKit examples will be used. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Front Panel.PNG|link=|alt=Front Panel]]&lt;br /&gt;
&lt;br /&gt;
You will see the front panel of the example. The front panel shows the user interface of the {{code|vi}} program.&lt;br /&gt;
&lt;br /&gt;
3. Next, let us take a look at the block diagram by navigating to {{Code|Window &amp;amp;rarr; Show Block  Diagram}}.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Block Diagram 1.PNG|link=|alt=Block Diagram]]&lt;br /&gt;
&lt;br /&gt;
The block diagram shows the logic of the application.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Block Diagram 2.PNG|link=|alt=Block Diagram]]&lt;br /&gt;
&lt;br /&gt;
4. The only thing left to do is to run the examples! Navigate to {{Code|Operate &amp;amp;rarr; Run}}.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Run 1.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
5. The application will run. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Run 2.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
You can determine that your device is connected to your application if you see the indicator for {{Code|attached}} turn green and the correct serial number is displayed. These features are available in most of the example {{Code|vis}} we provide.&lt;br /&gt;
 &lt;br /&gt;
6. When you are ready to terminate the application, click on the [[File:LabVIEW Win Stop.PNG|link=|alt=Stop]] button to release the hold on the device. Please keep in mind that the application may not terminate properly if you stop it by clicking on {{Code|Operate &amp;amp;rarr; Stop}}.&lt;br /&gt;
&lt;br /&gt;
Once you have the LabVIEW examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to add the Phidget LabVIEW library to your development environment. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Navigate to {{Code|Tools &amp;amp;rarr; Advanced &amp;amp;rarr; Edit Palette Set}} to modify the functions palette.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 1.PNG|link=|alt=Edit Function Palette]]&lt;br /&gt;
&lt;br /&gt;
2. The functions palette will show up. Right click an empty area, and select {{Code|Insert &amp;amp;rarr; Subpalette}}. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 2.PNG|link=|alt=Insert Function Palette]]&lt;br /&gt;
&lt;br /&gt;
3. Next, select {{Code|Link to a directory}}.&lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 3.PNG|link=|alt=Link to a library]]&lt;br /&gt;
&lt;br /&gt;
4. Make sure you have the Phidget LabVIEW library and examples in the [[#Libraries and Drivers| Quick Downloads]] section downloaded and extracted. After extracting, you will find the {{Code|Phidgets}} folder. In LabVIEW, browse to the {{Code|Phidgets}} folder, and select {{Code|Current Folder}}. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 4.PNG|link=|alt=Select Phidgets library]]&lt;br /&gt;
&lt;br /&gt;
This will load the Phidget LabVIEW library into the functions palette. You can find all the functions that pertain to Phidgets inside the {{Code|Phidgets}} palette. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 5.PNG|link=|alt=Phidgets LabVIEW Library]]&lt;br /&gt;
&lt;br /&gt;
5. Click on {{Code|Save Changes}} in the {{Code|Edit Controls and Functions Palette Set}} window. &lt;br /&gt;
&lt;br /&gt;
[[File:LabVIEW Win Functions Palette 6.PNG|link=|alt=Save Function Palette]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Since LabVIEW is a graphical language, the best way to get the &#039;code snippets&#039; you need is to take them from our examples.  The best way to find what blocks exist and how to use them is probably to switch between the block diagram view and the GUI view between examples that apply to you.  This will allow you to use pieces from our examples to create your own LabVIEW application.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing LabVIEW code will be our LabVIEW API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in LabVIEW|[{{SERVER}}/documentation/LabVIEW_Manual.pdf API Manual]}}&lt;br /&gt;
&lt;br /&gt;
If you are really getting in to using Phidgets, you probably want our more general programming resources as well.  Although these are focused on the text-based languages that we support (C++, Java, etc), the concepts remain the same on how Phidgets are used within code.  Our [[General Phidget Programming]] page gives more information about:&lt;br /&gt;
* [[General Phidget Programming#Using Multiple Phidgets|Using Multiple Phidgets]] (or a Phidget [[General Phidget Programming#Creating a Software Object|other than the Interface Kit]])&lt;br /&gt;
* Catching [[General Phidget Programming#Exceptions and Errors|exceptions and errors]] and [[General Phidget Programming#Logging|using logging]]&lt;br /&gt;
* [[General Phidget Programming#Event Driven Code|Event catching]] versus [[General Phidget Programming#Logic Code|direct polling]]&lt;br /&gt;
* And more....&lt;br /&gt;
Of course, most of these concepts are covered using block flow within LabVIEW, but knowing the general order of operations can help you structure your code.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: Events can occasionally cause issues, especially when there are multiple of the same type of event===&lt;br /&gt;
In other words, if you open 2 Interface Kits and have a sensor change event for each one your system can behave unpredictably.  To solve this issue you have to stop using events and simply poll the device.  Events work similarly to polling in LabVIEW anyway and should not cause substantial performance changes to your application.&lt;br /&gt;
&lt;br /&gt;
Note that Phidgets do not always work cleanly in Labview.  Sometimes they do not appear, sometimes they work veeerrryyy slowly.  No known fixes yet, hopefully soon.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Visual_Basic&amp;diff=20705</id>
		<title>Language - Visual Basic</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Visual_Basic&amp;diff=20705"/>
		<updated>2012-06-29T20:29:01Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Visual Basic Net.png|64x64px|link=|alt=]]|Visual Basic .NET, developed by [http://www.microsoft.com Microsoft] is a modern object oriented programming language and the successor to [[Language - Visual Basic 6.0 | Visual Basic 6.0]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Visual Basic .NET|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Visual Basic .NET|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21.NET.zip .NET}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/NETDoc/Index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/VBNET.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Visual Basic .NET==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Visual Basic .NET programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly environment-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compiler]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/VBNET.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and Visual Studio 2008, Visual Studio 2010 will easily open and upgrade them with the Visual Studio Conversion Wizard.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for Visual Basic .NET, and then you can set your main project to be the HelloWorld project that will work with any Phidget board.  Or you can choose the example that matches your device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the type Phidget is not defined, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Visual Basic .NET examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget .NET library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual Basic .NET Console Application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
As the Visual Basic .NET examples were written in Visual Studio 2005 and 2008, Visual Studio 2003 is not able to open the examples. Furthermore, it will be difficult to import the examples into your Visual Studio 2003 project as you will need to recreate the GUI components. Fortunately, taking a look at the source code will give you valuable programming insight. We have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual Basic Console Application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget21 function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching ]] section also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|vbnc}} compiler.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
We do not have Visual Basic .NET examples for the Mono framework. Fortunately, you can take a look at the source code for our [{{SERVER}}/downloads/examples/CSharp.zip Visual Studio 2005 and 2008 examples] for valuable programming insight. We have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your compiler to properly link the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code. &lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc /out:example.exe /r:Phidget21.NET.dll Example.vb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/VBNET.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will run with any Phidget. &lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but they are also compatible with MonoDevelop. Please note that the examples are only designed to be run under the .NET framework. The examples are not compatible with the Mono framework. Despite this, if you are using the Mono framework, you can use the code within the examples for valuable programming insight. &lt;br /&gt;
&lt;br /&gt;
The rest of this section will explain the steps needed to run our examples under the .NET framework. To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for Visual Basic .NET, and then you can set your main project to be the one that matches your device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Startup Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the Microsoft .NET framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the Phidget is not defined, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Visual Basic .NET examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new Visual Basic .NET console project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
Visual Basic .NET has excellent support on OS X through the Mono framework. &lt;br /&gt;
&lt;br /&gt;
The first step in using Visual Basic .NET on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X]] page, which also describes the different Phidget files, their installed locations, and their roles....  &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget VB.NET examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget Visual Basic .NET Examples (not the ones for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/VBNET.zip Visual Basic .NET Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in VB.NET/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
To check that your Mac, Phidget, and Mono setup is all working together, you&#039;ll want to run the Visual Basic (VB) examples.  You&#039;ll probably want to start with the Hello World VB example.  Alternatively, you could find the source code for your device. {{Template:FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
All of the .NET examples are much larger projects through Visual Studio, so you&#039;ll need to dig around within the project and find the source code and compile only that source code using Mono.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Hello World example.  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|VBNET/}} &amp;amp;rarr; {{Code|Hello World/}} &amp;amp;rarr; {{Code|Module1.vb}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name, rather than {{Code|Hello World}}.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Module1.vb}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in Visual Basic/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc Module1.vb -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Module1.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Visual Basic code on OS X, such as within a text editor. In your .vb source code file, you must include a reference to the Phidget software object.  In the case of a Phidget interface kit device, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Public Class Form1&lt;br /&gt;
   &#039;The Phidget object declaration&lt;br /&gt;
		&lt;br /&gt;
   Dim WithEvents ifKit As Phidgets.InterfaceKit&lt;br /&gt;
		&lt;br /&gt;
   &#039;... Form1_Load and Form1_OnClosing here&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, check the API for your device on our webpage for the software object name, and the [{{SERVER}}/documentation/Phidget21.NET.zip API for .NET] for the specific syntax to use.  Then, you would compile your completed VB code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided VB examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Visual Basic .NET has support on Linux through the Mono framework.  &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using Visual Basic .NET with Phidgets on Linux is to install Mono.  Although you probably have already done this if you&#039;re a Visual Basic .NET programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Visual Basic Mono framework also requires the Visual Basic .NET compiler, {{Code|vbnc}}.  This can be installed via another Mono package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get install mono-vbnc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget Visual Basic examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget Visual Basic .NET Examples (not the ones for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/VBNET.zip Visual Basic .NET Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the Visual Basic (VB) examples.  You&#039;ll probably want to start with the Hello World VB example.  Alternatively, you could find the source code for your device. {{Template:FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
All of the .NET examples are much larger projects through Visual Studio, so you&#039;ll need to dig around within the project and find the source code and compile only that source code using Mono.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Hello World example.  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|VBNET/}} &amp;amp;rarr; {{Code|Hello World/}} &amp;amp;rarr; {{Code|Module1.vb}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name, rather than {{Code|Hello World}}.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Module1.vb}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in Visual Basic/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc Module1.vb -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Module1.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Visual Basic code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .vb source code file, you must include a reference to the Phidget software object.  In the case of a Phidget interface kit device, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Public Class Form1&lt;br /&gt;
   &#039;The Phidget object declaration&lt;br /&gt;
		&lt;br /&gt;
   Dim WithEvents ifKit As Phidgets.InterfaceKit&lt;br /&gt;
		&lt;br /&gt;
   &#039;... Form1_Load and Form1_OnClosing here&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, check the API for your device on our webpage for the software object name, and the [{{SERVER}}/documentation/Phidget21.NET.zip API for .NET] for the specific syntax to use.  Then, you would compile your completed VB code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided VB examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Visual Basic .NET code will be our .NET API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in .NET|[{{SERVER}}m/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Visual Basic .NET, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like, although you must catch the events by name in the &amp;quot;Handles&amp;quot; portion of the function declaration.  The &amp;quot;Handles&amp;quot; portion of the function hooks them into the actual events when they occur. See our examples for details.&amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the device-specific examples to show you more detail on using your Phidget.  &lt;br /&gt;
|Creating a Phidget software object in Visual Basic .NET is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Visual Basic (VB) .NET will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the VB .NET syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware. So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using an Interface Kit Phidget board as our device, the create and open calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
ifKit = New Phidgets.InterfaceKit&lt;br /&gt;
ifKit.open()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded.&lt;br /&gt;
&lt;br /&gt;
When combined in your initialization function with the initialization and open from above, the wait for attachment would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)&lt;br /&gt;
Handles MyBase.Load&lt;br /&gt;
    ifKit = New Phidgets.InterfaceKit&lt;br /&gt;
    ifKit.open()&lt;br /&gt;
    ifKit.waitForAttachment(3000)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. In VB.NET we can hook an event handler into the event of a sensor changing on an Interface Kit board with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub ifKit_SensorChange(ByVal sender As Object, ByVal e As Phidgets.Events.SensorChangeEventArgs) Handles ifKit.SensorChange&lt;br /&gt;
    TextBox1.Text = &amp;quot;Index &amp;quot; + e.Index.ToString() + &amp;quot; Value: &amp;quot; + e.Value.ToString()&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this function, the code inside ifKit_SensorChange will get executed every time the Phidget Interface Kit reports a change on one of its analog inputs. This is because it &amp;quot;Handles&amp;quot; the SensorChange event.  Some events such as Attach and Detach belong to the base Phidget object and thus are common to all types of Phidgets. &lt;br /&gt;
&lt;br /&gt;
Some values can be read and sent directly to the Phidget, simply use the instance members and properties. This is also how you would set properties on the Phidget such as the output state or&lt;br /&gt;
sensor sensitivity.  For example, obtaining the value of analog input (sensor) 0 on an Interface Kit board would be via:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Dim val As Integer = ifKit.sensors(0).Value&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing&lt;br /&gt;
    RemoveHandler ifKit.SensorChange, AddressOf ifKit_SensorChange&lt;br /&gt;
    Application.DoEvents()&lt;br /&gt;
    ifKit.close()&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [{{SERVER}}/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [{{SERVER}} main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=20704</id>
		<title>Language - C Sharp</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=20704"/>
		<updated>2012-06-29T20:27:31Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-CSharp.png|64x64px|link=|alt=]]|C# is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C#|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21.NET.zip .NET}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/NETDoc/Index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/CSharp.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpacking them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld example which works with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
As the examples were written in newer versions of Visual Studio, Visual Studio 2003 is not able to open the examples. Fortunately, you can import the &#039;&#039;&#039;simple examples&#039;&#039;&#039; to a Visual Studio 2003 project. It will be difficult to import the full examples as you will need to recreate the GUI components. &lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Visual C# console application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. To import the simple example program into your project, please: open up {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
6. Traverse to the example in Windows Explorer and locate the {{Code|Program.cs}} file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the contents from that file into {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
8. Comment out the following line as it is not supported in .NET 1.1:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using System.Collections.Generic;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code 2.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
9. Now, you can run the example. Click on Debug &amp;amp;rarr; Start.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 2 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|mcs}} compiler. Other compilers such as {{Code|gmcs}}, {{Code|smcs}}, and {{Code|dmcs}} all work in the same way.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld program that will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}}. &lt;br /&gt;
&lt;br /&gt;
Please only use the simple examples. The full examples uses Windows Forms, which Mono and the Gtk# toolkit are not completely compatible with. Locate the {{Code|Program.cs}} file as this contains the example source code. Copy the file into your working directory, and rename it to {{Code|example.cs}}.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code.&lt;br /&gt;
&lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mcs /out:example.exe /r:phidget21.NET.dll example.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have the {{Code|Phidget21.NET.dll}} installed in another location, please change the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 3 | Use Our Example ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will work with any Phidget. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but are also compatible with MonoDevelop.&lt;br /&gt;
&lt;br /&gt;
To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C#, and then you can set your main project to be the one that matches your device.   If you are running under the .NET framework, you can use either the full or simple examples. Otherwise, if you are running under the Mono framework, please only use the simple examples. The full examples uses Windows Forms, which is not completely compatible with Mono&#039;s Gtk#.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Start Up.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the target framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Run As.PNG|link=|alt=Run As]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new C# empty project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for OS X.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C# has support on Linux through the Mono framework.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using C# with Phidgets on Linux is to make sure that you have all of Mono installed.  Although you probably have already done this if you&#039;re a C# programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the C# examples.  Specifically, you&#039;ll want to run the &#039;&#039;simple&#039;&#039; C# examples. You can either use the HelloWorld program that will work with any Phidget, or you can find the source code for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Temperature Sensor example (for the 1048 or 1051).  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|TemperatureSensorExamples}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|Program.cs}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Program.cs}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C# code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .cs source code file, you must include a reference to the Phidget Library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets; &lt;br /&gt;
using Phidgets.Events; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C# code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided C# examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}  Please ensure that you have set your start up project to be the one that matches your device before compiling. &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C# code will be our C# API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C#|[{{SERVER}}/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C#, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will add them to the Phidget .NET library in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are things like attach, detach, and error handling.&amp;lt;br&amp;gt;&lt;br /&gt;
Other event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
|Creating a Phidget software object in C# is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in C# will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the C# syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a Temperature Sensor board as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
// using.....&lt;br /&gt;
&lt;br /&gt;
namespace Program {&lt;br /&gt;
    class Code {&lt;br /&gt;
        static void Main(string[] args) {&lt;br /&gt;
            try {&lt;br /&gt;
&lt;br /&gt;
                // Declare a TemperatureSensor object&lt;br /&gt;
                TemperatureSensor device = new TemperatureSensor(); &lt;br /&gt;
                &lt;br /&gt;
                // Hook in any event handlers&lt;br /&gt;
                // ...&lt;br /&gt;
&lt;br /&gt;
                // Open the device&lt;br /&gt;
                device.open();&lt;br /&gt;
&lt;br /&gt;
            } catch (PhidgetException ex) { Console.WriteLine(ex.Description); }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  device.open();&lt;br /&gt;
  Console.WriteLine(&amp;quot;Waiting for TemperatureSensor to be attached....&amp;quot;);&lt;br /&gt;
  device.waitForAttachment();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event.  You can hook a custom function into an event trigger like this, using the Interface Kit Phidget as an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ifKit_SensorChange method is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
void ifKit_SensorChange(object sender, SensorChangeEventArgs e) {&lt;br /&gt;
   textBox1.Text = &amp;quot;Index &amp;quot; + e.Index + &amp;quot; Value: &amp;quot; + e.Value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget.  These functions can be used inside a polling loop as an alternative to event driven programming.  The line inside the loop would be something like this, after which you could do something with the value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
int val = device.sensors[0].Value;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)  {&lt;br /&gt;
    ifKit.SensorChange -= new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
    //run any events in the message queue&lt;br /&gt;
    Application.DoEvents();&lt;br /&gt;
    ifKit.close();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [{{SERVER}}/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [{{SERVER}} main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=20703</id>
		<title>Language - C Sharp</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=20703"/>
		<updated>2012-06-29T20:27:13Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-CSharp.png|64x64px|link=|alt=]]|C# is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C#|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21.NET.zip .NET}}&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/web/NETDoc/Index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/CSharp.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpacking them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld example which works with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
As the examples were written in newer versions of Visual Studio, Visual Studio 2003 is not able to open the examples. Fortunately, you can import the &#039;&#039;&#039;simple examples&#039;&#039;&#039; to a Visual Studio 2003 project. It will be difficult to import the full examples as you will need to recreate the GUI components. &lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Visual C# console application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. To import the simple example program into your project, please: open up {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
6. Traverse to the example in Windows Explorer and locate the {{Code|Program.cs}} file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the contents from that file into {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
8. Comment out the following line as it is not supported in .NET 1.1:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using System.Collections.Generic;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code 2.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
9. Now, you can run the example. Click on Debug &amp;amp;rarr; Start.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 2 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|mcs}} compiler. Other compilers such as {{Code|gmcs}}, {{Code|smcs}}, and {{Code|dmcs}} all work in the same way.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld program that will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}}. &lt;br /&gt;
&lt;br /&gt;
Please only use the simple examples. The full examples uses Windows Forms, which Mono and the Gtk# toolkit are not completely compatible with. Locate the {{Code|Program.cs}} file as this contains the example source code. Copy the file into your working directory, and rename it to {{Code|example.cs}}.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code.&lt;br /&gt;
&lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mcs /out:example.exe /r:phidget21.NET.dll example.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have the {{Code|Phidget21.NET.dll}} installed in another location, please change the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 3 | Use Our Example ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will work with any Phidget. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but are also compatible with MonoDevelop.&lt;br /&gt;
&lt;br /&gt;
To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C#, and then you can set your main project to be the one that matches your device.   If you are running under the .NET framework, you can use either the full or simple examples. Otherwise, if you are running under the Mono framework, please only use the simple examples. The full examples uses Windows Forms, which is not completely compatible with Mono&#039;s Gtk#.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Start Up.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the target framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Run As.PNG|link=|alt=Run As]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new C# empty project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for OS X.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C# has support on Linux through the Mono framework.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using C# with Phidgets on Linux is to make sure that you have all of Mono installed.  Although you probably have already done this if you&#039;re a C# programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the C# examples.  Specifically, you&#039;ll want to run the &#039;&#039;simple&#039;&#039; C# examples. You can either use the HelloWorld program that will work with any Phidget, or you can find the source code for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Temperature Sensor example (for the 1048 or 1051).  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|TemperatureSensorExamples}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|Program.cs}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Program.cs}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C# code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .cs source code file, you must include a reference to the Phidget Library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets; &lt;br /&gt;
using Phidgets.Events; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C# code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided C# examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [{{SERVER}}/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}  Please ensure that you have set your start up project to be the one that matches your device before compiling. &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C# code will be our C# API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C#|[{{SERVER}}/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C#, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will add them to the Phidget .NET library in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are things like attach, detach, and error handling.&amp;lt;br&amp;gt;&lt;br /&gt;
Other event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
|Creating a Phidget software object in C# is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in C# will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the C# syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a Temperature Sensor board as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
// using.....&lt;br /&gt;
&lt;br /&gt;
namespace Program {&lt;br /&gt;
    class Code {&lt;br /&gt;
        static void Main(string[] args) {&lt;br /&gt;
            try {&lt;br /&gt;
&lt;br /&gt;
                // Declare a TemperatureSensor object&lt;br /&gt;
                TemperatureSensor device = new TemperatureSensor(); &lt;br /&gt;
                &lt;br /&gt;
                // Hook in any event handlers&lt;br /&gt;
                // ...&lt;br /&gt;
&lt;br /&gt;
                // Open the device&lt;br /&gt;
                device.open();&lt;br /&gt;
&lt;br /&gt;
            } catch (PhidgetException ex) { Console.WriteLine(ex.Description); }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  device.open();&lt;br /&gt;
  Console.WriteLine(&amp;quot;Waiting for TemperatureSensor to be attached....&amp;quot;);&lt;br /&gt;
  device.waitForAttachment();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event.  You can hook a custom function into an event trigger like this, using the Interface Kit Phidget as an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ifKit_SensorChange method is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
void ifKit_SensorChange(object sender, SensorChangeEventArgs e) {&lt;br /&gt;
   textBox1.Text = &amp;quot;Index &amp;quot; + e.Index + &amp;quot; Value: &amp;quot; + e.Value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget.  These functions can be used inside a polling loop as an alternative to event driven programming.  The line inside the loop would be something like this, after which you could do something with the value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
int val = device.sensors[0].Value;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)  {&lt;br /&gt;
    ifKit.SensorChange -= new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
    //run any events in the message queue&lt;br /&gt;
    Application.DoEvents();&lt;br /&gt;
    ifKit.close();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [{{SERVER}}/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [{{SERVER}} main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20702</id>
		<title>Electricity Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Electricity_Primer&amp;diff=20702"/>
		<updated>2012-06-29T20:23:31Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Design of reliable systems is really, really hard.  The main challenge is the design of reliable building blocks - i.e. circuit and board layouts - from which to create your system.  Phidgets does the majority of this work for you.  And, once you have reliable building blocks, designing a reliable system from them is much easier.  &lt;br /&gt;
&lt;br /&gt;
However, you can still make an unreliable system out of Phidgets.  In fact, if you are building a more complex system than the common examples we show through our documentation, and you have limited experience in complex electrical design, you will probably - and unintentionally - introduce design flaws that will make your system unreliable.&lt;br /&gt;
&lt;br /&gt;
There are two reasons why you should read this primer:&lt;br /&gt;
# You want to build a complex system, more complex than we illustrate in our documentation.  To succeed, you need to understand concepts.&lt;br /&gt;
# You understand how to make your system work, and you want to ensure it is well designed for maximum reliability and/or precision.&lt;br /&gt;
&lt;br /&gt;
==The Basics==&lt;br /&gt;
&lt;br /&gt;
To understand our discussion of potential problems and their solutions below, you&#039;ll need to be familiar with the basics.  For this page, &#039;being familiar&#039; means more than simply having heard of voltage, amperage, and power.  You will need to have a working, conceptual model in your head, so that you can apply that model to your own system and examine it for problems.  This section is all about giving the tools to build that mental model.&lt;br /&gt;
&lt;br /&gt;
First, some terminology.  We introduce it by analogy.  If a circuit is a water system,&lt;br /&gt;
* The &#039;&#039;&#039;voltage&#039;&#039;&#039; is the &#039;&#039;pressure&#039;&#039; in the system&lt;br /&gt;
* The &#039;&#039;&#039;power supply&#039;&#039;&#039; is the &#039;&#039;pump&#039;&#039; creating the pressure&lt;br /&gt;
* The &#039;&#039;&#039;amperage&#039;&#039;&#039;, also known as current, is the amount of &#039;&#039;flow&#039;&#039;&lt;br /&gt;
* The &#039;&#039;&#039;load&#039;&#039;&#039; is the &#039;&#039;faucet&#039;&#039; - adjusting your load will adjust the flow&lt;br /&gt;
* The &#039;&#039;&#039;resistance&#039;&#039;&#039; is an attribute of the load - how tight or loose the faucet is&lt;br /&gt;
* The &#039;&#039;&#039;ground&#039;&#039;&#039; is the return path from load to pump.&lt;br /&gt;
&lt;br /&gt;
The basic concepts for all of these terms are presented below.&lt;br /&gt;
 &lt;br /&gt;
===Load===&lt;br /&gt;
&lt;br /&gt;
We start with the load, because the load is the purpose of your entire system.  &lt;br /&gt;
&lt;br /&gt;
In simple, USB-only Phidget systems, the load is the Phidget itself.  The USB port is ready to provide power, but it does not (and cannot) until a load is applied (i.e. the Phidget is attached) and the circuit is completed.  &lt;br /&gt;
&lt;br /&gt;
Without a load that connects in a loop, it is like attaching a closed pipe to your pump.  Initially, water will fill the pipe, and pressurize it, but once the pipe fills the system as a whole will do nothing more.  To allow the pump to drive the load, and the flow to supply the load, we need to have a completed circuit, like this:&lt;br /&gt;
 &lt;br /&gt;
[[Image:elec_flow.png|150px]]&lt;br /&gt;
&lt;br /&gt;
The load and the pump must &#039;&#039;&#039;match&#039;&#039;&#039;.  If the load lets too much flow through, the pump will work too hard and burn itself out.  This is what happens when you short circuit a power supply.  The load is then simply a wire, which basically opens the flood gates and drains your power supply pump.  The load must not let too much flow through, which it does by &#039;&#039;&#039;resistance&#039;&#039;&#039;. Likewise, the pump cannot push too hard on the load, or the load will break.  This is discussed in-depth as part of [[#Voltage and Amperage|Voltage and Amperage]] below.&lt;br /&gt;
&lt;br /&gt;
===Voltage and Amperage===&lt;br /&gt;
&lt;br /&gt;
Within the flow concept [[#Load|above]], voltage is pressure.  Specifically, it is the &#039;&#039;difference&#039;&#039; in pressure between the flow and the return.  Voltage is measured in volts, and is denoted by &#039;&#039;&#039;V&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Amperage - also known as current - is the flow, or the amount of water that moves.  At the pump, the amount of current out and the amount of current in are equal.  The pressure might vary widely (highly pressurized pipes out, low pressure pipes back) but the &#039;&#039;amount&#039;&#039; of current is always the same.  Amperage is measured in Amps, and is denoted by &#039;&#039;&#039;A&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To match a pump to a load, the voltage and amperage of the power (supply) and load (sink) must line up.  We discuss picking a power supply - whether [[#Wall Power|wall mains]], or [[#Battery Power|batteries]] - in the [[#Power Needs|Power Needs section]] farther along in the document, but we need a few more concepts before we get there.&lt;br /&gt;
&lt;br /&gt;
Power supplies - whether wall power or batteries - are usually rated based on voltage and amperage.  Voltage is the specification to be the most careful with for circuits.  Too much voltage is the same as overpressurizing your pipes - they will burst.  In the case of electronics, you device will break.  &lt;br /&gt;
&lt;br /&gt;
This can be counterintuitive - in reference to safety (for humans) around electronics, you may have heard &amp;quot;It is not the voltage that will kill you, it is the amperage&amp;quot;.  Because of this, it may be tempting to think that too high of an amperage will harm your device, but this is not true.  Our hearts are very susceptible to amperage but not voltage, hence amperage is considered dangerous for us whereas voltage is not.  But a circuit is not like a human body - in a circuit trying to handle a power supply it is the voltage that matters most.  &lt;br /&gt;
&lt;br /&gt;
====Set Voltage (No Control)====&lt;br /&gt;
&lt;br /&gt;
Most loads do no power regulation of their own.  They simply take the voltage given to them and do useful things with it.  You can tell that a pre-designed load (like a Phidget) falls into this category because it gives its voltage need &#039;&#039;as an exact value&#039;&#039;.  For example, most Phdigets use exactly 5 V of USB power.  These loads will also tell you their amperage, which is a flow need that must be met or exceeded.  A load will only use as much amperage as it needs.&lt;br /&gt;
&lt;br /&gt;
====Controlled Power====&lt;br /&gt;
&lt;br /&gt;
Some loads change the voltage or current they receive.  This can be with the intent to either (a) keep a constant amount of power flowing from a draining power source like batteries, or (b) to modify a common power source (i.e. 12 V at 1 A) into an uncommon power source (i.e. 1 V at 12 A).  This process is called &#039;&#039;&#039;regulation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can tell that a pre-designed load (like a Phidget) falls into this &amp;quot;power-regulated device&amp;quot; category because it gives its voltage need &#039;&#039;as a range&#039;&#039;. For example, the [[SBC|Phidget Single Board Computer]] can take 6 V to 15 V.  &lt;br /&gt;
&lt;br /&gt;
To understand how this works, take the example of a flywheel.  Flywheels are designed to be heavy and to take work in order to get them spinning at speed.  But once you have them spinning, you can extract that work later at a more consistent rate:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flywheel.png]]&lt;br /&gt;
&lt;br /&gt;
Flywheels can either make amperage or voltage be the more consistent blue line over time.  The most common one in Phidgets is for stable amperage.  Regulated amperage is also how LED lights can stay consistently bright for any length of time when using batteries.  Stable voltage design is usually applied when the voltage is too low to begin with (such as any device that runs on a single AA battery), and the flywheel must amplify and stabilize it over time.&lt;br /&gt;
&lt;br /&gt;
For those readers trying to envision how this works electrically, in practice the flywheel is an inductor (or, a transformer utilizing its inductor properties).  For both voltage and amperage regulation, one way relief valves (diodes) must be added. And, in amperage regulation a reservoir (capacitor) must be added to offset the current drop by pulling &#039;&#039;more&#039;&#039; amperage as a battery drains.  Then, a controller is needed to measure and then correspondingly enable and disable the flywheel system as the voltage or amperage drops from the supply.  &lt;br /&gt;
&lt;br /&gt;
But with those details in place, the inductor (and capacitor, in the case of amperage regulation) can effectively take the variety of voltages from, say, a draining battery, and still allow the board to run.  Some devices even do this naturally.  For example, motors often can take a variety of voltages because their construction (i.e. wire wrapping) naturally creates inductance.&lt;br /&gt;
&lt;br /&gt;
These regulated systems often list the power they need directly, using a type of power rating called &#039;&#039;&#039;watts&#039;&#039;&#039;.  Watts are voltage and amperage together (i.e. power):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Amperage} =\frac{\text{Watts}}{\text{Voltage}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Watts can be a handy way to describe flow and pressure together for these regulated devices.  Rather than separating voltage and amperage like the unregulated devices do (i.e. this load needs exactly 12 V, or this load will draw exactly 2 A), the unit of watts will allow different value combinations of volts and amps as long as the wattage remains the same.  For example, a 12 watt device with a voltage range of 5 to 12 volts can run on 6 V at 2 A, or 12 V at 1 A.  Either will work.  Amperage for all values in the device&#039;s range of 5 to 12 V can be found with the equation above.  Because of this, watts are often preferred when trying to match a power supply to a regulated load.&lt;br /&gt;
&lt;br /&gt;
===Ground===&lt;br /&gt;
&lt;br /&gt;
All circuits have a &#039;&#039;&#039;ground&#039;&#039;&#039;.  This is simply the return pipe to the pump.  In a circuit, it is denoted by an upside-down triangle:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground.png]]&lt;br /&gt;
&lt;br /&gt;
When drawing a circuit diagram, the symbol is placed on the wires that return to the pump:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_flow_ground.png|170px]]&lt;br /&gt;
&lt;br /&gt;
This electric ground provides a voltage reference throughout the circuit.  Ground is always &#039;&#039;&#039;0&#039;&#039;&#039; volts as far as the circuit is concerned. (Remember, voltage is the &#039;&#039;difference&#039;&#039; between the flow and return pipes at the pump.)  Ground is important because it provides a reference from which all the parts of the circuit can speak the same &amp;quot;voltage language&amp;quot; to each other, which matters a lot when a certain voltage means &amp;quot;1&amp;quot; and a certain voltage means &amp;quot;0&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
There is only one &#039;&#039;&#039;absolute&#039;&#039;&#039; ground, and that is the Earth, which is taken to be 0 volts as an absolute value.  Circuits not well-grounded to the Earth (of which there are many - your cell phone, car, etc) operate at a &#039;&#039;&#039;relative&#039;&#039;&#039; voltage.  The upside-down triangle above denotes a &#039;&#039;relative&#039;&#039; ground.&lt;br /&gt;
&lt;br /&gt;
With relative voltage, only the difference between local ground and the local high voltage matters.  For example, a cell phone might operate as a 3 volt device, which means relative to its ground it always operates between 0 and 3 volts.  But if that cell phone were compared carefully to Earth ground, its absolute voltage could be, say, between 10 and 13 volts.  Until comparison, the device doesn&#039;t &amp;quot;feel&amp;quot; charged.  This is the same as how you don&#039;t &amp;quot;feel&amp;quot; charged after skidding your feet in socks across a carpeted floor.  But, when you &amp;quot;compare&amp;quot; yourself to Earth ground by touching some well-grounded metal, you receive a static electricity shock.&lt;br /&gt;
&lt;br /&gt;
The same thing can happen when you combine two different power supplies, as we discuss [[#Projects With Different Power Sources|below]].&lt;br /&gt;
&lt;br /&gt;
===Power===&lt;br /&gt;
&lt;br /&gt;
There can be different types of pumps, and at this point we should supplant our heart symbol with some actual power supply pump symbols.  For example, this is the symbol for a direct current (DC) battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
The + end is on the out flow, and the - end is on the return (ground).  Batteries are usually listed with their voltages.  This is because the resistance of the load will determine how much amperage is drawn, but too much voltage and you will harm your load.&lt;br /&gt;
&lt;br /&gt;
This is the symbol for alternating current (AC) that you would get directly from the wall:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_wall_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
Again, this is listed using voltage for the same reasons as DC.  A relative ground symbol is still used on the return line here.  AC devices can still operate on relative voltage if they do not use Earth ground (the third prong on a wall plug in North America).  This is how some loads have AC cords with only two prongs - they operate on a relative voltage and relative ground.  And relative AC voltage, having significantly more voltage (pressure) behind it, can really hit a device hard when two power supplies meet across it.&lt;br /&gt;
&lt;br /&gt;
This connecting of multiple power supplies is quite a complex subject, and is described further in both [[#Power Needs|picking different power supplies]] and [[#One Powered Phidget|connecting different power supplies]] later on in this Primer.&lt;br /&gt;
&lt;br /&gt;
===Emissions and Wires===&lt;br /&gt;
&lt;br /&gt;
To talk about emissions, it is worth speaking more precisely about what a load is.  The typical, simple Phidget setup is receiving 5 V direct current (DC) from the computer over the USB port.  Let&#039;s model this as coming from a battery so that we can examine all parts of the system.  From the point of view of the battery, the Phidget load is not just the green board with the circuitry on it.  The load &#039;&#039;also&#039;&#039; includes the power cable (i.e. two wires in the USB cable), and anything else on the path out or back from the circuitry to the battery itself:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_basic.png|200px]]&lt;br /&gt;
&lt;br /&gt;
This is important because the wires play a role in the voltage that eventually makes it to the Phidget.  This is true all the time, even when the Phidget is attached to a computer instead of a battery.  All wires have some resistance, and so they are, in a way, in and of themselves circuits.    Therefore, because of their resistance, the wires &#039;use&#039; some of the 5 V heading out to the Phidget circuit board.  This is discussed more below, but essentially longer cables have more resistance and at some point the voltage will drop so much over the length that the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
To conceptually separate the wires from the Phidget in terms of the load, we can now start drawing the wires themselves in our circuit diagram, instead of the curved concept arrows indicating flow and return:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wires.png|200px]]&lt;br /&gt;
&lt;br /&gt;
When talking about the 5V relative ground in this system, we are in fact talking about the ground &#039;&#039;right at the battery&#039;&#039; so we move the ground symbol to the battery itself.&lt;br /&gt;
&lt;br /&gt;
Then, the resistance on these wires creates a possible problem - the emission of electromagnetic radiation as the wires naturally drop the voltage:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_emissions.png|200px]]&lt;br /&gt;
&lt;br /&gt;
These emissions are at a set frequency determined by the length of the wire:&lt;br /&gt;
* Long wires create low frequencies (harmful interference)&lt;br /&gt;
* Short wires create high frequencies (less harmful interference)&lt;br /&gt;
&lt;br /&gt;
This can be minimized by having the flow and return wires be the same length and sit right next to each other.  This way, the emissions somewhat cancel each other out from the flow and return going in opposite directions.  This is partially how USB cables minimize emissions.&lt;br /&gt;
&lt;br /&gt;
So, the way you design your connections (i.e. the resistance and placement of your wire) will have a direct affect on:&lt;br /&gt;
# The voltage that reaches the Phidget&lt;br /&gt;
# The emissions that your system produces&lt;br /&gt;
&lt;br /&gt;
With all this talk of emissions, you might be tempted to try to shield parts or all of your system from emissions that either your system or external systems create.  &lt;br /&gt;
&lt;br /&gt;
Keep in mind that shielding is actually really hard to do correctly.  Especially when grounding your shielding, with ad-hoc design you have a high chance of having an interfering signal (that has traveled out to the shield and traveled back via ground) creating a larger problem than not having a shield at all.  Rather than shielding, it is easier to simply keep your cables short and with as low a resistance as possible throughout your system to minimize your emissions in the first place.&lt;br /&gt;
&lt;br /&gt;
Identification of and solutions to these (and other more complex) problems are discussed in detail in the [[#Selecting Cables|section on choosing cables]] and the [[#Hooking Up The Pieces|section on connecting the pieces]] below.&lt;br /&gt;
&lt;br /&gt;
===Multiple Loads===&lt;br /&gt;
&lt;br /&gt;
The easiest way to hook up multiple Phidgets is in parallel, where the voltage stays the same but they share the amperage.  Here the DC supply is two USB ports, each at 5 V and 0.5 A:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
However, the length of your wires comes into play again, because the voltage that actually reaches the Phidgets above is somewhat less than 5 V.  So if your wires are long, or mismatched, the voltage may not match and will give you strange results.  The voltage is both affected on the way out, and on the way back.  Assuming the wires are the same length:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_phidget_wire_drop.png|350px]]&lt;br /&gt;
&lt;br /&gt;
In this way, you can create difficult-to-debug problems within a complex system, where one Phidget works but others mysteriously fail.&lt;br /&gt;
&lt;br /&gt;
==Power Needs==&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve understood the basics, it is time to actually talk about decisions and design.  This section will help you choose a power supply for your Phidget.  Let&#039;s say you want to run the [[SBC|Single Board Computer]] off of a battery.  Or you want to run a motor controller with a power supply you bought from the hobby store.  What do you need to buy?  Will one you already have work?  It is worth it to spend a moment with pencil and paper to work through this section and identify your power needs.&lt;br /&gt;
&lt;br /&gt;
As described [[#Voltage and Amperage|earlier]], voltage is pressure. Too much pressure behind your faucet, and the water mains or faucet will break.  Likewise, if you have too much voltage from a power supply, your circuit will break.  You should choose a supply with voltage that &#039;&#039;matches the range the Phidget can accept&#039;&#039;.  The voltage cannot be over the maximum (otherwise, like pressure in a pipe, the pipe will burst), and the voltage cannot be under the minimum (otherwise, like pressure in a pipe, no flow will occur).  Also, generally, a device (like a motor controller) will perform better at its maximum rated voltage if a range is available.&lt;br /&gt;
&lt;br /&gt;
But the faucet doesn&#039;t care whether there is a big reservoir or small reservoir feeding the system, as long as the pressure is managed.  Likewise, you can choose a power supply with more amperage than you need (a big reservoir to draw from) as long as the voltage matches.  In the same way that a faucet restricts water by design, loads draw and allow only the amperage that they need. However, the amperage cannot be less than the Phidget needs.  In that case, you will either overextend (and break) your power supply, or the circuit simply will not turn on at all.&lt;br /&gt;
&lt;br /&gt;
The specification [[#Device List|for your specific device]] will list its power needs. For most devices, the external power supply needs will simply be listed in voltage and amperage.  USB power is 5V at up to 500 mA (0.5 Amps).  Most Phidgets will draw less than this - if you need precision, you can check the specification for your particular Phidget.  And, if it is an Interface Kit, you can add the draw of each analog sensor and digital in/out from their specifications.&lt;br /&gt;
&lt;br /&gt;
However, some Phidgets (e.g. motors, and the [[SBC|Single Board Computer]]) do not have a straight amperage and voltage specification.  Instead, their power draw will be listed in watts, for which you [[#Voltage and Amperage|saw a relation earlier]] to convert to the values you need.&lt;br /&gt;
&lt;br /&gt;
===Wall Power===&lt;br /&gt;
&lt;br /&gt;
Wall power sources usually take the alternating current (AC) from the wall and convert it into a direct current (DC).  These power supplies often take your familiar two-or-three prong wall connector and put power out via a barrel plug-type connector.  AC power (typically 110 or 240 volts, depending where you live in the world) goes in the typical wall plug, and DC power (typically 5 to 24 volts) comes out the barrel plug.  Most power supplies of this type list the conversion explicitly, such as: 110-240 Volts to 12 Volts at 2 Amps.  You&#039;ll want to match your Phidget&#039;s needs against the 12 Volts at 2 Amps. &lt;br /&gt;
&lt;br /&gt;
*The voltage must match exactly&lt;br /&gt;
**If the Phidget takes a range of voltages, the supply must fall within the range&lt;br /&gt;
*The amperage can be equal to or greater than the Phidget needs&lt;br /&gt;
&lt;br /&gt;
A wall power supply is essentially an inexhaustible supply of current, so you don&#039;t need to worry about it running out like you would with batteries.&lt;br /&gt;
&lt;br /&gt;
===Battery Power===&lt;br /&gt;
&lt;br /&gt;
If you intend to use a battery bank (even of only one battery) to power your Phidget, you probably want to know what type of battery to purchase.  &lt;br /&gt;
&lt;br /&gt;
====Battery Chemistries====&lt;br /&gt;
The first thing that sets batteries apart is the type of materials used in their construction.  The following table shows several of the more common battery chemistries as well as the voltage per cell they produce and the specific energy of the chemistry.  &lt;br /&gt;
&lt;br /&gt;
{| border = 1&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Chemistry&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Nominal Cell Voltage&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Specific Energy (MJ/kg)&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Primary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| Alkaline||1.5||0.4||These are the most common form of battery.  Many commercially available AA and AAA batteries are alkaline. &lt;br /&gt;
|-&lt;br /&gt;
| Lithium (LiMnO2)||3||0.83-1.01||These are used in high drain devices or devices with a long shelf life as they have a very low self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Silver-oxide||1.55||0.47||Only used in small button cells as these are quite expensive.&lt;br /&gt;
|-&lt;br /&gt;
| align = &amp;quot;center&amp;quot; colspan = 4|Secondary Batteries&lt;br /&gt;
|-&lt;br /&gt;
| NiCd||1.2||0.14||Older technology, suffers from [[Electricity Primer#Memory Effect|memory effect]].  Capable of very high discharge rates with no ill effects.  Moderate self discharge rate.&lt;br /&gt;
|-&lt;br /&gt;
| Lead-acid||2.1||0.14||Not particularly good with high discharge rate.  Moderate rate of self discharge.  &lt;br /&gt;
|-&lt;br /&gt;
| NiMH||1.2||0.36||Very heavy.  Good performance in high drain devices.  Very high energy density naturally, at the cost of a high self discharge rate.  Newer versions are able to get rid of some of the self discharge though they suffer ~25% lower energy densities as a result.  &lt;br /&gt;
|-&lt;br /&gt;
| Lithium Ion||3.6||0.46||Expensive to produce but very high energy density.  Very low self discharge rate.  Safety hazard as short circuiting can yield explosive or fiery results. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Choosing a Battery====&lt;br /&gt;
Batteries are chosen first by their voltage (V).  Match the voltage exactly to the voltage the Phidget needs.  Over or under this value, you could harm the board or have it simply fail to turn on.&lt;br /&gt;
&lt;br /&gt;
Next, choose a battery that has adequate amperage to feed your device for the time you need. The lifespan of the battery will usually be listed in Amp-Hours (or Ah).  For example, a double wide 12 V lantern battery will have usually around 7-8 amp hours.  This means if you drew one amp from it for seven to eight hours, the battery would be totally drained.  Or you could draw two amps from it and drain it in 3.5-4 hours.  This does not mean however, that you can draw 36A for 15 minutes.  It is important to understand that there is a limit at which more power simply cannot be drawn from the battery.  Effectively, high drain devices will decrease the rated Ah.  The amount  differs from battery to battery so to be sure it is recommended to check the data sheets for the battery you are using.  If the battery did not come with a data sheet they can usually be found on the manufacturers website.  The data sheets should have a graph that shows the relationship between current draw (usually in mA) and capacity (Ah or mAh).  Another useful thing that can be gathered from the datasheets is the batteries response to temperature.  Batteries tend to not work as well in cold environments, most manufacturers will provide graphs of how the batteries lifespans will shorten at different temperatures.  This is often very significant, causing the battery to last a fraction of its normal lifespan at temperatures below -10&amp;amp;deg;C.&lt;br /&gt;
&lt;br /&gt;
Finding the amperage or voltage sometimes needs to be done indirectly by using a specification of watts.  The relationship between amperage, voltage, and watts is given above in the [[#Voltage and Amperage|voltage and amperage section]].&lt;br /&gt;
&lt;br /&gt;
For an example, let us say you want to use battery power to run the [[SBC|Phidget Single Board Computer]].  The specifications say that it uses 1.2 watts as a base value.  The specifications also say that it can take 12 V DC power.  If we choose to use a 12 V battery, at 1.2 watts it will use 0.1 amps according to the equation [[#Voltage and Amperage|shown earlier]].  Going by amp-hours alone, if our battery is a double-wide lantern type 12 V battery, with 7 amp hours, with 0.1 amp draw it will last 70 hours, or almost three days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\text{Maximum Running Days} =\frac{\text{Battery Amp Hours}}{\text{Device Amps} * \text{24}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, to estimate &#039;&#039;average&#039;&#039; running time (rather than maximum running time possible), amp-hours cannot be used so directly.  Over time, batteries decrease in voltage as their power is used up.  Practically speaking, this means one of two things for your load.  For loads that do not regulate voltage or current, the amperage will also decrease over time.  The classic example is an LED light source that grows dimmer and dimmer as the batteries are used up.&lt;br /&gt;
&lt;br /&gt;
You should usually only count on about 60% of the stated amp hour rating to apply before expecting to run into problems from escalated drain due to battery voltage drop.  This is especially true for deep cycle rechargeable batteries left in an installation, where draining more than 60% could also harm the battery.  &lt;br /&gt;
&lt;br /&gt;
Then, for lead-acid batteries, a typical battery is tested from full to complete drain over 20 hours by the manufacturer to obtain the advertised amp-hour rating.  Draining a battery at a faster rate than this will result in even more reduction in capacity, by 10% or even more.  This due to [http://en.wikipedia.org/wiki/Peukert%27s_law Peukert&#039;s Law].&lt;br /&gt;
&lt;br /&gt;
There are plenty of [http://www.google.ca/search?&amp;amp;q=battery+calculator battery calculators] around the Internet which take most or all of these additional factors into account when recommending an amp-hour rating.  For longer-term installations, the solar power online community has some excellent resources.&lt;br /&gt;
&lt;br /&gt;
====Setting up Multiple Batteries====&lt;br /&gt;
You can hook up multiple batteries in series to get more voltage at the same amperage.  The amperage is additive.  For example, you can hook up two single-wide 6 V lantern batteries in series to produce 12 V.  Or two 12 V batteries in series to produce 24 volts.  This system would still only have the amp hours of &#039;&#039;one&#039;&#039; of the lantern batteries, because you will be essentially using them both at once: &lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_series.png|250px]]&lt;br /&gt;
&lt;br /&gt;
The upside down triangle (ground) is explained above in a [[#Ground|section of its own]].&lt;br /&gt;
&lt;br /&gt;
Or, you can hook up multiple batteries in parallel to get more amperage at the same voltage.  For example, you could hook up two 12 V deep cycle batteries in parallel to provide more amperage at 12 V, which is like having a deeper reservoir of power for your device to use:&lt;br /&gt;
&lt;br /&gt;
[[Image:elec_battery_parallel.png|250px]]&lt;br /&gt;
&lt;br /&gt;
====Heat====&lt;br /&gt;
*all batteries have some sort of internal resistance&lt;br /&gt;
*can be found on the battery&#039;s data sheet&lt;br /&gt;
*the more power you pull from the battery the more heat is going to build up as a consequence of the internal resistance.&lt;br /&gt;
*larger internal resistances will cause heat to build up faster.&lt;br /&gt;
*when charging a battery you are not just limited to the power in the battery.  nothing stops you from dumping energy into the battery past the point where it is fully charged&lt;br /&gt;
**this is why charging batteries is a bit of a tricky business.&lt;br /&gt;
**many batteries come with custom chargers that have control systems to prevent this type of overcharging.&lt;br /&gt;
&lt;br /&gt;
====Weight====&lt;br /&gt;
Finally, weight matters - a car battery is much heavier than a lantern battery.  Batteries vary widely by weight per amperage.  Lithium batteries are usually very light for their power, followed by alkaline, followed by lead acid.  This may not seem important at first, but if you are building a mobile robot it is worth calculating in the work of carting around a battery.  You may find that, for the length of time you want it to run, your battery requires some system redesign.&lt;br /&gt;
&lt;br /&gt;
==Selecting Cables==&lt;br /&gt;
&lt;br /&gt;
===USB Cables===&lt;br /&gt;
&lt;br /&gt;
In general, use the shortest cables possible.  There are many reasons for this [[#Emissions and Wires|described above]], but as a summary:&lt;br /&gt;
&lt;br /&gt;
; Long cables reduce the voltage that reaches the Phidget.&lt;br /&gt;
: This happens in both directions.  So, for every unit cable length added, the voltage decreases by twice the electrical resistance of that length of cable. With especially long cables the Phidget may drop below its 4.6 volt threshold and simply never turn on.&lt;br /&gt;
&lt;br /&gt;
; Long cables increase the width of your circuit.  &lt;br /&gt;
:All circuits act as emitting antennas for the resonance frequency of the circuit structure.  The longer the wires in the circuit, the lower the frequency, and the higher chance that it will be emissions that will interfere with your data and system.&lt;br /&gt;
&lt;br /&gt;
; Longer cables have more length exposed to external interfering emissions.&lt;br /&gt;
&lt;br /&gt;
Also, use thick cables that are built to specification.  Some USB cables with thinner wiring have higher electrical resistance.  This can be equal to what a much longer wire would have, and thus create a similar voltage drop where the Phidget will not turn on.&lt;br /&gt;
&lt;br /&gt;
====Options for longer cables====&lt;br /&gt;
The maximum length for a USB cable is 5m.  This is laid out in the USB specifications.  Often times however a system requires more reach.  In this case there are a few options available to you.  You can use what is known as an active extension cable or USB extender.  These cables act like extension cables and add power to the line so that the signal can travel further.  A second option is to use a Cat5 extender.  These extenders are 2 USB dongles that connect on either end of your system.  You join them up with Cat5 cable.  This allows you to run over much longer distances than USB traditionally allows.&lt;br /&gt;
&lt;br /&gt;
===Power Cables===&lt;br /&gt;
&lt;br /&gt;
There are &amp;quot;DC Wire Table&amp;quot; references on the Internet which describe how to pick a wire appropriate for your voltage and amperage.  When selecting AC wires, you will probably be using pre-made extension cords.  Cords add interference resonance length to your circuit, just like USB cables do as [[#USB Cables|described above]].  A long extension cord can create huge electromagnetic interference for your circuit and other systems in the area when first plugged in.&lt;br /&gt;
&lt;br /&gt;
Also as with the USB cables above, cut the cables to the shortest length possible.  This is again both for voltage drop reasons and frequency emission reasons.&lt;br /&gt;
&lt;br /&gt;
===Hubs===&lt;br /&gt;
&lt;br /&gt;
Avoid hubs where possible.  Unpowered hubs are good for reading data from memory keys, but not for powering many external devices.  If you must use a hub, buy a powered one.&lt;br /&gt;
&lt;br /&gt;
===Sensor and Motor Wiring===&lt;br /&gt;
All Phidgets sensor class devices (products whose part numbers start with 11 such as the 1129) use a 3 channel ribbon cable for power and data transmission.  Similarly, all our motors and load cells use multichannel wire interfaces.  As mentioned previously, USB spec limits cables to 5m, this is not the case for these wires.  The biggest concerns are electromagnetic interference (EMI) and voltage drop.  In general you should be able to run these wires over significant distances (30m or more) with the load cells in particular having very long range.  If EMI starts causing issues you can always use ferrite beads on the cable near the sensor or motor and the controller to reduce noise.&lt;br /&gt;
&lt;br /&gt;
===Cable Gauges for Terminal Blocks===&lt;br /&gt;
&lt;br /&gt;
Many Phidgets products feature green terminal blocks that use screws to hold wires in place, making it easy to take apart and rebuild connections in your project. The size of the terminal block determines the gauge of wire you should use.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Terminal Block Size and Wire Gauge&#039;&#039;&#039;&lt;br /&gt;
! Terminal Block Width (mm/port)&lt;br /&gt;
! Recommended Wire Gauge (AWG)&lt;br /&gt;
|-&lt;br /&gt;
| 3.81&lt;br /&gt;
| 14 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 5.0&lt;br /&gt;
| 12 to 26&lt;br /&gt;
|-&lt;br /&gt;
| 9.5&lt;br /&gt;
| 10 to 26&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The gauge of cables and wires is measured in AWG, which is the American Wire Gauge standard. The following table lists the properties of wire gauges commonly used with Phidgets:&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;American Wire Gauge Sizes&#039;&#039;&#039;&lt;br /&gt;
! AWG Size&lt;br /&gt;
! Diameter (mm)&lt;br /&gt;
! Area (mm²)&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| 2.588&lt;br /&gt;
| 5.26&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| 2.305&lt;br /&gt;
| 4.17&lt;br /&gt;
|-&lt;br /&gt;
| 12&lt;br /&gt;
| 2.053&lt;br /&gt;
| 3.31&lt;br /&gt;
|-&lt;br /&gt;
| 13&lt;br /&gt;
| 1.828&lt;br /&gt;
| 2.62&lt;br /&gt;
|-&lt;br /&gt;
| 14&lt;br /&gt;
| 1.628&lt;br /&gt;
| 2.08&lt;br /&gt;
|-&lt;br /&gt;
| 15&lt;br /&gt;
| 1.450&lt;br /&gt;
| 1.65&lt;br /&gt;
|-&lt;br /&gt;
| 16&lt;br /&gt;
| 1.291&lt;br /&gt;
| 1.31&lt;br /&gt;
|-&lt;br /&gt;
| 17&lt;br /&gt;
| 1.150&lt;br /&gt;
| 1.04&lt;br /&gt;
|-&lt;br /&gt;
| 18&lt;br /&gt;
| 1.024&lt;br /&gt;
| 0.823&lt;br /&gt;
|-&lt;br /&gt;
| 19&lt;br /&gt;
| 0.912&lt;br /&gt;
| 0.653&lt;br /&gt;
|-&lt;br /&gt;
| 20&lt;br /&gt;
| 0.812&lt;br /&gt;
| 0.518&lt;br /&gt;
|-&lt;br /&gt;
| 21&lt;br /&gt;
| 0.723&lt;br /&gt;
| 0.410&lt;br /&gt;
|-&lt;br /&gt;
| 22&lt;br /&gt;
| 0.644&lt;br /&gt;
| 0.326&lt;br /&gt;
|-&lt;br /&gt;
| 23&lt;br /&gt;
| 0.573&lt;br /&gt;
| 0.258&lt;br /&gt;
|-&lt;br /&gt;
| 24&lt;br /&gt;
| 0.511&lt;br /&gt;
| 0.205&lt;br /&gt;
|-&lt;br /&gt;
| 25&lt;br /&gt;
| 0.455&lt;br /&gt;
| 0.162&lt;br /&gt;
|-&lt;br /&gt;
| 26&lt;br /&gt;
| 0.405&lt;br /&gt;
| 0.129&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Hooking Up The Pieces==&lt;br /&gt;
&lt;br /&gt;
Here, things can be tricky.  You might think: just plug everything in and go!  But often it is not that simple.  Many Phidgets require special care when hooking up.  We encourage a process where you apply the concepts in this Primer, through analysis, to your system.  So, we don&#039;t explicitly list the boards most commonly affected until the [[#Affected Products|end of this Primer]].&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;categories&#039;&#039; of the boards which require special attention within a complex system are:&lt;br /&gt;
&lt;br /&gt;
# Phidgets with more than one power source, and&lt;br /&gt;
# Phidgets needing precise measuring or control of an external power source&lt;br /&gt;
&lt;br /&gt;
If you are already thinking about your boards in your head and trying to figure out whether they fit into one category or another, you&#039;re on the right track!  The list of [[#Affected Products|commonly affected boards]] are only the common ones... with a sufficiently complex system, you could conceivably create problems with &#039;&#039;any&#039;&#039; boards.&lt;br /&gt;
&lt;br /&gt;
Both types of projects require a full understanding of [[#The Basics|electrical basics]].  Using those concepts, below we first describe problems that arise when hooking up different power sources, and extend that into using the solution to give more precise measurement and control.  &lt;br /&gt;
&lt;br /&gt;
===Shared Grounds===&lt;br /&gt;
&lt;br /&gt;
Shared grounds can occur in Phidgets that handle two different power sources.  Recognizing the sharing of a ground is not always easy.  We show what it is, how it can be possible, and why it creates problems by starting with the most basic Phidget system.  The simplest setup for a Phidget is to use the [[#Ground|ground]] of the computer it gets data and power from over a USB port:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_simple_case.png]]&lt;br /&gt;
&lt;br /&gt;
In this case, there is only one relative ground, and it is the PC ground, which is ground #1 in the image.  The PC ground determines what is considered 0 volts for all signals on the Phidget.  When you add different power sources or sinks in the system, you are pulling the system relative to the PC ground.  &lt;br /&gt;
&lt;br /&gt;
=====One Powered Phidget=====&lt;br /&gt;
&lt;br /&gt;
The next most complicated system is one Phidget that handles two power sources.  Let us say you have a motor controller, which takes power from USB, and which also takes power from a second power source.  Although the second power source is usually just a wall plug, the simpler case for thinking about ground is actually a battery.  A battery creates a second &#039;&#039;relative&#039;&#039; ground.  Through the Phidget, relative ground #1 (from the PC) and #2 (from the battery) actually become the same ground:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_wall_power.png]]&lt;br /&gt;
&lt;br /&gt;
This is the first reason why systems with powered Phidgets have to carefully manage ground.  If ground #1 and ground #2 are different with respect to each other (see the static shock analogy in the [[#Ground|ground section]] above), then whatever circuitry along the red dashed arrow must deal with the initial static shock.  In this case it would be the circuitry of the Phidget.  In the case of a battery, after the initial equalizing shock the battery will be whatever relative voltage the PC ground needs it to be.  Hence a battery relative ground can &#039;float&#039;.&lt;br /&gt;
&lt;br /&gt;
If ground #2 comes from the wall, on the other hand, the ground does not &#039;float&#039; and instead is always absolute 0 volts Earth ground.  With the PC giving the power, this is not a problem in practice because the PC can also float (as with a laptop), or it uses Earth ground.  But if you were using a different and more powerful USB power supply instead of a PC, and then connected it to the absolute Earth ground through the Phidget, the Phidget would bear the brunt of any ground equalization that would occur.  If neither the new ground nor the old ground float, and the power supplies were powerful enough, this would eventually destroy the Phidget.  In this case, you would want to use isolation, as described in [[#How To Fix This|How To Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Multiple Powered Phidgets=====&lt;br /&gt;
&lt;br /&gt;
A worse case comes in when you are using two powered Phidgets and one external power source.  Again, say you are using a battery as the external power source.  It would be tempting to simply wire both grounds from the Phidgets to the ground on the battery:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_phidget.png]]&lt;br /&gt;
&lt;br /&gt;
Although this looks benign, you have actually created a new circuit.  The circuit is a second path, via ground, for the current to return to the voltage source.  This is also known as a &#039;&#039;&#039;ground loop&#039;&#039;&#039;. The path we intuitively think of the current returning by is  &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;, but the sharing of grounds has created a new path through the motherboard, &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[Image:ground_two_paths.png]]&lt;br /&gt;
&lt;br /&gt;
All current gets &#039;pumped&#039; in a loop by voltage, and so it will use all return paths available to it, assuming all paths are equally easy (electrically) to use.  This extends the pipe analogy, where water will flow in every path that exists.  So, if your battery (or other power source with ground #2) is quite powerful, you can actually harm your motherboard within your PC (or at least your USB bus ground), because &#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;path B&amp;lt;/span&amp;gt;&#039;&#039;&#039; runs through the motherboard circuitry on the way back to the voltage source.&lt;br /&gt;
&lt;br /&gt;
This problem does &#039;&#039;not&#039;&#039; apply to using a different power source between a black power plug and for the green control terminal block on, say, a [[DC Motor and Controller Primer|DC motor controller]].  Although the grounds are connected, and they run across a part of a Phidget board, creating a ground loop does not actually run through any circuitry if only these types of boards are used.  If you have a complex system with other types of boards and therefore circuitry between black plug power port and green terminal block connections, draw out your system carefully to identify the loops.&lt;br /&gt;
&lt;br /&gt;
Ground loops can be fixed by one of the ways described in [[#How To Fix This|How to Fix This]] below.&lt;br /&gt;
&lt;br /&gt;
=====Single Board Computer And Powered Hub=====&lt;br /&gt;
&lt;br /&gt;
When combining one externally powered Phidget and the [[SBC|Single Board Computer]] or the [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]] on the same external power source, you still may inadvertently create a ground loop as described above in [[#Multiple Powered Phidgets|the multiple powered Phidgets section]].  If they share a true [[#Ground|Earth ground]], this is not a problem.  But if the ground is from a battery, or uninterruptible power supply, etc. then you should carefully draw out your system circuit and examine it for ground loops.&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
Once you are aware of shared grounds in your system, you have two options.  &lt;br /&gt;
&lt;br /&gt;
One, for ground loop problems in simple systems (two Phidgets), you could make the normal return path (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;) the most electrically desirable path.  This is best for simple systems where you have a lot of control over all of the ground wires within your system.  For the ground wires leading directly from the Phidget to the external power supply (&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;path A&amp;lt;/span&amp;gt;&#039;&#039;&#039;), lower the resistance in the wire as much as possible.  You can do this by keeping the wires short, and using a thick (large gague) wire for the hookups.  &lt;br /&gt;
&lt;br /&gt;
Although this solution works, sometimes you do not have much choice on how long your ground return wires can be, because the location of your power supply and and Phidgets are set by your system design.  If you cannot be totally sure that the direct ground path is the shortest and most electrically desirable path, it is best to use the second option: a &#039;&#039;&#039;USB Isolator&#039;&#039;&#039; such as the [[Product - 3060 - USB Isolator|Phidget 3060]].  This isolator is like any other USB isolator - it can be used on a Phidget system, as well as any system that needs ground isolation.&lt;br /&gt;
&lt;br /&gt;
You need isolators for every USB cable in your system, less one.  If you have two USB connections, you need one isolator; three USB connections, two isolators, and so on.  The one USB connection can remain non-isolated because a single ground connection cannot form a loop.  However, if you are concerned about connecting the grounds as described in the [[#One Powered Phidget|single connected Phidget section above]], use a USB isolator on every cable.&lt;br /&gt;
&lt;br /&gt;
===Precise Voltage Control===&lt;br /&gt;
&lt;br /&gt;
Precise voltage (or other system) control and measurement is related to the concept of [[#Shared Ground|shared ground above]].  But here, you want to keep grounds separate not only to prevent ground loops, but also to make your system more sensitive to what it will control or measure.&lt;br /&gt;
&lt;br /&gt;
For example, we make Phidgets that can create power precisely, or that can take it in and measure it.  One such product is the 1002, which outputs a precise analog voltage with which to control an analog system.  Now that you know about [[#Ground|relative ground]], however, you would be right to expect that you do not want to combine the ground in the PC and the ground in the system.&lt;br /&gt;
&lt;br /&gt;
Even if you don&#039;t care about system sensitivity, you can still create [[#Multiple Powered Phidgets|ground loops]] in a system with multiple of these types of Phidgets.  In addition, if you are using the Phidget to control a large, powerful system, even a single Phidget can receive damage from connecting two powerful power sources meeting across it, also as [[#One Powered Phidget|described earlier]].&lt;br /&gt;
&lt;br /&gt;
But above and beyond the powered Phidget problems, there is another reason to separate (isolate) the electrical grounds in your system.  The reason is: to make your system control more precise.  For example, with the 1002, if you are trying to control an external system with an Phidget output voltage, that output voltage should be relative to the &#039;&#039;system you are trying to control&#039;&#039;, not relative to the PC.  Rather than forcing the grounds - and therefore the relative voltages - to be equal to each other, you can provide more precise control by isolating the grounds and working with the relative voltage of the controlled system on its own terms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Schematic-type image of a ground isolated analog out on a 1002&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====How To Fix This====&lt;br /&gt;
&lt;br /&gt;
The solution to all of these problems in precise voltage control systems is to use USB isolation, even for a single Phidget.  The [[Product - 3060 - USB Isolator|Phidget 3060]] is one such isolator.  It inserts along the USB connection between your PC and the Phidget, and it separates the Phidget (and controlled system) ground from the PC ground.  This fixes ground loops, separates relative voltage mis-matches, and isolates the control system for better precision.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;Image of 1002 and Isolator connected, with lines superimposed on the image to show non-copper connection in isolator&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Affected Products==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure whether a certain concept applies to your Phidget within a complex system, the best way to figure this out is by doing some mental (or pencil and paper) simulation.  Draw the inputs and outputs for the entire board, and label them with voltage, list their required amperage (or watts), and draw connections (such as ground connections) through any circuitry.  &lt;br /&gt;
&lt;br /&gt;
With a technique like this, it is easy to see that some products - such as the [[Product - 1049 - PhidgetSpatial 0/0/3|Phidget Spatial]] - are simply not complex at all. Although you could conceivably create problems (such as by using separate power supplies instead of using USB power and connecting the grounds incorrectly, or by using really long wires), this would be an exceptional case.  &lt;br /&gt;
&lt;br /&gt;
Other Phidgets can be more easily used incorrectly without realizing it.  These are often devices that are simple in some systems and yet complex in others.  Your primary defense against designing unreliable systems is to draw the system out and identifying any problems using the concepts in this primer. To help you, however, you can generally think of two classes of Phidgets which usually need careful handling when they are part of complex systems:&lt;br /&gt;
# Phidgets with more than one power source, (these can be subject to the [[#Shared Grounds|multiple power source problems]] described above)&lt;br /&gt;
# Phidgets needing precise measuring of an external power source (these can be subject to the [[#Shared Grounds|multiple power source problems]] &#039;&#039;and&#039;&#039; [[#Precise Voltage Control|precise voltage control]] problems)&lt;br /&gt;
&lt;br /&gt;
Expanded into individual products, the Phidgets which are most often affected are.....&lt;br /&gt;
&lt;br /&gt;
# These Phidgets use a second type of external power:&lt;br /&gt;
#* Motor controllers &lt;br /&gt;
#**[[DC Motor and Controller Primer|DC controllers]] &lt;br /&gt;
#**[[Stepper Motor and Controller Primer|Stepper controllers]]&lt;br /&gt;
#**[[Servo Motor and Controller Primer|Servo controllers]]&lt;br /&gt;
#* Pure relay boards &lt;br /&gt;
#**[[Solid State Relay Primer|Solid state relay boards]]&lt;br /&gt;
#**[[Mechanical Relay Primer|Mechanical relay boards]]&lt;br /&gt;
#* Interface kits with relays &lt;br /&gt;
#**[[Product - 1017 - PhidgetInterfaceKit 0/0/8]]&lt;br /&gt;
#**[[Product - 1014 - PhidgetInterfaceKit 0/0/4]]&lt;br /&gt;
#* Powered Digital Output Interface Kits &lt;br /&gt;
#** [[Product - 1012 - PhidgetInterfaceKit 0/16/16]]&lt;br /&gt;
#* Interface Kits with Powered Hubs&lt;br /&gt;
#** The [[SBC|Single Board Computer]]&lt;br /&gt;
#** [[Product - 1019 - PhidgetInterfaceKit 8/8/8 w/6 Port Hub]]&lt;br /&gt;
# And these Phidgets may have a need to be sensitive to external power:&lt;br /&gt;
#* [[Temperature Sensor Primer|Thermocouple]] control&lt;br /&gt;
#* Analog Output ([[Product - 1002 - PhidgetAnalog 4-Output]])&lt;br /&gt;
#* Frequency Counter ([[Product - 1054 - PhidgetFrequencyCounter]])&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
&lt;br /&gt;
This page should have helped you to: &lt;br /&gt;
*Choose a power supply from either the [[#Wall Power|wall]] or a [[#Battery Power|battery]]&lt;br /&gt;
*Properly [[#Ground|ground]] and/or [[#How To Fix This|isolate]] that power supply from looping through other circuitry&lt;br /&gt;
*Also use [[#How To Fix This|isolation]] to make your control or measurement system more precise&lt;br /&gt;
*Keep your cables short and thick to reduce electromagnetic emissions and limit voltage drop&lt;br /&gt;
*Be more aware of system-wide power problems in general, and use drawing and analysis of systems to identify problems&lt;br /&gt;
&lt;br /&gt;
==Glossary==&lt;br /&gt;
===Memory Effect===&lt;br /&gt;
Memory effect is an effect observed in NiCd batteries that causes them to hold less charge.  It pertains to the specific situation in which NiCd batteries lose their maximum capacity if they are repeatedly recharged without being fully discharged.  The battery appears to remember the smaller capacity.  The term is often misused in cases where other batteries seem to hold less charge than originally, however this is most likely due to age and use.  This phenomenon is unique NiCd batteries.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20701</id>
		<title>LED Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20701"/>
		<updated>2012-06-29T20:22:55Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:RBG.jpg|500px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Like normal diodes, Light Emitting Diodes (LEDs) are semiconductor devices designed to conduct current in one direction only.  What makes LEDs unique is their internal material makeup:  when atoms in an LED release energy due to the flow of forward current, it is released in the form of photons (light).  Different construction materials and various phosphor coatings are used to produce numerous colors of light.&lt;br /&gt;
&lt;br /&gt;
LEDs that Phidgets sells are all operable via the [[Digital Output Primer|digital outputs]] on any of our interface kits.  However Phidgets also sells a specific [{{SERVER}}/products.php?product_id=1031 PhidgetLED-64 Advanced LED controller] since it is often desirable to control more LEDs than even the [{{SERVER}}/products.php?product_id=1012 1012 Phidget Interface Kit 0/16/16] can operate.  It offers some unique features such as brightness control.&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
[[image:led.png|thumb|350px|Parts of an LED.  The flat spot on the epoxy casing, is an anchor to prevent twisting from damaging the leads.]]&lt;br /&gt;
&lt;br /&gt;
LEDs emit light from current flowing through them.  As the current flows, the electronics experience a sudden drop in energy level (voltage).  When that happens they release energy in the form of light.  The amount of light produced is proportional to the current.  Depending on the material used to make the LED, different colors can be created.  Like a conventional diode, the current can only flow in one direction - from the anode to the cathode.&lt;br /&gt;
&lt;br /&gt;
==Controlling LEDs==&lt;br /&gt;
&lt;br /&gt;
===Forward Voltage===&lt;br /&gt;
&lt;br /&gt;
The materials used within LEDs that cause them to emit different colors of light affect a property called its forward voltage. The forward voltage is the voltage at which current in the forward direction will flow through the device and allow the LED to convert electrical energy into light.  If the voltage applied to the LED is below the forward voltage of the LED, very little current (or none) may flow, and therefore very little light will be emitted. Most standard LEDs with colors such as red, amber, orange, yellow, and green have forward voltages below 2.75 Volts, and can be used with a [[Digital Output Primer|digital output]] by simply soldering them to a connector-wire and inserting the wire into the output port. The forward voltage in the [{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED] will default to 2.75V, and the maximum current defaults to 20mA.&lt;br /&gt;
&lt;br /&gt;
===Supply Voltage===&lt;br /&gt;
{|&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|To be an effective LED controller your digital outputs must be capable of &amp;lt;br /&amp;gt;adjusting the forward voltage supplied to the LEDs to 1.7, 2.75, 3.9 and 5 volts&amp;lt;br /&amp;gt; settings allowing you to properly drive blue, white, violet, ultra violet and purple LEDs.&amp;lt;br /&amp;gt; The supply voltage will affect all LEDs. If you set the supplied voltage too high,&amp;lt;br /&amp;gt; power will be wasted and the controller may shut down from thermal overload. If you&amp;lt;br /&amp;gt; set the supply voltage too low, your LEDs will not be driven at the requested&amp;lt;br /&amp;gt; current, and will be dim or non-functional.&lt;br /&gt;
|&lt;br /&gt;
{| border = 1&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|Typical Forward Voltages&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Color&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Forward Voltage&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Infrared||&amp;lt; 1.9&lt;br /&gt;
|-&lt;br /&gt;
| Red||1.7 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Orange||2.0 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Yellow||2.1 to 2.4&lt;br /&gt;
|-&lt;br /&gt;
| Green||2 to 2.3&lt;br /&gt;
|-&lt;br /&gt;
| Blue||3.2 to 4.0&lt;br /&gt;
|-&lt;br /&gt;
| Ultraviolet||2.1 to 3.8&lt;br /&gt;
|-&lt;br /&gt;
| White||3.3 to 3.6&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Maximum Current and Brightness Control===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
Most LEDs fall within 20, 40, 60 or 80mA, and applies to all LEDs. The &amp;lt;br /&amp;gt;Phidgets DiscreteLED API call can be used to provide more current &amp;lt;br /&amp;gt;or control brightness and will adjust the current linearly between 0 &amp;lt;br /&amp;gt;and the set maximum. This however does not imply a precise method &amp;lt;br /&amp;gt;for controlling the visibility of emitted light, as this is affected by the &amp;lt;br /&amp;gt;construction and quality of the LED as well as the eyes of the viewer. &amp;lt;br /&amp;gt;Be cautious when changing the current property. Many small LEDs are &amp;lt;br /&amp;gt;designed for a maximum 20mA, and can be destroyed if driven at higher &amp;lt;br /&amp;gt;currents.&lt;br /&gt;
|&lt;br /&gt;
[[image:Ledcurrent.png|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Choosing Current and Voltage Settings===&lt;br /&gt;
&lt;br /&gt;
Make sure to choose the minimum supply voltage setting to drive the LED that requires the most voltage during operation. Any extra voltage not required by the LED will be converted to heat by the 1031. For example, a Blue LED being driven at 20mA, 3.9V Supply, that requires 3.7 volts will cause (3.9V-3.7V + 0.4V) * 0.02A = 12 milliwatts of heat to be produced on the 1031. If this example instead uses a high power, 1.5V infrared LED at 80mA, this will create (3.9V-1.5V+0.4V)*0.08 Amps = 224 milliwatts of heat. See the Heat Dissipation and Thermal Protection section later on in this manual for more information about this issue.&lt;br /&gt;
&lt;br /&gt;
==Multiplexed LEDs==&lt;br /&gt;
Multiplexing is a system wherein the entire display is not active at the same time.  Instead, sub-units of the display are driven one at a time and the electronics combine with human persistence of vision (the phenomenon of the eye by which an afterimage is thought to persist for approximately one twenty-fifth of a second on the retina) to make the viewer believe the entire display is continuously active.  Many controllers use this architecture to reduce power consumption.  7 segment display clocks are an example of this.&lt;br /&gt;
&lt;br /&gt;
In an effort to reduce electrical noise in the system the PhidgetLED does not use multiplexing. All 64 anodes are connected to the same power supply and the cathode of each LED connection is attached to an individual constant current sink. Also, the LEDs are not controlled by PWM - they are driven at a constant current.&lt;br /&gt;
&lt;br /&gt;
==Other uses for LED controllers==&lt;br /&gt;
&lt;br /&gt;
LED controllers are typically just a set of special digital outputs.  This means they aren&#039;t limited to just controlling LEDs. They can be used to control relays, solenoids and even very small motors. The PhidgetLED can also be used to drive opto-isolators and MOSFET SSRs. A diode integrated into the 1031 on each cathode will clamp inductive surges to the anode supply voltage.&lt;br /&gt;
&lt;br /&gt;
==Power Requirements and Power Supply Selection==&lt;br /&gt;
&lt;br /&gt;
The power supply that is included with the 1031 is rated at 12V and 2A (max).  If your application requires more power, a larger power supply may be necessary.  The on-board voltage regulator is able to supply up to 6A for each LED supply voltage setting, as long as the power supply is able to provide enough voltage and current to the regulator. Assume an efficiency of 80% for the on-board voltage regulator when determining if a different power supply is required.&lt;br /&gt;
&lt;br /&gt;
==Heat Dissipation and Thermal Protection==&lt;br /&gt;
&lt;br /&gt;
Projects that require a high supply voltage, or have a lot of heat being produced from over voltage settings, will have over-temperature problems.  This can be mitigated somewhat by understanding how channels are grouped and how the heat is distributed around the controller.  On the 1031 channels are split into four groups: (0-7,24-31), (8-23), (32-39, 56-63) and (40-55); each controlled by their own individual IC. Evenly distributing the LEDs that may produce a lot of heat across these groups will balance the load on the ICs and reduce the risk of thermal overload. When thermal overload occurs, the integrated circuit (IC) controlling the involved LEDs will disable the output of all the channels it controls.  For example, if an over-temperature occurs due to channel 12, all of the channels 8 through 23 will be disabled by the IC until the temperature back within the operating range.  Thermal protection is activated when the die of the IC reaches approximately 160 degrees Celsius.  Once the over-temperature fault has been corrected (ie, the IC has cooled down), the output channels will be re-enabled with the same settings as before the thermal shutdown. An error message will be produced during an over-temperature.&lt;br /&gt;
&lt;br /&gt;
==Products that fall under this category==&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED-64 Advanced]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3601 3601 - 10mm Red LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3602 3602 - 10mm Green LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3603 3603 - 10mm Blue LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3604 3604 - 10mm Yellow LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3605 3605 - 10mm White LED (Bag of 20)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3606 3606 - 5mm Four Chip Super Flux Red (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3607 3607 - 5mm Four Chip Super Flux Green (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3608 3608 - 5mm Four Chip Super Flux Blue (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3609 3609 - 5mm Four Chip Super Flux Yellow (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3610 3610 - 5mm Four Chip Super Flux White (Bag of 5)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3611 3611 - 5mm Diffused Red (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3612 3612 - 5mm Diffused Yellow/Green (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3613 - 5mm Diffused Blue (Bag of 30)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3614 3614 - Flexible LED Strip Green (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3615 3615 - Flexible LED Strip Blue (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3616 3616 - Flexible LED Strip White (5m)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3618 3618 - RGB LED Modules - String of 10]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_iOS&amp;diff=20699</id>
		<title>OS - iOS</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_iOS&amp;diff=20699"/>
		<updated>2012-06-29T20:06:19Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:Icon-iOS.png|64x64px|link=OS - iOS]]|iOS is the operating system used on iOS devices such as the iPad, iPhone, and iPod touch.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
Phidgets are designed to run on devices with an iOS version of 3.0 or later. It is strongly recommended that your device have the latest iOS version available to the device installed. As iOS devices do not have USB ports, the Phidgets will have to be connected on a computer with USB ports, and the iOS device will be able to interact with the Phidget over the [[Phidget_WebService|WebService]]. If you are looking for a compact and an inexpensive way to host Phidgets over a network, take a look at our [{{SERVER}}/products.php?product_id=1072|Single Board Computer].&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
If this is your first Phidget, we highly recommend working through the &#039;&#039;Getting Started&#039;&#039; guide for your specific Phidget device, which may be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the iOS drivers:&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget-iPhone.zip iOS Libraries]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with iOS==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
iOS code is developed on an OS X machine, and so getting your Phidget to work locally on the OS X machine first will help you distinguish any issues from network ones later. The OS X machine will need the Phidget drivers installed, please see the [[OS - OS X | OS X]] page for more information. &lt;br /&gt;
&lt;br /&gt;
You will also need to [{{SERVER}}/downloads/libraries/Phidget-iPhone.zip iOS drivers] to code your program against. &lt;br /&gt;
The &amp;quot;installation&amp;quot; of the Phidget iOS libraries is simply linking and distributing the libraries with your project. As the most common platform to do this is through Xcode, we provide brief instructions on how to easily follow along with our already-linked examples later.&lt;br /&gt;
&lt;br /&gt;
To install the libraries, follow these steps on the development computer:&lt;br /&gt;
&lt;br /&gt;
1. Download the Phidget [{{SERVER}}/downloads/libraries/Phidget-iPhone.zip drivers for iOS].&lt;br /&gt;
&lt;br /&gt;
2. Unzip the file, and you will find three things:&lt;br /&gt;
&lt;br /&gt;
# Libraries for the iOS device and iOS simulator.&lt;br /&gt;
# Example Xcode project for the PhidgetInterfaceKit and PhidgetManager.&lt;br /&gt;
# Skeleton Xcode project - contains the minimal project settings already filled in for Phidgets development. &lt;br /&gt;
&lt;br /&gt;
Feel free to browse around within the folders to get a sense of what will be going on the iOS side.  We describe how to link and use these library files later on the [[Language - iOS#Write Your Own Code | Write your own iOS code]] section of the iOS Cocoa Touch page.  For now, having found them means you can copy and install them to any project directory you want.&lt;br /&gt;
&lt;br /&gt;
First, though, it will be useful to check to make sure Phidgets work with your iOS system.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
When you run a Phidgets iOS example, you transfer and link the libraries and code all at the same time.  This should &amp;lt;i&amp;gt;just work&amp;lt;/i&amp;gt; with our examples, but if problems arise this section gives more detail on pinpointing the source of the problem.  We recommend starting with running the software examples right away - if the software works, you know the hardware works too.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
The easiest way to see whether your libraries are set up correctly within our examples or your own project is just to download them to the iOS device and run them.  Detailed instructions for this (including choosing the right {{Code|HelloWorld}} project to run) are on the [[Language - iOS]] page.  That page will be your next step - but if the examples do not run using the instructions, return here to debug your hardware.&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
If you are having problems running the examples, you should check the hardware of the host computer.&lt;br /&gt;
&lt;br /&gt;
When using the [[#WebService|WebService]] to control a Phidget, the problem may be with the USB connection on the remote computer.  Make sure both the server-side of (a) the webservice and (b) the USB connection are working by using the instructions on the [[OS - OS X|OS X page]]&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the examples &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your remote computer or iOS device can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* No other programs, drivers, or processes are using the Phidget on the host computer.&lt;br /&gt;
* You have copied and linked the Phidget iOS libraries (as described on the [[Language - iOS]] page)&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| quick downloads section]] to download them)&lt;br /&gt;
* Ensure that the webservice drivers and the iOS libraries are both the latest version&lt;br /&gt;
* Ensure that you have the most up to date iOS version installed for your device.&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB in [[#Hardware|hardware]] (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
iOS programs are written in [[Language - iOS|Objective C]] using the Cocoa Touch framework. You can read on within this page to learn how to use iOS with the Webservice, or you can jump ahead right now to the [[Language - iOS|iOS]] page and start writing code!&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network.&amp;lt;br&amp;gt;This section helps you use the WebService on iOS, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
Currently, iOS devices cannot &#039;&#039;host&#039;&#039; the WebService, but they can use data streaming from another computer over the WebService.&lt;br /&gt;
&lt;br /&gt;
===Setting Up the WebService===&lt;br /&gt;
&lt;br /&gt;
Using an iOS device, your network-controlled Phidget system will probably look something like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:webservice_general_pctoios.png|600px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
To begin, &lt;br /&gt;
&lt;br /&gt;
1. Start the WebService on the host computer&lt;br /&gt;
* How to do this [[OS - Windows#WebService|on Windows]]&lt;br /&gt;
* How to do this [[OS - OS X#WebService|on Mac OS]]&lt;br /&gt;
* How to do this [[OS - Linux#WebService|on Linux]]&lt;br /&gt;
* How to do this [[OS - Phidget SBC#WebService|on the Phidget Single Board Computer]]&lt;br /&gt;
&lt;br /&gt;
2. Download and unzip the [{{SERVER}}/downloads/libraries/Phidget-iPhone.zip iOS Examples] anywhere on the development computer.&lt;br /&gt;
&lt;br /&gt;
3. Open up the {{Code|HelloWorld.xcodeproj}} into Xcode. Select either an iOS device or iOS simulator as the destination. For more information, please see the [[Language - iOS#Use OurExamples|Use Our Examples]] section of the iOS language page.&lt;br /&gt;
&lt;br /&gt;
4. In Xcode, hit the {{Code|Run}} button to transfer the application to the device or simulator as well as run it.&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
After performing the steps above, you will be using the WebService already.  Plugging in the Phidget to the host computer will give you a screen like this:&lt;br /&gt;
&lt;br /&gt;
[[File:iOS Webservice Example HelloWorld Output.png|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows that a number of Phidgets are attached to the USB ports of computer connected to the network. Go ahead and detach the Phidgets from the USB port of the host computer, and see what happens.&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
Since an iOS device can only be a user and not a host of the WebService, you should use debugging server side.  Refer to the webservice sections for each operating system:&lt;br /&gt;
* [[OS - Windows#WebService|Windows]]&lt;br /&gt;
* [[OS - OS X#WebService|Mac OS]]&lt;br /&gt;
* [[OS - Linux#WebService|Linux]]&lt;br /&gt;
* [[OS - Phidget SBC#WebService|Phidget Single Board Computer]]&lt;br /&gt;
In addition, if you are having WebService problems, you will probably find the webservice section of our [[General Troubleshooting#WebService Troubleshooting|General Troubleshooting Guide]] helpful as well.&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Description of Installer files===&lt;br /&gt;
&lt;br /&gt;
Here is the list of files and their description for each file that is distributed through the iOS drivers.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|iphoneos/libPhidget21.a}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  This library is used when you are testing the example on the actual iOS device.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|iphonesimulator/libPhidget21.a}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  This library is used when you are testing the example an iOS simulator.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|SkeletonProject}}&amp;lt;/b&amp;gt; is a Xcode project containing the bare minimum project settings already filled in to code with the Phidget library.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
None at this time.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Android&amp;diff=20698</id>
		<title>OS - Android</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Android&amp;diff=20698"/>
		<updated>2012-06-29T20:05:57Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:Icon-Android.png‎|64x64px|link=]]|Android is a mobile OS commonly used on smartphones and tablet computers.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
Tablets with a USB port and Android version 3.1 or greater can control Phidgets directly plugged in to them.  Earlier Android versions (tested down to 2.1) can control Phidgets over a network using the [[#WebService|WebService]]. We do not currently support Android devices acting as a [[Phidget WebService]] server, but if you are looking for a compact and cheaper-than-a-tablet way to host Phidgets over a network, take a look at our [{{SERVER}}/products.php?product_id=1072 Single Board Computer].&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
Already a pro, and just need the downloads?  Here they are.&lt;br /&gt;
&lt;br /&gt;
Android does not need special drivers installed, though for developing code you will need the Android Java libraries when you start writing code:&lt;br /&gt;
* [{{SERVER}}/downloads/examples/android-examples.tar.gz Phidget Android examples and libraries]&lt;br /&gt;
* [[Language - Android Java#Quick Downloads|Android Java page]]&lt;br /&gt;
&lt;br /&gt;
Note that you will also need the libraries for the operating system your Phidget is directly connected to, if you don&#039;t have an Android 3.1+ tablet with USB:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Windows:&#039;&#039;&#039;&lt;br /&gt;
{{WindowsQuickDownloads}} &lt;br /&gt;
* Or refer to the main [[OS - Windows|Windows page]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;OS X:&#039;&#039;&#039;&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
* Or refer to the main [[OS - OS X|OS X page]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linux and the SBC:&#039;&#039;&#039;&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
* Or refer to the main [[OS - Linux|Linux page]]&lt;br /&gt;
* Direct connections work automatically with our [{{SERVER}}/products.php?product_id=1072 SBC], you can refer to its [[1072 - Getting Started|Getting Started]] page&lt;br /&gt;
&lt;br /&gt;
==Getting Started with Android==&lt;br /&gt;
&lt;br /&gt;
If this is your first Phidget, we highly recommend working through the Getting Started guide for your specific Phidget device, which may be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
Android code is developed on an external platform anyway (i.e. Windows, Mac OS, or Linux), and so getting your Phidget to work locally on that platform first will help you distinguish any issues from network ones later.  &lt;br /&gt;
&lt;br /&gt;
Near the end of the Windows, Mac OS, or Linux setup process, we direct you to choose a language.   At that point, please remember to return here to this Android Java page.  &lt;br /&gt;
&lt;br /&gt;
Alternately, you can first try using [[Language - Java|mainstream Java]] to control the Phidget on your host computer and become familiar with it.  On the mainstream Java page, we provide example code - including code that works on the Android development platform of Eclipse - to test your Phidget directly from your development computer.  &lt;br /&gt;
&lt;br /&gt;
For directly controlling a Phidget with your Android device (i.e. plugging a Phidget directly in to your tablet), you will need a USB host controller on your tablet.  Some tablets have these; some do not.  Just having a port that the USB cable can fit into does &#039;&#039;not&#039;&#039; necessarily indicate that the port can host a USB device.  Alternatively, some tablets (like the Samsung Galaxy Tab, for example) have the large 30-pin connectors that &#039;&#039;can&#039;&#039; be changed into a USB host using Samsung&#039;s adaptor.  &lt;br /&gt;
&lt;br /&gt;
The best way is to locate within the specifications for your device whether the ports on your device can serve as a &#039;&#039;USB host&#039;&#039;.    Another way to know is that you can host other devices (such as using a USB memory key) on your tablet.&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
The &#039;installation&#039; of the Phidget Android libraries is simply linking and distributing the libraries with your code.  As the most common platform to do this (on Windows, Mac, and Linux) is through Eclipse, we provide brief instructions on how to get and install Eclipse so you can more easily follow along with our already-linked examples later.&lt;br /&gt;
&lt;br /&gt;
====Eclipse (Android Java Development Platform)====&lt;br /&gt;
&lt;br /&gt;
Development for your Android OS Phidget application can occur on Linux, Mac OSX, or Windows.&lt;br /&gt;
&lt;br /&gt;
To install Eclipse, you will need the following:&lt;br /&gt;
&lt;br /&gt;
# The JDK and Java on your development system&lt;br /&gt;
#*See the [[Language - Java|mainstream Java]] page for details on Java for Windows, Mac, and Linux&lt;br /&gt;
# Eclipse (a Java Integrated Development Environment) on your development system&lt;br /&gt;
#*[http://www.eclipse.org/downloads/ http://www.eclipse.org/downloads/] (for Windows or MacOS)&lt;br /&gt;
#*&amp;lt;code&amp;gt;sudo apt-get install eclipse&amp;lt;/code&amp;gt; (for Linux)&lt;br /&gt;
#*For 64-bit Linux, you will need the &amp;lt;code&amp;gt;ia32-libs&amp;lt;/code&amp;gt; package (the bridge to 32-bit software) as well for Android development, try:&lt;br /&gt;
#*:{{Code|sudo apt-get install ia32-libs}}&lt;br /&gt;
&lt;br /&gt;
====Android SDK (and ADT Eclipse Plugin)====&lt;br /&gt;
&lt;br /&gt;
After installing Java and Eclipse, you can install the Android Software Developer&#039;s Toolkit (SDK) and the Android plugin for Eclipse (ADT).&lt;br /&gt;
&lt;br /&gt;
# Download and install the Android SDK package for your development system:&lt;br /&gt;
#*See the download instructions link at [http://developer.android.com/sdk/ http://developer.android.com/sdk/]&lt;br /&gt;
#*Google&#039;s instructions for installing are here: [http://developer.android.com/sdk/installing.html http://developer.android.com/sdk/installing.html]&lt;br /&gt;
# Download and install the ADT Eclipse Plugin for Android&lt;br /&gt;
#*Follow the instructions at [http://developer.android.com/sdk/eclipse-adt.html http://developer.android.com/sdk/eclipse-adt.html]&lt;br /&gt;
&lt;br /&gt;
To check that the JDK, the Android SDK, and Eclipse have all been configured correctly, use the Google HelloAndroid example:&lt;br /&gt;
&lt;br /&gt;
[http://developer.android.com/resources/tutorials/hello-world.html http://developer.android.com/resources/tutorials/hello-world.html]&lt;br /&gt;
&lt;br /&gt;
Once you have confirmed that the Android SDK has been correctly installed, you are ready to begin developing applications with Phidgets.&lt;br /&gt;
&lt;br /&gt;
=====Android SDK and ADT on Linux=====&lt;br /&gt;
&lt;br /&gt;
After downloading and unpacking the Android SDK package (the link is [[#Android SDK (and ADT Eclipse Plugin)|just above]]), run the Android SDK manager.  If {{Code|android-sdk-linux}} is the unpacked directory that was downloaded, try:&lt;br /&gt;
:{{Code|android-sdk-linux/tools/android}}&lt;br /&gt;
&lt;br /&gt;
This will give you the option to download the Android versions you want to support.  Running the SDK from within Eclipse ({{Code|Window}} &amp;amp;rarr; {{Code|Android SDK}}) will let you add those Android versions to Eclipse, for emulating them before downloading to an Android device and using with Phidgets.&lt;br /&gt;
&lt;br /&gt;
Then, to add Android support to your compilation process in Eclipse, make sure {{Code|adb}} is in your path (e.g. by adding it to {{Code|/etc/environment}}).&lt;br /&gt;
&lt;br /&gt;
====Phidget Libraries====&lt;br /&gt;
&lt;br /&gt;
The libraries from the [{{SERVER}}/downloads/examples/android-examples.tar.gz Phidget Android examples] (not our mainstream Java examples, despite the same name) are the libraries for including with your Android code. &lt;br /&gt;
&lt;br /&gt;
When you download and unzip the examples, each project (in addition to the source files, resources, and so on) contain three things:&lt;br /&gt;
&lt;br /&gt;
# A libs/ folder&lt;br /&gt;
# A jar file containing the general Phidget java library (phidget21.jar)&lt;br /&gt;
# A jar file for directly driving USB devices from a USB port on the Android device (PhidgetsUSB.jar)&lt;br /&gt;
&lt;br /&gt;
Feel free to browse around within these jar files to get a sense of what will be going on the Android OS side.  We describe how to link and use these library files later on the [[Language - Android Java#Write Your Own Code | Write your own Android code]] section of the Android Java page.  For now, having found them means you can copy and &#039;install&#039; them to any project directory you want.&lt;br /&gt;
&lt;br /&gt;
First, though, it will be useful to check to make sure Phidgets work with your Android system.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
When you run a Phidgets Android example, you transfer and link the libraries and code all at the same time.  This should &#039;just work&#039; with our examples, but if problems arise this section gives more detail on pinpointing the source of the problem.  We recommend starting with running the software examples right away - if the software works, you know the hardware works too.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
The easiest way to see whether your libraries are set up correctly within our examples or your own project is just to download them to the Android device and run them.  Detailed instructions for this (including choosing the right {{Code|HelloWorld}} project to run) are on the [[Language - Android Java]] page.  That page will be your next step - but if the examples do not run using the instructions, return here to debug your hardware.&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
If you are having problems running the examples, you should check the [[#Remote Phidget|hardware of the host computer]] if your Android device is controlling the Phidget over the WebService.  Or, you should check the hardware of your [[#Directly Connected Phidget|Android device]] if the Phidget is directly connected to the tablet&#039;s USB port.&lt;br /&gt;
&lt;br /&gt;
=====Remote Phidget=====&lt;br /&gt;
&lt;br /&gt;
When using the [[#WebService|WebService]] to control a Phidget, the problem may be with the USB connection on the remote computer.  Make sure both the server-side of (a) the webservice and (b) the USB connection are working by using the instructions on the [[Software Overview#Operating System Support|page specific to the operating system]]&lt;br /&gt;
&lt;br /&gt;
=====Directly Connected Phidget=====&lt;br /&gt;
&lt;br /&gt;
To check whether a Phidget is correctly connecting in your Android hardware (even if our examples do not work), you can use the kernel logs on your Android tablet in a similar way as you would on [[OS - Linux|Linux]].&lt;br /&gt;
&lt;br /&gt;
You need to access the logs from your debugging computer - e.g. the computer where you have installed Google&#039;s development plugins as described above.  Plug a USB Phidget into your Android device.  Then, as soon as possible, from a command line on that computer, use the ADB (Android Debugging Bridge) program to access the program {{Code|dmesg}} on your Android device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
adb shell dmesg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will print out the entirety of the kernel logs on your Android device.  Even if you have been running your device for only a little while, this could be thousands of lines of output.  If you plugged the Phidget in and then ran {{Code|dmesg}} right away, the kernel detection of the Phidget should be almost at the bottom of the logs.  If you are on Linux or Mac OS, you can mitigate the length of this output using {{Code|tail -n 50}} or so.  If you are on Windows, you may consider using a command redirection operator like {{Code|&amp;gt;}} to write to a file and then view the last 50 or so lines.&lt;br /&gt;
&lt;br /&gt;
Near the end of the output you will find something like this for a successful registration of a Phidget in the Android kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
&amp;lt;6&amp;gt;[ 3282.554249] usb 1-1.2: new full speed USB device using tegra-ehci and address 5&lt;br /&gt;
&amp;lt;6&amp;gt;[ 3282.612359] usb 1-1.2: New USB device found, idVendor=06c2, idProduct=0032&lt;br /&gt;
&amp;lt;6&amp;gt;[ 3282.612418] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3&lt;br /&gt;
&amp;lt;6&amp;gt;[ 3282.612466] usb 1-1.2: Product: PhidgetTemperatureSensor&lt;br /&gt;
&amp;lt;6&amp;gt;[ 3282.612504] usb 1-1.2: Manufacturer: Phidgets Inc.&lt;br /&gt;
&amp;lt;6&amp;gt;[ 3282.612540] usb 1-1.2: SerialNumber: 287638&lt;br /&gt;
&amp;lt;4&amp;gt;[ 3282.612576] device: &#039;1-1.2&#039;: device_add&lt;br /&gt;
&amp;lt;4&amp;gt;[ 3282.615639] device: &#039;1-1.2:1.0&#039;: device_add&lt;br /&gt;
&amp;lt;4&amp;gt;[ 3282.618632] device: &#039;0003:06C2:0032.0003&#039;: device_add&lt;br /&gt;
&amp;lt;3&amp;gt;[ 3282.631412] generic-usb 0003:06C2:0032.0003: claimed by neither input, hiddev nor hidraw&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the kernel log Phidget attachment does &#039;&#039;&#039;not&#039;&#039;&#039; appear, make sure that other devices that are supposed to work with your tablet (USB data keys, keyboards, etc. - the list depending entirely on which tablet) do indeed work.  Not having the Phidget appear in your kernel logs indicates there is a problem with your USB hardware on your Android device.  &lt;br /&gt;
&lt;br /&gt;
Note that in order to consider a port on your tablet to be compatible with Phidgets it must be able to &#039;&#039;&#039;host&#039;&#039;&#039; USB devices.  Simply finding and using a USB cable to connect the Phidget to the power charging port on your phone or tablet is not enough!  A host USB port should either say so explicitly, or at least act like a &#039;normal&#039; USB port such as ones you would find on your PC, and be able to use many common USB devices like memory sticks.&lt;br /&gt;
&lt;br /&gt;
If the kernel log attachment does appear, but your code doesn&#039;t run, the problem is probably with your code.  Work through the [[Language - Android Java]] page to make sure you have all the libraries, jar files, and permissions set and linked properly to use your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the examples &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your remote computer or Android device can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* No other programs, drivers, or processes are using that USB port in software&lt;br /&gt;
* You have properly set either android.permission.INTERNET or android.hardware.usb.host in your AndroidManifest.xml file (as described on the [[Language - Android Java]] page)&lt;br /&gt;
* You have copied and linked the Phidget jar libraries and libs/ folder into your project (as described on the [[Language - Android Java]] page)&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| quick downloads section]] to download them)&lt;br /&gt;
* If using the Phidget over the webservice, make sure the webservice drivers and the Android libraries are both the latest version&lt;br /&gt;
* If directly connecting to your Android device, the port you are using is a real USB host port (not a reduced-function power charging port)&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB in [[#Hardware|hardware]] (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Android OS programs are written in [[Language - Android Java|Android Java]] using the Android SDK and the Phidgets library.  You can read on within this page to learn how to use Android with the WebService, or you can jump ahead right now to the [[Language - Android Java|Android Java]] page and start writing code!&lt;br /&gt;
&lt;br /&gt;
Note that Android Java is NOT the same as mainstream Java.  Any Java programs you have will probably need significant modification before they run on Android, including our [[Language - Java|mainstream Java]] Phidget Examples.&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network.&amp;lt;br&amp;gt;This section helps you use the WebService on Android, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
Currently, Android devices cannot &#039;&#039;host&#039;&#039; the WebService, but they can use data streaming from another computer over the WebService.&lt;br /&gt;
&lt;br /&gt;
===Setting Up the WebService===&lt;br /&gt;
&lt;br /&gt;
Using an Android device, your network-controlled Phidget system will probably look something like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Webservice general pctoandroid.png|600px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
1. Start the WebService on the host computer&lt;br /&gt;
* How to do this [[OS - Windows#WebService|on Windows]]&lt;br /&gt;
* How to do this [[OS - OS X#WebService|on Mac OS]]&lt;br /&gt;
* How to do this [[OS - Linux#WebService|On Linux]]&lt;br /&gt;
* How to do this [[OS - Phidget SBC#WebService|On the Phidget Single Board Computer]]&lt;br /&gt;
&lt;br /&gt;
2. Download the [{{SERVER}}/downloads/examples/android-examples.tar.gz Android Examples].&lt;br /&gt;
* Edit the IP address and port in the {{Code|HelloWorldRemote}} example to match the IP address of the host computer (5001 is the default port)&lt;br /&gt;
* Transfer the example {{Code|HelloWorldRemote}} to your Android Device&lt;br /&gt;
* Run the example on your Android device, making sure it is also connected to the local network&lt;br /&gt;
** In Eclipse, right-click on project in Package Explorer (To open the Package Explorer, use Window &amp;amp;rarr; Show View &amp;amp;rarr; Package Explorer)&lt;br /&gt;
** Select Run As... &amp;amp;rarr; Android Application&lt;br /&gt;
&lt;br /&gt;
3. Plug a Phidget into the host computer&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
After performing the steps above, you will be using the WebService already.  Plugging in the Phidget to the host computer will probably give you a screen like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_remotehello.png|700px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
(The Phidget you actually plugged in will show up, be it a TemperatureSensor or something else)&lt;br /&gt;
&lt;br /&gt;
And when you unplug that Phidget from the remote host computer, you should see something like this on your Android device:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_remotegoodbye.png|700px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
As currently an Android device can only be a user and not a host of the WebService, you should use debugging server side.  Refer to the webservice sections for each operating system:&lt;br /&gt;
* [[OS - Windows#WebService|Windows]]&lt;br /&gt;
* [[OS - OS X#WebService|Mac OS]]&lt;br /&gt;
* [[OS - Linux#WebService|Linux]]&lt;br /&gt;
* [[OS - Phidget SBC#WebService|Phidget Single Board Computer]]&lt;br /&gt;
In addition, if you are having webservice problems, you will probably find the webservice section of our [[General Troubleshooting#WebService Troubleshooting|General Troubleshooting Guide]] helpful as well.&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
None yet, feel free to [[Contact Us|suggest some]]!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
None at this time.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=20695</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=20695"/>
		<updated>2012-06-29T20:01:50Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/JavaDoc.zip}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/javadoc/index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [{{SERVER}}/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [{{SERVER}}/downloads/libraries/phidget21jar.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [{{SERVER}}/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard OS X application suite., we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
To install NetBeans on a Mac, all  you have to do is download the installer from [http://netbeans.org/ their website] and run it.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [{{SERVER}}/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [{{SERVER}}/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[{{SERVER}}/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None at this time.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Android_Java&amp;diff=20694</id>
		<title>Language - Android Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Android_Java&amp;diff=20694"/>
		<updated>2012-06-29T20:00:59Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:Icon-Android.png‎|64x64px|link=|alt=]]|Android Java is the main language used to program for the [[OS - Android|Android OS]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Android|nearly the complete Phidget API, including events, and only excepting a few open() calls outlined later|the Phidget Interface Kit and two Hello World examples.|Eclipse on Windows, Mac OS, and Linux|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Android|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/JavaDoc.zip}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/javadoc/index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/android-examples.tar.gz|(and Phidget Android Library)}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/examples/android-examples.tar.gz||(Phidget21.jar included in Examples)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting Started with Android Java (Eclipse)==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
As Android development is primarily done on Eclipse, and Eclipse is relatively platform-independent, we provide instructions for Eclipse rather than by operating system.&lt;br /&gt;
&lt;br /&gt;
For basic differences on installing and setting up Eclipse on your development system, you can try the [[OS - Android|Android Operating System]] page.  However, your best bet for information about general use of Eclipse on your development operating system (Windows, Mac, or Linux) will be the [http://www.eclipse.org/documentation/ Eclipse support page] or the Internet at large.&lt;br /&gt;
&lt;br /&gt;
Phidgets can run directly plugged in to Android devices with a USB port and system 3.1 or later.  &lt;br /&gt;
&lt;br /&gt;
Otherwise, Android can control a Phidget remotely over a network, by using the [[Phidget WebService]]&lt;br /&gt;
&lt;br /&gt;
Hence, we split instructions up by Android OS version number.&lt;br /&gt;
&lt;br /&gt;
===Android Under 3.1 (and/or no USB Port)===&lt;br /&gt;
&lt;br /&gt;
These types of phones and tablets can use Phidgets only remotely over a network using the [[OS - Android#WebService|Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download and unpack the [{{SERVER}}/downloads/examples/android-examples.tar.gz Phidget Examples for Android].  There are two Hello World examples: {{Code|HelloWorldRemote}} (the one you want), and {{Code|HelloWorld}} (for tablets with a USB port).&lt;br /&gt;
&lt;br /&gt;
Import the {{Code|HelloWorldRemote}} example into Eclipse:&lt;br /&gt;
* File &amp;amp;rarr; Import... &amp;amp;rarr; General &amp;amp;rarr; Existing Projects Into Workspace &amp;amp;rarr; (Next)&lt;br /&gt;
* Select {{Code|HelloWorldRemote}} root directory &amp;amp;rarr; Select all files &amp;amp;rarr; Finish&lt;br /&gt;
&lt;br /&gt;
Next, you &#039;&#039;&#039;must change&#039;&#039;&#039; the IP address within the example code to the IP address of the computer directly connected to the Phidget you are trying to control.  This happens on the line that says something like:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
device.open(&amp;quot;192.168.3.133&amp;quot;, 5001);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, note that the HelloWorldRemote example was written for Android 2.1.  If needed, you can change this in:&lt;br /&gt;
(Right Click on Project) &amp;amp;rarr; Properties &amp;amp;rarr; Resource (on left) &amp;amp;rarr; Android&lt;br /&gt;
&lt;br /&gt;
To run the example: Right-click on project in Package Explorer (To open the Package Explorer, use Window &amp;amp;rarr; Show View &amp;amp;rarr; Package Explorer)&lt;br /&gt;
&lt;br /&gt;
Select Run As... &amp;amp;rarr; Android Application&lt;br /&gt;
&lt;br /&gt;
This will bring up the Android Virtual Device manager window.  If your Android hardware is plugged in to your debugging computer, you will see the hardware as an option on which to run the example.  You should run it directly on your Android device, unless you are comfortable setting up the emulator to run on your local network.&lt;br /&gt;
&lt;br /&gt;
After the {{Code|HelloWorldRemote}} application starts running on your Android device: &lt;br /&gt;
# Make sure the Phidget WebService is running on the computer with the IP address you put into the code&lt;br /&gt;
#*For directions on how to set up and run the webservice on a remote computer, refer to the page [[Software Overview#Operating System Support|for that operating system]]&lt;br /&gt;
# Plug a Phidget into that computer&lt;br /&gt;
&lt;br /&gt;
And on your Android device, depending on which Phidget you plug in, you should see something like:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_remotehello.png|700px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
And when you unplug that Phidget from the remote computer, you should see something like this on your Android device:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_remotegoodbye.png|700px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
If you have the specific Phidget for the other included Android examples (i.e. the InterfaceKit), you can run the other examples in the same way.&lt;br /&gt;
&lt;br /&gt;
To envision the system in the background, you can refer to the WebService section on the [[OS - Android]] page.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
To write your own code from scratch, start with an Android project in Eclipse (File &amp;amp;rarr; New &amp;amp;rarr; Android Project).  Then....&lt;br /&gt;
&lt;br /&gt;
=====Step One: Link the Phidget Libraries to your Project=====&lt;br /&gt;
&lt;br /&gt;
When you download and unzip the [{{SERVER}}/downloads/examples/android-examples.tar.gz Phidget Examples for Android], each project folder will (in addition to the project files themselves) contain three things:&lt;br /&gt;
# A libs/ folder (containing an armabi/ folder and a single file called libphidget21.so)&lt;br /&gt;
# A jar file containing the general Phidget java library (phidget21.jar)&lt;br /&gt;
# A jar file for directly driving USB devices from a USB port on the Android device (PhidgetsUSB.jar)&lt;br /&gt;
&lt;br /&gt;
Copy the {{Code|libs}} folder, the {{Code|PhidgetsUSB.jar}} file, and the {{Code|phidget21.jar}} file to your project folder.&lt;br /&gt;
&lt;br /&gt;
To install libraries to run a Phidget &#039;&#039;&#039;remotely&#039;&#039;&#039; over a network using the WebService:&lt;br /&gt;
# Add the libs/ folder to your project&lt;br /&gt;
#* To add the libs/ folder in Eclipse, simply place it in the root folder of your project&lt;br /&gt;
# Add the phidget21.jar file to your project&lt;br /&gt;
#* In Eclipse use the top-bar menu: Project &amp;amp;rarr; Properties &amp;amp;rarr; Java Build Path &amp;amp;rarr; Libraries (tab) &amp;amp;rarr; Add JAR&lt;br /&gt;
&lt;br /&gt;
=====Step Two: Give your Program Permission to use the Internet=====&lt;br /&gt;
&lt;br /&gt;
Add the following to your &amp;lt;code&amp;gt;AndroidManifest.xml&amp;lt;/code&amp;gt; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
    &amp;lt;uses-permission android:name=&amp;quot;android.permission.INTERNET&amp;quot;&amp;gt;&amp;lt;/uses-permission&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step Three: Include the Phidget Libraries in your Source=====&lt;br /&gt;
&lt;br /&gt;
Then, in your code, include an {{Code|import}} reference to the library. In Android Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // This contains all of the devices and the exceptions&lt;br /&gt;
  import com.phidgets.*;&lt;br /&gt;
 &lt;br /&gt;
  // This contains all of the event listeners&lt;br /&gt;
  import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you are ready to begin coding!&lt;br /&gt;
&lt;br /&gt;
===Android 3.1+ with USB Port===&lt;br /&gt;
&lt;br /&gt;
If your tablet has a USB host port and is running Android 3.1 or later, you can plug Phidgets directly into it.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download and unpack the [{{SERVER}}/downloads/examples/android-examples.tar.gz Phidget Examples for Android].  There are two Hello World examples: {{Code|HelloWorld}} (the one you want), and {{Code|HelloWorldRemote}} (for controlling Phidgets over the WebService).&lt;br /&gt;
&lt;br /&gt;
Import the {{Code|HelloWorld}} example into Eclipse:&lt;br /&gt;
* File &amp;amp;rarr; Import... &amp;amp;rarr; General &amp;amp;rarr; Existing Projects Into Workspace &amp;amp;rarr; (Next)&lt;br /&gt;
* Select {{Code|HelloWorldRemote}} root directory &amp;amp;rarr; Select all files &amp;amp;rarr; Finish&lt;br /&gt;
&lt;br /&gt;
Note that the HelloWorld example was written for Android 3.1.  If needed, you can change this in:&lt;br /&gt;
(Right Click on Project) &amp;amp;rarr; Properties &amp;amp;rarr; Resource (on left) &amp;amp;rarr; Android&lt;br /&gt;
&lt;br /&gt;
To run the example: Right-click on project in Package Explorer (To open the Package Explorer, use Window &amp;amp;rarr; Show View &amp;amp;rarr; Package Explorer)&lt;br /&gt;
&lt;br /&gt;
Select Run As... &amp;amp;rarr; Android Application&lt;br /&gt;
&lt;br /&gt;
This will bring up the Android Virtual Device manager window.  If your Android hardware is plugged in to your debugging computer, you will see the hardware as an option on which to run the example.  You should run it directly on your Android device, unless you are comfortable setting up the emulator to use your development computer&#039;s USB hub.&lt;br /&gt;
&lt;br /&gt;
After the {{Code|HelloWorld}} application starts running on your Android device, plug a Phidget into your Android tablet&#039;s USB port!&lt;br /&gt;
&lt;br /&gt;
Since the USB device requires special permission, the first thing you will probably see is a request from the Phidget example to use the USB port:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_usb_permissions.png|500px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
And on your Android device, depending on which Phidget you plug in, you should see something like:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_hello.png|700px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
And when you unplug that Phidget from the remote computer, you should see something like this on your Android device:&lt;br /&gt;
&lt;br /&gt;
[[Image:android_helloworld_goodbye.png|700px|alt=|link=]]&lt;br /&gt;
&lt;br /&gt;
If you have the specific Phidget for the other included Android examples (i.e. the InterfaceKit), you can run the other examples in the same way.&lt;br /&gt;
&lt;br /&gt;
If you are having trouble running the examples, a method to debug the Android USB port is on the [[OS - Android]] page, under the Hardware section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
To write your own code from scratch, start with an Android project in Eclipse (File &amp;amp;rarr; New &amp;amp;rarr; Android Project).  Then....&lt;br /&gt;
&lt;br /&gt;
=====Step One: Link the Phidget Libraries to your Project=====&lt;br /&gt;
&lt;br /&gt;
When you download and unzip the [{{SERVER}}/downloads/examples/android-examples.tar.gz Phidget Examples for Android], each project folder will (in addition to the project files themselves) contain three things:&lt;br /&gt;
# A libs/ folder (containing an armabi/ folder and a single file called libphidget21.so)&lt;br /&gt;
# A jar file containing the general Phidget java library (phidget21.jar)&lt;br /&gt;
# A jar file for directly driving USB devices from a USB port on the Android device (PhidgetsUSB.jar)&lt;br /&gt;
&lt;br /&gt;
Copy the {{Code|libs}} folder, the {{Code|PhidgetsUSB.jar}} file, and the {{Code|phidget21.jar}} file to your project folder.&lt;br /&gt;
&lt;br /&gt;
To install libraries to run a Phidget &#039;&#039;&#039;remotely&#039;&#039;&#039; over a network using the WebService:&lt;br /&gt;
# Add the libs/ folder to your project&lt;br /&gt;
#* To add the libs/ folder in Eclipse, simply place it in the root folder of your project&lt;br /&gt;
# Add the phidget21.jar file to your project&lt;br /&gt;
# Also add the PhidgetsUSB.jar file to your project&lt;br /&gt;
#* In Eclipse, to add jar files use the top-bar menu: Project &amp;amp;rarr; Properties &amp;amp;rarr; Java Build Path &amp;amp;rarr; Libraries (tab) &amp;amp;rarr; Add JAR&lt;br /&gt;
&lt;br /&gt;
=====Step Two: Give your Program Permission to use USB=====&lt;br /&gt;
&lt;br /&gt;
Add the following to your &amp;lt;code&amp;gt;AndroidManifest.xml&amp;lt;/code&amp;gt; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
    &amp;lt;uses-feature android:name=&amp;quot;android.hardware.usb.host&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step Three: Include the Phidget Libraries in your Source=====&lt;br /&gt;
&lt;br /&gt;
Then, in your code, include an {{Code|import}} reference to the library. In Android Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // This contains all of the devices and the exceptions&lt;br /&gt;
  import com.phidgets.*;&lt;br /&gt;
 &lt;br /&gt;
  // This contains all of the event listeners&lt;br /&gt;
  import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you are ready to begin coding!&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions above, you probably now have a working example and want to understand it better so you can change it to do what you want. This section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Programming with Phidgets in Android Java makes extensive use of the mainstream Java Phidgets library, so the Java API reference will be helpful:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|although you can only use the event code in Android|[{{SERVER}}/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===API Support===&lt;br /&gt;
&lt;br /&gt;
Most of the Java API is supported in Android.  However, only some of the available open calls are supported:&lt;br /&gt;
&lt;br /&gt;
When using a Phidget over a network, you can open the remote Phidget using one of the supported Java API calls:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
void open(int serial, java.lang.String ipAddress, int port)&lt;br /&gt;
void open(int serial, java.lang.String ipAddress, int port, java.lang.String password)&lt;br /&gt;
void openAny(java.lang.String ipAddress, int port)&lt;br /&gt;
void openAny(java.lang.String ipAddress, int port, java.lang.String password)&lt;br /&gt;
void openLabel(java.lang.String label, java.lang.String ipAddress, int port)&lt;br /&gt;
void openLabel(java.lang.String label, java.lang.String ipAddress, int port, java.lang.String password)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using a Phidget when it is directly plugged in to an Android 3.1 or later tablet, you can use one of these supported Java API calls:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
void open(int serial)&lt;br /&gt;
void openAny()&lt;br /&gt;
void openLabel(java.lang.String label)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This leaves these Java API calls, which are &#039;&#039;&#039;unsupported&#039;&#039;&#039; on Android:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
void open(int serial, java.lang.String serverID)&lt;br /&gt;
void open(int serial, java.lang.String serverID, java.lang.String password)&lt;br /&gt;
void openAny(java.lang.String serverID)&lt;br /&gt;
void openAny(java.lang.String serverID, java.lang.String password)&lt;br /&gt;
void openLabel(java.lang.String label, java.lang.String serverID)&lt;br /&gt;
void openLabel(java.lang.String label, java.lang.String serverID,&lt;br /&gt;
java.lang.String password)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Android Java will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the Android Java syntax.  However, many additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a [{{SERVER}}/products.php?product_id=1018 Phidget Interface Kit] as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
For opening a remote Phidget over the network using the WebService:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  InterfaceKitPhidget device;&lt;br /&gt;
  device = new InterfaceKitPhidget();&lt;br /&gt;
 &lt;br /&gt;
  // Open first detected Interface Kit, remotely with IP address and port&lt;br /&gt;
  device.open(&amp;quot;192.168.3.33&amp;quot;, 5001);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For opening a Phidget directly attached to the tablet&#039;s USB port:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 InterfaceKitPhidget device;&lt;br /&gt;
 com.phidgets.usb.Manager.Initialize(this);&lt;br /&gt;
 device = new InterfaceKitPhidget();&lt;br /&gt;
&lt;br /&gt;
 // Open locally, with Phidget in tablet USB port&lt;br /&gt;
 ik.open(&amp;quot;192.168.3.33&amp;quot;, 5001);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The direct open call prevents any other instances from retrieving data from the Phidget, including other programs. &lt;br /&gt;
The one connection per device limit does not apply when exclusively using the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
Both open calls will tell the program to continuously try to connect to a Phidget, based on the parameters given, even trying to reconnect if it gets disconnected. &lt;br /&gt;
This means that simply calling open does not guarantee you can use the Phidget immediately. We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents....&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in and a software event caught (i.e. attached). &lt;br /&gt;
&lt;br /&gt;
Android Java is &#039;&#039;&#039;only&#039;&#039;&#039; event-driven, so you cannot use {{Code|waitForAttachment()}} without hanging and being relatively unsafe with your threads.  Instead, you should define an event handler function that you can then synchronize and tie in with the attachment event itself.&lt;br /&gt;
&lt;br /&gt;
First, let&#039;s write our handler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  class AttachEventHandler implements Runnable { &lt;br /&gt;
    Phidget device; &lt;br /&gt;
    TextView eventOutput;&lt;br /&gt;
&lt;br /&gt;
    public AttachEventHandler(Phidget device, TextView eventOutput) {&lt;br /&gt;
      this.device = device;&lt;br /&gt;
      this.eventOutput = eventOutput; }&lt;br /&gt;
&lt;br /&gt;
    public void run() {&lt;br /&gt;
      try {&lt;br /&gt;
        // The actual useful thing our handler does&lt;br /&gt;
	eventOutput.setText(&amp;quot;Hello &amp;quot; + device.getDeviceName() + &amp;quot;, Serial &amp;quot; + Integer.toString(device.getSerialNumber()));&lt;br /&gt;
      } catch (PhidgetException e) { e.printStackTrace(); }&lt;br /&gt;
        &lt;br /&gt;
      // Notify whoever called us (and is waiting) that we&#039;re done&lt;br /&gt;
      synchronized(this) { this.notify(); }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may seem complex, but really it is just:&lt;br /&gt;
# A class wrapper so we can work independently once we get permission from the main thread, and&lt;br /&gt;
# A way to call back to the {{Code|synchronized()}} call to let them know we&#039;re done and stay thread safe&lt;br /&gt;
&lt;br /&gt;
Now that we have our &#039;handler&#039; we can hook it in as an event function to trigger on device attachment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
device.addAttachListener(new AttachListener() {&lt;br /&gt;
  public void attached(final AttachEvent attachEvent) {&lt;br /&gt;
    AttachEventHandler handler = new AttachEventHandler(attachEvent.getSource(), eventOutput);&lt;br /&gt;
&lt;br /&gt;
    // This is synchronised in case more than one device is attached before one completes attaching&lt;br /&gt;
    synchronized(handler) {&lt;br /&gt;
&lt;br /&gt;
      runOnUiThread(handler);&lt;br /&gt;
      try { handler.wait(); } catch (InterruptedException e) { e.printStackTrace(); }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}); &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
Again, because Android is event driven, use buttons (or timers) to schedule events if you want to poll the device at a certain interval or user specification.  Otherwise, simply set the sensitivity and/or data rate (depending on your device type) and catch events as they come in using the handler structure above.&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, don’t forget to call close to free any locks on the Phidget.&lt;br /&gt;
&lt;br /&gt;
We can put the close() call for Phidgets in Android within an overridden version of the onDestroy() Android application function.  Within it, we simply close the device.  For Phidgets directly attached to a USB Android tablet, you should also call Uninitialize():&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  @Override&lt;br /&gt;
  protected void onDestroy() {&lt;br /&gt;
    super.onDestroy();&lt;br /&gt;
      try { device.close(); } catch (PhidgetException e) { e.printStackTrace(); }&lt;br /&gt;
      // Uninitialize should only be called for directly connected Phidgets&lt;br /&gt;
      com.phidgets.usb.Manager.Uninitialize();&lt;br /&gt;
  }    &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [{{SERVER}}/documentation/JavaDoc.zip Java API].  You can also find more description on any device-specific function in the Device API for your specific Phidget, which can be found on its product page on [[{{SERVER}} our main website]].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
This section contains some Android Java and Eclipse-specific common problems.  For more answers about using Phidgets, visit our forums, FAQ, or contact us.&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|Eclipse Error|Unable to get view server protocol version from device emulator}}===&lt;br /&gt;
&lt;br /&gt;
Likely Fix: Project &amp;amp;rarr; Clean... &amp;amp;rarr; Clean All  (If that does not work, clean again and restart Eclipse)&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|Eclipse Error|Android requires compiler compliance level 5.0 or 6.0. Found &#039;X.Y&#039; instead}}===&lt;br /&gt;
&lt;br /&gt;
Likely Fix: This may happen when running the examples.  The javac and java version on the example do not match those on your computer.&lt;br /&gt;
* Find the version of java and javac on your computer (for example, &amp;lt;code&amp;gt;java -version&amp;lt;/code&amp;gt; on the command line)&lt;br /&gt;
* In Eclipse, open the Package Explorer (Window &amp;amp;rarr; Show View &amp;amp;rarr; Package Explorer)&lt;br /&gt;
* Find the project, right-click and select Properties&lt;br /&gt;
* In Properties &amp;amp;rarr; Java Compiler &amp;amp;rarr; (Checkbox) Enable Project Specific Settings &amp;amp;rarr; Set Compiler Compliance Level = Java Version &amp;amp;rarr; Apply&lt;br /&gt;
* When told this requires rebuild, say Rebuild Now&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_Linux&amp;diff=20692</id>
		<title>OS - Linux</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_Linux&amp;diff=20692"/>
		<updated>2012-06-29T19:59:16Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:icon-Linux.png|64x64px|link=OS - Linux]]|On Linux, Phidgets can be either plugged directly into a USB Port or run over a network using the [[#WebService | WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
 &lt;br /&gt;
You need kernel &#039;&#039;&#039;version 2.6&#039;&#039;&#039; (released in 2003) or later.&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
Linux has complete support for all Phidgets and their software APIs; the only thing it lacks when compared to Windows and Mac OSX is a graphical user interface.  We walk you through all steps for download,  installation, checking, and starting to write code below.  &lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the downloads:&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Libraries for Linux]&lt;br /&gt;
*[{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Phidget Generic C Examples]&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/phidgetwebservice.tar.gz Phidget WebService for Linux]&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#linux Software license]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with Linux==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
To install the libraries, follow these steps:&lt;br /&gt;
&lt;br /&gt;
#Download {{Code|libusb-0.1}} and its development libraries.  &lt;br /&gt;
#*Note that libusb may be already on your system, but the development libraries probably aren&#039;t.&lt;br /&gt;
#*Try {{Code|apt-cache search libusb}} in a terminal to find current installable packages from your source list&lt;br /&gt;
#*Or install [http://www.libusb.org/ from source], which includes the libusb development libraries by default&lt;br /&gt;
#Unpack and install the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Libraries]&lt;br /&gt;
#*From the main unpacked libraries directory, run:&lt;br /&gt;
#*:{{Code|./configure}}&lt;br /&gt;
#*:{{Code|make}}&lt;br /&gt;
#*:{{Code|sudo make install}}&lt;br /&gt;
#*This will compile phidget21.h and place the library into your gcc path&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Although these libraries are written in C, the additional libraries for Python, Java, and most other Phidget-supported languages depend on them.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
To confirm the libraries were installed and work correctly, you can check both the hardware and software sides of the interface.  It is worth checking the software side first, because if it works then you know the hardware side is also okay.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
To confirm that the libraries were installed correctly and can be used in code, you can use the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Phidget Generic C Examples].&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm correct installation will be to compile and run the {{Code|HelloWorld}} C example, included in the examples download.  This does not involve writing any C code, but it does involve compiling the example and running it, which is a quick process as we show below.  If you feel more comfortable running the {{Code|HelloWorld}} example for your specific language, you can skip below and pick your language, but keep in mind that any problems could be with the C library installation and not necessarily with your language.&lt;br /&gt;
&lt;br /&gt;
To compile and run the basic C example for checking your installation:&lt;br /&gt;
&lt;br /&gt;
1. Unpack the Phidget Generic C Examples&amp;lt;br&amp;gt;&lt;br /&gt;
2. Open a terminal (often Ctrl-Alt-T) and go to the directory where the examples are unpacked&amp;lt;br&amp;gt;&lt;br /&gt;
3. Compile the {{Code|HelloWorld.c}} example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 gcc HelloWorld.c -o HelloWorld -lphidget21&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
4. Run the {{Code|HelloWorld}} example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 sudo ./HelloWorld&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
(The sudo is needed for USB access for now, see the [[#Setting udev Rules|Setting udev Rules]] section for how to change this)&lt;br /&gt;
&lt;br /&gt;
The {{Code|-lphidget21}} will look in the standard library location for your Linux distribution (usually {{Code|/usr/lib/}}) for the Phidget 21 library file.  Generally, libraries to be linked on Linux through {{Code|gcc}} have a naming convention.  For example, {{Code|-lphidget21}} looks for the binary files &#039;&#039;&#039;{{Code|libphidget21.a}}&#039;&#039;&#039; and &#039;&#039;&#039;{{Code|libphidget21.so}}&#039;&#039;&#039; in the library location.  These files are automatically put in the library location during the {{Code|make install}} step of [[#Installing | installing the libraries]].&lt;br /&gt;
&lt;br /&gt;
The HelloWorld program will simply print out basic information for any device you plug in, and print a message upon unplugging the device.  For example, starting the program, plugging in an Interface Kit Phidget, unplugging the Interface Kit, and pressing Enter displays:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $ sudo ./HelloWorld &lt;br /&gt;
   &lt;br /&gt;
 Opening...&lt;br /&gt;
 Press Enter to end&lt;br /&gt;
&lt;br /&gt;
 Hello to Device Phidget InterfaceKit 8/8/8, Serial Number: 37299&lt;br /&gt;
 Goodbye Device Phidget InterfaceKit 8/8/8, Serial Number: 37299&lt;br /&gt;
&lt;br /&gt;
 Closing...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
If the out-of-the-box examples do not work, make sure the Phidget is seen by your USB interface.  To check this, you can use the kernel log reader {{Code|dmesg}}.  Pipe the output of {{Code|dmesg}} into the utility {{Code|tail}} to read the last ten lines of the log:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $&amp;gt; dmesg | tail&lt;br /&gt;
 ....(9 lines)....&lt;br /&gt;
 [24344.013638] usb 2-1.2: new low speed USB device number 5 using ehci_hcd&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The number between the [ ] is the system time in seconds since the last boot up, so you can tell whether the event was recent or not.  (This will also tell you the interrupt type of Phidget that is registered by the USB interface, see the [[#Common Problems and Solutions | common problems section below]] for more information on what this means.)&lt;br /&gt;
&lt;br /&gt;
The Phidget should both connect and disconnect properly, so unplugging it should result in an additional line at the tail:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $&amp;gt; dmesg | tail&lt;br /&gt;
 ....(8 lines)....&lt;br /&gt;
 [24344.013638] usb 2-1.2: new low speed USB device number 5 using ehci_hcd&lt;br /&gt;
 [25094.809328] usb 2-1.2: USB disconnect, device number 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t see similar lines to these at the tail of your kernel log, take a look at the [[#Troubleshooting|troubleshooting]] section below, as well as the &#039;&#039;&#039;Communications&#039;&#039;&#039; section of our [[General Troubleshooting#Communications Troubleshooting|general troubleshooting page]].&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the examples &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your computer can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* No other programs, drivers, or processes are using that USB port in software&lt;br /&gt;
* You are running the example program as root (or your udev rules have been set properly)&lt;br /&gt;
* You are using libusb 0.1 (not 1.0 or later)&lt;br /&gt;
* You have compiled versions of libphidget21.a and libphidget21.so in your system library location (usually {{Code|/usr/lib}})&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| quick downloads section]] to download them)&lt;br /&gt;
* Your Linux kernel version is 2.6 or later (type {{Code|uname -r}} in a terminal to get your kernel version)&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic libraries installed, you can pick your language and begin programming!  &lt;br /&gt;
&lt;br /&gt;
If you are not using the [[#WebService | webservice]] (discussed below) to control a Phidget over a network, your next step will be to delve into the use of your specific language.  Each page has its own set of specific libraries, code examples, and setup instructions.  &lt;br /&gt;
&lt;br /&gt;
On Linux, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Java | Java]]&lt;br /&gt;
*[[Language - Python | Python]]&lt;br /&gt;
*[[Language - Ruby | Ruby]]&lt;br /&gt;
*[[Language - C Sharp | C#]] (Using [[Language - C Sharp#Mono|Mono]])&lt;br /&gt;
*[[Language - Flash AS3 | Flash AS3]]&lt;br /&gt;
&lt;br /&gt;
You can also use these languages, but they do not support [[General Phidget Programming#Event Driven Code | event driven code]], and must use [[General Phidget Programming#Logic Code | logic code]] only:&lt;br /&gt;
&lt;br /&gt;
*[[Language - MATLAB|MATLAB]]&lt;br /&gt;
*[[Language - Simulink|Simulink]]&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network.&amp;lt;br&amp;gt;This section helps you install, check, and use the WebService on Linux, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
===Installing the WebService===&lt;br /&gt;
&lt;br /&gt;
To install the webservice, you must first have the [[#Installing|Phidget libraries installed]].  Then, follow these steps:&lt;br /&gt;
&lt;br /&gt;
#Download &#039;&#039;&#039;avahi&#039;&#039;&#039; and its development libraries (mdnsresponder/bonjour is also an option, see the [[#WebService with mDNSResponder|webservice with mDNSResponder]] section)&lt;br /&gt;
#*Try {{Code|apt-cache search avahi}} in a terminal to find current packages&lt;br /&gt;
#*Often, this is installed in a default system, you may already have it&lt;br /&gt;
#Unpack and install the [{{SERVER}}/downloads/libraries/phidgetwebservice.tar.gz Phidgets WebService] source code tarball for Linux&lt;br /&gt;
#*From the unpacked WebService source code directory, run:&lt;br /&gt;
#*:{{Code|./configure}}&lt;br /&gt;
#*:{{Code|make}}&lt;br /&gt;
#*:{{Code|sudo make install}}&lt;br /&gt;
#*This will compile the executable {{Code|phidgetwebservice21}} and place it into {{Code|/usr/bin/phidgetwebservice21}}&lt;br /&gt;
&lt;br /&gt;
====WebService with BSD====&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;BSD&#039;&#039;&#039;, the webservice has been found to work (BSD 8+) but requires a special configuration at the {{Code|./configure}} step:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 ./configure LIBS=/usr/lib/libphidget21.so CFLAGS=-pthread&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then {{Code|make}} and {{Code|sudo make install}} are the same.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The {{Code|LIBS}} argument may not be necessary, but sometimes BSD has trouble finding the library install location.  The {{Code|CFLAGS}} argument is needed because BSD needs explicit linking for using threads.&lt;br /&gt;
&lt;br /&gt;
====WebService with mDNSResponder====&lt;br /&gt;
&lt;br /&gt;
To use &#039;&#039;&#039;mdnsresponder&#039;&#039;&#039; instead of avahi, change the configure script to be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 ./configure --enable-zeroconf=bonjour&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(To see all options, use {{Code|./configure --help}} like you would any configure script)&lt;br /&gt;
&lt;br /&gt;
===Setting Up the WebService===&lt;br /&gt;
&lt;br /&gt;
To set up and use the webservice, it helps to have [[#Setting udev Rules|set your udev rules]].  Otherwise, you must run the webservice as root.&lt;br /&gt;
&lt;br /&gt;
You can get command line help with {{Code|phidgetwebservice21}} by using the {{Code|-h}} option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
$ phidgetwebservice21 -h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
&#039;phidgetwebservice21&#039; is a Phidget and Dictionary server from Phidgets Inc. See www.phidgets.com for more information.&lt;br /&gt;
Usage: phidgetwebservice21 [OPTION]&lt;br /&gt;
All parameters are optional. The default parameters are: port=5001, ServerName=(Computer Name) and no password&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
  -p      Port&lt;br /&gt;
  -n      Server Name&lt;br /&gt;
  -P      Password&lt;br /&gt;
  -v      Debug mode&lt;br /&gt;
  -h      Display this help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see this help regardless of whether the webservice was correctly hooked in to avahi.  In fact, you will see it even if you explicitly disabled mDNS in the {{Code|./configure}} step at compile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  ./configure --disable-zeroconf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(To see all options, use {{Code|./configure --help}} like you would any configure script)&lt;br /&gt;
&lt;br /&gt;
To find the defaults used by {{Code|phidget21webservice}}, the command line is the fastest way to learn the default server name and IP address of your computer:&lt;br /&gt;
*For the default server name, use {{Code|hostname}} on the command line.&lt;br /&gt;
*For your IP address, use {{Code|ifconfig -a}} on the command line.&lt;br /&gt;
**A line in the return text, under your main internet connection (usually {{Code|eth0}}) will say something like {{Code|inet addr:192.168.3.178}}, which is your IP.&lt;br /&gt;
&lt;br /&gt;
Using a server name to connect would not be an option without avahi or some other mDNS service; in this case you would only have the option to use an IP address.&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
To use a Phidget over the webservice, you&#039;ll want to:&lt;br /&gt;
* Obtain code you can use to open a Phidget remotely&lt;br /&gt;
* Start the webservice on the computer that directly connects to the Phidget&lt;br /&gt;
* Run your program on the remote computer that will control the Phidget over the network&lt;br /&gt;
&lt;br /&gt;
The easiest way to test these steps on Linux is simply to set up the webservice and run the Phidget program on the same computer, using the loopback interface.  Later, you can replace one of the two ends with a different computer and/or operating system.&lt;br /&gt;
&lt;br /&gt;
To quickly create code to run remotely, in our examples we include commented out lines with openRemote() function calls of different types.  In the C example for your device, find the line that says:&lt;br /&gt;
&lt;br /&gt;
{{Code|CPhidget_open((CPhidgetHandle) device, -1)}}&lt;br /&gt;
&lt;br /&gt;
and change it to be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 int serial_number = 37299&lt;br /&gt;
 CPhidget_openRemoteIP ((CPhidgetHandle) device, serial_number, &amp;quot;127.0.0.1&amp;quot;, 5001, NULL)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except that you should replace &#039;&#039;&#039;37299&#039;&#039;&#039; with the serial number of your Phidget, which you can obtain from either the Phidget board itself, or from when you [[#Checking|ran the HelloWorld example code]].  The IP address &amp;quot;127.0.0.1&amp;quot; simply loops back to the same computer, and 5001 is the default port as found from using {{Code|phidget21webservice -h}} in [[#Setting Up the WebService|the Setting Up the WebService]] section.  The NULL is used to not specify a password.&lt;br /&gt;
&lt;br /&gt;
Save the changed example under a different filename.  In the walkthrough here, we are using the {{Code|InterfaceKit.c}} example, and we rename it to be {{Code|InterfaceKitRemote.c}}&lt;br /&gt;
&lt;br /&gt;
Compile your new C file. In our {{Code|InterfaceKitRemote.c}} case, this would be by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 gcc InterfaceKitRemote.c -o InterfaceKitRemote -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Start two terminals to run this test, usually opened via Ctrl-Alt-T.  Your [[#Setting udev Rules|udev rules]] need to be set up or you should use sudo for every command.  First, start the webservice in Terminal #1:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_start.png]]&lt;br /&gt;
&lt;br /&gt;
This will broadcast any Phidget events, and receive any Phidget requests, both over the network.&lt;br /&gt;
&lt;br /&gt;
2. Start the InterfaceKitRemote program that you just compiled which will open the remote Phidget.  In this case, it is {{Code|InterfaceKitRemote}}:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_step2.png]]&lt;br /&gt;
&lt;br /&gt;
3. Now, plug in the Phidget!  The {{Code|phidget21webservice}} program captures the attach and other events and sends them out over the network (in the background in Terminal #1) and the Phidget software objected opened with openRemote in Terminal #2 receives them:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_step3.png]]&lt;br /&gt;
&lt;br /&gt;
4. You can confirm that the webservice was indeed behind this exchange by killing the webservice process while still allowing the remote program to run:&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux_ws_step4.png]]&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
In addition to enabling [[General Phidget Programming#Logging|logging]] in your Phidget code, you can get additional debugging information from the WebService itself.  This additional debugging is enabled via a re-compile of the webservice.  From the webservice source code directory, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 make clean&lt;br /&gt;
&lt;br /&gt;
 ./configure --enable-debug&lt;br /&gt;
&lt;br /&gt;
 make&lt;br /&gt;
&lt;br /&gt;
 sudo make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you suspect multicast DNS (mDNS) may be the problem, you can:&lt;br /&gt;
* Try compiling the webservice with mDNSResponder, as described in [[#Installing the WebService|Installing the WebService]], or &lt;br /&gt;
* Try compiling the webservice completely without mDNS, as described in [[#Setting Up the WebService|Setting Up the WebService]]&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
===Setting udev Rules===&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to be using {{Code|sudo}} to run Phidget programs (including the webservice) forever, you will want to create a {{Code|udev}} rule to allow yourself access to the Phidget when you are not root.&lt;br /&gt;
&lt;br /&gt;
Udev has an easy way to set the owner and permissions of the USB interface of the Phidget - it finds all devices that match a given set of rules, and applies new traits to them.  But you need to give udev something to match in order to apply the new settings.  Here, we will tell udev to match the vendor code for Phidgets, Inc.  You can get the vendor code in hex by using {{Code|lsusb}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 $&amp;gt; lsusb&lt;br /&gt;
 ....Information about other devices...&lt;br /&gt;
 Bus 002 Device 013: ID 06c2:0045 Phidgets Inc. (formerly GLAB) PhidgetInterface Kit 8-8-8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two numbers separated by a colon are the codes for &#039;&#039;&#039;vendor:product&#039;&#039;&#039;.  Since we want to set up the rule so that all Phidgets, no matter what product, can be used without root privileges, we use the vendor code, which is &#039;&#039;&#039;06c2&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The rules for udev are kept in files in {{Code|/etc/udev/rules.d/}} and are traditionally grouped into order of running (10 runs before 20, 30, etc) and device type (cd, network, etc).  There should be one or more files in there already - if this is your first time editing udev rules take a look at them to see the syntax to use:&lt;br /&gt;
* Commas separate each pair with == or =&lt;br /&gt;
* One rule on each line, no line breaks&lt;br /&gt;
* Quotes around the value to be matched or changed&lt;br /&gt;
* Comments can be added on lines starting with #&lt;br /&gt;
&lt;br /&gt;
Strictly speaking, the files run in lexical order (i.e. the order they&#039;re listed when you use {{Code|ls}}).  A device can match many rules, and all will apply (if possible).  If conflicting rules are found, the first rule found is followed.&lt;br /&gt;
&lt;br /&gt;
To make sure the Phidget udev rules are found first, we can create a file {{Code|10-persistent-usb.rules}} (all udev rule files need to end with {{Code|.rules}}) and add one line to it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 SUBSYSTEM==&amp;quot;usb&amp;quot;, ATTRS{idVendor}==&amp;quot;06c2&amp;quot;, MODE=&amp;quot;0666&amp;quot;, OWNER=&amp;quot;user&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure to replace {{Code|user}} with your user name.  You probably recognize the &#039;&#039;&#039;06c2&#039;&#039;&#039; from the vendor discussion above.  We have added the match on {{Code|SUBSYSTEM}} to search first within usb (within a possibly big database).  The {{Code|MODE}} sets read and write privileges for everyone to the device, and {{Code|OWNER}} sets the owner to be you.&lt;br /&gt;
&lt;br /&gt;
Save the {{Code|10-persistent-usb.rules}} in {{Code|/etc/udev/rules.d/}} and then change its permissions so it can be read by all:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo chmod a+r /etc/udev/rules.d/10-persistent-usb.rules&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The udev rule is now set, and it just has to get read in.  The reading of the rules is goverened by a daemon, {{Code|udevd}}, which you can manage via the program {{Code|udevadm}}.  The {{Code|udevadm}} man page is quite extensive for all sorts of uses of {{Code|udevadm}} while you are testing this or other udev rules.  To re-read and implement the rules without having to reset the daemon or reset the computer, you can use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo udevadm control --reload-rules&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, if you performed all of these steps with the Phidget plugged in to your computer, you will need to unplug and plug the Phidget back in before trying to use usb access without root privileges.&lt;br /&gt;
&lt;br /&gt;
===Starting the WebService at Boot===&lt;br /&gt;
&lt;br /&gt;
If you are tired of starting the webservice on the command line all the time, you can have the webservice start when your system starts, every time.&lt;br /&gt;
&lt;br /&gt;
====User Space====&lt;br /&gt;
&lt;br /&gt;
If you are running a standard Linux machine with an X-server (Unity, KDE) the easiest way to do this is to have the Phidget WebService start when your x server starts.&lt;br /&gt;
&lt;br /&gt;
In this case, the webservice will be running in user space, so your [[#Setting udev Rules|udev rules need to be set up]] for the your user permissions to be able to access the USB ports using libusb.&lt;br /&gt;
&lt;br /&gt;
Within the X-windowing system, there is usually some sort of {{Code|System &amp;amp;rarr; Settings/Preferences &amp;amp;rarr; Startup}} that you can choose to add programs that start when a user session starts.  On Ubuntu you can use Unity to find programs listing &amp;quot;startup&amp;quot; in their names to accomplish the same thing.  This will eventually lead you to a graphical tool like this to simply add the {{Code|/usr/bin/phidgetwebservice21}} program:&lt;br /&gt;
&lt;br /&gt;
[[Image:linux_ws_boot.png|400px]]&lt;br /&gt;
&lt;br /&gt;
====As A Service====&lt;br /&gt;
&lt;br /&gt;
You would want to set the boot start of {{Code|phidgetwebservice21}} to be a service if you are running a server, or a headless machine.  It is handy any time you need the webservice to be started as a booted, respawning service with a presence in different run levels and for all users.&lt;br /&gt;
&lt;br /&gt;
A service is essentially a program that hangs out in the background, waiting to be used by some incoming task.  When the service is needed, the service forks a program to handle that need.  Most services that run on your Linux computer already have the ability to fork themselves.  &lt;br /&gt;
&lt;br /&gt;
The webservice, however, is just a binary on Linux - {{Code|phidgetwebservice21}} - and so we need a program that handles the forking for us.  For this, we use the {{Code|start-stop-daemon}} program to spawn a standalone process for us, or kill it, based on our service-like start, stop, and restart commands.&lt;br /&gt;
&lt;br /&gt;
To do this, we need:&lt;br /&gt;
# A script that tells the boot process how to start and handle the webservice (i.e. by using {{Code|start-stop-daemon}})&lt;br /&gt;
# A link from that script to the boot list&lt;br /&gt;
# An initialization file for the script&lt;br /&gt;
&lt;br /&gt;
First, the script.  We will walk through Debian here, both because it is such a common distribution and because it is the distribution that our [{{SERVER}}products.php?product_id=1072 Single Board Computer] runs.  But {{Code|init}} is surprisingly diverse on Linux, including everything from a different boot order, to different initialization programs and structure, and even different runlevels.  &lt;br /&gt;
&lt;br /&gt;
On Debian (including Ubuntu), the initialization script covers:&lt;br /&gt;
* Runlevels that the service should be present on&lt;br /&gt;
* Dependencies of the service&lt;br /&gt;
* Name of the service and other informative data&lt;br /&gt;
* The location of the PIDFILE, which stores the process ID (pid) for later dealing with a spawned instance&lt;br /&gt;
* Any configuration file locations&lt;br /&gt;
* What to do when the service is given instructions to &#039;&#039;&#039;start&#039;&#039;&#039;, &#039;&#039;&#039;stop&#039;&#039;&#039;, or &#039;&#039;&#039;reload&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The Debian script we use to start the webservice on the [{{SERVER}}products.php?product_id=1072 Single Board Computer]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight line start=&amp;quot;1&amp;quot; lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
### BEGIN INIT INFO&lt;br /&gt;
# Provides:          phidgetwebservice&lt;br /&gt;
# Required-Start:    $network $remote_fs&lt;br /&gt;
# Required-Stop:     $network $remote_fs&lt;br /&gt;
# Should-Start:      avahi&lt;br /&gt;
# Should-Stop:       avahi&lt;br /&gt;
# Default-Start:     2 3 4 5&lt;br /&gt;
# Default-Stop:      0 1 6&lt;br /&gt;
# Short-Description: Phidget WebService&lt;br /&gt;
# Description:       Phidget WebService for controlling Phidgets over the network.&lt;br /&gt;
### END INIT INFO&lt;br /&gt;
&lt;br /&gt;
DESC=&amp;quot;Phidget WebService&amp;quot;&lt;br /&gt;
NAME=phidgetwebservice&lt;br /&gt;
BIN=phidgetwebservice21&lt;br /&gt;
DAEMON=/usr/bin/$BIN&lt;br /&gt;
PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
CFG=/etc/default/$NAME&lt;br /&gt;
&lt;br /&gt;
# Gracefully exit if the package has been removed.&lt;br /&gt;
test -x $DAEMON || exit 0&lt;br /&gt;
&lt;br /&gt;
# load config&lt;br /&gt;
pws_port=&amp;quot;5001&amp;quot;&lt;br /&gt;
pws_serverid=&amp;quot;&amp;quot;&lt;br /&gt;
pws_password=&amp;quot;&amp;quot;&lt;br /&gt;
[ -f $CFG ] &amp;amp;&amp;amp; . $CFG&lt;br /&gt;
&lt;br /&gt;
start() {&lt;br /&gt;
	[ -z &amp;quot;$pws_port&amp;quot; ] || OPTIONS=&amp;quot;-p $pws_port &amp;quot;&lt;br /&gt;
	[ -z &amp;quot;$pws_password&amp;quot; ] || OPTIONS=&amp;quot;$OPTIONS-P $pws_password &amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if [ -z &amp;quot;$pws_serverid&amp;quot; ]; then&lt;br /&gt;
		OPTIONS=&amp;quot;$OPTIONS -n $( hostname )&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		OPTIONS=&amp;quot;$OPTIONS -n $pws_serverid&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
	&lt;br /&gt;
	echo -n &amp;quot;Starting $DESC: &amp;quot;&lt;br /&gt;
	start-stop-daemon -S -b -q -p $PIDFILE -m -x $DAEMON -- $OPTIONS &amp;amp;&amp;amp; echo &amp;quot;OK&amp;quot; || echo &amp;quot;ALREADY RUNNING&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop() {&lt;br /&gt;
	echo -n &amp;quot;Stopping $DESC: &amp;quot;&lt;br /&gt;
	start-stop-daemon -K -q -p $PIDFILE -x $DAEMON &amp;amp;&amp;amp; echo &amp;quot;OK&amp;quot; || echo &amp;quot;NOT RUNNING&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
	start&lt;br /&gt;
	;;&lt;br /&gt;
  stop)&lt;br /&gt;
	stop&lt;br /&gt;
	;;&lt;br /&gt;
  restart|force-reload)&lt;br /&gt;
	stop&lt;br /&gt;
	sleep 1&lt;br /&gt;
	start&lt;br /&gt;
	;;&lt;br /&gt;
  *)&lt;br /&gt;
	echo &amp;quot;Usage: $0 {start|stop|restart}&amp;quot;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the script into a file called {{Code|phidgetwebservice}}, and use {{Code|chmod 755}} to make it executable.&lt;br /&gt;
&lt;br /&gt;
Also on Debian, startup service scripts should go in {{Code|/etc/init.d}}, and then put within the appropriate runlevel-numbered folder - by symbolic link.  There is a handy tool to do this for you, called {{Code|insserv}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo insserv -d phidgetwebservice&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The {{Code|insserv}} program is the program that makes use of the {{Code|### BEGIN INIT INFO...### END INIT INFO}} that appears at the top of the {{Code|phidgetwebservice}} script.  Use {{Code|man insserv}} for more information.  The {{Code|insserv}} tool handles the mess of finding the right runlevel folders (i.e. the {{Code|rc.d}} numbered folders) and making the appropriate links. You can see what links would be updated by running {{Code|insserv}} with the {{Code|-n}} option, for a dry run.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; When you run {{Code|insserv}}, all of the dependencies for the boot order are re-written.  This means that all of the initialization scripts in {{Code|/etc/init.d}} are re-examined.  So, you&#039;ll probably get a lot of output when you run the command.&lt;br /&gt;
&lt;br /&gt;
Then, you can check that {{Code|phidgetwebservice}} is on the service list with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 service --status-all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And you can start it right now without rebooting like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:linux_system_service_start.png]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|service}} command has many options to start and stop services like the phidgetwebservice, try {{Code|man service}} for more information.&lt;br /&gt;
&lt;br /&gt;
At this point, you can follow the client instructions on [[#Using the WebService|using the webservice]] to create a loopback test for the new webservice service that should now be running.&lt;br /&gt;
&lt;br /&gt;
The final piece, for future configuration changes, is that the {{Code|/etc/init.d}} script looks for the file {{Code|/etc/default/phidgetwebservice}} upon starting up.  The file is expected to contain the port, server ID, and password for the server side of the webservice.  These are also set in the {{Code|phidgetwebservice}} script in {{Code|init.d}}, as you can see from reading the code above, but if you want to change them a lot, you can edit the configuration file rather than changing the {{Code|phidgetwebservice}} script and re-installing by {{Code|insserv}} every time.  The configuration file in {{Code|/etc/default/}} should contain the same syntax as that used in the script source above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 pws_port=&amp;quot;5001&amp;quot;&lt;br /&gt;
 pws_serverid=&amp;quot;&amp;quot;&lt;br /&gt;
 pws_password=&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-Compiling with a Custom Toolchain===&lt;br /&gt;
&lt;br /&gt;
This would allow you to have the Phidget libraries compiled to include in code for an embedded device.  When developing for an embedded device, you will often write code for it on your &#039;normal&#039; computer, and then build the code to binary with a different target than the processor in your computer.  Many microcontrollers do not have the ability to run a full operating system, and hence cannot compile code natively.  &lt;br /&gt;
&lt;br /&gt;
The collection of tools used to create binary code for a separate system is called a &#039;&#039;toolchain&#039;&#039;.  Compiling the Phidget libraries specifically for an embedded system, and placing them into the path for writing code on top of the libraries is like adding another link in this chain.&lt;br /&gt;
&lt;br /&gt;
You can use the typical {{Code|./configure}} setup for custom build targets:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
./configure --prefix=toolchain_location --build=this_system --host=target_system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the Phidget libraries, the {{Code|./configure}} tool works this way as well. You&#039;d use this in the [[#Installing|install the libraries section]] setup. For example, let&#039;s say you&#039;re building the libraries to develop code for the [{{SERVER}}products.php?product_id=1072 Single Board Computer] as a target.  Your system is a standard Linux system (i686-pc-linux-gnu) and the target system for the [[SBC]] is {{Code|arm-linux-gnueabi}}.  For this target, you&#039;ll need the base of the GNU embedded Debian chain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 sudo apt-get install gcc-arm-linux-gnueabi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, download the Phidget libraries [[#Quick Downloads|above]] and unpack them into a folder {{Code|phidget_libraries}}.  If {{Code|/usr/arm-linux-gnueabi}} is the location of your ARM toolchain (downloaded above in {{Code|gcc-arm-linux-gnueabi}}), type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 ~/phidget_libraries $&amp;gt; ./configure --prefix=/usr/arm-linux-gnueabi --build=i686-pc-linux-gnu --host=arm-linux-gnueabi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Linux on Non-Standard Systems===&lt;br /&gt;
&lt;br /&gt;
We occasionally get requests to use Phidgets on Linux systems other than a standard laptop or desktop.  One example is the new Raspberry Pi system.  Often these systems include USB ports, so the combination makes sense.&lt;br /&gt;
&lt;br /&gt;
Our libraries are installed by building from source, and their main dependency is the {{Code|libusb-dev}} library, so if you can get gcc on your machine (or set up a cross compiler for it) and you can also install the libusb-0.1 development headers, you can probably get Phidgets to work.  Of course, we don&#039;t offer much support for these systems, so - depending on your system - expect to spend some raw time getting it up and going.  &lt;br /&gt;
&lt;br /&gt;
If you&#039;re new to the embedded computer thing, keep in mind that for these super basic systems, once you&#039;ve gotten a power supply, and storage, and put the kernel you want on it, and then spent a couple of days of time getting things working, and  more time getting your drivers going, costs add up pretty quickly.  If you want a compact system that works right out of the box (and which can use all of our analog sensors in addition to our USB Phidgets), check out our [{{SERVER}}products.php?product_id=1072 Single Board Computer].   Our SBC:&lt;br /&gt;
* Has many more USB ports than super-stripped devices, and also has digital and analog ports &lt;br /&gt;
* Includes a power supply and can run on batteries easily&lt;br /&gt;
* Has a nice amount of RAM, a decent embedded processor, and built-in onboard storage (we&#039;ve run R, GRASS, and X11 on it)&lt;br /&gt;
* Includes installed Debian, working Phidget drivers, and [[Phidget WebService|networked Phidget drivers]] from the moment it ships &lt;br /&gt;
* Has access to the full Debian repository including Python, Mono .NET, Ruby, and gcc&lt;br /&gt;
* Has a kernel development kit with patch file and instructions for adding new drivers (bluetooth, wireless, and so on)&lt;br /&gt;
* Comes with very in-depth documentation and technical support by phone and email &lt;br /&gt;
* Etc, etc.&lt;br /&gt;
The [[Phidget WebService|networked support]] in particular allows it to work with your cell phone and more.  &lt;br /&gt;
&lt;br /&gt;
But if you really do want a raw hobbyist system to tinker with, go for it!  We&#039;re all nerds here - we&#039;ve been there too and we certainly understand!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Low Speed Phidgets (Max of 8)|Linux will only schedule one low-speed interrupt transfer per millisecond.}}&lt;br /&gt;
&lt;br /&gt;
You can find out the type of your Phidget by attaching it and then running &amp;lt;code&amp;gt;&amp;lt;font size=3&amp;gt;dmesg | tail&amp;lt;/font&amp;gt;&amp;lt;/code&amp;gt;, which will display the type of Phidget from your kernel logs, as described above in the [[#Hardware|hardware section]]. The practical consequence of this is if your system has many low speed Phidgets attached, they will each be throttled down.  Low speed Phidgets require an interrupt transfer as often as every 8 milliseconds.  A Linux system could only have up to 8 of these Phidgets attached.&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Sample Overrun Error|The data read from a program, or the first packet on the WebService, can give a sample overrun error (EEPHIDGET_OVERRUN).}}&lt;br /&gt;
&lt;br /&gt;
Linux only polls data from the analog inputs on Phidgets when you ask it to.  So there is some delay between when you open the device and when it actually attaches when data from those inputs are accumulating...and overrunning the buffer.  This is simply in the nature of how Linux polls USB - we recommend catching (but ignoring) this one-time initial error.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=OS_-_macOS&amp;diff=20691</id>
		<title>OS - macOS</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=OS_-_macOS&amp;diff=20691"/>
		<updated>2012-06-29T19:58:42Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:OS]]&lt;br /&gt;
{{OSLang|[[File:Icon-Mac-OS.png‎|64x64px|link=]]|On OS X, Phidgets can be either plugged directly into a USB Port or run over a network using the [[#WebService|WebService]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
Phidgets are designed to run on &#039;&#039;&#039;OS X 10.4 Tiger or newer&#039;&#039;&#039;, and can run on PPC, 32-bit, and 64-bit systems.&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
If this is your first Phidget, we highly recommend working through the Getting Started guide for your specific Phidget device, which may be found on its product page on [{{SERVER}} our main website].  If you already have the Preference Pane Installed and know how to use it, then you&#039;ve already followed the guide and are ready to learn more about the workings behind the Preference Pane, the Phidget WebService, and more - all specific to OS X.&lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the drivers:&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}downloads/libraries/Phidget.dmg OS X Installer Download]&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#osx Software License]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with OS X==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
The Phidget installer will install the core Phidget files onto your system.&lt;br /&gt;
&lt;br /&gt;
To install the libraries, follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. Download the Phidget installer for your system:&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget.dmg OS X Installer]&lt;br /&gt;
&lt;br /&gt;
2. Open up the installer, and double click on {{Code|Phidgets.mpkg}} to install the libraries.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX Install 1.png|link=|alt=OS X Install]]&lt;br /&gt;
&lt;br /&gt;
3. Proceed through the wizard. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX Install 2.png|link=|alt=OS X Install]]&lt;br /&gt;
&lt;br /&gt;
4. Once the installation is complete, you are ready to program with Phidgets. To find out what files got installed, please see [[#Description of Installer files | Description of Installer files]] in the Appendix section.&lt;br /&gt;
&lt;br /&gt;
Proceed onto to the [[#Phidget Preference Pane | next]] section where the Phidget Preference Pane will be discussed.&lt;br /&gt;
&lt;br /&gt;
====Phidget Preference Pane====&lt;br /&gt;
&lt;br /&gt;
The Phidget Preference Pane is a tool to quickly determine whether your system is able to communicate with Phidgets, and also act as a debugging tool. &lt;br /&gt;
&lt;br /&gt;
Once the Phidget libraries are installed using the installer, open up the {{Code|System Preferences}} window.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX System Preferences.png|link=|alt=OS X System Preferences]]&lt;br /&gt;
&lt;br /&gt;
Click on the {{Code|Phidgets}} icon in the {{Code|Other}} section to bring up the Phidgets Preference Pane.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane General.png|link=|alt=OS X PreferencePane General]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|general}} tab shows the list of Phidgets currently physically attached to the computer. You can also view the currently installed Phidget library version. You can double click on a Phidget device to open up an example program for the device.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Example.png|link=|alt=OS X PreferencePane Example]]&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, the RFID example was opened. These examples are intended for demonstration and debugging purposes. If you have not yet already, please see the &#039;&#039;&#039;Getting Started&#039;&#039;&#039; guide for your device, which may be found on its product page on [{{SERVER}} our main website].  &lt;br /&gt;
&lt;br /&gt;
It is important to keep in mind that when an example Phidget application is opened from the Phidget Preference Pane or opened from any of your Phidget applications that you develop, it holds a lock on the Phidget. This prevents any other program from accessing the Phidget. Please ensure that this example application is closed(the Phidget Preference Pane can still be running) when you are running your own applications. &lt;br /&gt;
&lt;br /&gt;
The next tab is the {{Code|Web Service}} tab, which allows you to control Phidgets over a network. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Stopped.png|link=|alt=OS X PreferencePane WebService Stopped]]&lt;br /&gt;
&lt;br /&gt;
Here, you can start and stop the WebService. Details are provided in the [[#WebService | WebService]] section. This screen also tells you whether the Phidget WebService is currently running. &lt;br /&gt;
&lt;br /&gt;
The next tab is the {{Code|Labels}} tab. In this section, you can view the currently assigned labels of any Phidget attached to your computer. It is also possible to set the labels of Phidgets here too. You might want to set a label to a Phidget device because you can refer to it by its label as opposed to its serial number. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Labels Local.png|link=|alt=OS X PreferencePane WebService Labels Local]]&lt;br /&gt;
&lt;br /&gt;
You can also view the labels of any Phidget connected through the WebService&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Labels Remote.png|link=|alt=OS X PreferencePane WebService Labels Remote]]&lt;br /&gt;
&lt;br /&gt;
The {{Code|Bonjour}} tab gives a list of all currently attached Phidgets that are connected to the WebService. You can also double click on the Phidget to connect to it over the network using one or more computers, but still use the Phidget on the computer it is directly connected to.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Bonjour.png|link=|alt=OS X PreferencePane Bonjour]]&lt;br /&gt;
&lt;br /&gt;
The last tab is the {{Code|PhidgetSBC}} tab, which displays the complete list of PhidgetSBCs connected to the network. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane PhidgetSBC.png|link=|alt=OS X PreferencePane PhidgetSBC]]&lt;br /&gt;
&lt;br /&gt;
You can double click on the PhidgetSBC to bring up the PhidgetSBC Administration Console log-in page in your default browser.&lt;br /&gt;
&lt;br /&gt;
[[File:PhidgetSBCAdminConsole.PNG|link=|alt=PhidgetSBC Admin Console]]&lt;br /&gt;
&lt;br /&gt;
The PhidgetSBC Administration Console is where you can go to configure the PhidgetSBC. For more details, please see the [[1072 0 - Getting Started | PhidgetSBC]] section.&lt;br /&gt;
&lt;br /&gt;
===Checking===&lt;br /&gt;
&lt;br /&gt;
To confirm the libraries were installed and work correctly, you can check both the hardware and software components of the interface. It is worth checking the software side first, because if it works then you know the hardware side is also okay.&lt;br /&gt;
&lt;br /&gt;
====Software====&lt;br /&gt;
&lt;br /&gt;
If you have the Phidgets library installed on your system, you can verify that the software component is working by seeing if the Phidget device is listed in the General tab of the Phidget Preference Pane.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane General.png ‎|link=|alt=OS X Preference Pane General]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows that a PhidgetRFID and a PhidgetInterfaceKit are attached to the computer. If you see your Phidget in the list, you can continue to the [[#Programming Languages | programming languages]] section to learn more. If you are not able to see that the Phidget is in the list, there may be a hardware issue. Please see the [[#Hardware| hardware]] section for more details.&lt;br /&gt;
&lt;br /&gt;
====Hardware====&lt;br /&gt;
&lt;br /&gt;
You can verify that your computer detects that the Phidget is plugged in through a USB connection by going to the OS X System Profiler. You can access the System Profiler by selecting {{Code|About This Mac}} under the Apple icon. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX About This Mac.png‎|link=|alt=OS X About This Mac]]&lt;br /&gt;
&lt;br /&gt;
The new window will open up.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX More Info.png|link=|alt=OS X More Info]]&lt;br /&gt;
&lt;br /&gt;
Select {{Code|More Info}}. The System Profiler will show up. In the USB section, you will be able to find all connected USB devices. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX USB Devices.png ‎|link=|alt=OS X Attached USB Devices]]&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, The PhidgetInterfaceKit and PhidgetRFID are connected to the USB ports. &lt;br /&gt;
&lt;br /&gt;
If you don&#039;t see the Phidget in the list, then take a look at the [[#Troubleshooting|troubleshooting]] section below, as well as the &#039;&#039;&#039;Communications&#039;&#039;&#039; section of our [[General Troubleshooting#Communications Troubleshooting|general troubleshooting page]].&lt;br /&gt;
&lt;br /&gt;
====Troubleshooting====&lt;br /&gt;
&lt;br /&gt;
If the example programs &#039;&#039;&#039;do not&#039;&#039;&#039; work but USB &#039;&#039;&#039;does&#039;&#039;&#039; work (i.e. your computer can consistently see the device in the [[#Hardware|hardware]]), take a moment to check the basics:&lt;br /&gt;
* You are using OS X 10.4 or newer. &lt;br /&gt;
* No other programs, drivers, or processes are using that USB port in software&lt;br /&gt;
* The Phidget libraries are the latest version (visit the [[#Quick Downloads| quick downloads section]] to download them)&lt;br /&gt;
&lt;br /&gt;
* Check the [[#Common Problems and Solutions|common problems]] section below, some specific combinations can cause problems&lt;br /&gt;
&lt;br /&gt;
If your problem doesn&#039;t seem to be fixed by these steps, make sure that the Phidget is seen &#039;&#039;&#039;consistently&#039;&#039;&#039; by USB (if it is erratic, try our [[General Troubleshooting|general troubleshooting guide]]).  If you are still having problems after using the troubleshooting guide, please [[Contact Us|ask us]]!&lt;br /&gt;
&lt;br /&gt;
==Programming Languages==&lt;br /&gt;
Phidgets’ philosophy is that you do not have to be an electrical engineer in order to do projects that use devices like sensors, motors, motor controllers, and interface boards. All you need to know is how to program.&lt;br /&gt;
&lt;br /&gt;
After you have installed the drivers above, you should pick a programming language, install libraries, and run the examples for that specific language. You can learn more about what is needed to program in a particular language by choosing the language of your preference below. If you need help choosing a language, please look at the [[Software Overview#Language Support |language comparison table]]. &lt;br /&gt;
&lt;br /&gt;
We recommend the following languages for OS X:&lt;br /&gt;
* [[Language - Applescript|AppleScript]]&lt;br /&gt;
* [[Language - C/C++|C/C++]]&lt;br /&gt;
* [[Language - C Sharp|C# (Using Mono)]]&lt;br /&gt;
* [[Language - Cocoa | Cocoa]]&lt;br /&gt;
* [[Language - Flash AS3 | Flash AS3]]&lt;br /&gt;
* [[Language - Flex AS3 | Flex AS3]]&lt;br /&gt;
* [[Language - LiveCode | LiveCode]]&lt;br /&gt;
* [[Language - Java | Java]]&lt;br /&gt;
* [[Language - Max/MSP|Max/MSP]]&lt;br /&gt;
* [[Language - Python | Python]]&lt;br /&gt;
* [[Language - Ruby|Ruby]]&lt;br /&gt;
&lt;br /&gt;
You can also use these languages, but they do not support [[General Phidget Programming#Event Driven Code | event driven code]], and must use [[General Phidget Programming#Logic Code | logic code]] only:&lt;br /&gt;
&lt;br /&gt;
*[[Language - MATLAB|MATLAB]]&lt;br /&gt;
*[[Language - Simulink|Simulink]]&lt;br /&gt;
&lt;br /&gt;
==WebService==&lt;br /&gt;
&lt;br /&gt;
The Phidget WebService allows you to remotely control a Phidget over a network.&lt;br /&gt;
&lt;br /&gt;
Drivers for the Phidget WebService on OS X are already included in the [[#Quick Downloads | Drivers]] above. If you see the Phidget Preference Pane in System Preferences, then you already have the WebService drivers installed.&lt;br /&gt;
&lt;br /&gt;
There are two ways that you can connect to a Phidget hosted on another computer. The first method is by using the IP address/host name and port of the host computer. The second method makes the use of [http://en.wikipedia.org/wiki/Multicast_DNS mDNS], which allows Phidgets to be found and opened on the network by a server id instead of an IP address/host name. When using a server id, both the client and server will need to be running an implementation of zero configuration networking. The Phidget WebService takes advantage of [http://www.apple.com/support/downloads/bonjourforwindows.html Bonjour] software, which is built-in to OS X. It is a tool developed by Apple to locate devices, such as Phidgets,  on a network.&lt;br /&gt;
&lt;br /&gt;
This section helps you install, check, and use the WebService on Windows, but we also have an overview of the [[Phidget WebService]] in general.&lt;br /&gt;
&lt;br /&gt;
===Turning the WebService On and Off===&lt;br /&gt;
&lt;br /&gt;
There are two methods that can be used to turn the WebService on and off. The first method is through the Phidget Preference Pane. In the {{Code|WebService}} tab, you can start or stop the WebService. You can also choose to have the WebService start up automatically upon system boot up by selecting the {{Code|Start Automatically}} checkbox. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Stopped.png|link=|alt=OS X PreferencePane WebService]]&lt;br /&gt;
&lt;br /&gt;
The second method of turning the WebService on and off is through command line. After using our installer, the WebService utility is automatically installed in {{Code|/usr/bin/phidget21webservice}}. &lt;br /&gt;
&lt;br /&gt;
You can get command line help with {{Code|phidgetwebservice21}} using the -h option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21 -h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
&#039;phidgetwebservice21&#039; is a Phidget and Dictionary server from Phidgets Inc. See www.phidgets.com for more information.&lt;br /&gt;
Usage: phidgetwebservice21 [OPTION]&lt;br /&gt;
All parameters are optional. The default parameters are: port=5001, ServerName=(Computer Name) and no password&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
  -p      Port&lt;br /&gt;
  -n      Server Name&lt;br /&gt;
  -P      Password&lt;br /&gt;
  -v      Debug mode&lt;br /&gt;
  -h      Display this help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mapping out which command line options to which Phidget Preference Pane option is as follows:&lt;br /&gt;
&lt;br /&gt;
-p: {{Code|Port}} field&lt;br /&gt;
&lt;br /&gt;
-n: {{Code|ServerID}} field&lt;br /&gt;
&lt;br /&gt;
-P: {{Code|Password}} field&lt;br /&gt;
&lt;br /&gt;
-v: Not supported under the Phidget Preference Pane&lt;br /&gt;
&lt;br /&gt;
To find the defaults used by {{Code|phidget21webservice}}, the command line is the fastest way to learn the default server name and IP address of your computer:&lt;br /&gt;
*For the default server name, use {{Code|hostname}} on the command line.&lt;br /&gt;
*For your IP address, use {{Code|ifconfig -a}} on the command line.&lt;br /&gt;
**A line in the return text, under your main internet connection (usually {{Code|eth0}}) will say something like {{Code|inet addr:192.168.3.178}}, which is your IP.&lt;br /&gt;
&lt;br /&gt;
Here are some usage examples:&lt;br /&gt;
&lt;br /&gt;
To start the WebService with default parameters:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To start the WebService with a server name of {{Code|myServer}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21-n myServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To stop the WebService, simply close the command line window or press {{Code|Control}} and {{Code|c}} at the same time in the command line window.&lt;br /&gt;
&lt;br /&gt;
===Using the WebService===&lt;br /&gt;
&lt;br /&gt;
To use a Phidget over the WebService, you&#039;ll want to:&lt;br /&gt;
* Have two different computers connected to the same network. We will call the computer that has the Phidget directly connected to the USB port the host. The client will be the computer that runs a Phidget application to connect to the Phidget attached to the host. Please note that if you only have a single computer, you can also connect to the Phidget over the WebService. The computer will simply act as both a host and client. This will allow you to bypass the [[General Phidget Programming # Details for Open() | one application per Phidget limitation]]. &lt;br /&gt;
&lt;br /&gt;
* Start the WebService on the computer that directly connects to the Phidget&lt;br /&gt;
* Run your program on the remote computer that will control the Phidget over the network&lt;br /&gt;
&lt;br /&gt;
The easiest way to test these steps on OS X is to set up the WebService and run the Phidget program on the client. Please follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. On the host, open up the Phidget Preference Pane and traverse to the {{Code|Web Service}} tab.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Stopped.png |link=|alt=OS X Preference Pane WebService]]&lt;br /&gt;
&lt;br /&gt;
2. Leave all fields the way they are, and click on {{Code|Start WebService}} to run the WebService.&lt;br /&gt;
&lt;br /&gt;
3. You can determine that the WebService is running by looking at the status on the right side.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Running.png|link=|alt=OS X PreferencePane WebService Running]]&lt;br /&gt;
&lt;br /&gt;
4. Ensure that the Phidget is plugged in to the host. &lt;br /&gt;
&lt;br /&gt;
5. On the client&#039;s Phidget Preference Pane, open up the {{Code|Bonjour}} tab. You will see the Phidget that is plugged into the host as one of the entries listed. Double click it to open the example application.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Bonjour.png ‎‎ |link=|alt=OS X PreferencePane Bonjour.png ‎]]&lt;br /&gt;
&lt;br /&gt;
6. The example application will open up, and you will be able to communicate with the Phidget over the WebService.&lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Example.png ‎ |link=|alt=OS X PreferencePane Example]]&lt;br /&gt;
&lt;br /&gt;
7. You can confirm that the WebService was indeed behind this exchange by terminating the WebService process while still allowing the remote program to run. On the host&#039;s Phidget Preference Pane, traverse to the {{Code|WebService}} tab. Hit {{Code|Stop WebService}} to terminate the WebService. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Webservice Running.png|link=|alt=OS X PreferencePane WebService Running]]&lt;br /&gt;
&lt;br /&gt;
8. Take a look at the example application on the client. Since the application can no longer connect to the WebService, there is nothing attached. &lt;br /&gt;
&lt;br /&gt;
[[File:OSX PreferencePane Example Stopped.png |link=|alt=OS X PreferencePane Example Stopped]]&lt;br /&gt;
&lt;br /&gt;
===Debugging the WebService===&lt;br /&gt;
&lt;br /&gt;
In addition to enabling [[General Phidget Programming#Logging|logging]] in your Phidget code, you can get additional debugging information from the WebService itself.  This additional debugging can only be enabled from the command line approach to start the WebService. Debug information is enabled by specifying the {{Code|-v}} option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
 phidgetwebservice21 -v -n &amp;quot;myServer&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugging information will be shown as output in the command line console.&lt;br /&gt;
&lt;br /&gt;
==Advanced Uses==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Description of Installer files===&lt;br /&gt;
&lt;br /&gt;
Here is the list of files and their description for each file the installer puts onto your system. &lt;br /&gt;
===Description of Library files===&lt;br /&gt;
&lt;br /&gt;
This section will explain the files that were placed onto your system as part of the installation process.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.framework}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed into {{Code|/Library/Frameworks}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget.kext}}&amp;lt;/b&amp;gt; is the kernel extension.  It is placed into {{Code|/System/Library/Extensions}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|libphidget21.jnilib}}&amp;lt;/b&amp;gt; is the JNI library for Java.  It is placed into {{Code|/Library/Java/Extensions}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidgets.prefpane}}&amp;lt;/b&amp;gt; is the Phidgets Preference Pane.  It is placed into {{Code|/Library/PreferencePanes}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidgetwebservice21}}&amp;lt;/b&amp;gt; is the Phidget WebService.  It is placed into {{Code|/usr/bin}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetsOSA.app}}&amp;lt;/b&amp;gt; is the the Phidgets agent for AppleScript.  It is placed into {{Code|/Library/ScriptingAdditions}}.&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
None, yet.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=20689</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=20689"/>
		<updated>2012-06-29T19:53:19Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21_C_Doc.zip}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/cdoc/index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [{{SERVER}}/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [{{SERVER}}/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [{{SERVER}}/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://sourceforge.net/projects/mingw/ reimp tool].  Reimp is part of MinGW, a minimal UNIX emulator for Windows, and it is specifically within the mingw-utils package.  You can check MinGW&#039;s [http://sourceforge.net/project/shownotes.php?release_id=126568 release notes] to ensure Reimp is in the version you are using.&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [{{SERVER}} our main website].  Then, the [[OS - OS X#Description of Library files|OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=20686</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=20686"/>
		<updated>2012-06-29T19:49:14Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21_C_Doc.zip}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/documentation/web/cdoc/index.html|HTML Version of API|}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [{{SERVER}}/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [{{SERVER}}/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [{{SERVER}}/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://sourceforge.net/projects/mingw/ reimp tool].  Reimp is part of MinGW, a minimal UNIX emulator for Windows, and it is specifically within the mingw-utils package.  You can check MinGW&#039;s [http://sourceforge.net/project/shownotes.php?release_id=126568 release notes] to ensure Reimp is in the version you are using.&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [{{SERVER}} our main website].  Then, the [[OS - OS X#Description of Library files|OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=20685</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=20685"/>
		<updated>2012-06-29T19:48:57Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Quick Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21_C_Doc.zip}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/documentation/web/cdoc/index.html|HTML Version of API|}}&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [{{SERVER}}/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [{{SERVER}}/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [{{SERVER}}/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://sourceforge.net/projects/mingw/ reimp tool].  Reimp is part of MinGW, a minimal UNIX emulator for Windows, and it is specifically within the mingw-utils package.  You can check MinGW&#039;s [http://sourceforge.net/project/shownotes.php?release_id=126568 release notes] to ensure Reimp is in the version you are using.&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [{{SERVER}} our main website].  Then, the [[OS - OS X#Description of Library files|OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[{{SERVER}}/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20684</id>
		<title>LED Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20684"/>
		<updated>2012-06-29T18:53:37Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Controlling LEDs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:RBG.jpg|500px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Like normal diodes, Light Emitting Diodes (LEDs) are semiconductor devices designed to conduct current in one direction only.  What makes LEDs unique is their internal material makeup:  when atoms in an LED release energy due to the flow of forward current, it is released in the form of photons (light).  Different construction materials and various phosphor coatings are used to produce numerous colors of light.&lt;br /&gt;
&lt;br /&gt;
LEDs that Phidgets sells are all operable via the [[Digital Output Primer|digital outputs]] on any of our interface kits.  However Phidgets also sells a specific [{{SERVER}}/products.php?product_id=1031 PhidgetLED-64 Advanced LED controller] since it is often desirable to control more LEDs than even the [{{SERVER}}/products.php?product_id=1012 1012 Phidget Interface Kit 0/16/16] can operate.  It offers some unique features such as brightness control.&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
[[image:led.png|thumb|350px|Parts of an LED.  The flat spot on the epoxy casing, is an anchor to prevent twisting from damaging the leads.]]&lt;br /&gt;
&lt;br /&gt;
LEDs emit light from current flowing through them.  As the current flows, the electronics experience a sudden drop in energy level (voltage).  When that happens they release energy in the form of light.  The amount of light produced is proportional to the current.  Depending on the material used to make the LED, different colors can be created.  Like a conventional diode, the current can only flow in one direction - from the anode to the cathode.&lt;br /&gt;
&lt;br /&gt;
==Controlling LEDs==&lt;br /&gt;
&lt;br /&gt;
===Forward Voltage===&lt;br /&gt;
&lt;br /&gt;
The materials used within LEDs that cause them to emit different colors of light affect a property called its forward voltage. The forward voltage is the voltage at which current in the forward direction will flow through the device and allow the LED to convert electrical energy into light.  If the voltage applied to the LED is below the forward voltage of the LED, very little current (or none) may flow, and therefore very little light will be emitted. Most standard LEDs with colors such as red, amber, orange, yellow, and green have forward voltages below 2.75 Volts, and can be used with a [[Digital Output Primer|digital output]] by simply soldering them to a connector-wire and inserting the wire into the output port. The forward voltage in the [{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED] will default to 2.75V, and the maximum current defaults to 20mA.&lt;br /&gt;
&lt;br /&gt;
===Supply Voltage===&lt;br /&gt;
{|&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|To be an effective LED controller your digital outputs must be capable of &amp;lt;br /&amp;gt;adjusting the forward voltage supplied to the LEDs to 1.7, 2.75, 3.9 and 5 volts&amp;lt;br /&amp;gt; settings allowing you to properly drive blue, white, violet, ultra violet and purple LEDs.&amp;lt;br /&amp;gt; The supply voltage will affect all LEDs. If you set the supplied voltage too high,&amp;lt;br /&amp;gt; power will be wasted and the controller may shut down from thermal overload. If you&amp;lt;br /&amp;gt; set the supply voltage too low, your LEDs will not be driven at the requested&amp;lt;br /&amp;gt; current, and will be dim or non-functional.&lt;br /&gt;
|&lt;br /&gt;
{| {{table}} border = 1&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|Typical Forward Voltages&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Color&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Forward Voltage&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Infrared||&amp;lt; 1.9&lt;br /&gt;
|-&lt;br /&gt;
| Red||1.7 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Orange||2.0 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Yellow||2.1 to 2.4&lt;br /&gt;
|-&lt;br /&gt;
| Green||2 to 2.3&lt;br /&gt;
|-&lt;br /&gt;
| Blue||3.2 to 4.0&lt;br /&gt;
|-&lt;br /&gt;
| Ultraviolet||2.1 to 3.8&lt;br /&gt;
|-&lt;br /&gt;
| White||3.3 to 3.6&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Maximum Current and Brightness Control===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
Most LEDs fall within 20, 40, 60 or 80mA, and applies to all LEDs. The &amp;lt;br /&amp;gt;Phidgets DiscreteLED API call can be used to provide more current &amp;lt;br /&amp;gt;or control brightness and will adjust the current linearly between 0 &amp;lt;br /&amp;gt;and the set maximum. This however does not imply a precise method &amp;lt;br /&amp;gt;for controlling the visibility of emitted light, as this is affected by the &amp;lt;br /&amp;gt;construction and quality of the LED as well as the eyes of the viewer. &amp;lt;br /&amp;gt;Be cautious when changing the current property. Many small LEDs are &amp;lt;br /&amp;gt;designed for a maximum 20mA, and can be destroyed if driven at higher &amp;lt;br /&amp;gt;currents.&lt;br /&gt;
|&lt;br /&gt;
[[image:Ledcurrent.png|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Choosing Current and Voltage Settings===&lt;br /&gt;
&lt;br /&gt;
Make sure to choose the minimum supply voltage setting to drive the LED that requires the most voltage during operation. Any extra voltage not required by the LED will be converted to heat by the 1031. For example, a Blue LED being driven at 20mA, 3.9V Supply, that requires 3.7 volts will cause (3.9V-3.7V + 0.4V) * 0.02A = 12 milliwatts of heat to be produced on the 1031. If this example instead uses a high power, 1.5V infrared LED at 80mA, this will create (3.9V-1.5V+0.4V)*0.08 Amps = 224 milliwatts of heat. See the Heat Dissipation and Thermal Protection section later on in this manual for more information about this issue.&lt;br /&gt;
&lt;br /&gt;
==Multiplexed LEDs==&lt;br /&gt;
Multiplexing is a system wherein the entire display is not active at the same time.  Instead, sub-units of the display are driven one at a time and the electronics combine with human persistence of vision (the phenomenon of the eye by which an afterimage is thought to persist for approximately one twenty-fifth of a second on the retina) to make the viewer believe the entire display is continuously active.  Many controllers use this architecture to reduce power consumption.  7 segment display clocks are an example of this.&lt;br /&gt;
&lt;br /&gt;
In an effort to reduce electrical noise in the system the PhidgetLED does not use multiplexing. All 64 anodes are connected to the same power supply and the cathode of each LED connection is attached to an individual constant current sink. Also, the LEDs are not controlled by PWM - they are driven at a constant current.&lt;br /&gt;
&lt;br /&gt;
==Other uses for LED controllers==&lt;br /&gt;
&lt;br /&gt;
LED controllers are typically just a set of special digital outputs.  This means they aren&#039;t limited to just controlling LEDs. They can be used to control relays, solenoids and even very small motors. The PhidgetLED can also be used to drive opto-isolators and MOSFET SSRs. A diode integrated into the 1031 on each cathode will clamp inductive surges to the anode supply voltage.&lt;br /&gt;
&lt;br /&gt;
==Power Requirements and Power Supply Selection==&lt;br /&gt;
&lt;br /&gt;
The power supply that is included with the 1031 is rated at 12V and 2A (max).  If your application requires more power, a larger power supply may be necessary.  The on-board voltage regulator is able to supply up to 6A for each LED supply voltage setting, as long as the power supply is able to provide enough voltage and current to the regulator. Assume an efficiency of 80% for the on-board voltage regulator when determining if a different power supply is required.&lt;br /&gt;
&lt;br /&gt;
==Heat Dissipation and Thermal Protection==&lt;br /&gt;
&lt;br /&gt;
Projects that require a high supply voltage, or have a lot of heat being produced from over voltage settings, will have over-temperature problems.  This can be mitigated somewhat by understanding how channels are grouped and how the heat is distributed around the controller.  On the 1031 channels are split into four groups: (0-7,24-31), (8-23), (32-39, 56-63) and (40-55); each controlled by their own individual IC. Evenly distributing the LEDs that may produce a lot of heat across these groups will balance the load on the ICs and reduce the risk of thermal overload. When thermal overload occurs, the integrated circuit (IC) controlling the involved LEDs will disable the output of all the channels it controls.  For example, if an over-temperature occurs due to channel 12, all of the channels 8 through 23 will be disabled by the IC until the temperature back within the operating range.  Thermal protection is activated when the die of the IC reaches approximately 160 degrees Celsius.  Once the over-temperature fault has been corrected (ie, the IC has cooled down), the output channels will be re-enabled with the same settings as before the thermal shutdown. An error message will be produced during an over-temperature.&lt;br /&gt;
&lt;br /&gt;
==Products that fall under this category==&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED-64 Advanced]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3601 3601 - 10mm Red LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3602 3602 - 10mm Green LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3603 3603 - 10mm Blue LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3604 3604 - 10mm Yellow LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3605 3605 - 10mm White LED (Bag of 20)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3606 3606 - 5mm Four Chip Super Flux Red (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3607 3607 - 5mm Four Chip Super Flux Green (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3608 3608 - 5mm Four Chip Super Flux Blue (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3609 3609 - 5mm Four Chip Super Flux Yellow (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3610 3610 - 5mm Four Chip Super Flux White (Bag of 5)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3611 3611 - 5mm Diffused Red (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3612 3612 - 5mm Diffused Yellow/Green (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3613 - 5mm Diffused Blue (Bag of 30)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3614 3614 - Flexible LED Strip Green (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3615 3615 - Flexible LED Strip Blue (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3616 3616 - Flexible LED Strip White (5m)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3618 3618 - RGB LED Modules - String of 10]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20683</id>
		<title>LED Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20683"/>
		<updated>2012-06-29T18:53:09Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Forward Voltage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:RBG.jpg|500px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Like normal diodes, Light Emitting Diodes (LEDs) are semiconductor devices designed to conduct current in one direction only.  What makes LEDs unique is their internal material makeup:  when atoms in an LED release energy due to the flow of forward current, it is released in the form of photons (light).  Different construction materials and various phosphor coatings are used to produce numerous colors of light.&lt;br /&gt;
&lt;br /&gt;
LEDs that Phidgets sells are all operable via the [[Digital Output Primer|digital outputs]] on any of our interface kits.  However Phidgets also sells a specific [{{SERVER}}/products.php?product_id=1031 PhidgetLED-64 Advanced LED controller] since it is often desirable to control more LEDs than even the [{{SERVER}}/products.php?product_id=1012 1012 Phidget Interface Kit 0/16/16] can operate.  It offers some unique features such as brightness control.&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
[[image:led.png|thumb|350px|Parts of an LED.  The flat spot on the epoxy casing, is an anchor to prevent twisting from damaging the leads.]]&lt;br /&gt;
&lt;br /&gt;
LEDs emit light from current flowing through them.  As the current flows, the electronics experience a sudden drop in energy level (voltage).  When that happens they release energy in the form of light.  The amount of light produced is proportional to the current.  Depending on the material used to make the LED, different colors can be created.  Like a conventional diode, the current can only flow in one direction - from the anode to the cathode.&lt;br /&gt;
&lt;br /&gt;
==Controlling LEDs==&lt;br /&gt;
&lt;br /&gt;
===Forward Voltage===&lt;br /&gt;
&lt;br /&gt;
The materials used within LEDs that cause them to emit different colors of light affect a property called its forward voltage. The forward voltage is the voltage at which current in the forward direction will flow through the device and allow the LED to convert electrical energy into light.  If the voltage applied to the LED is below the forward voltage of the LED, very little current (or none) may flow, and therefore very little light will be emitted. Most standard LEDs with colors such as red, amber, orange, yellow, and green have forward voltages below 2.75 Volts, and can be used with a [[Digital Output Primer|digital output]] by simply soldering them to a connector-wire and inserting the wire into the output port. The forward voltage in the [{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED|PhidgetLED] will default to 2.75V, and the maximum current defaults to 20mA.&lt;br /&gt;
&lt;br /&gt;
===Supply Voltage===&lt;br /&gt;
{|&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|To be an effective LED controller your digital outputs must be capable of &amp;lt;br /&amp;gt;adjusting the forward voltage supplied to the LEDs to 1.7, 2.75, 3.9 and 5 volts&amp;lt;br /&amp;gt; settings allowing you to properly drive blue, white, violet, ultra violet and purple LEDs.&amp;lt;br /&amp;gt; The supply voltage will affect all LEDs. If you set the supplied voltage too high,&amp;lt;br /&amp;gt; power will be wasted and the controller may shut down from thermal overload. If you&amp;lt;br /&amp;gt; set the supply voltage too low, your LEDs will not be driven at the requested&amp;lt;br /&amp;gt; current, and will be dim or non-functional.&lt;br /&gt;
|&lt;br /&gt;
{| {{table}} border = 1&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|Typical Forward Voltages&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Color&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Forward Voltage&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Infrared||&amp;lt; 1.9&lt;br /&gt;
|-&lt;br /&gt;
| Red||1.7 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Orange||2.0 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Yellow||2.1 to 2.4&lt;br /&gt;
|-&lt;br /&gt;
| Green||2 to 2.3&lt;br /&gt;
|-&lt;br /&gt;
| Blue||3.2 to 4.0&lt;br /&gt;
|-&lt;br /&gt;
| Ultraviolet||2.1 to 3.8&lt;br /&gt;
|-&lt;br /&gt;
| White||3.3 to 3.6&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Maximum Current and Brightness Control===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
Most LEDs fall within 20, 40, 60 or 80mA, and applies to all LEDs. The &amp;lt;br /&amp;gt;Phidgets DiscreteLED API call can be used to provide more current &amp;lt;br /&amp;gt;or control brightness and will adjust the current linearly between 0 &amp;lt;br /&amp;gt;and the set maximum. This however does not imply a precise method &amp;lt;br /&amp;gt;for controlling the visibility of emitted light, as this is affected by the &amp;lt;br /&amp;gt;construction and quality of the LED as well as the eyes of the viewer. &amp;lt;br /&amp;gt;Be cautious when changing the current property. Many small LEDs are &amp;lt;br /&amp;gt;designed for a maximum 20mA, and can be destroyed if driven at higher &amp;lt;br /&amp;gt;currents.&lt;br /&gt;
|&lt;br /&gt;
[[image:Ledcurrent.png|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Choosing Current and Voltage Settings===&lt;br /&gt;
&lt;br /&gt;
Make sure to choose the minimum supply voltage setting to drive the LED that requires the most voltage during operation. Any extra voltage not required by the LED will be converted to heat by the 1031. For example, a Blue LED being driven at 20mA, 3.9V Supply, that requires 3.7 volts will cause (3.9V-3.7V + 0.4V) * 0.02A = 12 milliwatts of heat to be produced on the 1031. If this example instead uses a high power, 1.5V infrared LED at 80mA, this will create (3.9V-1.5V+0.4V)*0.08 Amps = 224 milliwatts of heat. See the Heat Dissipation and Thermal Protection section later on in this manual for more information about this issue.&lt;br /&gt;
&lt;br /&gt;
==Multiplexed LEDs==&lt;br /&gt;
Multiplexing is a system wherein the entire display is not active at the same time.  Instead, sub-units of the display are driven one at a time and the electronics combine with human persistence of vision (the phenomenon of the eye by which an afterimage is thought to persist for approximately one twenty-fifth of a second on the retina) to make the viewer believe the entire display is continuously active.  Many controllers use this architecture to reduce power consumption.  7 segment display clocks are an example of this.&lt;br /&gt;
&lt;br /&gt;
In an effort to reduce electrical noise in the system the PhidgetLED does not use multiplexing. All 64 anodes are connected to the same power supply and the cathode of each LED connection is attached to an individual constant current sink. Also, the LEDs are not controlled by PWM - they are driven at a constant current.&lt;br /&gt;
&lt;br /&gt;
==Other uses for LED controllers==&lt;br /&gt;
&lt;br /&gt;
LED controllers are typically just a set of special digital outputs.  This means they aren&#039;t limited to just controlling LEDs. They can be used to control relays, solenoids and even very small motors. The PhidgetLED can also be used to drive opto-isolators and MOSFET SSRs. A diode integrated into the 1031 on each cathode will clamp inductive surges to the anode supply voltage.&lt;br /&gt;
&lt;br /&gt;
==Power Requirements and Power Supply Selection==&lt;br /&gt;
&lt;br /&gt;
The power supply that is included with the 1031 is rated at 12V and 2A (max).  If your application requires more power, a larger power supply may be necessary.  The on-board voltage regulator is able to supply up to 6A for each LED supply voltage setting, as long as the power supply is able to provide enough voltage and current to the regulator. Assume an efficiency of 80% for the on-board voltage regulator when determining if a different power supply is required.&lt;br /&gt;
&lt;br /&gt;
==Heat Dissipation and Thermal Protection==&lt;br /&gt;
&lt;br /&gt;
Projects that require a high supply voltage, or have a lot of heat being produced from over voltage settings, will have over-temperature problems.  This can be mitigated somewhat by understanding how channels are grouped and how the heat is distributed around the controller.  On the 1031 channels are split into four groups: (0-7,24-31), (8-23), (32-39, 56-63) and (40-55); each controlled by their own individual IC. Evenly distributing the LEDs that may produce a lot of heat across these groups will balance the load on the ICs and reduce the risk of thermal overload. When thermal overload occurs, the integrated circuit (IC) controlling the involved LEDs will disable the output of all the channels it controls.  For example, if an over-temperature occurs due to channel 12, all of the channels 8 through 23 will be disabled by the IC until the temperature back within the operating range.  Thermal protection is activated when the die of the IC reaches approximately 160 degrees Celsius.  Once the over-temperature fault has been corrected (ie, the IC has cooled down), the output channels will be re-enabled with the same settings as before the thermal shutdown. An error message will be produced during an over-temperature.&lt;br /&gt;
&lt;br /&gt;
==Products that fall under this category==&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED-64 Advanced]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3601 3601 - 10mm Red LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3602 3602 - 10mm Green LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3603 3603 - 10mm Blue LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3604 3604 - 10mm Yellow LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3605 3605 - 10mm White LED (Bag of 20)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3606 3606 - 5mm Four Chip Super Flux Red (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3607 3607 - 5mm Four Chip Super Flux Green (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3608 3608 - 5mm Four Chip Super Flux Blue (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3609 3609 - 5mm Four Chip Super Flux Yellow (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3610 3610 - 5mm Four Chip Super Flux White (Bag of 5)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3611 3611 - 5mm Diffused Red (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3612 3612 - 5mm Diffused Yellow/Green (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3613 - 5mm Diffused Blue (Bag of 30)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3614 3614 - Flexible LED Strip Green (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3615 3615 - Flexible LED Strip Blue (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3616 3616 - Flexible LED Strip White (5m)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3618 3618 - RGB LED Modules - String of 10]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20682</id>
		<title>LED Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20682"/>
		<updated>2012-06-29T18:52:48Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:RBG.jpg|500px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Like normal diodes, Light Emitting Diodes (LEDs) are semiconductor devices designed to conduct current in one direction only.  What makes LEDs unique is their internal material makeup:  when atoms in an LED release energy due to the flow of forward current, it is released in the form of photons (light).  Different construction materials and various phosphor coatings are used to produce numerous colors of light.&lt;br /&gt;
&lt;br /&gt;
LEDs that Phidgets sells are all operable via the [[Digital Output Primer|digital outputs]] on any of our interface kits.  However Phidgets also sells a specific [{{SERVER}}/products.php?product_id=1031 PhidgetLED-64 Advanced LED controller] since it is often desirable to control more LEDs than even the [{{SERVER}}/products.php?product_id=1012 1012 Phidget Interface Kit 0/16/16] can operate.  It offers some unique features such as brightness control.&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
[[image:led.png|thumb|350px|Parts of an LED.  The flat spot on the epoxy casing, is an anchor to prevent twisting from damaging the leads.]]&lt;br /&gt;
&lt;br /&gt;
LEDs emit light from current flowing through them.  As the current flows, the electronics experience a sudden drop in energy level (voltage).  When that happens they release energy in the form of light.  The amount of light produced is proportional to the current.  Depending on the material used to make the LED, different colors can be created.  Like a conventional diode, the current can only flow in one direction - from the anode to the cathode.&lt;br /&gt;
&lt;br /&gt;
==Controlling LEDs==&lt;br /&gt;
&lt;br /&gt;
===Forward Voltage===&lt;br /&gt;
&lt;br /&gt;
The materials used within LEDs that cause them to emit different colors of light affect a property called its forward voltage. The forward voltage is the voltage at which current in the forward direction will flow through the device and allow the LED to convert electrical energy into light.  If the voltage applied to the LED is below the forward voltage of the LED, very little current (or none) may flow, and therefore very little light will be emitted. Most standard LEDs with colors such as red, amber, orange, yellow, and green have forward voltages below 2.75 Volts, and can be used with a [[Digital Output Primer|digital output]] by simply soldering them to a connector-wire and inserting the wire into the output port. The forward voltage in the [{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED|PhidgetLED]] will default to 2.75V, and the maximum current defaults to 20mA.&lt;br /&gt;
&lt;br /&gt;
===Supply Voltage===&lt;br /&gt;
{|&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|To be an effective LED controller your digital outputs must be capable of &amp;lt;br /&amp;gt;adjusting the forward voltage supplied to the LEDs to 1.7, 2.75, 3.9 and 5 volts&amp;lt;br /&amp;gt; settings allowing you to properly drive blue, white, violet, ultra violet and purple LEDs.&amp;lt;br /&amp;gt; The supply voltage will affect all LEDs. If you set the supplied voltage too high,&amp;lt;br /&amp;gt; power will be wasted and the controller may shut down from thermal overload. If you&amp;lt;br /&amp;gt; set the supply voltage too low, your LEDs will not be driven at the requested&amp;lt;br /&amp;gt; current, and will be dim or non-functional.&lt;br /&gt;
|&lt;br /&gt;
{| {{table}} border = 1&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|Typical Forward Voltages&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Color&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Forward Voltage&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Infrared||&amp;lt; 1.9&lt;br /&gt;
|-&lt;br /&gt;
| Red||1.7 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Orange||2.0 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Yellow||2.1 to 2.4&lt;br /&gt;
|-&lt;br /&gt;
| Green||2 to 2.3&lt;br /&gt;
|-&lt;br /&gt;
| Blue||3.2 to 4.0&lt;br /&gt;
|-&lt;br /&gt;
| Ultraviolet||2.1 to 3.8&lt;br /&gt;
|-&lt;br /&gt;
| White||3.3 to 3.6&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Maximum Current and Brightness Control===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
Most LEDs fall within 20, 40, 60 or 80mA, and applies to all LEDs. The &amp;lt;br /&amp;gt;Phidgets DiscreteLED API call can be used to provide more current &amp;lt;br /&amp;gt;or control brightness and will adjust the current linearly between 0 &amp;lt;br /&amp;gt;and the set maximum. This however does not imply a precise method &amp;lt;br /&amp;gt;for controlling the visibility of emitted light, as this is affected by the &amp;lt;br /&amp;gt;construction and quality of the LED as well as the eyes of the viewer. &amp;lt;br /&amp;gt;Be cautious when changing the current property. Many small LEDs are &amp;lt;br /&amp;gt;designed for a maximum 20mA, and can be destroyed if driven at higher &amp;lt;br /&amp;gt;currents.&lt;br /&gt;
|&lt;br /&gt;
[[image:Ledcurrent.png|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Choosing Current and Voltage Settings===&lt;br /&gt;
&lt;br /&gt;
Make sure to choose the minimum supply voltage setting to drive the LED that requires the most voltage during operation. Any extra voltage not required by the LED will be converted to heat by the 1031. For example, a Blue LED being driven at 20mA, 3.9V Supply, that requires 3.7 volts will cause (3.9V-3.7V + 0.4V) * 0.02A = 12 milliwatts of heat to be produced on the 1031. If this example instead uses a high power, 1.5V infrared LED at 80mA, this will create (3.9V-1.5V+0.4V)*0.08 Amps = 224 milliwatts of heat. See the Heat Dissipation and Thermal Protection section later on in this manual for more information about this issue.&lt;br /&gt;
&lt;br /&gt;
==Multiplexed LEDs==&lt;br /&gt;
Multiplexing is a system wherein the entire display is not active at the same time.  Instead, sub-units of the display are driven one at a time and the electronics combine with human persistence of vision (the phenomenon of the eye by which an afterimage is thought to persist for approximately one twenty-fifth of a second on the retina) to make the viewer believe the entire display is continuously active.  Many controllers use this architecture to reduce power consumption.  7 segment display clocks are an example of this.&lt;br /&gt;
&lt;br /&gt;
In an effort to reduce electrical noise in the system the PhidgetLED does not use multiplexing. All 64 anodes are connected to the same power supply and the cathode of each LED connection is attached to an individual constant current sink. Also, the LEDs are not controlled by PWM - they are driven at a constant current.&lt;br /&gt;
&lt;br /&gt;
==Other uses for LED controllers==&lt;br /&gt;
&lt;br /&gt;
LED controllers are typically just a set of special digital outputs.  This means they aren&#039;t limited to just controlling LEDs. They can be used to control relays, solenoids and even very small motors. The PhidgetLED can also be used to drive opto-isolators and MOSFET SSRs. A diode integrated into the 1031 on each cathode will clamp inductive surges to the anode supply voltage.&lt;br /&gt;
&lt;br /&gt;
==Power Requirements and Power Supply Selection==&lt;br /&gt;
&lt;br /&gt;
The power supply that is included with the 1031 is rated at 12V and 2A (max).  If your application requires more power, a larger power supply may be necessary.  The on-board voltage regulator is able to supply up to 6A for each LED supply voltage setting, as long as the power supply is able to provide enough voltage and current to the regulator. Assume an efficiency of 80% for the on-board voltage regulator when determining if a different power supply is required.&lt;br /&gt;
&lt;br /&gt;
==Heat Dissipation and Thermal Protection==&lt;br /&gt;
&lt;br /&gt;
Projects that require a high supply voltage, or have a lot of heat being produced from over voltage settings, will have over-temperature problems.  This can be mitigated somewhat by understanding how channels are grouped and how the heat is distributed around the controller.  On the 1031 channels are split into four groups: (0-7,24-31), (8-23), (32-39, 56-63) and (40-55); each controlled by their own individual IC. Evenly distributing the LEDs that may produce a lot of heat across these groups will balance the load on the ICs and reduce the risk of thermal overload. When thermal overload occurs, the integrated circuit (IC) controlling the involved LEDs will disable the output of all the channels it controls.  For example, if an over-temperature occurs due to channel 12, all of the channels 8 through 23 will be disabled by the IC until the temperature back within the operating range.  Thermal protection is activated when the die of the IC reaches approximately 160 degrees Celsius.  Once the over-temperature fault has been corrected (ie, the IC has cooled down), the output channels will be re-enabled with the same settings as before the thermal shutdown. An error message will be produced during an over-temperature.&lt;br /&gt;
&lt;br /&gt;
==Products that fall under this category==&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED-64 Advanced]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3601 3601 - 10mm Red LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3602 3602 - 10mm Green LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3603 3603 - 10mm Blue LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3604 3604 - 10mm Yellow LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3605 3605 - 10mm White LED (Bag of 20)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3606 3606 - 5mm Four Chip Super Flux Red (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3607 3607 - 5mm Four Chip Super Flux Green (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3608 3608 - 5mm Four Chip Super Flux Blue (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3609 3609 - 5mm Four Chip Super Flux Yellow (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3610 3610 - 5mm Four Chip Super Flux White (Bag of 5)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3611 3611 - 5mm Diffused Red (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3612 3612 - 5mm Diffused Yellow/Green (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3613 - 5mm Diffused Blue (Bag of 30)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3614 3614 - Flexible LED Strip Green (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3615 3615 - Flexible LED Strip Blue (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3616 3616 - Flexible LED Strip White (5m)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3618 3618 - RGB LED Modules - String of 10]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20681</id>
		<title>LED Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=LED_Guide&amp;diff=20681"/>
		<updated>2012-06-29T18:52:08Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center width=300px| __TOC__ &lt;br /&gt;
| [[Image:RBG.jpg|500px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Like normal diodes, Light Emitting Diodes (LEDs) are semiconductor devices designed to conduct current in one direction only.  What makes LEDs unique is their internal material makeup:  when atoms in an LED release energy due to the flow of forward current, it is released in the form of photons (light).  Different construction materials and various phosphor coatings are used to produce numerous colors of light.&lt;br /&gt;
&lt;br /&gt;
LEDs that Phidgets sells are all operable via the [[Digital Output Primer|digital outputs]] on any of our interface kits.  However Phidgets also sells a specific [{{SERVER}}/products.php?product_id=1031 PhidgetLED-64 Advanced LED controller] since it is often desirable to control more LEDs than even the [{{SERVER}}/products.php?product_id=1012 1012 Phidget Interface Kit 0/16/16] can operate.  It offers some unique features such as brightness control.&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
[[image:led.png|thumb|350px|Parts of an LED.  The flat spot on the epoxy casing, is an anchor to prevent twisting from damaging the leads.]]&lt;br /&gt;
&lt;br /&gt;
LEDs emit light from current flowing through them.  As the current flows, the electronics experience a sudden drop in energy level (voltage).  When that happens they release energy in the form of light.  The amount of light produced is proportional to the current.  Depending on the material used to make the LED, different colors can be created.  Like a conventional diode, the current can only flow in one direction - from the anode to the cathode.&lt;br /&gt;
&lt;br /&gt;
==Controlling LEDs==&lt;br /&gt;
&lt;br /&gt;
===Forward Voltage===&lt;br /&gt;
&lt;br /&gt;
The materials used within LEDs that cause them to emit different colors of light affect a property called its forward voltage. The forward voltage is the voltage at which current in the forward direction will flow through the device and allow the LED to convert electrical energy into light.  If the voltage applied to the LED is below the forward voltage of the LED, very little current (or none) may flow, and therefore very little light will be emitted. Most standard LEDs with colors such as red, amber, orange, yellow, and green have forward voltages below 2.75 Volts, and can be used with a [[Digital Output Primer|digital output]] by simply soldering them to a connector-wire and inserting the wire into the output port. The forward voltage in the [[1031 - PhidgetLED|PhidgetLED]] will default to 2.75V, and the maximum current defaults to 20mA.&lt;br /&gt;
&lt;br /&gt;
===Supply Voltage===&lt;br /&gt;
{|&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|To be an effective LED controller your digital outputs must be capable of &amp;lt;br /&amp;gt;adjusting the forward voltage supplied to the LEDs to 1.7, 2.75, 3.9 and 5 volts&amp;lt;br /&amp;gt; settings allowing you to properly drive blue, white, violet, ultra violet and purple LEDs.&amp;lt;br /&amp;gt; The supply voltage will affect all LEDs. If you set the supplied voltage too high,&amp;lt;br /&amp;gt; power will be wasted and the controller may shut down from thermal overload. If you&amp;lt;br /&amp;gt; set the supply voltage too low, your LEDs will not be driven at the requested&amp;lt;br /&amp;gt; current, and will be dim or non-functional.&lt;br /&gt;
|&lt;br /&gt;
{| {{table}} border = 1&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|Typical Forward Voltages&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Color&#039;&#039;&#039;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; style=&amp;quot;background:#f0f0f0;&amp;quot;|&#039;&#039;&#039;Forward Voltage&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Infrared||&amp;lt; 1.9&lt;br /&gt;
|-&lt;br /&gt;
| Red||1.7 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Orange||2.0 to 2.2&lt;br /&gt;
|-&lt;br /&gt;
| Yellow||2.1 to 2.4&lt;br /&gt;
|-&lt;br /&gt;
| Green||2 to 2.3&lt;br /&gt;
|-&lt;br /&gt;
| Blue||3.2 to 4.0&lt;br /&gt;
|-&lt;br /&gt;
| Ultraviolet||2.1 to 3.8&lt;br /&gt;
|-&lt;br /&gt;
| White||3.3 to 3.6&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Maximum Current and Brightness Control===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
Most LEDs fall within 20, 40, 60 or 80mA, and applies to all LEDs. The &amp;lt;br /&amp;gt;Phidgets DiscreteLED API call can be used to provide more current &amp;lt;br /&amp;gt;or control brightness and will adjust the current linearly between 0 &amp;lt;br /&amp;gt;and the set maximum. This however does not imply a precise method &amp;lt;br /&amp;gt;for controlling the visibility of emitted light, as this is affected by the &amp;lt;br /&amp;gt;construction and quality of the LED as well as the eyes of the viewer. &amp;lt;br /&amp;gt;Be cautious when changing the current property. Many small LEDs are &amp;lt;br /&amp;gt;designed for a maximum 20mA, and can be destroyed if driven at higher &amp;lt;br /&amp;gt;currents.&lt;br /&gt;
|&lt;br /&gt;
[[image:Ledcurrent.png|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Choosing Current and Voltage Settings===&lt;br /&gt;
&lt;br /&gt;
Make sure to choose the minimum supply voltage setting to drive the LED that requires the most voltage during operation. Any extra voltage not required by the LED will be converted to heat by the 1031. For example, a Blue LED being driven at 20mA, 3.9V Supply, that requires 3.7 volts will cause (3.9V-3.7V + 0.4V) * 0.02A = 12 milliwatts of heat to be produced on the 1031. If this example instead uses a high power, 1.5V infrared LED at 80mA, this will create (3.9V-1.5V+0.4V)*0.08 Amps = 224 milliwatts of heat. See the Heat Dissipation and Thermal Protection section later on in this manual for more information about this issue.&lt;br /&gt;
&lt;br /&gt;
==Multiplexed LEDs==&lt;br /&gt;
Multiplexing is a system wherein the entire display is not active at the same time.  Instead, sub-units of the display are driven one at a time and the electronics combine with human persistence of vision (the phenomenon of the eye by which an afterimage is thought to persist for approximately one twenty-fifth of a second on the retina) to make the viewer believe the entire display is continuously active.  Many controllers use this architecture to reduce power consumption.  7 segment display clocks are an example of this.&lt;br /&gt;
&lt;br /&gt;
In an effort to reduce electrical noise in the system the PhidgetLED does not use multiplexing. All 64 anodes are connected to the same power supply and the cathode of each LED connection is attached to an individual constant current sink. Also, the LEDs are not controlled by PWM - they are driven at a constant current.&lt;br /&gt;
&lt;br /&gt;
==Other uses for LED controllers==&lt;br /&gt;
&lt;br /&gt;
LED controllers are typically just a set of special digital outputs.  This means they aren&#039;t limited to just controlling LEDs. They can be used to control relays, solenoids and even very small motors. The PhidgetLED can also be used to drive opto-isolators and MOSFET SSRs. A diode integrated into the 1031 on each cathode will clamp inductive surges to the anode supply voltage.&lt;br /&gt;
&lt;br /&gt;
==Power Requirements and Power Supply Selection==&lt;br /&gt;
&lt;br /&gt;
The power supply that is included with the 1031 is rated at 12V and 2A (max).  If your application requires more power, a larger power supply may be necessary.  The on-board voltage regulator is able to supply up to 6A for each LED supply voltage setting, as long as the power supply is able to provide enough voltage and current to the regulator. Assume an efficiency of 80% for the on-board voltage regulator when determining if a different power supply is required.&lt;br /&gt;
&lt;br /&gt;
==Heat Dissipation and Thermal Protection==&lt;br /&gt;
&lt;br /&gt;
Projects that require a high supply voltage, or have a lot of heat being produced from over voltage settings, will have over-temperature problems.  This can be mitigated somewhat by understanding how channels are grouped and how the heat is distributed around the controller.  On the 1031 channels are split into four groups: (0-7,24-31), (8-23), (32-39, 56-63) and (40-55); each controlled by their own individual IC. Evenly distributing the LEDs that may produce a lot of heat across these groups will balance the load on the ICs and reduce the risk of thermal overload. When thermal overload occurs, the integrated circuit (IC) controlling the involved LEDs will disable the output of all the channels it controls.  For example, if an over-temperature occurs due to channel 12, all of the channels 8 through 23 will be disabled by the IC until the temperature back within the operating range.  Thermal protection is activated when the die of the IC reaches approximately 160 degrees Celsius.  Once the over-temperature fault has been corrected (ie, the IC has cooled down), the output channels will be re-enabled with the same settings as before the thermal shutdown. An error message will be produced during an over-temperature.&lt;br /&gt;
&lt;br /&gt;
==Products that fall under this category==&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=1031 1031 - PhidgetLED-64 Advanced]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3601 3601 - 10mm Red LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3602 3602 - 10mm Green LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3603 3603 - 10mm Blue LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3604 3604 - 10mm Yellow LED (Bag of 20)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3605 3605 - 10mm White LED (Bag of 20)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3606 3606 - 5mm Four Chip Super Flux Red (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3607 3607 - 5mm Four Chip Super Flux Green (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3608 3608 - 5mm Four Chip Super Flux Blue (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3609 3609 - 5mm Four Chip Super Flux Yellow (Bag of 5)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3610 3610 - 5mm Four Chip Super Flux White (Bag of 5)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3611 3611 - 5mm Diffused Red (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3612 3612 - 5mm Diffused Yellow/Green (Bag of 30)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3613 - 5mm Diffused Blue (Bag of 30)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3614 3614 - Flexible LED Strip Green (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3615 3615 - Flexible LED Strip Blue (5m)]&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3616 3616 - Flexible LED Strip White (5m)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/products.php?product_id=3618 3618 - RGB LED Modules - String of 10]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20674</id>
		<title>General Phidget Programming</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20674"/>
		<updated>2012-06-29T17:49:31Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Creating a Software Object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Overview]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page presents the general &#039;&#039;&#039;concepts&#039;&#039;&#039; needed to write code for a Phidget.&lt;br /&gt;
&lt;br /&gt;
By this point, you should have installed the drivers for your [[Software Overview#Operating System Support|operating system]] and the libraries for your [[Software Overview#Language Support|specific programming language]].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Basic Functions==&lt;br /&gt;
&lt;br /&gt;
To use your Phidget within code, you&#039;ll want to:&lt;br /&gt;
# Create a Phidget [[#Creating a Software Object|software &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], which gives you access to the functions specific to that device&lt;br /&gt;
# [[#Opening the Phidget|Open the Phidget]] using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Detect when a [[#Attaching the Phidget|Phidget is attached]] (plugged in) by using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Use [[#Do Things with the Phidget|functions that the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt; provides]], like turning on LEDs, reading sensors, triggering events on data change, etc&lt;br /&gt;
# [[#Close the Phidget|Close the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], when you are done&lt;br /&gt;
&lt;br /&gt;
Small code snippets are provided for each step below.  [[Language - C/C++|C++]] and [[Language - Java|Java]] were selected because Java is a relatively high-level language and C++ is a relatively low level language, thereby showing how specific each language API really is.  So, the most useful resource for the &#039;&#039;actual functions&#039;&#039; would be the API for [[Software Overview#Language Support | your specific language]].  This page is a high-level introduction, by design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Software Object ===&lt;br /&gt;
&lt;br /&gt;
Phidget devices are controlled using software objects.  All software device objects have a common API and set of functions that allow you to &#039;&#039;&#039;open&#039;&#039;&#039; it, &#039;&#039;&#039;close&#039;&#039;&#039; it, and set a few listeners to general events such as &#039;&#039;&#039;attach&#039;&#039;&#039; (plug in), &#039;&#039;&#039;detach&#039;&#039;&#039; (unplug), and errors.  &lt;br /&gt;
&lt;br /&gt;
But when you create an actual software object, it is a software object &#039;&#039;&#039;specific&#039;&#039;&#039; to your device.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 AccelerometerPhidget device = new AccelerometerPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 CPhidgetAccelerometerHandle device = 0;&lt;br /&gt;
 CPhidgetAccelerometer_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 CPhidgetRFIDHandle device = 0;&lt;br /&gt;
 CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each software object has an API and available functions which are specific to that device.  For example, the RFID device API includes a function to turn on the RFID antenna.  The accelerometer device API includes a function to set the sensitivity on each axis.  Other APIs control all of our other Phidgets (i.e. those boards with a USB port), with applicable functions.&lt;br /&gt;
&lt;br /&gt;
=== Opening the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Phidgets can either be opened when attached directly to a computer, or they can be opened remotely using the [[Phidget WebService]].  This section deals primarily with opening Phidgets directly.&lt;br /&gt;
&lt;br /&gt;
Once you have created your [[#Creating a Software Object|software object]] for your specific type of device, you can call the &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in your language on that object.  For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, -1);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All specific language calls can be found in the API documentation located on each [[Software Overview#Language Support|individual language page]].&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in any language opens the software object for use, not the hardware itself.  Having the software &amp;quot;open&amp;quot; before the hardware means that the software can capture all events, including multiple attach (plug in) and detach (unplug) events for one &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; call.&lt;br /&gt;
&lt;br /&gt;
====Details for Open()====&lt;br /&gt;
&lt;br /&gt;
Open will return immediately once called, because it can be called even if the Phidget to be used is not attached to the system. This is known as an asynchronous call. It’s important to understand that most calls on a Phidget will fail if they are calls when the Phidget is not attached - in fact the only calls that are allowed on a detached Phidget are &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;waitForAttachment()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getAttached()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Open is also pervasive. This means that once open has been called, it will constantly try to stay attached to a Phidget. Even if the Phidget is unplugged from the computer and then plugged back in, you will simply get a Detach event, and then an Attach event. It’s a good idea to handle the Detach event in order to avoid calling the Phidget after it has detached.&lt;br /&gt;
&lt;br /&gt;
The different types of open(), such as openAny(), openRemote(), etc. can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network.  The list all of the available modes that open provides, and the syntax for your language, can be found in the API for [[Software Overview#Language Support|your specific language]].  If there are more than one of the same type of Phidget attached to a computer, and you use open() with no serial number, there is no way of knowing which Phidget will be opened first.&lt;br /&gt;
&lt;br /&gt;
If you are looking to do a remote open call, to use the [[Phidget WebService]], you usually have to change only the open() call (to a remote open call) to change your program from a locally-running one to one that can control a Phidget over the network.  We give an in-depth example of using the WebService on each of our [[Software Overview#Operating System Support|operating system pages]], we have a brief overview of the WebService (with code snippets) in the [[#Using Phidgets over a Network|Using Phidgets over a Network]] section, and we often have WebService code snippets on the [[Software Overview#Language Support|language pages]] which do not easily extend from the examples on this page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Once a Phidget is opened by an application, it cannot be opened again in another application until closed by the first.  When open and attached in software, no other programs or instances can read data from or change the Phidget. This includes it being open via the Windows Control Panel application!  The one exception is if the Phidget is controlled &#039;&#039;only&#039;&#039; over the network with the [[Phidget WebService]], and not directly.  Then, you can use multiple remote control programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attaching the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Physically, attaching a Phidget means plugging it in.  The real guts behind the &#039;attach&#039; command, however, occur within the software libraries.  The &#039;attach&#039; call is what makes the final connections between the opened software object and the corresponding thread and events.  This is why all Phidget object must be attached in software, even those that are not actually plugged in with a cable.  This includes Phidgets used remotely via our [[Phidget WebService]], it includes Interface Kits on the same board as our Single Board Computer, and it even includes the [[Phidget Manager]] software object, which is a sort of meta-Phidget from which you can [[#Using the Manager|control other Phidgets]].&lt;br /&gt;
&lt;br /&gt;
In your code, you can detect an attachment either with an &#039;&#039;&#039;event&#039;&#039;&#039; in [[#Event Driven Code|event-driven programming]], or &#039;&#039;&#039;waiting&#039;&#039;&#039; for it, in [[#Logic Code|logic programming]].  &lt;br /&gt;
&lt;br /&gt;
==== Event Attachment ====&lt;br /&gt;
&lt;br /&gt;
For example, to use an event to detect attachment in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addAttachListener(new AttachListener() {&lt;br /&gt;
      public void attached(AttachEvent ae) {&lt;br /&gt;
          System.out.println(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
          // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
  int AttachHandler (CPhidgetHandle device, void *userData) {&lt;br /&gt;
      printf(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
      // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnAttach_Handler((CPhidgetHandle) device, AttachHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both of the code snippets above do the same thing.  The function &amp;lt;code&amp;gt;AttachHandler(...)&amp;lt;/code&amp;gt; is called automatically when a device is plugged in.&lt;br /&gt;
&lt;br /&gt;
You will want to attach events (via &amp;lt;code&amp;gt;addAttachListener()&amp;lt;/code&amp;gt; above, for example) &#039;&#039;&#039;before you open the Phidget object&#039;&#039;&#039;.  Otherwise, triggered events may be lost.&lt;br /&gt;
&lt;br /&gt;
This method for using events to detect attachment can be expanded to other events and more complex control flow.  Where possible, all example code downloads from the [[Software Overview#Language Support|specific language pages]] shows event-driven programming.&lt;br /&gt;
&lt;br /&gt;
==== Wait for Attachment ====&lt;br /&gt;
&lt;br /&gt;
Waiting for attachment is a straightforward process.  Your code does not handle events, it simply waits for a device to be plugged in before moving on and doing something else.&lt;br /&gt;
&lt;br /&gt;
For example, in Java you wait for attachment on a &#039;&#039;&#039;created and open&#039;&#039;&#039; software object (called device) like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 // Wait until a device is plugged in&lt;br /&gt;
 device.waitForAttachment();&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C (again, device has been &#039;&#039;&#039;created and opened&#039;&#039;&#039;) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 int result;&lt;br /&gt;
 // Wait up to 10000 ms for a device to be plugged in&lt;br /&gt;
 if((result = CPhidget_waitForAttachment((CPhidgetHandle) device, 10000))) {&lt;br /&gt;
     // No attachment, error&lt;br /&gt;
 }&lt;br /&gt;
 // Successful attachment&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, unlike the event model above, a Phidget software object should be open before waiting for a device to be plugged in.&lt;br /&gt;
&lt;br /&gt;
=== Do Things with the Phidget ===&lt;br /&gt;
&lt;br /&gt;
After you have a [[#Creating a Software Object|properly created]] Phidget software object, you can actually call function to turn LEDs on, change output state, read data from sensors, etc.&lt;br /&gt;
&lt;br /&gt;
The thing you probably want to do with your Phidget is read data from its sensors or inputs.  This might be, say, a sensor plugged in to a [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] used in the code snippets below.  You can do this either by detecting changes via [[#Event Driven Code|event driven code]], or polling for new values via [[#Logic Code|logic code]]. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Details about data handling:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*When a Phidget is opened, its initial state will be read before it is marked as attached. This allows polling of many properties -- including some data -- even during the Attach event, and anytime afterwards.&lt;br /&gt;
&lt;br /&gt;
*Your computer can poll much faster than the Phidget can respond.  If you poll in a continuous &#039;&#039;&#039;&amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt;&#039;&#039;&#039; loop in byte code, you will probably swamp the Phidget with requests.&lt;br /&gt;
&lt;br /&gt;
*Similarly, if you set a value and then immediately read the value on the next line in your program, the Phidget may not have time to finish the set.  In our examples, we use &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements within loops.  Print functions are relatively slow; you can also use &amp;lt;code&amp;gt;wait()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;sleep()&amp;lt;/code&amp;gt; depending on your language.&lt;br /&gt;
&lt;br /&gt;
*If you are handling data using events as described below, the data event functions will fire when the device is plugged in and its initial state is read.&lt;br /&gt;
&lt;br /&gt;
*Some properties have default values, but these should not be trusted. Remember: &#039;&#039;&#039;always set&#039;&#039;&#039;, don’t rely on defaults.  Trying to read an uninitialized value with no default will result in an Exception.&lt;br /&gt;
&lt;br /&gt;
*Usually, sensor &#039;sensitivity&#039; will &#039;&#039;&#039;not&#039;&#039;&#039; be 0 (i.e. set to sense all changes) by default.  This can be good because it prevents your screen from being completely overloaded with event output.  But, depending on the sensor, it may make your sensor seem to have very high lag, and very poor sensitivity.  To capture all events, set the sensitivity to 0.&lt;br /&gt;
&lt;br /&gt;
*Often Phidgets will retain their last state unless power is lost. This can give surprising results as the previous state may not always be what you expect. For example, if you open an InterfaceKit and set an output, this output may stay set even after the Phidget is closed.&lt;br /&gt;
&lt;br /&gt;
====Capture Data Change with Events====&lt;br /&gt;
&lt;br /&gt;
To capture data changes in sensors or inputs as they happen, you need to use [[#Event Driven Code|event driven code]].&lt;br /&gt;
&lt;br /&gt;
Like defining an event function that fires [[#Event Attachment|when the Phidget is plugged in]], you can create functions that automatically run when, for example, a sensor value or input value changes.&lt;br /&gt;
&lt;br /&gt;
For example, for an Interface Kit, you can create a function that gets called when a sensor changes.  You would do this &#039;&#039;&#039;before&#039;&#039;&#039; the Phidget software object has been [[#Opening the Phidget|opened]].&lt;br /&gt;
&lt;br /&gt;
In Java, this would look like:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addSensorChangeListener(new SensorChangeListener() {&lt;br /&gt;
      public void sensorChanged(SensorChangeEvent sensorEvent) {&lt;br /&gt;
          System.out.println(&amp;quot;New Value: &amp;quot; + sensorEvent.getValue());&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int SensorChangeHandler (CPhidgetHandle device, void *userData, int boardIndex, int newValue) {&lt;br /&gt;
      printf(&amp;quot;New Value %d from sensor at location %d\n&amp;quot;, newValue, boardIndex);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnSensorChange_Handler((CPhidgetHandle) device, SensorChangeHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Poll for Data Change====&lt;br /&gt;
&lt;br /&gt;
To poll for sensor data, or output state, you usually want to look for a &#039;&#039;&#039;get...Value&#039;&#039;&#039; or &#039;&#039;&#039;get...State&#039;&#039;&#039; function available in the API for your device.  (The API can be found on the product page for your device on our [{{SERVER}} main web site].)  Then, you simply set up a loop that get the value of a sensor continuously.&lt;br /&gt;
&lt;br /&gt;
To poll your software object, the object must be [[#Opening the Phidget|open]].  This is in contrast to the event-driven method above, where all event functions are declared and attached before opening the object.&lt;br /&gt;
&lt;br /&gt;
Note that when you poll the value of a sensor or another attribute, this will probably be within a loop.  When you create this loop, the &#039;&#039;more code&#039;&#039; you have within a loop, the &#039;&#039;more slowly&#039;&#039; your loop will run, and the &#039;&#039;more slowly&#039;&#039; you will be sampling the value in practice.  This may make you lose data, as described further in the [[#Data Rate|Data Rate]] section.&lt;br /&gt;
&lt;br /&gt;
This effect is also felt with interpreted languages (Java, Python) versus purely compiled languages, as the interpreted languages sample more slowly even within an otherwise completely empty loop.&lt;br /&gt;
&lt;br /&gt;
So if you want to sample as fast as possible, and capture all of the changes that a sensor produces, you should [[#Capture Data Change with Events|capture data with event programming]].  If you choose not to use the event-driven design, you should keep the code run between polls to a minimum. This way you can sample as quickly as possible.&lt;br /&gt;
&lt;br /&gt;
These code snippets assume &amp;lt;code&amp;gt;device&amp;lt;/code&amp;gt; is an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit 8/8/8].  For example, in Java, for the Sensor at location 5 on the board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    val = device.getSensorValue(5);&lt;br /&gt;
    System.out.println(&amp;quot;Value: &amp;quot; + val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C, for the Sensor at location 5 on the Interface Kit board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;val);&lt;br /&gt;
    printf(&amp;quot;Value: %d\n&amp;quot;, val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sensors, Input, and Output====&lt;br /&gt;
&lt;br /&gt;
Often, your Phidget will be something like an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] which has either analog inputs (black plug holes), or digital inputs and outputs (green screw attachments), or often both.&lt;br /&gt;
&lt;br /&gt;
* To the analog inputs, you can attach various sensors, including sensors for temperature, humidity, light, sound, and so on.   &lt;br /&gt;
* To the digital inputs, you can attach various input devices, including switches.&lt;br /&gt;
* To the digital outputs, you can attach status tools like LEDs.&lt;br /&gt;
&lt;br /&gt;
You use these sensors in software entirely through the software object for the Phidget plugged in to your USB port.  For example, to turn off an LED at output block 1 on on an RFID tag reader, you&#039;ll want to set the output at location 1 to &amp;quot;0&amp;quot; (or false).  In C, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  CPhidgetRFIDHandle device = 0;&lt;br /&gt;
  CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the PhidgetRFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  CPhidgetRFID_setOutputState(device, 1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the RFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  device.setOutputState(1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a digital input would follow the same pattern, except you would use the getOutputState function and you would not pass the function a new output state.&lt;br /&gt;
&lt;br /&gt;
Getting an analog input is a little more complicated because:&lt;br /&gt;
# You must declare the sensor as one of two types (ratiometric or non-ratiometric)&lt;br /&gt;
#* To find out which your sensor is, read the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
# You must translate the 1-1000 reading that you get from the input into the data that you need (temperature, etc)&lt;br /&gt;
#* If the sensor comes from Phidgets, we provide a translation equation in the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
&lt;br /&gt;
Other than that, reading an analog sensor mirrors reading a digital input.  For example, to obtain the lux from the [{{SERVER}}/products.php?product_id=1127 - PrecisionLightSensor], a &#039;&#039;&#039;non-ratiometric&#039;&#039;&#039; sensor plugged into analog input 5, you would do this in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 // Change measurement to non-ratiometric style&lt;br /&gt;
 CPhidgetInterfaceKit_setRatiometric(device, 0);&lt;br /&gt;
&lt;br /&gt;
 // Get the data from analog input 5&lt;br /&gt;
 int sensorValue;&lt;br /&gt;
 CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;sensorValue);&lt;br /&gt;
&lt;br /&gt;
 // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
 int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Change measurement to non-ratiometric style&lt;br /&gt;
  device.setRatiometric(0);&lt;br /&gt;
&lt;br /&gt;
  // Get the data from analog input 5&lt;br /&gt;
  int sensorValue = getSensorValue(5);&lt;br /&gt;
&lt;br /&gt;
  // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
  int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Learning Everything You Can Do====&lt;br /&gt;
&lt;br /&gt;
The things you can do with your particular Phidget are many and varied, so we only include general concepts on this page.&lt;br /&gt;
&lt;br /&gt;
You can go one of two places for more information on what functions are available for your specific device.  We provide both documentation on the raw API for each programming language as well as a language-independent description of the calls for each device.&lt;br /&gt;
* Read the API for your [[Software Overview#Language Support| specific programming language]], available as a download on each page.&lt;br /&gt;
* Read the API overview for your hardware, which can be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
=== Close the Phidget ===&lt;br /&gt;
&lt;br /&gt;
When you are finished with the Phidget software object at the end of your program, you should close and (in some languages) delete it.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  device.close();&lt;br /&gt;
  device = null;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or, in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_close((CPhidgetHandle) device);&lt;br /&gt;
 CPhidget_delete((CPhidgetHandle) device);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt; call removes the lock that [[#Opening the Phidget|open]] put on the Phidget.  Make sure to close your object, so other software can use the Phidget!&lt;br /&gt;
&lt;br /&gt;
The close() function also makes sure the thread associated with the Phidget close properly.  Any outstanding writes will block close() until they complete, because writes are guaranteed to complete (unless a device is detached).&lt;br /&gt;
&lt;br /&gt;
Also note that a device should be put into a known state before calling close. For example, if a motor controller is driving a motor and close is called, it will continue to drive the motor even though the application has exited. This may or may not be what you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Multiple Phidgets===&lt;br /&gt;
&lt;br /&gt;
It is of course possible to use more than one Phidget within your program.  The trick lies in using a unique identifier for each one.  You can either hard-code the [[#Using the Serial Number|serial number in by hand]] (the number will be on the bottom of the board, or you can run our example code for the Phidget to obtain it on-screen), or you can use the [[#Using the Manager|Phidget Manager within your program]] to detect attached devices and return their serial numbers and Phidget types.&lt;br /&gt;
&lt;br /&gt;
====Using the Serial Number====&lt;br /&gt;
&lt;br /&gt;
Each Phidget has a unique serial number.  Using this serial number, you can use a specific [[General Phidget Programming#Opening the Phidget|open]] call to open by serial number.&lt;br /&gt;
&lt;br /&gt;
For example, in Java, this would be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open(SerialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, serialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Using the Label====&lt;br /&gt;
&lt;br /&gt;
If you want to have a human-readable way to reference your Phidget (as opposed to a serial number), or to have multiple different Phidgets of the same type with the same handle (for re-usable system code), you can use the Label feature of Phidgets.  In many development setups, you can change the label to whatever you like, get the label within your code, and open a Phidget based on its label, for any newer generation Phidget.  The disadvantage of Labels is that they are not available on all operating systems and languages.&lt;br /&gt;
&lt;br /&gt;
Some limitations are:&lt;br /&gt;
* You cannot &#039;&#039;&#039;set&#039;&#039;&#039; a label using any language in [[OS - Windows|Windows]], for any language&lt;br /&gt;
**However, you can get the label of a Phidget on Windows, and open a Phidget by its label&lt;br /&gt;
* [[Language - Android Java|Android Java]] has support for only a subset of the open() functions that use labels, see the [[Language - Android Java|Android Java language page]] for details&lt;br /&gt;
* Older Phidgets do not support labels&lt;br /&gt;
* No .COM language on Windows supports opening by Label&lt;br /&gt;
** This includes [[Language - AutoIt|AutoIt]], [[Language - Adobe Director|Adobe Director]], [[Language - Delphi|Delphi]], and all of the Visual Basic flavours.&lt;br /&gt;
* [[Language - LabVIEW|LabVIEW]] cannot open by label&lt;br /&gt;
* [[Language - Python|Python]] cannot open by label&lt;br /&gt;
* [[Language - LiveCode|LiveCode]] cannot open by label&lt;br /&gt;
&lt;br /&gt;
When opening by label, you would use the {{Code|openLabel(&amp;quot;mylabel&amp;quot;)}} function (or similar, check the [[Software Overview#Language Support|API for your language]]) rather than the generic open() function.&lt;br /&gt;
&lt;br /&gt;
Note that setting the label should be done by a separate program.  On a Mac OS computer, you can set a label through the Phidget Preference Pane.  On a Linux computer, you should write a special short program specifically for setting the label.  There are two reasons to &#039;&#039;&#039;not&#039;&#039;&#039; set a label within your main program:&lt;br /&gt;
* If you set a label every time you run that program, when not needing to, you can easily reach the 10,000 re-write limit for the flash that stores the label&lt;br /&gt;
* If you are using event driven programming, you cannot set the label from any function called from the attach event, as it will hang (on a mutual exclusion lock).&lt;br /&gt;
Because of the second point, your special program to set the label on a Phidget should use {{Code|waitForAttach()}} in [[#Logic Code|logic code]] and not [[#Event Driven Code|event-driven]] programming&lt;br /&gt;
&lt;br /&gt;
====Using the Manager====&lt;br /&gt;
&lt;br /&gt;
The Phidget Manager object can detect all Phidgets attached to a system and return their attributes in a list (or array, vector, etc. - depending on the language).  With this, you can obtain the serial numbers and types of Phidgets currently attached.  This is the preferred method for systems where you will be using multiple Phidgets and expecting the system to operate long enough (or under harsh enough conditions)  that the Phidgets would need to be replaced.  &lt;br /&gt;
&lt;br /&gt;
This is especially true for running programs [[OS - Phidget SBC#Running a Program Automatically| automatically at scheduled times on the Single Board Computer]], where you would be replacing Phidgets without the benefit of keyboard or screen. &lt;br /&gt;
&lt;br /&gt;
For example, in Java (note for Enumerations you also need to include {{Code|java.util.*}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  Manager manager;&lt;br /&gt;
  manager = new Manager();&lt;br /&gt;
  try {&lt;br /&gt;
      manager.open();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  Thread.sleep(1000);&lt;br /&gt;
&lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  Vector phidgetList = manager.getPhidgets();&lt;br /&gt;
&lt;br /&gt;
  // Use an enumeration to iterate over the vector&lt;br /&gt;
  // Vectors also have iterators in Java 2&lt;br /&gt;
  Enumeration phidgetListEnum = phidgetList.elements();&lt;br /&gt;
  while(phidgetListEnum.hasMoreElements()) { &lt;br /&gt;
      Phidget phidgetElement = (Phidget)phidgetListEnum.nextElement();&lt;br /&gt;
      System.out.print(phidgetElement.getDeviceName() + &amp;quot;, &amp;quot;); &lt;br /&gt;
      System.out.println(phidgetElement.getSerialNumber()); &lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Close the manager &lt;br /&gt;
  try {&lt;br /&gt;
      manager.close();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
  manager = null;&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C (note for sleep you also need to include {{Code|unistd.h}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  CPhidgetManagerHandle manager = 0;&lt;br /&gt;
  CPhidgetManager_create(&amp;amp;manager);&lt;br /&gt;
  CPhidgetManager_open((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  sleep(1);&lt;br /&gt;
    &lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  CPhidgetHandle* phidgetList;&lt;br /&gt;
  int count;&lt;br /&gt;
    &lt;br /&gt;
  CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) manager, &amp;amp;phidgetList, &amp;amp;count);&lt;br /&gt;
    &lt;br /&gt;
  int serialNumber;&lt;br /&gt;
  const char *name;&lt;br /&gt;
    &lt;br /&gt;
  // Iterate over the returned Phidget data&lt;br /&gt;
  int i;&lt;br /&gt;
  for (i = 0; i &amp;lt; count; i++) {&lt;br /&gt;
      CPhidget_getDeviceName(phidgetList[i], &amp;amp;name);&lt;br /&gt;
      CPhidget_getSerialNumber(phidgetList[i], &amp;amp;serialNumber);&lt;br /&gt;
      printf(&amp;quot;%s, %d\n&amp;quot;, name, serialNumber);&lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Use the Phidget API to free the memory in the phidgetList Array    &lt;br /&gt;
  CPhidgetManager_freeAttachedDevicesArray(phidgetList);&lt;br /&gt;
&lt;br /&gt;
  // Close the manager    &lt;br /&gt;
  CPhidgetManager_close((CPhidgetManagerHandle) manager);&lt;br /&gt;
  CPhidgetManager_delete((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Distinguishing Events====&lt;br /&gt;
&lt;br /&gt;
If you are using [[#Event Driven Code|event-driven code]], once you have correctly opened multiple Phidgets of different types, they will have different event handlers and hence you will know what Phidget triggered which event.  &lt;br /&gt;
If you are using multiple Phidgets of the same type, or you are trying to determine within general events (such as Attach Events) which Phidget triggered the event, you can then check the serial number (or device type) of the triggering device and act accordingly.  &lt;br /&gt;
&lt;br /&gt;
For example, in Java, your [[General Phidget Programming#Event Attachment|attach event handler]] might look like this:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
    detachHandler = new DetachListener() { &lt;br /&gt;
        public void detached(DetachEvent event) {&lt;br /&gt;
            int serialNumber = ((Phidget)event.getSource()).getSerialNumber();&lt;br /&gt;
            // Do something according to serialNumber&lt;br /&gt;
    }    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
    int AttachHandler(CPhidgetHandle device, void *userptr) {&lt;br /&gt;
	int serialNo;&lt;br /&gt;
	CPhidget_getSerialNumber(device, &amp;amp;serialNo);&lt;br /&gt;
         // Do something according to serialNumber&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Phidgets over a Network===&lt;br /&gt;
&lt;br /&gt;
Control of a Phidget over a network uses the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
We have an in-depth description of the WebService, with images to illustrate its use, on the main [[Phidget WebService]] page.&lt;br /&gt;
&lt;br /&gt;
In the code on the remote computer where you are receiving Phidget data and controlling the Phidget, you would simply use a different open call, and then the Phidget software object will work as if the object were local and normal.&lt;br /&gt;
&lt;br /&gt;
The different, remote open call in C would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
int serial_number = 37299;&lt;br /&gt;
CPhidget_openRemoteIP ((CPhidgetHandle) device, serial_number, &amp;quot;127.0.0.1&amp;quot;, 5001, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simply uses the same computer in a &#039;loopback&#039; connection (127.0.0.1) and the default port 5001.  You can replace the serial number with your own Phidget&#039;s serial number.&lt;br /&gt;
&lt;br /&gt;
And in Java, the different, remote open call would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
openAny(&amp;quot;127.0.0.1&amp;quot;, 5001, null);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are other options for opening remotely, including by name rather than IP.  You can refer to the [[Software Overview#Language Support|API for your language]] for options and specific syntax.&lt;br /&gt;
&lt;br /&gt;
== Putting It Together ==&lt;br /&gt;
&lt;br /&gt;
User and device actions can be handled by either:&lt;br /&gt;
*Letting the program tell you when they happen and then doing something (&#039;&#039;&#039;event driven&#039;&#039;&#039; code)&lt;br /&gt;
*Polling for things to happen then doing something (&#039;&#039;&#039;logic&#039;&#039;&#039; code)&lt;br /&gt;
&lt;br /&gt;
The style of programming you choose (and hence the language you might prefer) would depend on what you want to do with the Phidget.  The two sections, [[#Event Driven Code|Event Driven Code]] and [[#Logic Code|Logic Code]] below give benefits, drawbacks, and general examples of each style.&lt;br /&gt;
&lt;br /&gt;
The styles can also mix.  For example, you can take a defined set of steps at first such as turning on an LED or antenna (logic code) and then doing nothing until an output change event is fired (event code).&lt;br /&gt;
&lt;br /&gt;
With languages that support both styles, you can mix and match.  For languages that support only logic code (see the [[Software Overview#Language Support|Language Support Categories]] above) you can only use the logic paradigm style.&lt;br /&gt;
&lt;br /&gt;
Examples in pseudo-code are given below for each style type so you can see how your language choice can affect your code design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logic Code ===&lt;br /&gt;
&lt;br /&gt;
Logic code has use for:&lt;br /&gt;
* Simple, single-device applications&lt;br /&gt;
* Non-GUI applications (GUIs usually are event driven)&lt;br /&gt;
* The user driving the device rather than listening to it&lt;br /&gt;
&lt;br /&gt;
Logic code is relatively easy to design well.  For example, using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, logic code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:logic.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although this design does not explicitly capture every event that fires when data or input changes, by polling the device often enough no data will be lost.&lt;br /&gt;
&lt;br /&gt;
However, logic code cannot handle constant, asynchronous events as cleanly as [[#Event Driven Code|event driven code]] can.&lt;br /&gt;
&lt;br /&gt;
These designs can be mixed.  So, if you find that in logic code you have a highly complex &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; loop driving your program, you should consider changing some of it to event driven code.  This type of awkward if-loop might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Create Device Software Object&lt;br /&gt;
  Open Device&lt;br /&gt;
&lt;br /&gt;
  Loop Until Exit Requested {&lt;br /&gt;
     if No Device Attached {&lt;br /&gt;
         Wait For Attachment until Timeout&lt;br /&gt;
         if Wait Timeout Reached {&lt;br /&gt;
             break&lt;br /&gt;
         } else { &lt;br /&gt;
             Initialize Device&lt;br /&gt;
         }&lt;br /&gt;
     } else {  // Device Is Attached&lt;br /&gt;
         if Device Data Type 1 Changed {&lt;br /&gt;
             Do Something&lt;br /&gt;
         }&lt;br /&gt;
         if Device Data Type 2 Changed {&lt;br /&gt;
             Do Something Else&lt;br /&gt;
         }&lt;br /&gt;
         // ... More data change functions here&lt;br /&gt;
     }&lt;br /&gt;
     Collect User Input&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  Close Device&lt;br /&gt;
  Delete Device&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the other hand, you can probably see that if your language does not give the option for events, you can use this structure to mimic what events would enable you to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Event Driven Code ===&lt;br /&gt;
&lt;br /&gt;
Event driven code allows for clean handling of complex, asynchronous programs:&lt;br /&gt;
*Handling multiple Phidgets&lt;br /&gt;
*Handling active plugging or unplugging of the Phidget (multiple attach and detach events)&lt;br /&gt;
*Working behind a GUI, as many GUIs are already event driven&lt;br /&gt;
*Capturing all sensor data - or input and output - without constantly polling&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Without&#039;&#039; event driven code, you will need to constantly poll the device to see if any state has changed.  If you poll at a slower rate than your input or output changes, you will not capture all data.&lt;br /&gt;
&lt;br /&gt;
However, event driven code is usually not as useful or efficient for:&lt;br /&gt;
*Only one open and close event &lt;br /&gt;
*Using only one device&lt;br /&gt;
*Having the user (or program) &#039;&#039;put&#039;&#039; changes onto the device (in contrast to reading data &#039;&#039;from&#039;&#039; the device)&lt;br /&gt;
&lt;br /&gt;
Event driven code is relatively hard to design well.  It may help to draw out a &#039;&#039;&#039;flowchart&#039;&#039;&#039;, &#039;&#039;&#039;state machine&#039;&#039;&#039;, or at least a &#039;&#039;&#039;pseudo-code outline&#039;&#039;&#039; of your system design and all events you wish to handle before writing code.&lt;br /&gt;
&lt;br /&gt;
The code examples given for each [[Software Overview#Language Support|specific language]] use events if they are supported by the language.&lt;br /&gt;
&lt;br /&gt;
Using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, event code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
[[File:event.png]]&lt;br /&gt;
&lt;br /&gt;
Once you have written this code flow, the actual order of events that occur within the program look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Eventhandler.jpg|160px]]&lt;br /&gt;
&lt;br /&gt;
Note that the device itself initiates the function call, by &#039;firing&#039; the event.  This allows you to update only when events fire, and capture all changes, because the low-level interface is telling you when a change occurs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Advanced Concepts==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, there are other useful concepts which will help you design your code to be persistent and stable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Logging===&lt;br /&gt;
&lt;br /&gt;
You can enable logging to get more debugging information.  Turning on logging happens through a Phidget API function.  This would happen at the very start of your program, before even initializing your software object or opening it.  Logging lets you get feedback from the Phidget libraries about every Phidget API call you make.&lt;br /&gt;
&lt;br /&gt;
In C, turning on logging to the command line would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  CPhidget_enableLogging(PHIDGET_LOG_DEBUG, NULL);&lt;br /&gt;
&lt;br /&gt;
  //... All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  CPhidget_disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  enableLogging(PHIDGET_LOG_DEBUG, null);&lt;br /&gt;
&lt;br /&gt;
  //...All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The use of null is to indicate that the output is not to a file (and hence to the command line).  Otherwise, the second argument would be a string filename.&lt;br /&gt;
&lt;br /&gt;
There are six different logging levels, ranging from &amp;quot;Give me Everything!&amp;quot; to &amp;quot;Tell me only about critical problems&amp;quot;.  The level in the examples above - &#039;&#039;&#039;&amp;lt;code&amp;gt;PHIDGET_LOG_DEBUG&amp;lt;/code&amp;gt;&#039;&#039;&#039; - is a medium output level.  For more information about each level and what it gives you, see the API for [[Software Overview#Language Support|your specific language]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Threading===&lt;br /&gt;
&lt;br /&gt;
Due to the use of events, the Phidget library uses threading extensively.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
* Calling &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; starts a central thread. &lt;br /&gt;
* Closing everything will shut that central thread down (before the final close returns). &lt;br /&gt;
* Each device, once attached, starts its own read and write threads. &lt;br /&gt;
&lt;br /&gt;
These threads provide the support to perform your typical [[#The Basic Functions|Basic Functions]]:&lt;br /&gt;
&lt;br /&gt;
* Triggering of data events come from the context of a device read thread. &lt;br /&gt;
* Attach and detach events come from the context of the central thread.&lt;br /&gt;
* The central thread looks for device attaches and detached, keeping track of which devices are attached internally, and sending out attach and detach events to Phidgets and Managers.&lt;br /&gt;
* Writes are performed asynchronously by the write thread. The write queue is only 1 deep so calling a write function while there is a write pending will block.&lt;br /&gt;
&lt;br /&gt;
All Phidget libraries are &#039;&#039;&#039;thread safe&#039;&#039;&#039;, so you don’t need to do any locking on the Phidget objects.  If you have a GUI, however, or another program with a separate thread, make sure to use one thread for events, and a separate thread with your GUI, and some form of mutual exclusion if they are both writing to the same thing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Exceptions and Errors===&lt;br /&gt;
&lt;br /&gt;
There are two different types of errors that you can use to confirm that your program is running correctly.&lt;br /&gt;
&lt;br /&gt;
====One: An error generated by a function call====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by &#039;&#039;you&#039;&#039; calling a function.  For example, you might try to read analog sensor port number 150 on a board that only has eight.  The function you used to read port 150 would return an error (in C/C++) or throw an error (in languages that support exceptions like Java, .NET, Python, or AS3).  &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;synchronously&#039;&#039; to function calls, that is, they are returned or thrown right after a function returns.  You can handle these by checking the return values on your functions (in C/C++) or using an error catching method like &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; in languages that support exceptions (e.g., Java, .NET, Python, AS3).&lt;br /&gt;
&lt;br /&gt;
For example, in C, you might write a LocalErrorCatcher function that you can then use on every Phidget function call to detect and deal with errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int LocalErrorCatcher (int errorCode) {&lt;br /&gt;
&lt;br /&gt;
      if (errorCode != 0) {  // Everything is okay if errorCode = 0&lt;br /&gt;
    &lt;br /&gt;
          switch (errorCode) {&lt;br /&gt;
             default:&lt;br /&gt;
               const char *errorDescription;&lt;br /&gt;
               LocalErrorCatcher(&lt;br /&gt;
                   CPhidget_getErrorDescription (errorCode, &amp;amp;errorDescription));&lt;br /&gt;
               printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
               break;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // ... Then, later, you would use it on any Phidget function:&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_open((CPhidgetHandle) device, -1));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
# The function LocalErrorCatcher uses itself to check for errors on getting an error description.  &lt;br /&gt;
# You can handle individual error codes as they are listed in the API.  This only prints a general message.&lt;br /&gt;
&lt;br /&gt;
Or in Java, you would try a Phidget function call, and catch any resulting exception that occurs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
      device.openAny();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, you could also use a &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; statement around the exception.getErrorNumber() and exception.getDescription() functions to catch any errors from those calls.&lt;br /&gt;
&lt;br /&gt;
The consequences of not catching this type of error (on &#039;&#039;every&#039;&#039; function) differ by programming language.&lt;br /&gt;
In C/C++ these errors must be &#039;&#039;explicitly&#039;&#039; checked for after each function call, otherwise the program will simply continue on in an incorrect state.  In languages that support exceptions (e.g., Java, .NET, Python, AS3), errors are returned using exceptions which will leave you no choice but to catch them, or have your program terminate without warning.&lt;br /&gt;
&lt;br /&gt;
====Two: An error generated by an event====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by the Phidget library during runtime.  For example, the Phidget device might be experiencing too high a temperature, and trigger an error.  This would not necessarily be due to any one function your program called; rather, the error would appear when the problem appears and would trigger an event. &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;asynchronously&#039;&#039;, that is, something happens apart from any function calls and an error event is triggered. You can handle these by setting up an Error Event Handler.&lt;br /&gt;
&lt;br /&gt;
In C, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int ErrorEventHandler (CPhidgetHandle device, void *usrptr, int errorCode, const char *errorDescription) {&lt;br /&gt;
    printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
    // Do something useful based on the error code&lt;br /&gt;
    return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Actually hook the Error Event Handler in to receive events&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_set_OnError_Handler((CPhidgetHandle) device, LibraryErrorHandler, NULL));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the &#039;&#039;&#039;LibraryErrorHandler&#039;&#039;&#039; function is what gets called when an error event occurs, and it gives you an opportunity to handle the error.  &lt;br /&gt;
&lt;br /&gt;
You&#039;ll also note that there is a second function called &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039;.  This second function handles the return value from setting the  error handler.  We included it here because, as these are examples on how to handle errors, the example would leave a possibly unhandled error without it. This second type of error handling  and the &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039; function are [[#One: An error generated by a function call|described above]].&lt;br /&gt;
&lt;br /&gt;
In Java, it would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
    device.addErrorListener(new ErrorListener() {&lt;br /&gt;
        public void error(ErrorEvent event) {&lt;br /&gt;
            System.out.println(event);&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, the act of hooking an error listener in to the device can itself generate an error, which should be caught.  &lt;br /&gt;
&lt;br /&gt;
These event-type errors are also how a Phidget being run over a network announces bad passwords, lost packets, and other network problems.  Locally, the errors can announce incorrect temperatures, current, and power. So, it is in your best interest to set up an error event handler and take action based on the codes and error types in the API [[Software Overview#Language Support|for your programming language]].&lt;br /&gt;
&lt;br /&gt;
See the API for your [[Software Overview#Language Support|specific programming language]] for error code documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Sensitivity and Filtering===&lt;br /&gt;
&lt;br /&gt;
Change Triggers are used to filter the number of events that are returned to an Application, by setting a minimum amount of activity before a Change Event is sent to your program. &lt;br /&gt;
&lt;br /&gt;
This is a simple hysteresis - a minimum amount of change has to occur since the last event before another event will be fired. &lt;br /&gt;
&lt;br /&gt;
If your application is implementing its own filtering, setting the ChangeTrigger, or &#039;&#039;&#039;sensitivity&#039;&#039;&#039; to zero will cause all events to fire. Change triggers are generally available only for sensor inputs events. Change triggers are referred to as &#039;&#039;Sensitivity&#039;&#039; in some device-specific APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Data Rate===&lt;br /&gt;
&lt;br /&gt;
Some devices support a user-defined data rate for events.  &lt;br /&gt;
&lt;br /&gt;
* The data rate is set in milliseconds, with a range from up 1ms to 1000ms, depending on the Phidget. &lt;br /&gt;
* Data rates greater then 8ms generally need to be a multiple of 8 (8,16,24,...,496,...,996,1000). &lt;br /&gt;
* Data rates lower then 8ms are supported as: 4ms, 2ms, 1ms. &lt;br /&gt;
* Data rate is a maximum rate &lt;br /&gt;
* Data rate will be superseded by a non-zero sensitivity on devices that support both sensitivity and data rate. &lt;br /&gt;
&lt;br /&gt;
See the main page for your device - found on its product page on [{{SERVER}} our main website] for more details on available data rates and specifications.&lt;br /&gt;
&lt;br /&gt;
Note that this data rate &#039;&#039;&#039;is not the rate at which you will receive data&#039;&#039;&#039;.  Rather, it is the amount of time over which events are averaged before being sent.  It may help to think of our specification of data rate as an &#039;&#039;averaging time&#039;&#039;.  This means that setting a data rate of 24 ms will try to give you data averaged over 24 ms, and send it every 24 ms.  Depending on your computer, events may or may not be dropped.  If events are dropped, the data points that are received still represent 24 ms (or whatever the data rate is set to).  This means data is lost.  &lt;br /&gt;
&lt;br /&gt;
Conversely, if you are [[#Logic Code|polling]], and you set the data rate to longer than your polling rate, you will receive duplicate, averaged data.  For example, setting the data rate to 24 ms and then polling every 12 ms will give you duplicate readings every other poll.  To poll and not miss any data, the rate that your code polls must match the rate that you set for the {{Code|setDataRate()}} function in our API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using the Dictionary===&lt;br /&gt;
&lt;br /&gt;
The Phidget Dictionary is a service provided by the Phidget WebService.   The dictionary:&lt;br /&gt;
* Is a centralized collection of key-value pairs &lt;br /&gt;
* Works only over the webservice&lt;br /&gt;
* Can be accessed and changed from any number of webservice clients&lt;br /&gt;
* Makes use of extended regular expressions (denoted between two forward slashes) for key matching&lt;br /&gt;
* Is also a foundation part of the webservice itself, and controls access of all Phidgets through the {{Code|openRemote}} and {{Code|openRemoteIP}} interfaces &lt;br /&gt;
* Can be used as an abstracted or higher-level interface for remotely managing Phidgets&lt;br /&gt;
&lt;br /&gt;
We have a more in-depth description of the Dictionary (with pictures) on the main [[Phidget Dictionary]] page.&lt;br /&gt;
&lt;br /&gt;
The intended use for the dictionary is as a central repository for communication and persistent storage of data between several client applications. For example, the computer directly connected to a Phidget could create and change keys for additional events on top of (or even instead of) those already thrown by the Phidget device API.  The dictionary API is very high-level and thus very flexible - essentially any application of adding keys, changing keys (and throwing events), and getting values of keys can be handled by the Dictionary.&lt;br /&gt;
&lt;br /&gt;
Note that you should never add or modify a key that starts with {{Code|/PSK/}} or {{Code|/PCK/}} as these are the keys that Phidgets use.  Unless, of course, you want to explicitly modify Phidget specific data - and this is highly discouraged, as it’s very easy to break things. Listening to these keys is fine if so desired.&lt;br /&gt;
&lt;br /&gt;
Refer to the API [[Software Overview#Language Support|for your specific language]] for the full Dictionary API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Long Term Code Maintenance===&lt;br /&gt;
&lt;br /&gt;
Thinking long term from the start is incredibly useful.  Phidgets as a company is constantly developing and inventing, and our API gets improved and changed to still work with older devices while adding support for new ones.  &lt;br /&gt;
&lt;br /&gt;
We release library updates - both for operating systems and languages - on a regular basis.  We &#039;&#039;&#039;strongly&#039;&#039;&#039; recommend updating your own libraries as we release them.  This goes for both the libraries and the WebService, as the versions must match.  &lt;br /&gt;
&lt;br /&gt;
This form of updating (did we mention that we strongly recommend it?) is the single most important thing you can do to reduce maintenance issues with your Phidget software down the road.&lt;br /&gt;
&lt;br /&gt;
Every so often, customers come to us having run the same code for years, without updating.  Then, for some reason, they have to update (say, for an operating system migration).  And their code no longer works. What do to then?  We can work with these customers to find out which of the many updates was the one to cause the problem - a difficult and very time consuming process.  And over the course of multiple years, we may no longer stock or even manufacture that particular Phidget.  You can imagine that a process with these limitations can take a very long time to resolve, if it can be resolved at all.&lt;br /&gt;
&lt;br /&gt;
Conversely, if you update every time, this time frame is greatly reduced.  We make a serious effort to test every library update, and although some backwards-compatibility problems do (rarely) get through, we have a fresh memory of what was changed and can work with you to quickly either debug the new libraries or get you a working version.&lt;br /&gt;
&lt;br /&gt;
In addition to library updates, here are a few other tips and tricks to reduce your maintenance time:&lt;br /&gt;
* If you are using [[#Logging|Logging]], don&#039;t remove the logging code when you finalize your release.  Simply comment it out so you can turn it on again later and debug quickly.&lt;br /&gt;
* Some long-term problems can be detected early by listening to library messages and errors.  Handling [[#Exceptions and Errors|Exceptions and Errors]] will allow your code to run silently until something is wrong, in which case you&#039;ll know right away.&lt;br /&gt;
&lt;br /&gt;
If you are looking for more help on how to work with our library updating, please feel welcome to [[Contact Us|contact us]].&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
This page has gone through [[#The Basic Functions|basic]] to [[#Advanced Concepts|advanced]] uses of the Phidget API.  We&#039;ve used C and Java here as example languages.  If you&#039;re using a different language, we include similar snippets of code (without the in-depth description) in the documentation [[Software Overview#Language Support|for your language]].&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve read this far and are still hungry for more, try learning more about your hardware; we have a number of [[:Category:Primer|hardware learning pages]] as well.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20673</id>
		<title>General Phidget Programming</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20673"/>
		<updated>2012-06-29T17:48:15Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Overview]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page presents the general &#039;&#039;&#039;concepts&#039;&#039;&#039; needed to write code for a Phidget.&lt;br /&gt;
&lt;br /&gt;
By this point, you should have installed the drivers for your [[Software Overview#Operating System Support|operating system]] and the libraries for your [[Software Overview#Language Support|specific programming language]].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Basic Functions==&lt;br /&gt;
&lt;br /&gt;
To use your Phidget within code, you&#039;ll want to:&lt;br /&gt;
# Create a Phidget [[#Creating a Software Object|software &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], which gives you access to the functions specific to that device&lt;br /&gt;
# [[#Opening the Phidget|Open the Phidget]] using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Detect when a [[#Attaching the Phidget|Phidget is attached]] (plugged in) by using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Use [[#Do Things with the Phidget|functions that the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt; provides]], like turning on LEDs, reading sensors, triggering events on data change, etc&lt;br /&gt;
# [[#Close the Phidget|Close the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], when you are done&lt;br /&gt;
&lt;br /&gt;
Small code snippets are provided for each step below.  [[Language - C/C++|C++]] and [[Language - Java|Java]] were selected because Java is a relatively high-level language and C++ is a relatively low level language, thereby showing how specific each language API really is.  So, the most useful resource for the &#039;&#039;actual functions&#039;&#039; would be the API for [[Software Overview#Language Support | your specific language]].  This page is a high-level introduction, by design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Software Object ===&lt;br /&gt;
&lt;br /&gt;
Phidget devices are controlled using software objects.  All software device objects have a common API and set of functions that allow you to &#039;&#039;&#039;open&#039;&#039;&#039; it, &#039;&#039;&#039;close&#039;&#039;&#039; it, and set a few listeners to general events such as &#039;&#039;&#039;attach&#039;&#039;&#039; (plug in), &#039;&#039;&#039;detach&#039;&#039;&#039; (unplug), and errors.  &lt;br /&gt;
&lt;br /&gt;
But when you create an actual software object, it is a software object &#039;&#039;&#039;specific&#039;&#039;&#039; to your device.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 AccelerometerPhidget device = new AccelerometerPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 CPhidgetAccelerometerHandle device = 0;&lt;br /&gt;
 CPhidgetAccelerometer_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 CPhidgetRFIDHandle device = 0;&lt;br /&gt;
 CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each software object has an API and available functions which are specific to that device.  For example, the RFID device API includes a function to turn on the RFID antenna.  The accelerometer device API includes a function to set the sensitivity on each axis.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Opening the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Phidgets can either be opened when attached directly to a computer, or they can be opened remotely using the [[Phidget WebService]].  This section deals primarily with opening Phidgets directly.&lt;br /&gt;
&lt;br /&gt;
Once you have created your [[#Creating a Software Object|software object]] for your specific type of device, you can call the &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in your language on that object.  For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, -1);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All specific language calls can be found in the API documentation located on each [[Software Overview#Language Support|individual language page]].&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in any language opens the software object for use, not the hardware itself.  Having the software &amp;quot;open&amp;quot; before the hardware means that the software can capture all events, including multiple attach (plug in) and detach (unplug) events for one &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; call.&lt;br /&gt;
&lt;br /&gt;
====Details for Open()====&lt;br /&gt;
&lt;br /&gt;
Open will return immediately once called, because it can be called even if the Phidget to be used is not attached to the system. This is known as an asynchronous call. It’s important to understand that most calls on a Phidget will fail if they are calls when the Phidget is not attached - in fact the only calls that are allowed on a detached Phidget are &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;waitForAttachment()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getAttached()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Open is also pervasive. This means that once open has been called, it will constantly try to stay attached to a Phidget. Even if the Phidget is unplugged from the computer and then plugged back in, you will simply get a Detach event, and then an Attach event. It’s a good idea to handle the Detach event in order to avoid calling the Phidget after it has detached.&lt;br /&gt;
&lt;br /&gt;
The different types of open(), such as openAny(), openRemote(), etc. can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network.  The list all of the available modes that open provides, and the syntax for your language, can be found in the API for [[Software Overview#Language Support|your specific language]].  If there are more than one of the same type of Phidget attached to a computer, and you use open() with no serial number, there is no way of knowing which Phidget will be opened first.&lt;br /&gt;
&lt;br /&gt;
If you are looking to do a remote open call, to use the [[Phidget WebService]], you usually have to change only the open() call (to a remote open call) to change your program from a locally-running one to one that can control a Phidget over the network.  We give an in-depth example of using the WebService on each of our [[Software Overview#Operating System Support|operating system pages]], we have a brief overview of the WebService (with code snippets) in the [[#Using Phidgets over a Network|Using Phidgets over a Network]] section, and we often have WebService code snippets on the [[Software Overview#Language Support|language pages]] which do not easily extend from the examples on this page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Once a Phidget is opened by an application, it cannot be opened again in another application until closed by the first.  When open and attached in software, no other programs or instances can read data from or change the Phidget. This includes it being open via the Windows Control Panel application!  The one exception is if the Phidget is controlled &#039;&#039;only&#039;&#039; over the network with the [[Phidget WebService]], and not directly.  Then, you can use multiple remote control programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attaching the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Physically, attaching a Phidget means plugging it in.  The real guts behind the &#039;attach&#039; command, however, occur within the software libraries.  The &#039;attach&#039; call is what makes the final connections between the opened software object and the corresponding thread and events.  This is why all Phidget object must be attached in software, even those that are not actually plugged in with a cable.  This includes Phidgets used remotely via our [[Phidget WebService]], it includes Interface Kits on the same board as our Single Board Computer, and it even includes the [[Phidget Manager]] software object, which is a sort of meta-Phidget from which you can [[#Using the Manager|control other Phidgets]].&lt;br /&gt;
&lt;br /&gt;
In your code, you can detect an attachment either with an &#039;&#039;&#039;event&#039;&#039;&#039; in [[#Event Driven Code|event-driven programming]], or &#039;&#039;&#039;waiting&#039;&#039;&#039; for it, in [[#Logic Code|logic programming]].  &lt;br /&gt;
&lt;br /&gt;
==== Event Attachment ====&lt;br /&gt;
&lt;br /&gt;
For example, to use an event to detect attachment in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addAttachListener(new AttachListener() {&lt;br /&gt;
      public void attached(AttachEvent ae) {&lt;br /&gt;
          System.out.println(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
          // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
  int AttachHandler (CPhidgetHandle device, void *userData) {&lt;br /&gt;
      printf(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
      // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnAttach_Handler((CPhidgetHandle) device, AttachHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both of the code snippets above do the same thing.  The function &amp;lt;code&amp;gt;AttachHandler(...)&amp;lt;/code&amp;gt; is called automatically when a device is plugged in.&lt;br /&gt;
&lt;br /&gt;
You will want to attach events (via &amp;lt;code&amp;gt;addAttachListener()&amp;lt;/code&amp;gt; above, for example) &#039;&#039;&#039;before you open the Phidget object&#039;&#039;&#039;.  Otherwise, triggered events may be lost.&lt;br /&gt;
&lt;br /&gt;
This method for using events to detect attachment can be expanded to other events and more complex control flow.  Where possible, all example code downloads from the [[Software Overview#Language Support|specific language pages]] shows event-driven programming.&lt;br /&gt;
&lt;br /&gt;
==== Wait for Attachment ====&lt;br /&gt;
&lt;br /&gt;
Waiting for attachment is a straightforward process.  Your code does not handle events, it simply waits for a device to be plugged in before moving on and doing something else.&lt;br /&gt;
&lt;br /&gt;
For example, in Java you wait for attachment on a &#039;&#039;&#039;created and open&#039;&#039;&#039; software object (called device) like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 // Wait until a device is plugged in&lt;br /&gt;
 device.waitForAttachment();&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C (again, device has been &#039;&#039;&#039;created and opened&#039;&#039;&#039;) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 int result;&lt;br /&gt;
 // Wait up to 10000 ms for a device to be plugged in&lt;br /&gt;
 if((result = CPhidget_waitForAttachment((CPhidgetHandle) device, 10000))) {&lt;br /&gt;
     // No attachment, error&lt;br /&gt;
 }&lt;br /&gt;
 // Successful attachment&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, unlike the event model above, a Phidget software object should be open before waiting for a device to be plugged in.&lt;br /&gt;
&lt;br /&gt;
=== Do Things with the Phidget ===&lt;br /&gt;
&lt;br /&gt;
After you have a [[#Creating a Software Object|properly created]] Phidget software object, you can actually call function to turn LEDs on, change output state, read data from sensors, etc.&lt;br /&gt;
&lt;br /&gt;
The thing you probably want to do with your Phidget is read data from its sensors or inputs.  This might be, say, a sensor plugged in to a [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] used in the code snippets below.  You can do this either by detecting changes via [[#Event Driven Code|event driven code]], or polling for new values via [[#Logic Code|logic code]]. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Details about data handling:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*When a Phidget is opened, its initial state will be read before it is marked as attached. This allows polling of many properties -- including some data -- even during the Attach event, and anytime afterwards.&lt;br /&gt;
&lt;br /&gt;
*Your computer can poll much faster than the Phidget can respond.  If you poll in a continuous &#039;&#039;&#039;&amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt;&#039;&#039;&#039; loop in byte code, you will probably swamp the Phidget with requests.&lt;br /&gt;
&lt;br /&gt;
*Similarly, if you set a value and then immediately read the value on the next line in your program, the Phidget may not have time to finish the set.  In our examples, we use &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements within loops.  Print functions are relatively slow; you can also use &amp;lt;code&amp;gt;wait()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;sleep()&amp;lt;/code&amp;gt; depending on your language.&lt;br /&gt;
&lt;br /&gt;
*If you are handling data using events as described below, the data event functions will fire when the device is plugged in and its initial state is read.&lt;br /&gt;
&lt;br /&gt;
*Some properties have default values, but these should not be trusted. Remember: &#039;&#039;&#039;always set&#039;&#039;&#039;, don’t rely on defaults.  Trying to read an uninitialized value with no default will result in an Exception.&lt;br /&gt;
&lt;br /&gt;
*Usually, sensor &#039;sensitivity&#039; will &#039;&#039;&#039;not&#039;&#039;&#039; be 0 (i.e. set to sense all changes) by default.  This can be good because it prevents your screen from being completely overloaded with event output.  But, depending on the sensor, it may make your sensor seem to have very high lag, and very poor sensitivity.  To capture all events, set the sensitivity to 0.&lt;br /&gt;
&lt;br /&gt;
*Often Phidgets will retain their last state unless power is lost. This can give surprising results as the previous state may not always be what you expect. For example, if you open an InterfaceKit and set an output, this output may stay set even after the Phidget is closed.&lt;br /&gt;
&lt;br /&gt;
====Capture Data Change with Events====&lt;br /&gt;
&lt;br /&gt;
To capture data changes in sensors or inputs as they happen, you need to use [[#Event Driven Code|event driven code]].&lt;br /&gt;
&lt;br /&gt;
Like defining an event function that fires [[#Event Attachment|when the Phidget is plugged in]], you can create functions that automatically run when, for example, a sensor value or input value changes.&lt;br /&gt;
&lt;br /&gt;
For example, for an Interface Kit, you can create a function that gets called when a sensor changes.  You would do this &#039;&#039;&#039;before&#039;&#039;&#039; the Phidget software object has been [[#Opening the Phidget|opened]].&lt;br /&gt;
&lt;br /&gt;
In Java, this would look like:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addSensorChangeListener(new SensorChangeListener() {&lt;br /&gt;
      public void sensorChanged(SensorChangeEvent sensorEvent) {&lt;br /&gt;
          System.out.println(&amp;quot;New Value: &amp;quot; + sensorEvent.getValue());&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int SensorChangeHandler (CPhidgetHandle device, void *userData, int boardIndex, int newValue) {&lt;br /&gt;
      printf(&amp;quot;New Value %d from sensor at location %d\n&amp;quot;, newValue, boardIndex);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnSensorChange_Handler((CPhidgetHandle) device, SensorChangeHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Poll for Data Change====&lt;br /&gt;
&lt;br /&gt;
To poll for sensor data, or output state, you usually want to look for a &#039;&#039;&#039;get...Value&#039;&#039;&#039; or &#039;&#039;&#039;get...State&#039;&#039;&#039; function available in the API for your device.  (The API can be found on the product page for your device on our [{{SERVER}} main web site].)  Then, you simply set up a loop that get the value of a sensor continuously.&lt;br /&gt;
&lt;br /&gt;
To poll your software object, the object must be [[#Opening the Phidget|open]].  This is in contrast to the event-driven method above, where all event functions are declared and attached before opening the object.&lt;br /&gt;
&lt;br /&gt;
Note that when you poll the value of a sensor or another attribute, this will probably be within a loop.  When you create this loop, the &#039;&#039;more code&#039;&#039; you have within a loop, the &#039;&#039;more slowly&#039;&#039; your loop will run, and the &#039;&#039;more slowly&#039;&#039; you will be sampling the value in practice.  This may make you lose data, as described further in the [[#Data Rate|Data Rate]] section.&lt;br /&gt;
&lt;br /&gt;
This effect is also felt with interpreted languages (Java, Python) versus purely compiled languages, as the interpreted languages sample more slowly even within an otherwise completely empty loop.&lt;br /&gt;
&lt;br /&gt;
So if you want to sample as fast as possible, and capture all of the changes that a sensor produces, you should [[#Capture Data Change with Events|capture data with event programming]].  If you choose not to use the event-driven design, you should keep the code run between polls to a minimum. This way you can sample as quickly as possible.&lt;br /&gt;
&lt;br /&gt;
These code snippets assume &amp;lt;code&amp;gt;device&amp;lt;/code&amp;gt; is an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit 8/8/8].  For example, in Java, for the Sensor at location 5 on the board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    val = device.getSensorValue(5);&lt;br /&gt;
    System.out.println(&amp;quot;Value: &amp;quot; + val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C, for the Sensor at location 5 on the Interface Kit board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;val);&lt;br /&gt;
    printf(&amp;quot;Value: %d\n&amp;quot;, val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sensors, Input, and Output====&lt;br /&gt;
&lt;br /&gt;
Often, your Phidget will be something like an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] which has either analog inputs (black plug holes), or digital inputs and outputs (green screw attachments), or often both.&lt;br /&gt;
&lt;br /&gt;
* To the analog inputs, you can attach various sensors, including sensors for temperature, humidity, light, sound, and so on.   &lt;br /&gt;
* To the digital inputs, you can attach various input devices, including switches.&lt;br /&gt;
* To the digital outputs, you can attach status tools like LEDs.&lt;br /&gt;
&lt;br /&gt;
You use these sensors in software entirely through the software object for the Phidget plugged in to your USB port.  For example, to turn off an LED at output block 1 on on an RFID tag reader, you&#039;ll want to set the output at location 1 to &amp;quot;0&amp;quot; (or false).  In C, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  CPhidgetRFIDHandle device = 0;&lt;br /&gt;
  CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the PhidgetRFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  CPhidgetRFID_setOutputState(device, 1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the RFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  device.setOutputState(1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a digital input would follow the same pattern, except you would use the getOutputState function and you would not pass the function a new output state.&lt;br /&gt;
&lt;br /&gt;
Getting an analog input is a little more complicated because:&lt;br /&gt;
# You must declare the sensor as one of two types (ratiometric or non-ratiometric)&lt;br /&gt;
#* To find out which your sensor is, read the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
# You must translate the 1-1000 reading that you get from the input into the data that you need (temperature, etc)&lt;br /&gt;
#* If the sensor comes from Phidgets, we provide a translation equation in the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
&lt;br /&gt;
Other than that, reading an analog sensor mirrors reading a digital input.  For example, to obtain the lux from the [{{SERVER}}/products.php?product_id=1127 - PrecisionLightSensor], a &#039;&#039;&#039;non-ratiometric&#039;&#039;&#039; sensor plugged into analog input 5, you would do this in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 // Change measurement to non-ratiometric style&lt;br /&gt;
 CPhidgetInterfaceKit_setRatiometric(device, 0);&lt;br /&gt;
&lt;br /&gt;
 // Get the data from analog input 5&lt;br /&gt;
 int sensorValue;&lt;br /&gt;
 CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;sensorValue);&lt;br /&gt;
&lt;br /&gt;
 // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
 int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Change measurement to non-ratiometric style&lt;br /&gt;
  device.setRatiometric(0);&lt;br /&gt;
&lt;br /&gt;
  // Get the data from analog input 5&lt;br /&gt;
  int sensorValue = getSensorValue(5);&lt;br /&gt;
&lt;br /&gt;
  // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
  int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Learning Everything You Can Do====&lt;br /&gt;
&lt;br /&gt;
The things you can do with your particular Phidget are many and varied, so we only include general concepts on this page.&lt;br /&gt;
&lt;br /&gt;
You can go one of two places for more information on what functions are available for your specific device.  We provide both documentation on the raw API for each programming language as well as a language-independent description of the calls for each device.&lt;br /&gt;
* Read the API for your [[Software Overview#Language Support| specific programming language]], available as a download on each page.&lt;br /&gt;
* Read the API overview for your hardware, which can be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
=== Close the Phidget ===&lt;br /&gt;
&lt;br /&gt;
When you are finished with the Phidget software object at the end of your program, you should close and (in some languages) delete it.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  device.close();&lt;br /&gt;
  device = null;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or, in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_close((CPhidgetHandle) device);&lt;br /&gt;
 CPhidget_delete((CPhidgetHandle) device);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt; call removes the lock that [[#Opening the Phidget|open]] put on the Phidget.  Make sure to close your object, so other software can use the Phidget!&lt;br /&gt;
&lt;br /&gt;
The close() function also makes sure the thread associated with the Phidget close properly.  Any outstanding writes will block close() until they complete, because writes are guaranteed to complete (unless a device is detached).&lt;br /&gt;
&lt;br /&gt;
Also note that a device should be put into a known state before calling close. For example, if a motor controller is driving a motor and close is called, it will continue to drive the motor even though the application has exited. This may or may not be what you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Multiple Phidgets===&lt;br /&gt;
&lt;br /&gt;
It is of course possible to use more than one Phidget within your program.  The trick lies in using a unique identifier for each one.  You can either hard-code the [[#Using the Serial Number|serial number in by hand]] (the number will be on the bottom of the board, or you can run our example code for the Phidget to obtain it on-screen), or you can use the [[#Using the Manager|Phidget Manager within your program]] to detect attached devices and return their serial numbers and Phidget types.&lt;br /&gt;
&lt;br /&gt;
====Using the Serial Number====&lt;br /&gt;
&lt;br /&gt;
Each Phidget has a unique serial number.  Using this serial number, you can use a specific [[General Phidget Programming#Opening the Phidget|open]] call to open by serial number.&lt;br /&gt;
&lt;br /&gt;
For example, in Java, this would be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open(SerialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, serialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Using the Label====&lt;br /&gt;
&lt;br /&gt;
If you want to have a human-readable way to reference your Phidget (as opposed to a serial number), or to have multiple different Phidgets of the same type with the same handle (for re-usable system code), you can use the Label feature of Phidgets.  In many development setups, you can change the label to whatever you like, get the label within your code, and open a Phidget based on its label, for any newer generation Phidget.  The disadvantage of Labels is that they are not available on all operating systems and languages.&lt;br /&gt;
&lt;br /&gt;
Some limitations are:&lt;br /&gt;
* You cannot &#039;&#039;&#039;set&#039;&#039;&#039; a label using any language in [[OS - Windows|Windows]], for any language&lt;br /&gt;
**However, you can get the label of a Phidget on Windows, and open a Phidget by its label&lt;br /&gt;
* [[Language - Android Java|Android Java]] has support for only a subset of the open() functions that use labels, see the [[Language - Android Java|Android Java language page]] for details&lt;br /&gt;
* Older Phidgets do not support labels&lt;br /&gt;
* No .COM language on Windows supports opening by Label&lt;br /&gt;
** This includes [[Language - AutoIt|AutoIt]], [[Language - Adobe Director|Adobe Director]], [[Language - Delphi|Delphi]], and all of the Visual Basic flavours.&lt;br /&gt;
* [[Language - LabVIEW|LabVIEW]] cannot open by label&lt;br /&gt;
* [[Language - Python|Python]] cannot open by label&lt;br /&gt;
* [[Language - LiveCode|LiveCode]] cannot open by label&lt;br /&gt;
&lt;br /&gt;
When opening by label, you would use the {{Code|openLabel(&amp;quot;mylabel&amp;quot;)}} function (or similar, check the [[Software Overview#Language Support|API for your language]]) rather than the generic open() function.&lt;br /&gt;
&lt;br /&gt;
Note that setting the label should be done by a separate program.  On a Mac OS computer, you can set a label through the Phidget Preference Pane.  On a Linux computer, you should write a special short program specifically for setting the label.  There are two reasons to &#039;&#039;&#039;not&#039;&#039;&#039; set a label within your main program:&lt;br /&gt;
* If you set a label every time you run that program, when not needing to, you can easily reach the 10,000 re-write limit for the flash that stores the label&lt;br /&gt;
* If you are using event driven programming, you cannot set the label from any function called from the attach event, as it will hang (on a mutual exclusion lock).&lt;br /&gt;
Because of the second point, your special program to set the label on a Phidget should use {{Code|waitForAttach()}} in [[#Logic Code|logic code]] and not [[#Event Driven Code|event-driven]] programming&lt;br /&gt;
&lt;br /&gt;
====Using the Manager====&lt;br /&gt;
&lt;br /&gt;
The Phidget Manager object can detect all Phidgets attached to a system and return their attributes in a list (or array, vector, etc. - depending on the language).  With this, you can obtain the serial numbers and types of Phidgets currently attached.  This is the preferred method for systems where you will be using multiple Phidgets and expecting the system to operate long enough (or under harsh enough conditions)  that the Phidgets would need to be replaced.  &lt;br /&gt;
&lt;br /&gt;
This is especially true for running programs [[OS - Phidget SBC#Running a Program Automatically| automatically at scheduled times on the Single Board Computer]], where you would be replacing Phidgets without the benefit of keyboard or screen. &lt;br /&gt;
&lt;br /&gt;
For example, in Java (note for Enumerations you also need to include {{Code|java.util.*}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  Manager manager;&lt;br /&gt;
  manager = new Manager();&lt;br /&gt;
  try {&lt;br /&gt;
      manager.open();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  Thread.sleep(1000);&lt;br /&gt;
&lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  Vector phidgetList = manager.getPhidgets();&lt;br /&gt;
&lt;br /&gt;
  // Use an enumeration to iterate over the vector&lt;br /&gt;
  // Vectors also have iterators in Java 2&lt;br /&gt;
  Enumeration phidgetListEnum = phidgetList.elements();&lt;br /&gt;
  while(phidgetListEnum.hasMoreElements()) { &lt;br /&gt;
      Phidget phidgetElement = (Phidget)phidgetListEnum.nextElement();&lt;br /&gt;
      System.out.print(phidgetElement.getDeviceName() + &amp;quot;, &amp;quot;); &lt;br /&gt;
      System.out.println(phidgetElement.getSerialNumber()); &lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Close the manager &lt;br /&gt;
  try {&lt;br /&gt;
      manager.close();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
  manager = null;&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C (note for sleep you also need to include {{Code|unistd.h}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  CPhidgetManagerHandle manager = 0;&lt;br /&gt;
  CPhidgetManager_create(&amp;amp;manager);&lt;br /&gt;
  CPhidgetManager_open((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  sleep(1);&lt;br /&gt;
    &lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  CPhidgetHandle* phidgetList;&lt;br /&gt;
  int count;&lt;br /&gt;
    &lt;br /&gt;
  CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) manager, &amp;amp;phidgetList, &amp;amp;count);&lt;br /&gt;
    &lt;br /&gt;
  int serialNumber;&lt;br /&gt;
  const char *name;&lt;br /&gt;
    &lt;br /&gt;
  // Iterate over the returned Phidget data&lt;br /&gt;
  int i;&lt;br /&gt;
  for (i = 0; i &amp;lt; count; i++) {&lt;br /&gt;
      CPhidget_getDeviceName(phidgetList[i], &amp;amp;name);&lt;br /&gt;
      CPhidget_getSerialNumber(phidgetList[i], &amp;amp;serialNumber);&lt;br /&gt;
      printf(&amp;quot;%s, %d\n&amp;quot;, name, serialNumber);&lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Use the Phidget API to free the memory in the phidgetList Array    &lt;br /&gt;
  CPhidgetManager_freeAttachedDevicesArray(phidgetList);&lt;br /&gt;
&lt;br /&gt;
  // Close the manager    &lt;br /&gt;
  CPhidgetManager_close((CPhidgetManagerHandle) manager);&lt;br /&gt;
  CPhidgetManager_delete((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Distinguishing Events====&lt;br /&gt;
&lt;br /&gt;
If you are using [[#Event Driven Code|event-driven code]], once you have correctly opened multiple Phidgets of different types, they will have different event handlers and hence you will know what Phidget triggered which event.  &lt;br /&gt;
If you are using multiple Phidgets of the same type, or you are trying to determine within general events (such as Attach Events) which Phidget triggered the event, you can then check the serial number (or device type) of the triggering device and act accordingly.  &lt;br /&gt;
&lt;br /&gt;
For example, in Java, your [[General Phidget Programming#Event Attachment|attach event handler]] might look like this:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
    detachHandler = new DetachListener() { &lt;br /&gt;
        public void detached(DetachEvent event) {&lt;br /&gt;
            int serialNumber = ((Phidget)event.getSource()).getSerialNumber();&lt;br /&gt;
            // Do something according to serialNumber&lt;br /&gt;
    }    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
    int AttachHandler(CPhidgetHandle device, void *userptr) {&lt;br /&gt;
	int serialNo;&lt;br /&gt;
	CPhidget_getSerialNumber(device, &amp;amp;serialNo);&lt;br /&gt;
         // Do something according to serialNumber&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Phidgets over a Network===&lt;br /&gt;
&lt;br /&gt;
Control of a Phidget over a network uses the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
We have an in-depth description of the WebService, with images to illustrate its use, on the main [[Phidget WebService]] page.&lt;br /&gt;
&lt;br /&gt;
In the code on the remote computer where you are receiving Phidget data and controlling the Phidget, you would simply use a different open call, and then the Phidget software object will work as if the object were local and normal.&lt;br /&gt;
&lt;br /&gt;
The different, remote open call in C would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
int serial_number = 37299;&lt;br /&gt;
CPhidget_openRemoteIP ((CPhidgetHandle) device, serial_number, &amp;quot;127.0.0.1&amp;quot;, 5001, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simply uses the same computer in a &#039;loopback&#039; connection (127.0.0.1) and the default port 5001.  You can replace the serial number with your own Phidget&#039;s serial number.&lt;br /&gt;
&lt;br /&gt;
And in Java, the different, remote open call would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
openAny(&amp;quot;127.0.0.1&amp;quot;, 5001, null);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are other options for opening remotely, including by name rather than IP.  You can refer to the [[Software Overview#Language Support|API for your language]] for options and specific syntax.&lt;br /&gt;
&lt;br /&gt;
== Putting It Together ==&lt;br /&gt;
&lt;br /&gt;
User and device actions can be handled by either:&lt;br /&gt;
*Letting the program tell you when they happen and then doing something (&#039;&#039;&#039;event driven&#039;&#039;&#039; code)&lt;br /&gt;
*Polling for things to happen then doing something (&#039;&#039;&#039;logic&#039;&#039;&#039; code)&lt;br /&gt;
&lt;br /&gt;
The style of programming you choose (and hence the language you might prefer) would depend on what you want to do with the Phidget.  The two sections, [[#Event Driven Code|Event Driven Code]] and [[#Logic Code|Logic Code]] below give benefits, drawbacks, and general examples of each style.&lt;br /&gt;
&lt;br /&gt;
The styles can also mix.  For example, you can take a defined set of steps at first such as turning on an LED or antenna (logic code) and then doing nothing until an output change event is fired (event code).&lt;br /&gt;
&lt;br /&gt;
With languages that support both styles, you can mix and match.  For languages that support only logic code (see the [[Software Overview#Language Support|Language Support Categories]] above) you can only use the logic paradigm style.&lt;br /&gt;
&lt;br /&gt;
Examples in pseudo-code are given below for each style type so you can see how your language choice can affect your code design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logic Code ===&lt;br /&gt;
&lt;br /&gt;
Logic code has use for:&lt;br /&gt;
* Simple, single-device applications&lt;br /&gt;
* Non-GUI applications (GUIs usually are event driven)&lt;br /&gt;
* The user driving the device rather than listening to it&lt;br /&gt;
&lt;br /&gt;
Logic code is relatively easy to design well.  For example, using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, logic code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:logic.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although this design does not explicitly capture every event that fires when data or input changes, by polling the device often enough no data will be lost.&lt;br /&gt;
&lt;br /&gt;
However, logic code cannot handle constant, asynchronous events as cleanly as [[#Event Driven Code|event driven code]] can.&lt;br /&gt;
&lt;br /&gt;
These designs can be mixed.  So, if you find that in logic code you have a highly complex &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; loop driving your program, you should consider changing some of it to event driven code.  This type of awkward if-loop might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Create Device Software Object&lt;br /&gt;
  Open Device&lt;br /&gt;
&lt;br /&gt;
  Loop Until Exit Requested {&lt;br /&gt;
     if No Device Attached {&lt;br /&gt;
         Wait For Attachment until Timeout&lt;br /&gt;
         if Wait Timeout Reached {&lt;br /&gt;
             break&lt;br /&gt;
         } else { &lt;br /&gt;
             Initialize Device&lt;br /&gt;
         }&lt;br /&gt;
     } else {  // Device Is Attached&lt;br /&gt;
         if Device Data Type 1 Changed {&lt;br /&gt;
             Do Something&lt;br /&gt;
         }&lt;br /&gt;
         if Device Data Type 2 Changed {&lt;br /&gt;
             Do Something Else&lt;br /&gt;
         }&lt;br /&gt;
         // ... More data change functions here&lt;br /&gt;
     }&lt;br /&gt;
     Collect User Input&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  Close Device&lt;br /&gt;
  Delete Device&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the other hand, you can probably see that if your language does not give the option for events, you can use this structure to mimic what events would enable you to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Event Driven Code ===&lt;br /&gt;
&lt;br /&gt;
Event driven code allows for clean handling of complex, asynchronous programs:&lt;br /&gt;
*Handling multiple Phidgets&lt;br /&gt;
*Handling active plugging or unplugging of the Phidget (multiple attach and detach events)&lt;br /&gt;
*Working behind a GUI, as many GUIs are already event driven&lt;br /&gt;
*Capturing all sensor data - or input and output - without constantly polling&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Without&#039;&#039; event driven code, you will need to constantly poll the device to see if any state has changed.  If you poll at a slower rate than your input or output changes, you will not capture all data.&lt;br /&gt;
&lt;br /&gt;
However, event driven code is usually not as useful or efficient for:&lt;br /&gt;
*Only one open and close event &lt;br /&gt;
*Using only one device&lt;br /&gt;
*Having the user (or program) &#039;&#039;put&#039;&#039; changes onto the device (in contrast to reading data &#039;&#039;from&#039;&#039; the device)&lt;br /&gt;
&lt;br /&gt;
Event driven code is relatively hard to design well.  It may help to draw out a &#039;&#039;&#039;flowchart&#039;&#039;&#039;, &#039;&#039;&#039;state machine&#039;&#039;&#039;, or at least a &#039;&#039;&#039;pseudo-code outline&#039;&#039;&#039; of your system design and all events you wish to handle before writing code.&lt;br /&gt;
&lt;br /&gt;
The code examples given for each [[Software Overview#Language Support|specific language]] use events if they are supported by the language.&lt;br /&gt;
&lt;br /&gt;
Using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, event code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
[[File:event.png]]&lt;br /&gt;
&lt;br /&gt;
Once you have written this code flow, the actual order of events that occur within the program look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Eventhandler.jpg|160px]]&lt;br /&gt;
&lt;br /&gt;
Note that the device itself initiates the function call, by &#039;firing&#039; the event.  This allows you to update only when events fire, and capture all changes, because the low-level interface is telling you when a change occurs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Advanced Concepts==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, there are other useful concepts which will help you design your code to be persistent and stable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Logging===&lt;br /&gt;
&lt;br /&gt;
You can enable logging to get more debugging information.  Turning on logging happens through a Phidget API function.  This would happen at the very start of your program, before even initializing your software object or opening it.  Logging lets you get feedback from the Phidget libraries about every Phidget API call you make.&lt;br /&gt;
&lt;br /&gt;
In C, turning on logging to the command line would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  CPhidget_enableLogging(PHIDGET_LOG_DEBUG, NULL);&lt;br /&gt;
&lt;br /&gt;
  //... All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  CPhidget_disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  enableLogging(PHIDGET_LOG_DEBUG, null);&lt;br /&gt;
&lt;br /&gt;
  //...All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The use of null is to indicate that the output is not to a file (and hence to the command line).  Otherwise, the second argument would be a string filename.&lt;br /&gt;
&lt;br /&gt;
There are six different logging levels, ranging from &amp;quot;Give me Everything!&amp;quot; to &amp;quot;Tell me only about critical problems&amp;quot;.  The level in the examples above - &#039;&#039;&#039;&amp;lt;code&amp;gt;PHIDGET_LOG_DEBUG&amp;lt;/code&amp;gt;&#039;&#039;&#039; - is a medium output level.  For more information about each level and what it gives you, see the API for [[Software Overview#Language Support|your specific language]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Threading===&lt;br /&gt;
&lt;br /&gt;
Due to the use of events, the Phidget library uses threading extensively.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
* Calling &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; starts a central thread. &lt;br /&gt;
* Closing everything will shut that central thread down (before the final close returns). &lt;br /&gt;
* Each device, once attached, starts its own read and write threads. &lt;br /&gt;
&lt;br /&gt;
These threads provide the support to perform your typical [[#The Basic Functions|Basic Functions]]:&lt;br /&gt;
&lt;br /&gt;
* Triggering of data events come from the context of a device read thread. &lt;br /&gt;
* Attach and detach events come from the context of the central thread.&lt;br /&gt;
* The central thread looks for device attaches and detached, keeping track of which devices are attached internally, and sending out attach and detach events to Phidgets and Managers.&lt;br /&gt;
* Writes are performed asynchronously by the write thread. The write queue is only 1 deep so calling a write function while there is a write pending will block.&lt;br /&gt;
&lt;br /&gt;
All Phidget libraries are &#039;&#039;&#039;thread safe&#039;&#039;&#039;, so you don’t need to do any locking on the Phidget objects.  If you have a GUI, however, or another program with a separate thread, make sure to use one thread for events, and a separate thread with your GUI, and some form of mutual exclusion if they are both writing to the same thing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Exceptions and Errors===&lt;br /&gt;
&lt;br /&gt;
There are two different types of errors that you can use to confirm that your program is running correctly.&lt;br /&gt;
&lt;br /&gt;
====One: An error generated by a function call====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by &#039;&#039;you&#039;&#039; calling a function.  For example, you might try to read analog sensor port number 150 on a board that only has eight.  The function you used to read port 150 would return an error (in C/C++) or throw an error (in languages that support exceptions like Java, .NET, Python, or AS3).  &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;synchronously&#039;&#039; to function calls, that is, they are returned or thrown right after a function returns.  You can handle these by checking the return values on your functions (in C/C++) or using an error catching method like &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; in languages that support exceptions (e.g., Java, .NET, Python, AS3).&lt;br /&gt;
&lt;br /&gt;
For example, in C, you might write a LocalErrorCatcher function that you can then use on every Phidget function call to detect and deal with errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int LocalErrorCatcher (int errorCode) {&lt;br /&gt;
&lt;br /&gt;
      if (errorCode != 0) {  // Everything is okay if errorCode = 0&lt;br /&gt;
    &lt;br /&gt;
          switch (errorCode) {&lt;br /&gt;
             default:&lt;br /&gt;
               const char *errorDescription;&lt;br /&gt;
               LocalErrorCatcher(&lt;br /&gt;
                   CPhidget_getErrorDescription (errorCode, &amp;amp;errorDescription));&lt;br /&gt;
               printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
               break;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // ... Then, later, you would use it on any Phidget function:&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_open((CPhidgetHandle) device, -1));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
# The function LocalErrorCatcher uses itself to check for errors on getting an error description.  &lt;br /&gt;
# You can handle individual error codes as they are listed in the API.  This only prints a general message.&lt;br /&gt;
&lt;br /&gt;
Or in Java, you would try a Phidget function call, and catch any resulting exception that occurs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
      device.openAny();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, you could also use a &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; statement around the exception.getErrorNumber() and exception.getDescription() functions to catch any errors from those calls.&lt;br /&gt;
&lt;br /&gt;
The consequences of not catching this type of error (on &#039;&#039;every&#039;&#039; function) differ by programming language.&lt;br /&gt;
In C/C++ these errors must be &#039;&#039;explicitly&#039;&#039; checked for after each function call, otherwise the program will simply continue on in an incorrect state.  In languages that support exceptions (e.g., Java, .NET, Python, AS3), errors are returned using exceptions which will leave you no choice but to catch them, or have your program terminate without warning.&lt;br /&gt;
&lt;br /&gt;
====Two: An error generated by an event====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by the Phidget library during runtime.  For example, the Phidget device might be experiencing too high a temperature, and trigger an error.  This would not necessarily be due to any one function your program called; rather, the error would appear when the problem appears and would trigger an event. &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;asynchronously&#039;&#039;, that is, something happens apart from any function calls and an error event is triggered. You can handle these by setting up an Error Event Handler.&lt;br /&gt;
&lt;br /&gt;
In C, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int ErrorEventHandler (CPhidgetHandle device, void *usrptr, int errorCode, const char *errorDescription) {&lt;br /&gt;
    printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
    // Do something useful based on the error code&lt;br /&gt;
    return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Actually hook the Error Event Handler in to receive events&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_set_OnError_Handler((CPhidgetHandle) device, LibraryErrorHandler, NULL));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the &#039;&#039;&#039;LibraryErrorHandler&#039;&#039;&#039; function is what gets called when an error event occurs, and it gives you an opportunity to handle the error.  &lt;br /&gt;
&lt;br /&gt;
You&#039;ll also note that there is a second function called &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039;.  This second function handles the return value from setting the  error handler.  We included it here because, as these are examples on how to handle errors, the example would leave a possibly unhandled error without it. This second type of error handling  and the &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039; function are [[#One: An error generated by a function call|described above]].&lt;br /&gt;
&lt;br /&gt;
In Java, it would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
    device.addErrorListener(new ErrorListener() {&lt;br /&gt;
        public void error(ErrorEvent event) {&lt;br /&gt;
            System.out.println(event);&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, the act of hooking an error listener in to the device can itself generate an error, which should be caught.  &lt;br /&gt;
&lt;br /&gt;
These event-type errors are also how a Phidget being run over a network announces bad passwords, lost packets, and other network problems.  Locally, the errors can announce incorrect temperatures, current, and power. So, it is in your best interest to set up an error event handler and take action based on the codes and error types in the API [[Software Overview#Language Support|for your programming language]].&lt;br /&gt;
&lt;br /&gt;
See the API for your [[Software Overview#Language Support|specific programming language]] for error code documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Sensitivity and Filtering===&lt;br /&gt;
&lt;br /&gt;
Change Triggers are used to filter the number of events that are returned to an Application, by setting a minimum amount of activity before a Change Event is sent to your program. &lt;br /&gt;
&lt;br /&gt;
This is a simple hysteresis - a minimum amount of change has to occur since the last event before another event will be fired. &lt;br /&gt;
&lt;br /&gt;
If your application is implementing its own filtering, setting the ChangeTrigger, or &#039;&#039;&#039;sensitivity&#039;&#039;&#039; to zero will cause all events to fire. Change triggers are generally available only for sensor inputs events. Change triggers are referred to as &#039;&#039;Sensitivity&#039;&#039; in some device-specific APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Data Rate===&lt;br /&gt;
&lt;br /&gt;
Some devices support a user-defined data rate for events.  &lt;br /&gt;
&lt;br /&gt;
* The data rate is set in milliseconds, with a range from up 1ms to 1000ms, depending on the Phidget. &lt;br /&gt;
* Data rates greater then 8ms generally need to be a multiple of 8 (8,16,24,...,496,...,996,1000). &lt;br /&gt;
* Data rates lower then 8ms are supported as: 4ms, 2ms, 1ms. &lt;br /&gt;
* Data rate is a maximum rate &lt;br /&gt;
* Data rate will be superseded by a non-zero sensitivity on devices that support both sensitivity and data rate. &lt;br /&gt;
&lt;br /&gt;
See the main page for your device - found on its product page on [{{SERVER}} our main website] for more details on available data rates and specifications.&lt;br /&gt;
&lt;br /&gt;
Note that this data rate &#039;&#039;&#039;is not the rate at which you will receive data&#039;&#039;&#039;.  Rather, it is the amount of time over which events are averaged before being sent.  It may help to think of our specification of data rate as an &#039;&#039;averaging time&#039;&#039;.  This means that setting a data rate of 24 ms will try to give you data averaged over 24 ms, and send it every 24 ms.  Depending on your computer, events may or may not be dropped.  If events are dropped, the data points that are received still represent 24 ms (or whatever the data rate is set to).  This means data is lost.  &lt;br /&gt;
&lt;br /&gt;
Conversely, if you are [[#Logic Code|polling]], and you set the data rate to longer than your polling rate, you will receive duplicate, averaged data.  For example, setting the data rate to 24 ms and then polling every 12 ms will give you duplicate readings every other poll.  To poll and not miss any data, the rate that your code polls must match the rate that you set for the {{Code|setDataRate()}} function in our API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using the Dictionary===&lt;br /&gt;
&lt;br /&gt;
The Phidget Dictionary is a service provided by the Phidget WebService.   The dictionary:&lt;br /&gt;
* Is a centralized collection of key-value pairs &lt;br /&gt;
* Works only over the webservice&lt;br /&gt;
* Can be accessed and changed from any number of webservice clients&lt;br /&gt;
* Makes use of extended regular expressions (denoted between two forward slashes) for key matching&lt;br /&gt;
* Is also a foundation part of the webservice itself, and controls access of all Phidgets through the {{Code|openRemote}} and {{Code|openRemoteIP}} interfaces &lt;br /&gt;
* Can be used as an abstracted or higher-level interface for remotely managing Phidgets&lt;br /&gt;
&lt;br /&gt;
We have a more in-depth description of the Dictionary (with pictures) on the main [[Phidget Dictionary]] page.&lt;br /&gt;
&lt;br /&gt;
The intended use for the dictionary is as a central repository for communication and persistent storage of data between several client applications. For example, the computer directly connected to a Phidget could create and change keys for additional events on top of (or even instead of) those already thrown by the Phidget device API.  The dictionary API is very high-level and thus very flexible - essentially any application of adding keys, changing keys (and throwing events), and getting values of keys can be handled by the Dictionary.&lt;br /&gt;
&lt;br /&gt;
Note that you should never add or modify a key that starts with {{Code|/PSK/}} or {{Code|/PCK/}} as these are the keys that Phidgets use.  Unless, of course, you want to explicitly modify Phidget specific data - and this is highly discouraged, as it’s very easy to break things. Listening to these keys is fine if so desired.&lt;br /&gt;
&lt;br /&gt;
Refer to the API [[Software Overview#Language Support|for your specific language]] for the full Dictionary API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Long Term Code Maintenance===&lt;br /&gt;
&lt;br /&gt;
Thinking long term from the start is incredibly useful.  Phidgets as a company is constantly developing and inventing, and our API gets improved and changed to still work with older devices while adding support for new ones.  &lt;br /&gt;
&lt;br /&gt;
We release library updates - both for operating systems and languages - on a regular basis.  We &#039;&#039;&#039;strongly&#039;&#039;&#039; recommend updating your own libraries as we release them.  This goes for both the libraries and the WebService, as the versions must match.  &lt;br /&gt;
&lt;br /&gt;
This form of updating (did we mention that we strongly recommend it?) is the single most important thing you can do to reduce maintenance issues with your Phidget software down the road.&lt;br /&gt;
&lt;br /&gt;
Every so often, customers come to us having run the same code for years, without updating.  Then, for some reason, they have to update (say, for an operating system migration).  And their code no longer works. What do to then?  We can work with these customers to find out which of the many updates was the one to cause the problem - a difficult and very time consuming process.  And over the course of multiple years, we may no longer stock or even manufacture that particular Phidget.  You can imagine that a process with these limitations can take a very long time to resolve, if it can be resolved at all.&lt;br /&gt;
&lt;br /&gt;
Conversely, if you update every time, this time frame is greatly reduced.  We make a serious effort to test every library update, and although some backwards-compatibility problems do (rarely) get through, we have a fresh memory of what was changed and can work with you to quickly either debug the new libraries or get you a working version.&lt;br /&gt;
&lt;br /&gt;
In addition to library updates, here are a few other tips and tricks to reduce your maintenance time:&lt;br /&gt;
* If you are using [[#Logging|Logging]], don&#039;t remove the logging code when you finalize your release.  Simply comment it out so you can turn it on again later and debug quickly.&lt;br /&gt;
* Some long-term problems can be detected early by listening to library messages and errors.  Handling [[#Exceptions and Errors|Exceptions and Errors]] will allow your code to run silently until something is wrong, in which case you&#039;ll know right away.&lt;br /&gt;
&lt;br /&gt;
If you are looking for more help on how to work with our library updating, please feel welcome to [[Contact Us|contact us]].&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
This page has gone through [[#The Basic Functions|basic]] to [[#Advanced Concepts|advanced]] uses of the Phidget API.  We&#039;ve used C and Java here as example languages.  If you&#039;re using a different language, we include similar snippets of code (without the in-depth description) in the documentation [[Software Overview#Language Support|for your language]].&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve read this far and are still hungry for more, try learning more about your hardware; we have a number of [[:Category:Primer|hardware learning pages]] as well.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20672</id>
		<title>General Phidget Programming</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20672"/>
		<updated>2012-06-29T17:46:52Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Do Things with the Phidget */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Overview]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page presents the general &#039;&#039;&#039;concepts&#039;&#039;&#039; needed to write code for a Phidget.&lt;br /&gt;
&lt;br /&gt;
By this point, you should have installed the drivers for your [[Software Overview#Operating System Support|operating system]] and the libraries for your [[Software Overview#Language Support|specific programming language]].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Basic Functions==&lt;br /&gt;
&lt;br /&gt;
To use your Phidget within code, you&#039;ll want to:&lt;br /&gt;
# Create a Phidget [[#Creating a Software Object|software &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], which gives you access to the functions specific to that device&lt;br /&gt;
# [[#Opening the Phidget|Open the Phidget]] using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Detect when a [[#Attaching the Phidget|Phidget is attached]] (plugged in) by using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Use [[#Do Things with the Phidget|functions that the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt; provides]], like turning on LEDs, reading sensors, triggering events on data change, etc&lt;br /&gt;
# [[#Close the Phidget|Close the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], when you are done&lt;br /&gt;
&lt;br /&gt;
Small code snippets are provided for each step below.  [[Language - C/C++|C++]] and [[Language - Java|Java]] were selected because Java is a relatively high-level language and C++ is a relatively low level language, thereby showing how specific each language API really is.  So, the most useful resource for the &#039;&#039;actual functions&#039;&#039; would be the API for [[Software Overview#Language Support | your specific language]].  This page is a high-level introduction, by design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Software Object ===&lt;br /&gt;
&lt;br /&gt;
Phidget devices are controlled using software objects.  All software device objects have a common API and set of functions that allow you to &#039;&#039;&#039;open&#039;&#039;&#039; it, &#039;&#039;&#039;close&#039;&#039;&#039; it, and set a few listeners to general events such as &#039;&#039;&#039;attach&#039;&#039;&#039; (plug in), &#039;&#039;&#039;detach&#039;&#039;&#039; (unplug), and errors.  &lt;br /&gt;
&lt;br /&gt;
But when you create an actual software object, it is a software object &#039;&#039;&#039;specific&#039;&#039;&#039; to your device.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 AccelerometerPhidget device = new AccelerometerPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 CPhidgetAccelerometerHandle device = 0;&lt;br /&gt;
 CPhidgetAccelerometer_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 CPhidgetRFIDHandle device = 0;&lt;br /&gt;
 CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each software object has an API and available functions which are specific to that device.  For example, the RFID device API includes a function to turn on the RFID antenna.  The accelerometer device API includes a function to set the sensitivity on each axis.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Opening the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Phidgets can either be opened when attached directly to a computer, or they can be opened remotely using the [[Phidget WebService]].  This section deals primarily with opening Phidgets directly.&lt;br /&gt;
&lt;br /&gt;
Once you have created your [[#Creating a Software Object|software object]] for your specific type of device, you can call the &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in your language on that object.  For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, -1);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All specific language calls can be found in the API documentation located on each [[Software Overview#Language Support|individual language page]].&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in any language opens the software object for use, not the hardware itself.  Having the software &amp;quot;open&amp;quot; before the hardware means that the software can capture all events, including multiple attach (plug in) and detach (unplug) events for one &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; call.&lt;br /&gt;
&lt;br /&gt;
====Details for Open()====&lt;br /&gt;
&lt;br /&gt;
Open will return immediately once called, because it can be called even if the Phidget to be used is not attached to the system. This is known as an asynchronous call. It’s important to understand that most calls on a Phidget will fail if they are calls when the Phidget is not attached - in fact the only calls that are allowed on a detached Phidget are &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;waitForAttachment()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getAttached()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Open is also pervasive. This means that once open has been called, it will constantly try to stay attached to a Phidget. Even if the Phidget is unplugged from the computer and then plugged back in, you will simply get a Detach event, and then an Attach event. It’s a good idea to handle the Detach event in order to avoid calling the Phidget after it has detached.&lt;br /&gt;
&lt;br /&gt;
The different types of open(), such as openAny(), openRemote(), etc. can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network.  The list all of the available modes that open provides, and the syntax for your language, can be found in the API for [[Software Overview#Language Support|your specific language]].  If there are more than one of the same type of Phidget attached to a computer, and you use open() with no serial number, there is no way of knowing which Phidget will be opened first.&lt;br /&gt;
&lt;br /&gt;
If you are looking to do a remote open call, to use the [[Phidget WebService]], you usually have to change only the open() call (to a remote open call) to change your program from a locally-running one to one that can control a Phidget over the network.  We give an in-depth example of using the WebService on each of our [[Software Overview#Operating System Support|operating system pages]], we have a brief overview of the WebService (with code snippets) in the [[#Using Phidgets over a Network|Using Phidgets over a Network]] section, and we often have WebService code snippets on the [[Software Overview#Language Support|language pages]] which do not easily extend from the examples on this page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Once a Phidget is opened by an application, it cannot be opened again in another application until closed by the first.  When open and attached in software, no other programs or instances can read data from or change the Phidget. This includes it being open via the Windows Control Panel application!  The one exception is if the Phidget is controlled &#039;&#039;only&#039;&#039; over the network with the [[Phidget WebService]], and not directly.  Then, you can use multiple remote control programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attaching the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Physically, attaching a Phidget means plugging it in.  The real guts behind the &#039;attach&#039; command, however, occur within the software libraries.  The &#039;attach&#039; call is what makes the final connections between the opened software object and the corresponding thread and events.  This is why all Phidget object must be attached in software, even those that are not actually plugged in with a cable.  This includes Phidgets used remotely via our [[Phidget WebService]], it includes Interface Kits on the same board as our Single Board Computer, and it even includes the [[Phidget Manager]] software object, which is a sort of meta-Phidget from which you can [[#Using the Manager|control other Phidgets]].&lt;br /&gt;
&lt;br /&gt;
In your code, you can detect an attachment either with an &#039;&#039;&#039;event&#039;&#039;&#039; in [[#Event Driven Code|event-driven programming]], or &#039;&#039;&#039;waiting&#039;&#039;&#039; for it, in [[#Logic Code|logic programming]].  &lt;br /&gt;
&lt;br /&gt;
==== Event Attachment ====&lt;br /&gt;
&lt;br /&gt;
For example, to use an event to detect attachment in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addAttachListener(new AttachListener() {&lt;br /&gt;
      public void attached(AttachEvent ae) {&lt;br /&gt;
          System.out.println(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
          // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
  int AttachHandler (CPhidgetHandle device, void *userData) {&lt;br /&gt;
      printf(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
      // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnAttach_Handler((CPhidgetHandle) device, AttachHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both of the code snippets above do the same thing.  The function &amp;lt;code&amp;gt;AttachHandler(...)&amp;lt;/code&amp;gt; is called automatically when a device is plugged in.&lt;br /&gt;
&lt;br /&gt;
You will want to attach events (via &amp;lt;code&amp;gt;addAttachListener()&amp;lt;/code&amp;gt; above, for example) &#039;&#039;&#039;before you open the Phidget object&#039;&#039;&#039;.  Otherwise, triggered events may be lost.&lt;br /&gt;
&lt;br /&gt;
This method for using events to detect attachment can be expanded to other events and more complex control flow.  Where possible, all example code downloads from the [[Software Overview#Language Support|specific language pages]] shows event-driven programming.&lt;br /&gt;
&lt;br /&gt;
==== Wait for Attachment ====&lt;br /&gt;
&lt;br /&gt;
Waiting for attachment is a straightforward process.  Your code does not handle events, it simply waits for a device to be plugged in before moving on and doing something else.&lt;br /&gt;
&lt;br /&gt;
For example, in Java you wait for attachment on a &#039;&#039;&#039;created and open&#039;&#039;&#039; software object (called device) like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 // Wait until a device is plugged in&lt;br /&gt;
 device.waitForAttachment();&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C (again, device has been &#039;&#039;&#039;created and opened&#039;&#039;&#039;) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 int result;&lt;br /&gt;
 // Wait up to 10000 ms for a device to be plugged in&lt;br /&gt;
 if((result = CPhidget_waitForAttachment((CPhidgetHandle) device, 10000))) {&lt;br /&gt;
     // No attachment, error&lt;br /&gt;
 }&lt;br /&gt;
 // Successful attachment&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, unlike the event model above, a Phidget software object should be open before waiting for a device to be plugged in.&lt;br /&gt;
&lt;br /&gt;
=== Do Things with the Phidget ===&lt;br /&gt;
&lt;br /&gt;
After you have a [[#Creating a Software Object|properly created]] Phidget software object, you can actually call function to turn LEDs on, change output state, read data from sensors, etc.&lt;br /&gt;
&lt;br /&gt;
The thing you probably want to do with your Phidget is read data from its sensors or inputs.  This might be, say, a sensor plugged in to a [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] used in the code snippets below.  You can do this either by detecting changes via [[#Event Driven Code|event driven code]], or polling for new values via [[#Logic Code|logic code]]. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Details about data handling:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*When a Phidget is opened, its initial state will be read before it is marked as attached. This allows polling of many properties -- including some data -- even during the Attach event, and anytime afterwards.&lt;br /&gt;
&lt;br /&gt;
*Your computer can poll much faster than the Phidget can respond.  If you poll in a continuous &#039;&#039;&#039;&amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt;&#039;&#039;&#039; loop in byte code, you will probably swamp the Phidget with requests.&lt;br /&gt;
&lt;br /&gt;
*Similarly, if you set a value and then immediately read the value on the next line in your program, the Phidget may not have time to finish the set.  In our examples, we use &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements within loops.  Print functions are relatively slow; you can also use &amp;lt;code&amp;gt;wait()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;sleep()&amp;lt;/code&amp;gt; depending on your language.&lt;br /&gt;
&lt;br /&gt;
*If you are handling data using events as described below, the data event functions will fire when the device is plugged in and its initial state is read.&lt;br /&gt;
&lt;br /&gt;
*Some properties have default values, but these should not be trusted. Remember: &#039;&#039;&#039;always set&#039;&#039;&#039;, don’t rely on defaults.  Trying to read an uninitialized value with no default will result in an Exception.&lt;br /&gt;
&lt;br /&gt;
*Usually, sensor &#039;sensitivity&#039; will &#039;&#039;&#039;not&#039;&#039;&#039; be 0 (i.e. set to sense all changes) by default.  This can be good because it prevents your screen from being completely overloaded with event output.  But, depending on the sensor, it may make your sensor seem to have very high lag, and very poor sensitivity.  To capture all events, set the sensitivity to 0.&lt;br /&gt;
&lt;br /&gt;
*Often Phidgets will retain their last state unless power is lost. This can give surprising results as the previous state may not always be what you expect. For example, if you open an InterfaceKit and set an output, this output may stay set even after the Phidget is closed.&lt;br /&gt;
&lt;br /&gt;
====Capture Data Change with Events====&lt;br /&gt;
&lt;br /&gt;
To capture data changes in sensors or inputs as they happen, you need to use [[#Event Driven Code|event driven code]].&lt;br /&gt;
&lt;br /&gt;
Like defining an event function that fires [[#Event Attachment|when the Phidget is plugged in]], you can create functions that automatically run when, for example, a sensor value or input value changes.&lt;br /&gt;
&lt;br /&gt;
For example, for an Interface Kit, you can create a function that gets called when a sensor changes.  You would do this &#039;&#039;&#039;before&#039;&#039;&#039; the Phidget software object has been [[#Opening the Phidget|opened]].&lt;br /&gt;
&lt;br /&gt;
In Java, this would look like:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addSensorChangeListener(new SensorChangeListener() {&lt;br /&gt;
      public void sensorChanged(SensorChangeEvent sensorEvent) {&lt;br /&gt;
          System.out.println(&amp;quot;New Value: &amp;quot; + sensorEvent.getValue());&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int SensorChangeHandler (CPhidgetHandle device, void *userData, int boardIndex, int newValue) {&lt;br /&gt;
      printf(&amp;quot;New Value %d from sensor at location %d\n&amp;quot;, newValue, boardIndex);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnSensorChange_Handler((CPhidgetHandle) device, SensorChangeHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Poll for Data Change====&lt;br /&gt;
&lt;br /&gt;
To poll for sensor data, or output state, you usually want to look for a &#039;&#039;&#039;get...Value&#039;&#039;&#039; or &#039;&#039;&#039;get...State&#039;&#039;&#039; function available in the API for your device.  (The API can be found on the product page for your device on our [{{SERVER}} main web site].)  Then, you simply set up a loop that get the value of a sensor continuously.&lt;br /&gt;
&lt;br /&gt;
To poll your software object, the object must be [[#Opening the Phidget|open]].  This is in contrast to the event-driven method above, where all event functions are declared and attached before opening the object.&lt;br /&gt;
&lt;br /&gt;
Note that when you poll the value of a sensor or another attribute, this will probably be within a loop.  When you create this loop, the &#039;&#039;more code&#039;&#039; you have within a loop, the &#039;&#039;more slowly&#039;&#039; your loop will run, and the &#039;&#039;more slowly&#039;&#039; you will be sampling the value in practice.  This may make you lose data, as described further in the [[#Data Rate|Data Rate]] section.&lt;br /&gt;
&lt;br /&gt;
This effect is also felt with interpreted languages (Java, Python) versus purely compiled languages, as the interpreted languages sample more slowly even within an otherwise completely empty loop.&lt;br /&gt;
&lt;br /&gt;
So if you want to sample as fast as possible, and capture all of the changes that a sensor produces, you should [[#Capture Data Change with Events|capture data with event programming]].  If you choose not to use the event-driven design, you should keep the code run between polls to a minimum. This way you can sample as quickly as possible.&lt;br /&gt;
&lt;br /&gt;
These code snippets assume &amp;lt;code&amp;gt;device&amp;lt;/code&amp;gt; is an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit 8/8/8].  For example, in Java, for the Sensor at location 5 on the board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    val = device.getSensorValue(5);&lt;br /&gt;
    System.out.println(&amp;quot;Value: &amp;quot; + val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C, for the Sensor at location 5 on the Interface Kit board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;val);&lt;br /&gt;
    printf(&amp;quot;Value: %d\n&amp;quot;, val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sensors, Input, and Output====&lt;br /&gt;
&lt;br /&gt;
Often, your Phidget will be something like an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] which has either analog inputs (black plug holes), or digital inputs and outputs (green screw attachments), or often both.&lt;br /&gt;
&lt;br /&gt;
* To the analog inputs, you can attach various sensors, including sensors for temperature, humidity, light, sound, and so on.   &lt;br /&gt;
* To the digital inputs, you can attach various input devices, including switches.&lt;br /&gt;
* To the digital outputs, you can attach status tools like LEDs.&lt;br /&gt;
&lt;br /&gt;
You use these sensors in software entirely through the software object for the Phidget plugged in to your USB port.  For example, to turn off an LED at output block 1 on on an RFID tag reader, you&#039;ll want to set the output at location 1 to &amp;quot;0&amp;quot; (or false).  In C, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  CPhidgetRFIDHandle device = 0;&lt;br /&gt;
  CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the PhidgetRFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  CPhidgetRFID_setOutputState(device, 1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the RFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  device.setOutputState(1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a digital input would follow the same pattern, except you would use the getOutputState function and you would not pass the function a new output state.&lt;br /&gt;
&lt;br /&gt;
Getting an analog input is a little more complicated because:&lt;br /&gt;
# You must declare the sensor as one of two types (ratiometric or non-ratiometric)&lt;br /&gt;
#* To find out which your sensor is, read the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
# You must translate the 1-1000 reading that you get from the input into the data that you need (temperature, etc)&lt;br /&gt;
#* If the sensor comes from Phidgets, we provide a translation equation in the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
&lt;br /&gt;
Other than that, reading an analog sensor mirrors reading a digital input.  For example, to obtain the lux from the [{{SERVER}}/products.php?product_id=1127 - PrecisionLightSensor], a &#039;&#039;&#039;non-ratiometric&#039;&#039;&#039; sensor plugged into analog input 5, you would do this in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 // Change measurement to non-ratiometric style&lt;br /&gt;
 CPhidgetInterfaceKit_setRatiometric(device, 0);&lt;br /&gt;
&lt;br /&gt;
 // Get the data from analog input 5&lt;br /&gt;
 int sensorValue;&lt;br /&gt;
 CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;sensorValue);&lt;br /&gt;
&lt;br /&gt;
 // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
 int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Change measurement to non-ratiometric style&lt;br /&gt;
  device.setRatiometric(0);&lt;br /&gt;
&lt;br /&gt;
  // Get the data from analog input 5&lt;br /&gt;
  int sensorValue = getSensorValue(5);&lt;br /&gt;
&lt;br /&gt;
  // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
  int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Learning Everything You Can Do====&lt;br /&gt;
&lt;br /&gt;
The things you can do with your particular Phidget are many and varied, so we only include general concepts on this page.&lt;br /&gt;
&lt;br /&gt;
You can go one of two places for more information on what functions are available for your specific device.  We provide both documentation on the raw API for each programming language as well as a language-independent description of the calls for each device.&lt;br /&gt;
* Read the API for your [[Software Overview#Language Support| specific programming language]], available as a download on each page.&lt;br /&gt;
* Read the API overview for your hardware, which can be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
=== Close the Phidget ===&lt;br /&gt;
&lt;br /&gt;
When you are finished with the Phidget software object at the end of your program, you should close and (in some languages) delete it.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  device.close();&lt;br /&gt;
  device = null;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or, in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_close((CPhidgetHandle) device);&lt;br /&gt;
 CPhidget_delete((CPhidgetHandle) device);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt; call removes the lock that [[#Opening the Phidget|open]] put on the Phidget.  Make sure to close your object, so other software can use the Phidget!&lt;br /&gt;
&lt;br /&gt;
The close() function also makes sure the thread associated with the Phidget close properly.  Any outstanding writes will block close() until they complete, because writes are guaranteed to complete (unless a device is detached).&lt;br /&gt;
&lt;br /&gt;
Also note that a device should be put into a known state before calling close. For example, if a motor controller is driving a motor and close is called, it will continue to drive the motor even though the application has exited. This may or may not be what you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Multiple Phidgets===&lt;br /&gt;
&lt;br /&gt;
It is of course possible to use more than one Phidget within your program.  The trick lies in using a unique identifier for each one.  You can either hard-code the [[#Using the Serial Number|serial number in by hand]] (the number will be on the bottom of the board, or you can run our example code for the Phidget to obtain it on-screen), or you can use the [[#Using the Manager|Phidget Manager within your program]] to detect attached devices and return their serial numbers and Phidget types.&lt;br /&gt;
&lt;br /&gt;
====Using the Serial Number====&lt;br /&gt;
&lt;br /&gt;
Each Phidget has a unique serial number.  Using this serial number, you can use a specific [[General Phidget Programming#Opening the Phidget|open]] call to open by serial number.&lt;br /&gt;
&lt;br /&gt;
For example, in Java, this would be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open(SerialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, serialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Using the Label====&lt;br /&gt;
&lt;br /&gt;
If you want to have a human-readable way to reference your Phidget (as opposed to a serial number), or to have multiple different Phidgets of the same type with the same handle (for re-usable system code), you can use the Label feature of Phidgets.  In many development setups, you can change the label to whatever you like, get the label within your code, and open a Phidget based on its label, for any newer generation Phidget.  The disadvantage of Labels is that they are not available on all operating systems and languages.&lt;br /&gt;
&lt;br /&gt;
Some limitations are:&lt;br /&gt;
* You cannot &#039;&#039;&#039;set&#039;&#039;&#039; a label using any language in [[OS - Windows|Windows]], for any language&lt;br /&gt;
**However, you can get the label of a Phidget on Windows, and open a Phidget by its label&lt;br /&gt;
* [[Language - Android Java|Android Java]] has support for only a subset of the open() functions that use labels, see the [[Language - Android Java|Android Java language page]] for details&lt;br /&gt;
* Older Phidgets do not support labels&lt;br /&gt;
* No .COM language on Windows supports opening by Label&lt;br /&gt;
** This includes [[Language - AutoIt|AutoIt]], [[Language - Adobe Director|Adobe Director]], [[Language - Delphi|Delphi]], and all of the Visual Basic flavours.&lt;br /&gt;
* [[Language - LabVIEW|LabVIEW]] cannot open by label&lt;br /&gt;
* [[Language - Python|Python]] cannot open by label&lt;br /&gt;
* [[Language - LiveCode|LiveCode]] cannot open by label&lt;br /&gt;
&lt;br /&gt;
When opening by label, you would use the {{Code|openLabel(&amp;quot;mylabel&amp;quot;)}} function (or similar, check the [[Software Overview#Language Support|API for your language]]) rather than the generic open() function.&lt;br /&gt;
&lt;br /&gt;
Note that setting the label should be done by a separate program.  On a Mac OS computer, you can set a label through the Phidget Preference Pane.  On a Linux computer, you should write a special short program specifically for setting the label.  There are two reasons to &#039;&#039;&#039;not&#039;&#039;&#039; set a label within your main program:&lt;br /&gt;
* If you set a label every time you run that program, when not needing to, you can easily reach the 10,000 re-write limit for the flash that stores the label&lt;br /&gt;
* If you are using event driven programming, you cannot set the label from any function called from the attach event, as it will hang (on a mutual exclusion lock).&lt;br /&gt;
Because of the second point, your special program to set the label on a Phidget should use {{Code|waitForAttach()}} in [[#Logic Code|logic code]] and not [[#Event Driven Code|event-driven]] programming&lt;br /&gt;
&lt;br /&gt;
====Using the Manager====&lt;br /&gt;
&lt;br /&gt;
The Phidget Manager object can detect all Phidgets attached to a system and return their attributes in a list (or array, vector, etc. - depending on the language).  With this, you can obtain the serial numbers and types of Phidgets currently attached.  This is the preferred method for systems where you will be using multiple Phidgets and expecting the system to operate long enough (or under harsh enough conditions)  that the Phidgets would need to be replaced.  &lt;br /&gt;
&lt;br /&gt;
This is especially true for running programs [[OS - Phidget SBC#Running a Program Automatically| automatically at scheduled times on the Single Board Computer]], where you would be replacing Phidgets without the benefit of keyboard or screen. &lt;br /&gt;
&lt;br /&gt;
For example, in Java (note for Enumerations you also need to include {{Code|java.util.*}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  Manager manager;&lt;br /&gt;
  manager = new Manager();&lt;br /&gt;
  try {&lt;br /&gt;
      manager.open();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  Thread.sleep(1000);&lt;br /&gt;
&lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  Vector phidgetList = manager.getPhidgets();&lt;br /&gt;
&lt;br /&gt;
  // Use an enumeration to iterate over the vector&lt;br /&gt;
  // Vectors also have iterators in Java 2&lt;br /&gt;
  Enumeration phidgetListEnum = phidgetList.elements();&lt;br /&gt;
  while(phidgetListEnum.hasMoreElements()) { &lt;br /&gt;
      Phidget phidgetElement = (Phidget)phidgetListEnum.nextElement();&lt;br /&gt;
      System.out.print(phidgetElement.getDeviceName() + &amp;quot;, &amp;quot;); &lt;br /&gt;
      System.out.println(phidgetElement.getSerialNumber()); &lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Close the manager &lt;br /&gt;
  try {&lt;br /&gt;
      manager.close();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
  manager = null;&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C (note for sleep you also need to include {{Code|unistd.h}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  CPhidgetManagerHandle manager = 0;&lt;br /&gt;
  CPhidgetManager_create(&amp;amp;manager);&lt;br /&gt;
  CPhidgetManager_open((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  sleep(1);&lt;br /&gt;
    &lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  CPhidgetHandle* phidgetList;&lt;br /&gt;
  int count;&lt;br /&gt;
    &lt;br /&gt;
  CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) manager, &amp;amp;phidgetList, &amp;amp;count);&lt;br /&gt;
    &lt;br /&gt;
  int serialNumber;&lt;br /&gt;
  const char *name;&lt;br /&gt;
    &lt;br /&gt;
  // Iterate over the returned Phidget data&lt;br /&gt;
  int i;&lt;br /&gt;
  for (i = 0; i &amp;lt; count; i++) {&lt;br /&gt;
      CPhidget_getDeviceName(phidgetList[i], &amp;amp;name);&lt;br /&gt;
      CPhidget_getSerialNumber(phidgetList[i], &amp;amp;serialNumber);&lt;br /&gt;
      printf(&amp;quot;%s, %d\n&amp;quot;, name, serialNumber);&lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Use the Phidget API to free the memory in the phidgetList Array    &lt;br /&gt;
  CPhidgetManager_freeAttachedDevicesArray(phidgetList);&lt;br /&gt;
&lt;br /&gt;
  // Close the manager    &lt;br /&gt;
  CPhidgetManager_close((CPhidgetManagerHandle) manager);&lt;br /&gt;
  CPhidgetManager_delete((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Distinguishing Events====&lt;br /&gt;
&lt;br /&gt;
If you are using [[#Event Driven Code|event-driven code]], once you have correctly opened multiple Phidgets of different types, they will have different event handlers and hence you will know what Phidget triggered which event.  &lt;br /&gt;
If you are using multiple Phidgets of the same type, or you are trying to determine within general events (such as Attach Events) which Phidget triggered the event, you can then check the serial number (or device type) of the triggering device and act accordingly.  &lt;br /&gt;
&lt;br /&gt;
For example, in Java, your [[General Phidget Programming#Event Attachment|attach event handler]] might look like this:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
    detachHandler = new DetachListener() { &lt;br /&gt;
        public void detached(DetachEvent event) {&lt;br /&gt;
            int serialNumber = ((Phidget)event.getSource()).getSerialNumber();&lt;br /&gt;
            // Do something according to serialNumber&lt;br /&gt;
    }    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
    int AttachHandler(CPhidgetHandle device, void *userptr) {&lt;br /&gt;
	int serialNo;&lt;br /&gt;
	CPhidget_getSerialNumber(device, &amp;amp;serialNo);&lt;br /&gt;
         // Do something according to serialNumber&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Phidgets over a Network===&lt;br /&gt;
&lt;br /&gt;
Control of a Phidget over a network uses the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
We have an in-depth description of the WebService, with images to illustrate its use, on the main [[Phidget WebService]] page.&lt;br /&gt;
&lt;br /&gt;
In the code on the remote computer where you are receiving Phidget data and controlling the Phidget, you would simply use a different open call, and then the Phidget software object will work as if the object were local and normal.&lt;br /&gt;
&lt;br /&gt;
The different, remote open call in C would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
int serial_number = 37299;&lt;br /&gt;
CPhidget_openRemoteIP ((CPhidgetHandle) device, serial_number, &amp;quot;127.0.0.1&amp;quot;, 5001, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simply uses the same computer in a &#039;loopback&#039; connection (127.0.0.1) and the default port 5001.  You can replace the serial number with your own Phidget&#039;s serial number.&lt;br /&gt;
&lt;br /&gt;
And in Java, the different, remote open call would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
openAny(&amp;quot;127.0.0.1&amp;quot;, 5001, null);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are other options for opening remotely, including by name rather than IP.  You can refer to the [[Software Overview#Language Support|API for your language]] for options and specific syntax.&lt;br /&gt;
&lt;br /&gt;
== Putting It Together ==&lt;br /&gt;
&lt;br /&gt;
User and device actions can be handled by either:&lt;br /&gt;
*Letting the program tell you when they happen and then doing something (&#039;&#039;&#039;event driven&#039;&#039;&#039; code)&lt;br /&gt;
*Polling for things to happen then doing something (&#039;&#039;&#039;logic&#039;&#039;&#039; code)&lt;br /&gt;
&lt;br /&gt;
The style of programming you choose (and hence the language you might prefer) would depend on what you want to do with the Phidget.  The two sections, [[#Event Driven Code|Event Driven Code]] and [[#Logic Code|Logic Code]] below give benefits, drawbacks, and general examples of each style.&lt;br /&gt;
&lt;br /&gt;
The styles can also mix.  For example, you can take a defined set of steps at first such as turning on an LED or antenna (logic code) and then doing nothing until an output change event is fired (event code).&lt;br /&gt;
&lt;br /&gt;
With languages that support both styles, you can mix and match.  For languages that support only logic code (see the [[Software Overview#Language Support|Language Support Categories]] above) you can only use the logic paradigm style.&lt;br /&gt;
&lt;br /&gt;
Examples in pseudo-code are given below for each style type so you can see how your language choice can affect your code design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logic Code ===&lt;br /&gt;
&lt;br /&gt;
Logic code has use for:&lt;br /&gt;
* Simple, single-device applications&lt;br /&gt;
* Non-GUI applications (GUIs usually are event driven)&lt;br /&gt;
* The user driving the device rather than listening to it&lt;br /&gt;
&lt;br /&gt;
Logic code is relatively easy to design well.  For example, using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, logic code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:logic.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although this design does not explicitly capture every event that fires when data or input changes, by polling the device often enough no data will be lost.&lt;br /&gt;
&lt;br /&gt;
However, logic code cannot handle constant, asynchronous events as cleanly as [[#Event Driven Code|event driven code]] can.&lt;br /&gt;
&lt;br /&gt;
These designs can be mixed.  So, if you find that in logic code you have a highly complex &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; loop driving your program, you should consider changing some of it to event driven code.  This type of awkward if-loop might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Create Device Software Object&lt;br /&gt;
  Open Device&lt;br /&gt;
&lt;br /&gt;
  Loop Until Exit Requested {&lt;br /&gt;
     if No Device Attached {&lt;br /&gt;
         Wait For Attachment until Timeout&lt;br /&gt;
         if Wait Timeout Reached {&lt;br /&gt;
             break&lt;br /&gt;
         } else { &lt;br /&gt;
             Initialize Device&lt;br /&gt;
         }&lt;br /&gt;
     } else {  // Device Is Attached&lt;br /&gt;
         if Device Data Type 1 Changed {&lt;br /&gt;
             Do Something&lt;br /&gt;
         }&lt;br /&gt;
         if Device Data Type 2 Changed {&lt;br /&gt;
             Do Something Else&lt;br /&gt;
         }&lt;br /&gt;
         // ... More data change functions here&lt;br /&gt;
     }&lt;br /&gt;
     Collect User Input&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  Close Device&lt;br /&gt;
  Delete Device&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the other hand, you can probably see that if your language does not give the option for events, you can use this structure to mimic what events would enable you to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Event Driven Code ===&lt;br /&gt;
&lt;br /&gt;
Event driven code allows for clean handling of complex, asynchronous programs:&lt;br /&gt;
*Handling multiple Phidgets&lt;br /&gt;
*Handling active plugging or unplugging of the Phidget (multiple attach and detach events)&lt;br /&gt;
*Working behind a GUI, as many GUIs are already event driven&lt;br /&gt;
*Capturing all sensor data - or input and output - without constantly polling&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Without&#039;&#039; event driven code, you will need to constantly poll the device to see if any state has changed.  If you poll at a slower rate than your input or output changes, you will not capture all data.&lt;br /&gt;
&lt;br /&gt;
However, event driven code is usually not as useful or efficient for:&lt;br /&gt;
*Only one open and close event &lt;br /&gt;
*Using only one device&lt;br /&gt;
*Having the user (or program) &#039;&#039;put&#039;&#039; changes onto the device (in contrast to reading data &#039;&#039;from&#039;&#039; the device)&lt;br /&gt;
&lt;br /&gt;
Event driven code is relatively hard to design well.  It may help to draw out a &#039;&#039;&#039;flowchart&#039;&#039;&#039;, &#039;&#039;&#039;state machine&#039;&#039;&#039;, or at least a &#039;&#039;&#039;pseudo-code outline&#039;&#039;&#039; of your system design and all events you wish to handle before writing code.&lt;br /&gt;
&lt;br /&gt;
The code examples given for each [[Software Overview#Language Support|specific language]] use events if they are supported by the language.&lt;br /&gt;
&lt;br /&gt;
Using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, event code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
[[File:event.png]]&lt;br /&gt;
&lt;br /&gt;
Once you have written this code flow, the actual order of events that occur within the program look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Eventhandler.jpg|160px]]&lt;br /&gt;
&lt;br /&gt;
Note that the device itself initiates the function call, by &#039;firing&#039; the event.  This allows you to update only when events fire, and capture all changes, because the low-level interface is telling you when a change occurs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Advanced Concepts==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, there are other useful concepts which will help you design your code to be persistent and stable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Logging===&lt;br /&gt;
&lt;br /&gt;
You can enable logging to get more debugging information.  Turning on logging happens through a Phidget API function.  This would happen at the very start of your program, before even initializing your software object or opening it.  Logging lets you get feedback from the Phidget libraries about every Phidget API call you make.&lt;br /&gt;
&lt;br /&gt;
In C, turning on logging to the command line would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  CPhidget_enableLogging(PHIDGET_LOG_DEBUG, NULL);&lt;br /&gt;
&lt;br /&gt;
  //... All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  CPhidget_disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  enableLogging(PHIDGET_LOG_DEBUG, null);&lt;br /&gt;
&lt;br /&gt;
  //...All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The use of null is to indicate that the output is not to a file (and hence to the command line).  Otherwise, the second argument would be a string filename.&lt;br /&gt;
&lt;br /&gt;
There are six different logging levels, ranging from &amp;quot;Give me Everything!&amp;quot; to &amp;quot;Tell me only about critical problems&amp;quot;.  The level in the examples above - &#039;&#039;&#039;&amp;lt;code&amp;gt;PHIDGET_LOG_DEBUG&amp;lt;/code&amp;gt;&#039;&#039;&#039; - is a medium output level.  For more information about each level and what it gives you, see the API for [[Software Overview#Language Support|your specific language]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Threading===&lt;br /&gt;
&lt;br /&gt;
Due to the use of events, the Phidget library uses threading extensively.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
* Calling &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; starts a central thread. &lt;br /&gt;
* Closing everything will shut that central thread down (before the final close returns). &lt;br /&gt;
* Each device, once attached, starts its own read and write threads. &lt;br /&gt;
&lt;br /&gt;
These threads provide the support to perform your typical [[#The Basic Functions|Basic Functions]]:&lt;br /&gt;
&lt;br /&gt;
* Triggering of data events come from the context of a device read thread. &lt;br /&gt;
* Attach and detach events come from the context of the central thread.&lt;br /&gt;
* The central thread looks for device attaches and detached, keeping track of which devices are attached internally, and sending out attach and detach events to Phidgets and Managers.&lt;br /&gt;
* Writes are performed asynchronously by the write thread. The write queue is only 1 deep so calling a write function while there is a write pending will block.&lt;br /&gt;
&lt;br /&gt;
All Phidget libraries are &#039;&#039;&#039;thread safe&#039;&#039;&#039;, so you don’t need to do any locking on the Phidget objects.  If you have a GUI, however, or another program with a separate thread, make sure to use one thread for events, and a separate thread with your GUI, and some form of mutual exclusion if they are both writing to the same thing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Exceptions and Errors===&lt;br /&gt;
&lt;br /&gt;
There are two different types of errors that you can use to confirm that your program is running correctly.&lt;br /&gt;
&lt;br /&gt;
====One: An error generated by a function call====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by &#039;&#039;you&#039;&#039; calling a function.  For example, you might try to read analog sensor port number 150 on a board that only has eight.  The function you used to read port 150 would return an error (in C/C++) or throw an error (in languages that support exceptions like Java, .NET, Python, or AS3).  &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;synchronously&#039;&#039; to function calls, that is, they are returned or thrown right after a function returns.  You can handle these by checking the return values on your functions (in C/C++) or using an error catching method like &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; in languages that support exceptions (e.g., Java, .NET, Python, AS3).&lt;br /&gt;
&lt;br /&gt;
For example, in C, you might write a LocalErrorCatcher function that you can then use on every Phidget function call to detect and deal with errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int LocalErrorCatcher (int errorCode) {&lt;br /&gt;
&lt;br /&gt;
      if (errorCode != 0) {  // Everything is okay if errorCode = 0&lt;br /&gt;
    &lt;br /&gt;
          switch (errorCode) {&lt;br /&gt;
             default:&lt;br /&gt;
               const char *errorDescription;&lt;br /&gt;
               LocalErrorCatcher(&lt;br /&gt;
                   CPhidget_getErrorDescription (errorCode, &amp;amp;errorDescription));&lt;br /&gt;
               printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
               break;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // ... Then, later, you would use it on any Phidget function:&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_open((CPhidgetHandle) device, -1));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
# The function LocalErrorCatcher uses itself to check for errors on getting an error description.  &lt;br /&gt;
# You can handle individual error codes as they are listed in the API.  This only prints a general message.&lt;br /&gt;
&lt;br /&gt;
Or in Java, you would try a Phidget function call, and catch any resulting exception that occurs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
      device.openAny();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, you could also use a &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; statement around the exception.getErrorNumber() and exception.getDescription() functions to catch any errors from those calls.&lt;br /&gt;
&lt;br /&gt;
The consequences of not catching this type of error (on &#039;&#039;every&#039;&#039; function) differ by programming language.&lt;br /&gt;
In C/C++ these errors must be &#039;&#039;explicitly&#039;&#039; checked for after each function call, otherwise the program will simply continue on in an incorrect state.  In languages that support exceptions (e.g., Java, .NET, Python, AS3), errors are returned using exceptions which will leave you no choice but to catch them, or have your program terminate without warning.&lt;br /&gt;
&lt;br /&gt;
====Two: An error generated by an event====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by the Phidget library during runtime.  For example, the Phidget device might be experiencing too high a temperature, and trigger an error.  This would not necessarily be due to any one function your program called; rather, the error would appear when the problem appears and would trigger an event. &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;asynchronously&#039;&#039;, that is, something happens apart from any function calls and an error event is triggered. You can handle these by setting up an Error Event Handler.&lt;br /&gt;
&lt;br /&gt;
In C, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int ErrorEventHandler (CPhidgetHandle device, void *usrptr, int errorCode, const char *errorDescription) {&lt;br /&gt;
    printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
    // Do something useful based on the error code&lt;br /&gt;
    return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Actually hook the Error Event Handler in to receive events&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_set_OnError_Handler((CPhidgetHandle) device, LibraryErrorHandler, NULL));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the &#039;&#039;&#039;LibraryErrorHandler&#039;&#039;&#039; function is what gets called when an error event occurs, and it gives you an opportunity to handle the error.  &lt;br /&gt;
&lt;br /&gt;
You&#039;ll also note that there is a second function called &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039;.  This second function handles the return value from setting the  error handler.  We included it here because, as these are examples on how to handle errors, the example would leave a possibly unhandled error without it. This second type of error handling  and the &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039; function are [[#One: An error generated by a function call|described above]].&lt;br /&gt;
&lt;br /&gt;
In Java, it would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
    device.addErrorListener(new ErrorListener() {&lt;br /&gt;
        public void error(ErrorEvent event) {&lt;br /&gt;
            System.out.println(event);&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, the act of hooking an error listener in to the device can itself generate an error, which should be caught.  &lt;br /&gt;
&lt;br /&gt;
These event-type errors are also how a Phidget being run over a network announces bad passwords, lost packets, and other network problems.  Locally, the errors can announce incorrect temperatures, current, and power. So, it is in your best interest to set up an error event handler and take action based on the codes and error types in the API [[Software Overview#Language Support|for your programming language]].&lt;br /&gt;
&lt;br /&gt;
See the API for your [[Software Overview#Language Support|specific programming language]] for error code documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Sensitivity and Filtering===&lt;br /&gt;
&lt;br /&gt;
Change Triggers are used to filter the number of events that are returned to an Application, by setting a minimum amount of activity before a Change Event is sent to your program. &lt;br /&gt;
&lt;br /&gt;
This is a simple hysteresis - a minimum amount of change has to occur since the last event before another event will be fired. &lt;br /&gt;
&lt;br /&gt;
If your application is implementing its own filtering, setting the ChangeTrigger, or &#039;&#039;&#039;sensitivity&#039;&#039;&#039; to zero will cause all events to fire. Change triggers are generally available only for sensor inputs events. Change triggers are referred to as &#039;&#039;Sensitivity&#039;&#039; in some device-specific APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Data Rate===&lt;br /&gt;
&lt;br /&gt;
Some devices support a user-defined data rate for events.  &lt;br /&gt;
&lt;br /&gt;
* The data rate is set in milliseconds, with a range from up 1ms to 1000ms, depending on the Phidget. &lt;br /&gt;
* Data rates greater then 8ms generally need to be a multiple of 8 (8,16,24,...,496,...,996,1000). &lt;br /&gt;
* Data rates lower then 8ms are supported as: 4ms, 2ms, 1ms. &lt;br /&gt;
* Data rate is a maximum rate &lt;br /&gt;
* Data rate will be superseded by a non-zero sensitivity on devices that support both sensitivity and data rate. &lt;br /&gt;
&lt;br /&gt;
See the main page for your device - found on its product page on [{{SERVER}} our main website] for more details on available data rates and specifications.&lt;br /&gt;
&lt;br /&gt;
Note that this data rate &#039;&#039;&#039;is not the rate at which you will receive data&#039;&#039;&#039;.  Rather, it is the amount of time over which events are averaged before being sent.  It may help to think of our specification of data rate as an &#039;&#039;averaging time&#039;&#039;.  This means that setting a data rate of 24 ms will try to give you data averaged over 24 ms, and send it every 24 ms.  Depending on your computer, events may or may not be dropped.  If events are dropped, the data points that are received still represent 24 ms (or whatever the data rate is set to).  This means data is lost.  &lt;br /&gt;
&lt;br /&gt;
Conversely, if you are [[#Logic Code|polling]], and you set the data rate to longer than your polling rate, you will receive duplicate, averaged data.  For example, setting the data rate to 24 ms and then polling every 12 ms will give you duplicate readings every other poll.  To poll and not miss any data, the rate that your code polls must match the rate that you set for the {{Code|setDataRate()}} function in our API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using the Dictionary===&lt;br /&gt;
&lt;br /&gt;
The Phidget Dictionary is a service provided by the Phidget WebService.   The dictionary:&lt;br /&gt;
* Is a centralized collection of key-value pairs &lt;br /&gt;
* Works only over the webservice&lt;br /&gt;
* Can be accessed and changed from any number of webservice clients&lt;br /&gt;
* Makes use of extended regular expressions (denoted between two forward slashes) for key matching&lt;br /&gt;
* Is also a foundation part of the webservice itself, and controls access of all Phidgets through the {{Code|openRemote}} and {{Code|openRemoteIP}} interfaces &lt;br /&gt;
* Can be used as an abstracted or higher-level interface for remotely managing Phidgets&lt;br /&gt;
&lt;br /&gt;
We have a more in-depth description of the Dictionary (with pictures) on the main [[Phidget Dictionary]] page.&lt;br /&gt;
&lt;br /&gt;
The intended use for the dictionary is as a central repository for communication and persistent storage of data between several client applications. For example, the computer directly connected to a Phidget could create and change keys for additional events on top of (or even instead of) those already thrown by the Phidget device API.  The dictionary API is very high-level and thus very flexible - essentially any application of adding keys, changing keys (and throwing events), and getting values of keys can be handled by the Dictionary.&lt;br /&gt;
&lt;br /&gt;
Note that you should never add or modify a key that starts with {{Code|/PSK/}} or {{Code|/PCK/}} as these are the keys that Phidgets use.  Unless, of course, you want to explicitly modify Phidget specific data - and this is highly discouraged, as it’s very easy to break things. Listening to these keys is fine if so desired.&lt;br /&gt;
&lt;br /&gt;
Refer to the API [[Software Overview#Language Support|for your specific language]] for the full Dictionary API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Long Term Code Maintenance===&lt;br /&gt;
&lt;br /&gt;
Thinking long term from the start is incredibly useful.  Phidgets as a company is constantly developing and inventing, and our API gets improved and changed to still work with older devices while adding support for new ones.  &lt;br /&gt;
&lt;br /&gt;
We release library updates - both for operating systems and languages - on a regular basis.  We &#039;&#039;&#039;strongly&#039;&#039;&#039; recommend updating your own libraries as we release them.  This goes for both the libraries and the WebService, as the versions must match.  &lt;br /&gt;
&lt;br /&gt;
This form of updating (did we mention that we strongly recommend it?) is the single most important thing you can do to reduce maintenance issues with your Phidget software down the road.&lt;br /&gt;
&lt;br /&gt;
Every so often, customers come to us having run the same code for years, without updating.  Then, for some reason, they have to update (say, for an operating system migration).  And their code no longer works. What do to then?  We can work with these customers to find out which of the many updates was the one to cause the problem - a difficult and very time consuming process.  And over the course of multiple years, we may no longer stock or even manufacture that particular Phidget.  You can imagine that a process with these limitations can take a very long time to resolve, if it can be resolved at all.&lt;br /&gt;
&lt;br /&gt;
Conversely, if you update every time, this time frame is greatly reduced.  We make a serious effort to test every library update, and although some backwards-compatibility problems do (rarely) get through, we have a fresh memory of what was changed and can work with you to quickly either debug the new libraries or get you a working version.&lt;br /&gt;
&lt;br /&gt;
In addition to library updates, here are a few other tips and tricks to reduce your maintenance time:&lt;br /&gt;
* If you are using [[#Logging|Logging]], don&#039;t remove the logging code when you finalize your release.  Simply comment it out so you can turn it on again later and debug quickly.&lt;br /&gt;
* Some long-term problems can be detected early by listening to library messages and errors.  Handling [[#Exceptions and Errors|Exceptions and Errors]] will allow your code to run silently until something is wrong, in which case you&#039;ll know right away.&lt;br /&gt;
&lt;br /&gt;
If you are looking for more help on how to work with our library updating, please feel welcome to [[Contact Us|contact us]].&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
This page has gone through [[#The Basic Functions|basic]] to [[#Advanced Concepts|advanced]] uses of the Phidget API.  We&#039;ve used C and Java here as example languages.  If you&#039;re using a different language, we include similar snippets of code (without the in-depth description) in the documentation [[Software Overview#Language Support|for your language]].&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve read this far and are still hungry for more, try learning more about your hardware; we have a number of [[Primers|high level teaching pages]] about hardware as well.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20671</id>
		<title>General Phidget Programming</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=General_Phidget_Programming&amp;diff=20671"/>
		<updated>2012-06-29T17:45:05Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Overview]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page presents the general &#039;&#039;&#039;concepts&#039;&#039;&#039; needed to write code for a Phidget.&lt;br /&gt;
&lt;br /&gt;
By this point, you should have installed the drivers for your [[Software Overview#Operating System Support|operating system]] and the libraries for your [[Software Overview#Language Support|specific programming language]].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Basic Functions==&lt;br /&gt;
&lt;br /&gt;
To use your Phidget within code, you&#039;ll want to:&lt;br /&gt;
# Create a Phidget [[#Creating a Software Object|software &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], which gives you access to the functions specific to that device&lt;br /&gt;
# [[#Opening the Phidget|Open the Phidget]] using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Detect when a [[#Attaching the Phidget|Phidget is attached]] (plugged in) by using the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;&lt;br /&gt;
# Use [[#Do Things with the Phidget|functions that the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt; provides]], like turning on LEDs, reading sensors, triggering events on data change, etc&lt;br /&gt;
# [[#Close the Phidget|Close the &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt;]], when you are done&lt;br /&gt;
&lt;br /&gt;
Small code snippets are provided for each step below.  [[Language - C/C++|C++]] and [[Language - Java|Java]] were selected because Java is a relatively high-level language and C++ is a relatively low level language, thereby showing how specific each language API really is.  So, the most useful resource for the &#039;&#039;actual functions&#039;&#039; would be the API for [[Software Overview#Language Support | your specific language]].  This page is a high-level introduction, by design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Software Object ===&lt;br /&gt;
&lt;br /&gt;
Phidget devices are controlled using software objects.  All software device objects have a common API and set of functions that allow you to &#039;&#039;&#039;open&#039;&#039;&#039; it, &#039;&#039;&#039;close&#039;&#039;&#039; it, and set a few listeners to general events such as &#039;&#039;&#039;attach&#039;&#039;&#039; (plug in), &#039;&#039;&#039;detach&#039;&#039;&#039; (unplug), and errors.  &lt;br /&gt;
&lt;br /&gt;
But when you create an actual software object, it is a software object &#039;&#039;&#039;specific&#039;&#039;&#039; to your device.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 AccelerometerPhidget device = new AccelerometerPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new Accelerometer object&lt;br /&gt;
 CPhidgetAccelerometerHandle device = 0;&lt;br /&gt;
 CPhidgetAccelerometer_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 // Create a new RFID device object&lt;br /&gt;
 CPhidgetRFIDHandle device = 0;&lt;br /&gt;
 CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each software object has an API and available functions which are specific to that device.  For example, the RFID device API includes a function to turn on the RFID antenna.  The accelerometer device API includes a function to set the sensitivity on each axis.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Opening the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Phidgets can either be opened when attached directly to a computer, or they can be opened remotely using the [[Phidget WebService]].  This section deals primarily with opening Phidgets directly.&lt;br /&gt;
&lt;br /&gt;
Once you have created your [[#Creating a Software Object|software object]] for your specific type of device, you can call the &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in your language on that object.  For example, in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, -1);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All specific language calls can be found in the API documentation located on each [[Software Overview#Language Support|individual language page]].&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; function in any language opens the software object for use, not the hardware itself.  Having the software &amp;quot;open&amp;quot; before the hardware means that the software can capture all events, including multiple attach (plug in) and detach (unplug) events for one &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; call.&lt;br /&gt;
&lt;br /&gt;
====Details for Open()====&lt;br /&gt;
&lt;br /&gt;
Open will return immediately once called, because it can be called even if the Phidget to be used is not attached to the system. This is known as an asynchronous call. It’s important to understand that most calls on a Phidget will fail if they are calls when the Phidget is not attached - in fact the only calls that are allowed on a detached Phidget are &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;waitForAttachment()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getAttached()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Open is also pervasive. This means that once open has been called, it will constantly try to stay attached to a Phidget. Even if the Phidget is unplugged from the computer and then plugged back in, you will simply get a Detach event, and then an Attach event. It’s a good idea to handle the Detach event in order to avoid calling the Phidget after it has detached.&lt;br /&gt;
&lt;br /&gt;
The different types of open(), such as openAny(), openRemote(), etc. can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network.  The list all of the available modes that open provides, and the syntax for your language, can be found in the API for [[Software Overview#Language Support|your specific language]].  If there are more than one of the same type of Phidget attached to a computer, and you use open() with no serial number, there is no way of knowing which Phidget will be opened first.&lt;br /&gt;
&lt;br /&gt;
If you are looking to do a remote open call, to use the [[Phidget WebService]], you usually have to change only the open() call (to a remote open call) to change your program from a locally-running one to one that can control a Phidget over the network.  We give an in-depth example of using the WebService on each of our [[Software Overview#Operating System Support|operating system pages]], we have a brief overview of the WebService (with code snippets) in the [[#Using Phidgets over a Network|Using Phidgets over a Network]] section, and we often have WebService code snippets on the [[Software Overview#Language Support|language pages]] which do not easily extend from the examples on this page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Once a Phidget is opened by an application, it cannot be opened again in another application until closed by the first.  When open and attached in software, no other programs or instances can read data from or change the Phidget. This includes it being open via the Windows Control Panel application!  The one exception is if the Phidget is controlled &#039;&#039;only&#039;&#039; over the network with the [[Phidget WebService]], and not directly.  Then, you can use multiple remote control programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attaching the Phidget ===&lt;br /&gt;
&lt;br /&gt;
Physically, attaching a Phidget means plugging it in.  The real guts behind the &#039;attach&#039; command, however, occur within the software libraries.  The &#039;attach&#039; call is what makes the final connections between the opened software object and the corresponding thread and events.  This is why all Phidget object must be attached in software, even those that are not actually plugged in with a cable.  This includes Phidgets used remotely via our [[Phidget WebService]], it includes Interface Kits on the same board as our Single Board Computer, and it even includes the [[Phidget Manager]] software object, which is a sort of meta-Phidget from which you can [[#Using the Manager|control other Phidgets]].&lt;br /&gt;
&lt;br /&gt;
In your code, you can detect an attachment either with an &#039;&#039;&#039;event&#039;&#039;&#039; in [[#Event Driven Code|event-driven programming]], or &#039;&#039;&#039;waiting&#039;&#039;&#039; for it, in [[#Logic Code|logic programming]].  &lt;br /&gt;
&lt;br /&gt;
==== Event Attachment ====&lt;br /&gt;
&lt;br /&gt;
For example, to use an event to detect attachment in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addAttachListener(new AttachListener() {&lt;br /&gt;
      public void attached(AttachEvent ae) {&lt;br /&gt;
          System.out.println(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
          // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
  int AttachHandler (CPhidgetHandle device, void *userData) {&lt;br /&gt;
      printf(&amp;quot;A new device has been plugged in!&amp;quot;);&lt;br /&gt;
      // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnAttach_Handler((CPhidgetHandle) device, AttachHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both of the code snippets above do the same thing.  The function &amp;lt;code&amp;gt;AttachHandler(...)&amp;lt;/code&amp;gt; is called automatically when a device is plugged in.&lt;br /&gt;
&lt;br /&gt;
You will want to attach events (via &amp;lt;code&amp;gt;addAttachListener()&amp;lt;/code&amp;gt; above, for example) &#039;&#039;&#039;before you open the Phidget object&#039;&#039;&#039;.  Otherwise, triggered events may be lost.&lt;br /&gt;
&lt;br /&gt;
This method for using events to detect attachment can be expanded to other events and more complex control flow.  Where possible, all example code downloads from the [[Software Overview#Language Support|specific language pages]] shows event-driven programming.&lt;br /&gt;
&lt;br /&gt;
==== Wait for Attachment ====&lt;br /&gt;
&lt;br /&gt;
Waiting for attachment is a straightforward process.  Your code does not handle events, it simply waits for a device to be plugged in before moving on and doing something else.&lt;br /&gt;
&lt;br /&gt;
For example, in Java you wait for attachment on a &#039;&#039;&#039;created and open&#039;&#039;&#039; software object (called device) like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 // Wait until a device is plugged in&lt;br /&gt;
 device.waitForAttachment();&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C (again, device has been &#039;&#039;&#039;created and opened&#039;&#039;&#039;) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
 int result;&lt;br /&gt;
 // Wait up to 10000 ms for a device to be plugged in&lt;br /&gt;
 if((result = CPhidget_waitForAttachment((CPhidgetHandle) device, 10000))) {&lt;br /&gt;
     // No attachment, error&lt;br /&gt;
 }&lt;br /&gt;
 // Successful attachment&lt;br /&gt;
 // Do things after attachment (i.e. read data, control the device)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, unlike the event model above, a Phidget software object should be open before waiting for a device to be plugged in.&lt;br /&gt;
&lt;br /&gt;
=== Do Things with the Phidget ===&lt;br /&gt;
&lt;br /&gt;
After you have a [[#Creating a Software Object|properly created]] Phidget software object, you can actually call function to turn LEDs on, change output state, read data from sensors, etc.&lt;br /&gt;
&lt;br /&gt;
The thing you probably want to do with your Phidget is read data from its sensors or inputs.  This might be, say, a sensor plugged in to a [[Product - 1018 - PhidgetInterfaceKit 8/8/8 | 1018 - Interface Kit 8/8/8]] used in the code snippets below.  You can do this either by detecting changes via [[#Event Driven Code|event driven code]], or polling for new values via [[#Logic Code|logic code]]. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Details about data handling:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*When a Phidget is opened, its initial state will be read before it is marked as attached. This allows polling of many properties -- including some data -- even during the Attach event, and anytime afterwards.&lt;br /&gt;
&lt;br /&gt;
*Your computer can poll much faster than the Phidget can respond.  If you poll in a continuous &#039;&#039;&#039;&amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt;&#039;&#039;&#039; loop in byte code, you will probably swamp the Phidget with requests.&lt;br /&gt;
&lt;br /&gt;
*Similarly, if you set a value and then immediately read the value on the next line in your program, the Phidget may not have time to finish the set.  In our examples, we use &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements within loops.  Print functions are relatively slow; you can also use &amp;lt;code&amp;gt;wait()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;sleep()&amp;lt;/code&amp;gt; depending on your language.&lt;br /&gt;
&lt;br /&gt;
*If you are handling data using events as described below, the data event functions will fire when the device is plugged in and its initial state is read.&lt;br /&gt;
&lt;br /&gt;
*Some properties have default values, but these should not be trusted. Remember: &#039;&#039;&#039;always set&#039;&#039;&#039;, don’t rely on defaults.  Trying to read an uninitialized value with no default will result in an Exception.&lt;br /&gt;
&lt;br /&gt;
*Usually, sensor &#039;sensitivity&#039; will &#039;&#039;&#039;not&#039;&#039;&#039; be 0 (i.e. set to sense all changes) by default.  This can be good because it prevents your screen from being completely overloaded with event output.  But, depending on the sensor, it may make your sensor seem to have very high lag, and very poor sensitivity.  To capture all events, set the sensitivity to 0.&lt;br /&gt;
&lt;br /&gt;
*Often Phidgets will retain their last state unless power is lost. This can give surprising results as the previous state may not always be what you expect. For example, if you open an InterfaceKit and set an output, this output may stay set even after the Phidget is closed.&lt;br /&gt;
&lt;br /&gt;
====Capture Data Change with Events====&lt;br /&gt;
&lt;br /&gt;
To capture data changes in sensors or inputs as they happen, you need to use [[#Event Driven Code|event driven code]].&lt;br /&gt;
&lt;br /&gt;
Like defining an event function that fires [[#Event Attachment|when the Phidget is plugged in]], you can create functions that automatically run when, for example, a sensor value or input value changes.&lt;br /&gt;
&lt;br /&gt;
For example, for an Interface Kit, you can create a function that gets called when a sensor changes.  You would do this &#039;&#039;&#039;before&#039;&#039;&#039; the Phidget software object has been [[#Opening the Phidget|opened]].&lt;br /&gt;
&lt;br /&gt;
In Java, this would look like:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // After creating a Phidget object called &amp;quot;device&amp;quot;:&lt;br /&gt;
  device.addSensorChangeListener(new SensorChangeListener() {&lt;br /&gt;
      public void sensorChanged(SensorChangeEvent sensorEvent) {&lt;br /&gt;
          System.out.println(&amp;quot;New Value: &amp;quot; + sensorEvent.getValue());&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use an event to detect attachment in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int SensorChangeHandler (CPhidgetHandle device, void *userData, int boardIndex, int newValue) {&lt;br /&gt;
      printf(&amp;quot;New Value %d from sensor at location %d\n&amp;quot;, newValue, boardIndex);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // .....Then, in the main code after creating a Phidget object &amp;quot;device&amp;quot;:&lt;br /&gt;
  CPhidget_set_OnSensorChange_Handler((CPhidgetHandle) device, SensorChangeHandler, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Poll for Data Change====&lt;br /&gt;
&lt;br /&gt;
To poll for sensor data, or output state, you usually want to look for a &#039;&#039;&#039;get...Value&#039;&#039;&#039; or &#039;&#039;&#039;get...State&#039;&#039;&#039; function available in the API for your device.  (The API can be found on the product page for your device on our [{{SERVER}} main web site].)  Then, you simply set up a loop that get the value of a sensor continuously.&lt;br /&gt;
&lt;br /&gt;
To poll your software object, the object must be [[#Opening the Phidget|open]].  This is in contrast to the event-driven method above, where all event functions are declared and attached before opening the object.&lt;br /&gt;
&lt;br /&gt;
Note that when you poll the value of a sensor or another attribute, this will probably be within a loop.  When you create this loop, the &#039;&#039;more code&#039;&#039; you have within a loop, the &#039;&#039;more slowly&#039;&#039; your loop will run, and the &#039;&#039;more slowly&#039;&#039; you will be sampling the value in practice.  This may make you lose data, as described further in the [[#Data Rate|Data Rate]] section.&lt;br /&gt;
&lt;br /&gt;
This effect is also felt with interpreted languages (Java, Python) versus purely compiled languages, as the interpreted languages sample more slowly even within an otherwise completely empty loop.&lt;br /&gt;
&lt;br /&gt;
So if you want to sample as fast as possible, and capture all of the changes that a sensor produces, you should [[#Capture Data Change with Events|capture data with event programming]].  If you choose not to use the event-driven design, you should keep the code run between polls to a minimum. This way you can sample as quickly as possible.&lt;br /&gt;
&lt;br /&gt;
These code snippets assume &amp;lt;code&amp;gt;device&amp;lt;/code&amp;gt; is an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit 8/8/8].  For example, in Java, for the Sensor at location 5 on the board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    val = device.getSensorValue(5);&lt;br /&gt;
    System.out.println(&amp;quot;Value: &amp;quot; + val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C, for the Sensor at location 5 on the Interface Kit board:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  int val;&lt;br /&gt;
  for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;
    CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;val);&lt;br /&gt;
    printf(&amp;quot;Value: %d\n&amp;quot;, val);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sensors, Input, and Output====&lt;br /&gt;
&lt;br /&gt;
Often, your Phidget will be something like an [{{SERVER}}/products.php?product_id=1018 1018 Phidget Interface Kit] which has either analog inputs (black plug holes), or digital inputs and outputs (green screw attachments), or often both.&lt;br /&gt;
&lt;br /&gt;
* To the analog inputs, you can attach various sensors, including sensors for temperature, humidity, light, sound, and so on.   &lt;br /&gt;
* To the digital inputs, you can attach various input devices, including switches.&lt;br /&gt;
* To the digital outputs, you can attach status tools like LEDs.&lt;br /&gt;
&lt;br /&gt;
You use these sensors in software entirely through the software object for the Phidget plugged in to your USB port.  For example, to turn off an LED at output block 1 on on an RFID tag reader, you&#039;ll want to set the output at location 1 to &amp;quot;0&amp;quot; (or false).  In C, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  CPhidgetRFIDHandle device = 0;&lt;br /&gt;
  CPhidgetRFID_create(&amp;amp;device);&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the PhidgetRFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  CPhidgetRFID_setOutputState(device, 1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create the RFID software object:&lt;br /&gt;
  RFIDPhidget device = new RFIDPhidget();&lt;br /&gt;
&lt;br /&gt;
  // Open and handle the attachment of the RFID object&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
  // Then, turn the LED off, passing first the output number, then the new state:&lt;br /&gt;
  device.setOutputState(1, 0);	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a digital input would follow the same pattern, except you would use the getOutputState function and you would not pass the function a new output state.&lt;br /&gt;
&lt;br /&gt;
Getting an analog input is a little more complicated because:&lt;br /&gt;
# You must declare the sensor as one of two types (ratiometric or non-ratiometric)&lt;br /&gt;
#* To find out which your sensor is, read the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
# You must translate the 1-1000 reading that you get from the input into the data that you need (temperature, etc)&lt;br /&gt;
#* If the sensor comes from Phidgets, we provide a translation equation in the product information for your specific sensor on our [{{SERVER}} main web site].&lt;br /&gt;
&lt;br /&gt;
Other than that, reading an analog sensor mirrors reading a digital input.  For example, to obtain the lux from the [[Product - 1127 - PrecisionLightSensor | Precision Light Sensor]], a &#039;&#039;&#039;non-ratiometric&#039;&#039;&#039; sensor plugged into analog input 5, you would do this in C:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 // Change measurement to non-ratiometric style&lt;br /&gt;
 CPhidgetInterfaceKit_setRatiometric(device, 0);&lt;br /&gt;
&lt;br /&gt;
 // Get the data from analog input 5&lt;br /&gt;
 int sensorValue;&lt;br /&gt;
 CPhidgetInterfaceKit_getSensorValue(device, 5, &amp;amp;sensorValue);&lt;br /&gt;
&lt;br /&gt;
 // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
 int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Change measurement to non-ratiometric style&lt;br /&gt;
  device.setRatiometric(0);&lt;br /&gt;
&lt;br /&gt;
  // Get the data from analog input 5&lt;br /&gt;
  int sensorValue = getSensorValue(5);&lt;br /&gt;
&lt;br /&gt;
  // In this case, the measured light lux equals the sensor value.&lt;br /&gt;
  int lux = sensorValue;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Learning Everything You Can Do====&lt;br /&gt;
&lt;br /&gt;
The things you can do with your particular Phidget are many and varied, so we only include general concepts on this page.&lt;br /&gt;
&lt;br /&gt;
You can go one of two places for more information on what functions are available for your specific device.  We provide both documentation on the raw API for each programming language as well as a language-independent description of the calls for each device.&lt;br /&gt;
* Read the API for your [[Software Overview#Language Support| specific programming language]], available as a download on each page.&lt;br /&gt;
* Read the API overview for your hardware, which can be found on its product page on [{{SERVER}} our main website].&lt;br /&gt;
&lt;br /&gt;
=== Close the Phidget ===&lt;br /&gt;
&lt;br /&gt;
When you are finished with the Phidget software object at the end of your program, you should close and (in some languages) delete it.&lt;br /&gt;
&lt;br /&gt;
For example, in Java:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  device.close();&lt;br /&gt;
  device = null;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or, in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_close((CPhidgetHandle) device);&lt;br /&gt;
 CPhidget_delete((CPhidgetHandle) device);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt; call removes the lock that [[#Opening the Phidget|open]] put on the Phidget.  Make sure to close your object, so other software can use the Phidget!&lt;br /&gt;
&lt;br /&gt;
The close() function also makes sure the thread associated with the Phidget close properly.  Any outstanding writes will block close() until they complete, because writes are guaranteed to complete (unless a device is detached).&lt;br /&gt;
&lt;br /&gt;
Also note that a device should be put into a known state before calling close. For example, if a motor controller is driving a motor and close is called, it will continue to drive the motor even though the application has exited. This may or may not be what you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Multiple Phidgets===&lt;br /&gt;
&lt;br /&gt;
It is of course possible to use more than one Phidget within your program.  The trick lies in using a unique identifier for each one.  You can either hard-code the [[#Using the Serial Number|serial number in by hand]] (the number will be on the bottom of the board, or you can run our example code for the Phidget to obtain it on-screen), or you can use the [[#Using the Manager|Phidget Manager within your program]] to detect attached devices and return their serial numbers and Phidget types.&lt;br /&gt;
&lt;br /&gt;
====Using the Serial Number====&lt;br /&gt;
&lt;br /&gt;
Each Phidget has a unique serial number.  Using this serial number, you can use a specific [[General Phidget Programming#Opening the Phidget|open]] call to open by serial number.&lt;br /&gt;
&lt;br /&gt;
For example, in Java, this would be:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
 device.open(SerialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
 CPhidget_open((CPhidgetHandle) device, serialNumber);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Using the Label====&lt;br /&gt;
&lt;br /&gt;
If you want to have a human-readable way to reference your Phidget (as opposed to a serial number), or to have multiple different Phidgets of the same type with the same handle (for re-usable system code), you can use the Label feature of Phidgets.  In many development setups, you can change the label to whatever you like, get the label within your code, and open a Phidget based on its label, for any newer generation Phidget.  The disadvantage of Labels is that they are not available on all operating systems and languages.&lt;br /&gt;
&lt;br /&gt;
Some limitations are:&lt;br /&gt;
* You cannot &#039;&#039;&#039;set&#039;&#039;&#039; a label using any language in [[OS - Windows|Windows]], for any language&lt;br /&gt;
**However, you can get the label of a Phidget on Windows, and open a Phidget by its label&lt;br /&gt;
* [[Language - Android Java|Android Java]] has support for only a subset of the open() functions that use labels, see the [[Language - Android Java|Android Java language page]] for details&lt;br /&gt;
* Older Phidgets do not support labels&lt;br /&gt;
* No .COM language on Windows supports opening by Label&lt;br /&gt;
** This includes [[Language - AutoIt|AutoIt]], [[Language - Adobe Director|Adobe Director]], [[Language - Delphi|Delphi]], and all of the Visual Basic flavours.&lt;br /&gt;
* [[Language - LabVIEW|LabVIEW]] cannot open by label&lt;br /&gt;
* [[Language - Python|Python]] cannot open by label&lt;br /&gt;
* [[Language - LiveCode|LiveCode]] cannot open by label&lt;br /&gt;
&lt;br /&gt;
When opening by label, you would use the {{Code|openLabel(&amp;quot;mylabel&amp;quot;)}} function (or similar, check the [[Software Overview#Language Support|API for your language]]) rather than the generic open() function.&lt;br /&gt;
&lt;br /&gt;
Note that setting the label should be done by a separate program.  On a Mac OS computer, you can set a label through the Phidget Preference Pane.  On a Linux computer, you should write a special short program specifically for setting the label.  There are two reasons to &#039;&#039;&#039;not&#039;&#039;&#039; set a label within your main program:&lt;br /&gt;
* If you set a label every time you run that program, when not needing to, you can easily reach the 10,000 re-write limit for the flash that stores the label&lt;br /&gt;
* If you are using event driven programming, you cannot set the label from any function called from the attach event, as it will hang (on a mutual exclusion lock).&lt;br /&gt;
Because of the second point, your special program to set the label on a Phidget should use {{Code|waitForAttach()}} in [[#Logic Code|logic code]] and not [[#Event Driven Code|event-driven]] programming&lt;br /&gt;
&lt;br /&gt;
====Using the Manager====&lt;br /&gt;
&lt;br /&gt;
The Phidget Manager object can detect all Phidgets attached to a system and return their attributes in a list (or array, vector, etc. - depending on the language).  With this, you can obtain the serial numbers and types of Phidgets currently attached.  This is the preferred method for systems where you will be using multiple Phidgets and expecting the system to operate long enough (or under harsh enough conditions)  that the Phidgets would need to be replaced.  &lt;br /&gt;
&lt;br /&gt;
This is especially true for running programs [[OS - Phidget SBC#Running a Program Automatically| automatically at scheduled times on the Single Board Computer]], where you would be replacing Phidgets without the benefit of keyboard or screen. &lt;br /&gt;
&lt;br /&gt;
For example, in Java (note for Enumerations you also need to include {{Code|java.util.*}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  Manager manager;&lt;br /&gt;
  manager = new Manager();&lt;br /&gt;
  try {&lt;br /&gt;
      manager.open();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  Thread.sleep(1000);&lt;br /&gt;
&lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  Vector phidgetList = manager.getPhidgets();&lt;br /&gt;
&lt;br /&gt;
  // Use an enumeration to iterate over the vector&lt;br /&gt;
  // Vectors also have iterators in Java 2&lt;br /&gt;
  Enumeration phidgetListEnum = phidgetList.elements();&lt;br /&gt;
  while(phidgetListEnum.hasMoreElements()) { &lt;br /&gt;
      Phidget phidgetElement = (Phidget)phidgetListEnum.nextElement();&lt;br /&gt;
      System.out.print(phidgetElement.getDeviceName() + &amp;quot;, &amp;quot;); &lt;br /&gt;
      System.out.println(phidgetElement.getSerialNumber()); &lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Close the manager &lt;br /&gt;
  try {&lt;br /&gt;
      manager.close();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      printError(exception.getErrorNumber(), exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
  manager = null;&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, in C (note for sleep you also need to include {{Code|unistd.h}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  // Create and open the manager&lt;br /&gt;
  CPhidgetManagerHandle manager = 0;&lt;br /&gt;
  CPhidgetManager_create(&amp;amp;manager);&lt;br /&gt;
  CPhidgetManager_open((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Allow the Phidgets time to attach&lt;br /&gt;
  sleep(1);&lt;br /&gt;
    &lt;br /&gt;
  // Retrieve the list of attached Phidgets from the manager&lt;br /&gt;
  CPhidgetHandle* phidgetList;&lt;br /&gt;
  int count;&lt;br /&gt;
    &lt;br /&gt;
  CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) manager, &amp;amp;phidgetList, &amp;amp;count);&lt;br /&gt;
    &lt;br /&gt;
  int serialNumber;&lt;br /&gt;
  const char *name;&lt;br /&gt;
    &lt;br /&gt;
  // Iterate over the returned Phidget data&lt;br /&gt;
  int i;&lt;br /&gt;
  for (i = 0; i &amp;lt; count; i++) {&lt;br /&gt;
      CPhidget_getDeviceName(phidgetList[i], &amp;amp;name);&lt;br /&gt;
      CPhidget_getSerialNumber(phidgetList[i], &amp;amp;serialNumber);&lt;br /&gt;
      printf(&amp;quot;%s, %d\n&amp;quot;, name, serialNumber);&lt;br /&gt;
      // Store name and serial number into a persistent variable&lt;br /&gt;
      ....&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Use the Phidget API to free the memory in the phidgetList Array    &lt;br /&gt;
  CPhidgetManager_freeAttachedDevicesArray(phidgetList);&lt;br /&gt;
&lt;br /&gt;
  // Close the manager    &lt;br /&gt;
  CPhidgetManager_close((CPhidgetManagerHandle) manager);&lt;br /&gt;
  CPhidgetManager_delete((CPhidgetManagerHandle) manager);&lt;br /&gt;
&lt;br /&gt;
  // Do something with names and serial numbers stored above (i.e. open and use Phidget objects)&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Distinguishing Events====&lt;br /&gt;
&lt;br /&gt;
If you are using [[#Event Driven Code|event-driven code]], once you have correctly opened multiple Phidgets of different types, they will have different event handlers and hence you will know what Phidget triggered which event.  &lt;br /&gt;
If you are using multiple Phidgets of the same type, or you are trying to determine within general events (such as Attach Events) which Phidget triggered the event, you can then check the serial number (or device type) of the triggering device and act accordingly.  &lt;br /&gt;
&lt;br /&gt;
For example, in Java, your [[General Phidget Programming#Event Attachment|attach event handler]] might look like this:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
    detachHandler = new DetachListener() { &lt;br /&gt;
        public void detached(DetachEvent event) {&lt;br /&gt;
            int serialNumber = ((Phidget)event.getSource()).getSerialNumber();&lt;br /&gt;
            // Do something according to serialNumber&lt;br /&gt;
    }    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Or in C:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
    int AttachHandler(CPhidgetHandle device, void *userptr) {&lt;br /&gt;
	int serialNo;&lt;br /&gt;
	CPhidget_getSerialNumber(device, &amp;amp;serialNo);&lt;br /&gt;
         // Do something according to serialNumber&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Phidgets over a Network===&lt;br /&gt;
&lt;br /&gt;
Control of a Phidget over a network uses the Phidget WebService.&lt;br /&gt;
&lt;br /&gt;
We have an in-depth description of the WebService, with images to illustrate its use, on the main [[Phidget WebService]] page.&lt;br /&gt;
&lt;br /&gt;
In the code on the remote computer where you are receiving Phidget data and controlling the Phidget, you would simply use a different open call, and then the Phidget software object will work as if the object were local and normal.&lt;br /&gt;
&lt;br /&gt;
The different, remote open call in C would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
int serial_number = 37299;&lt;br /&gt;
CPhidget_openRemoteIP ((CPhidgetHandle) device, serial_number, &amp;quot;127.0.0.1&amp;quot;, 5001, NULL);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simply uses the same computer in a &#039;loopback&#039; connection (127.0.0.1) and the default port 5001.  You can replace the serial number with your own Phidget&#039;s serial number.&lt;br /&gt;
&lt;br /&gt;
And in Java, the different, remote open call would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
openAny(&amp;quot;127.0.0.1&amp;quot;, 5001, null);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are other options for opening remotely, including by name rather than IP.  You can refer to the [[Software Overview#Language Support|API for your language]] for options and specific syntax.&lt;br /&gt;
&lt;br /&gt;
== Putting It Together ==&lt;br /&gt;
&lt;br /&gt;
User and device actions can be handled by either:&lt;br /&gt;
*Letting the program tell you when they happen and then doing something (&#039;&#039;&#039;event driven&#039;&#039;&#039; code)&lt;br /&gt;
*Polling for things to happen then doing something (&#039;&#039;&#039;logic&#039;&#039;&#039; code)&lt;br /&gt;
&lt;br /&gt;
The style of programming you choose (and hence the language you might prefer) would depend on what you want to do with the Phidget.  The two sections, [[#Event Driven Code|Event Driven Code]] and [[#Logic Code|Logic Code]] below give benefits, drawbacks, and general examples of each style.&lt;br /&gt;
&lt;br /&gt;
The styles can also mix.  For example, you can take a defined set of steps at first such as turning on an LED or antenna (logic code) and then doing nothing until an output change event is fired (event code).&lt;br /&gt;
&lt;br /&gt;
With languages that support both styles, you can mix and match.  For languages that support only logic code (see the [[Software Overview#Language Support|Language Support Categories]] above) you can only use the logic paradigm style.&lt;br /&gt;
&lt;br /&gt;
Examples in pseudo-code are given below for each style type so you can see how your language choice can affect your code design.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logic Code ===&lt;br /&gt;
&lt;br /&gt;
Logic code has use for:&lt;br /&gt;
* Simple, single-device applications&lt;br /&gt;
* Non-GUI applications (GUIs usually are event driven)&lt;br /&gt;
* The user driving the device rather than listening to it&lt;br /&gt;
&lt;br /&gt;
Logic code is relatively easy to design well.  For example, using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, logic code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:logic.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although this design does not explicitly capture every event that fires when data or input changes, by polling the device often enough no data will be lost.&lt;br /&gt;
&lt;br /&gt;
However, logic code cannot handle constant, asynchronous events as cleanly as [[#Event Driven Code|event driven code]] can.&lt;br /&gt;
&lt;br /&gt;
These designs can be mixed.  So, if you find that in logic code you have a highly complex &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; loop driving your program, you should consider changing some of it to event driven code.  This type of awkward if-loop might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Create Device Software Object&lt;br /&gt;
  Open Device&lt;br /&gt;
&lt;br /&gt;
  Loop Until Exit Requested {&lt;br /&gt;
     if No Device Attached {&lt;br /&gt;
         Wait For Attachment until Timeout&lt;br /&gt;
         if Wait Timeout Reached {&lt;br /&gt;
             break&lt;br /&gt;
         } else { &lt;br /&gt;
             Initialize Device&lt;br /&gt;
         }&lt;br /&gt;
     } else {  // Device Is Attached&lt;br /&gt;
         if Device Data Type 1 Changed {&lt;br /&gt;
             Do Something&lt;br /&gt;
         }&lt;br /&gt;
         if Device Data Type 2 Changed {&lt;br /&gt;
             Do Something Else&lt;br /&gt;
         }&lt;br /&gt;
         // ... More data change functions here&lt;br /&gt;
     }&lt;br /&gt;
     Collect User Input&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  Close Device&lt;br /&gt;
  Delete Device&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the other hand, you can probably see that if your language does not give the option for events, you can use this structure to mimic what events would enable you to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Event Driven Code ===&lt;br /&gt;
&lt;br /&gt;
Event driven code allows for clean handling of complex, asynchronous programs:&lt;br /&gt;
*Handling multiple Phidgets&lt;br /&gt;
*Handling active plugging or unplugging of the Phidget (multiple attach and detach events)&lt;br /&gt;
*Working behind a GUI, as many GUIs are already event driven&lt;br /&gt;
*Capturing all sensor data - or input and output - without constantly polling&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Without&#039;&#039; event driven code, you will need to constantly poll the device to see if any state has changed.  If you poll at a slower rate than your input or output changes, you will not capture all data.&lt;br /&gt;
&lt;br /&gt;
However, event driven code is usually not as useful or efficient for:&lt;br /&gt;
*Only one open and close event &lt;br /&gt;
*Using only one device&lt;br /&gt;
*Having the user (or program) &#039;&#039;put&#039;&#039; changes onto the device (in contrast to reading data &#039;&#039;from&#039;&#039; the device)&lt;br /&gt;
&lt;br /&gt;
Event driven code is relatively hard to design well.  It may help to draw out a &#039;&#039;&#039;flowchart&#039;&#039;&#039;, &#039;&#039;&#039;state machine&#039;&#039;&#039;, or at least a &#039;&#039;&#039;pseudo-code outline&#039;&#039;&#039; of your system design and all events you wish to handle before writing code.&lt;br /&gt;
&lt;br /&gt;
The code examples given for each [[Software Overview#Language Support|specific language]] use events if they are supported by the language.&lt;br /&gt;
&lt;br /&gt;
Using the [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, event code to handle a Phidget might be written like this:&lt;br /&gt;
&lt;br /&gt;
[[File:event.png]]&lt;br /&gt;
&lt;br /&gt;
Once you have written this code flow, the actual order of events that occur within the program look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Eventhandler.jpg|160px]]&lt;br /&gt;
&lt;br /&gt;
Note that the device itself initiates the function call, by &#039;firing&#039; the event.  This allows you to update only when events fire, and capture all changes, because the low-level interface is telling you when a change occurs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Advanced Concepts==&lt;br /&gt;
&lt;br /&gt;
Now that you have the basic [[#Creating a Software Object|create]], [[#Opening the Phidget|open]], [[#Attaching the Phidget|attach]], [[#Do Things with the Phidget|do stuff]], and [[#Close the Phidget|close]] concepts introduced above, there are other useful concepts which will help you design your code to be persistent and stable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Logging===&lt;br /&gt;
&lt;br /&gt;
You can enable logging to get more debugging information.  Turning on logging happens through a Phidget API function.  This would happen at the very start of your program, before even initializing your software object or opening it.  Logging lets you get feedback from the Phidget libraries about every Phidget API call you make.&lt;br /&gt;
&lt;br /&gt;
In C, turning on logging to the command line would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  CPhidget_enableLogging(PHIDGET_LOG_DEBUG, NULL);&lt;br /&gt;
&lt;br /&gt;
  //... All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  CPhidget_disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  enableLogging(PHIDGET_LOG_DEBUG, null);&lt;br /&gt;
&lt;br /&gt;
  //...All of your Phidget calls.  Events called after enable will also log.&lt;br /&gt;
&lt;br /&gt;
  disableLogging();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The use of null is to indicate that the output is not to a file (and hence to the command line).  Otherwise, the second argument would be a string filename.&lt;br /&gt;
&lt;br /&gt;
There are six different logging levels, ranging from &amp;quot;Give me Everything!&amp;quot; to &amp;quot;Tell me only about critical problems&amp;quot;.  The level in the examples above - &#039;&#039;&#039;&amp;lt;code&amp;gt;PHIDGET_LOG_DEBUG&amp;lt;/code&amp;gt;&#039;&#039;&#039; - is a medium output level.  For more information about each level and what it gives you, see the API for [[Software Overview#Language Support|your specific language]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Threading===&lt;br /&gt;
&lt;br /&gt;
Due to the use of events, the Phidget library uses threading extensively.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
* Calling &amp;lt;code&amp;gt;open()&amp;lt;/code&amp;gt; starts a central thread. &lt;br /&gt;
* Closing everything will shut that central thread down (before the final close returns). &lt;br /&gt;
* Each device, once attached, starts its own read and write threads. &lt;br /&gt;
&lt;br /&gt;
These threads provide the support to perform your typical [[#The Basic Functions|Basic Functions]]:&lt;br /&gt;
&lt;br /&gt;
* Triggering of data events come from the context of a device read thread. &lt;br /&gt;
* Attach and detach events come from the context of the central thread.&lt;br /&gt;
* The central thread looks for device attaches and detached, keeping track of which devices are attached internally, and sending out attach and detach events to Phidgets and Managers.&lt;br /&gt;
* Writes are performed asynchronously by the write thread. The write queue is only 1 deep so calling a write function while there is a write pending will block.&lt;br /&gt;
&lt;br /&gt;
All Phidget libraries are &#039;&#039;&#039;thread safe&#039;&#039;&#039;, so you don’t need to do any locking on the Phidget objects.  If you have a GUI, however, or another program with a separate thread, make sure to use one thread for events, and a separate thread with your GUI, and some form of mutual exclusion if they are both writing to the same thing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Exceptions and Errors===&lt;br /&gt;
&lt;br /&gt;
There are two different types of errors that you can use to confirm that your program is running correctly.&lt;br /&gt;
&lt;br /&gt;
====One: An error generated by a function call====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by &#039;&#039;you&#039;&#039; calling a function.  For example, you might try to read analog sensor port number 150 on a board that only has eight.  The function you used to read port 150 would return an error (in C/C++) or throw an error (in languages that support exceptions like Java, .NET, Python, or AS3).  &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;synchronously&#039;&#039; to function calls, that is, they are returned or thrown right after a function returns.  You can handle these by checking the return values on your functions (in C/C++) or using an error catching method like &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; in languages that support exceptions (e.g., Java, .NET, Python, AS3).&lt;br /&gt;
&lt;br /&gt;
For example, in C, you might write a LocalErrorCatcher function that you can then use on every Phidget function call to detect and deal with errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int LocalErrorCatcher (int errorCode) {&lt;br /&gt;
&lt;br /&gt;
      if (errorCode != 0) {  // Everything is okay if errorCode = 0&lt;br /&gt;
    &lt;br /&gt;
          switch (errorCode) {&lt;br /&gt;
             default:&lt;br /&gt;
               const char *errorDescription;&lt;br /&gt;
               LocalErrorCatcher(&lt;br /&gt;
                   CPhidget_getErrorDescription (errorCode, &amp;amp;errorDescription));&lt;br /&gt;
               printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
               break;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // ... Then, later, you would use it on any Phidget function:&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_open((CPhidgetHandle) device, -1));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
# The function LocalErrorCatcher uses itself to check for errors on getting an error description.  &lt;br /&gt;
# You can handle individual error codes as they are listed in the API.  This only prints a general message.&lt;br /&gt;
&lt;br /&gt;
Or in Java, you would try a Phidget function call, and catch any resulting exception that occurs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
      device.openAny();&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, you could also use a &amp;lt;code&amp;gt;try...catch&amp;lt;/code&amp;gt; statement around the exception.getErrorNumber() and exception.getDescription() functions to catch any errors from those calls.&lt;br /&gt;
&lt;br /&gt;
The consequences of not catching this type of error (on &#039;&#039;every&#039;&#039; function) differ by programming language.&lt;br /&gt;
In C/C++ these errors must be &#039;&#039;explicitly&#039;&#039; checked for after each function call, otherwise the program will simply continue on in an incorrect state.  In languages that support exceptions (e.g., Java, .NET, Python, AS3), errors are returned using exceptions which will leave you no choice but to catch them, or have your program terminate without warning.&lt;br /&gt;
&lt;br /&gt;
====Two: An error generated by an event====&lt;br /&gt;
&lt;br /&gt;
These errors are generated by the Phidget library during runtime.  For example, the Phidget device might be experiencing too high a temperature, and trigger an error.  This would not necessarily be due to any one function your program called; rather, the error would appear when the problem appears and would trigger an event. &lt;br /&gt;
&lt;br /&gt;
So, these errors happen &#039;&#039;asynchronously&#039;&#039;, that is, something happens apart from any function calls and an error event is triggered. You can handle these by setting up an Error Event Handler.&lt;br /&gt;
&lt;br /&gt;
In C, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  int ErrorEventHandler (CPhidgetHandle device, void *usrptr, int errorCode, const char *errorDescription) {&lt;br /&gt;
    printf(&amp;quot;The description for error %d is: %s\n&amp;quot;, errorCode, errorDescription);&lt;br /&gt;
    // Do something useful based on the error code&lt;br /&gt;
    return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Actually hook the Error Event Handler in to receive events&lt;br /&gt;
  LocalErrorCatcher(&lt;br /&gt;
      CPhidget_set_OnError_Handler((CPhidgetHandle) device, LibraryErrorHandler, NULL));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the &#039;&#039;&#039;LibraryErrorHandler&#039;&#039;&#039; function is what gets called when an error event occurs, and it gives you an opportunity to handle the error.  &lt;br /&gt;
&lt;br /&gt;
You&#039;ll also note that there is a second function called &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039;.  This second function handles the return value from setting the  error handler.  We included it here because, as these are examples on how to handle errors, the example would leave a possibly unhandled error without it. This second type of error handling  and the &#039;&#039;&#039;LocalErrorCatcher&#039;&#039;&#039; function are [[#One: An error generated by a function call|described above]].&lt;br /&gt;
&lt;br /&gt;
In Java, it would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
  try {&lt;br /&gt;
    device.addErrorListener(new ErrorListener() {&lt;br /&gt;
        public void error(ErrorEvent event) {&lt;br /&gt;
            System.out.println(event);&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
  } catch (PhidgetException exception) {&lt;br /&gt;
      system.out.println(&amp;quot;The description for error &amp;quot; + Integer.toString(exception.getErrorNumber()) +  &lt;br /&gt;
                             &amp;quot; is: &amp;quot;, exception.getDescription());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like C above, the act of hooking an error listener in to the device can itself generate an error, which should be caught.  &lt;br /&gt;
&lt;br /&gt;
These event-type errors are also how a Phidget being run over a network announces bad passwords, lost packets, and other network problems.  Locally, the errors can announce incorrect temperatures, current, and power. So, it is in your best interest to set up an error event handler and take action based on the codes and error types in the API [[Software Overview#Language Support|for your programming language]].&lt;br /&gt;
&lt;br /&gt;
See the API for your [[Software Overview#Language Support|specific programming language]] for error code documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Sensitivity and Filtering===&lt;br /&gt;
&lt;br /&gt;
Change Triggers are used to filter the number of events that are returned to an Application, by setting a minimum amount of activity before a Change Event is sent to your program. &lt;br /&gt;
&lt;br /&gt;
This is a simple hysteresis - a minimum amount of change has to occur since the last event before another event will be fired. &lt;br /&gt;
&lt;br /&gt;
If your application is implementing its own filtering, setting the ChangeTrigger, or &#039;&#039;&#039;sensitivity&#039;&#039;&#039; to zero will cause all events to fire. Change triggers are generally available only for sensor inputs events. Change triggers are referred to as &#039;&#039;Sensitivity&#039;&#039; in some device-specific APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Data Rate===&lt;br /&gt;
&lt;br /&gt;
Some devices support a user-defined data rate for events.  &lt;br /&gt;
&lt;br /&gt;
* The data rate is set in milliseconds, with a range from up 1ms to 1000ms, depending on the Phidget. &lt;br /&gt;
* Data rates greater then 8ms generally need to be a multiple of 8 (8,16,24,...,496,...,996,1000). &lt;br /&gt;
* Data rates lower then 8ms are supported as: 4ms, 2ms, 1ms. &lt;br /&gt;
* Data rate is a maximum rate &lt;br /&gt;
* Data rate will be superseded by a non-zero sensitivity on devices that support both sensitivity and data rate. &lt;br /&gt;
&lt;br /&gt;
See the main page for your device - found on its product page on [{{SERVER}} our main website] for more details on available data rates and specifications.&lt;br /&gt;
&lt;br /&gt;
Note that this data rate &#039;&#039;&#039;is not the rate at which you will receive data&#039;&#039;&#039;.  Rather, it is the amount of time over which events are averaged before being sent.  It may help to think of our specification of data rate as an &#039;&#039;averaging time&#039;&#039;.  This means that setting a data rate of 24 ms will try to give you data averaged over 24 ms, and send it every 24 ms.  Depending on your computer, events may or may not be dropped.  If events are dropped, the data points that are received still represent 24 ms (or whatever the data rate is set to).  This means data is lost.  &lt;br /&gt;
&lt;br /&gt;
Conversely, if you are [[#Logic Code|polling]], and you set the data rate to longer than your polling rate, you will receive duplicate, averaged data.  For example, setting the data rate to 24 ms and then polling every 12 ms will give you duplicate readings every other poll.  To poll and not miss any data, the rate that your code polls must match the rate that you set for the {{Code|setDataRate()}} function in our API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using the Dictionary===&lt;br /&gt;
&lt;br /&gt;
The Phidget Dictionary is a service provided by the Phidget WebService.   The dictionary:&lt;br /&gt;
* Is a centralized collection of key-value pairs &lt;br /&gt;
* Works only over the webservice&lt;br /&gt;
* Can be accessed and changed from any number of webservice clients&lt;br /&gt;
* Makes use of extended regular expressions (denoted between two forward slashes) for key matching&lt;br /&gt;
* Is also a foundation part of the webservice itself, and controls access of all Phidgets through the {{Code|openRemote}} and {{Code|openRemoteIP}} interfaces &lt;br /&gt;
* Can be used as an abstracted or higher-level interface for remotely managing Phidgets&lt;br /&gt;
&lt;br /&gt;
We have a more in-depth description of the Dictionary (with pictures) on the main [[Phidget Dictionary]] page.&lt;br /&gt;
&lt;br /&gt;
The intended use for the dictionary is as a central repository for communication and persistent storage of data between several client applications. For example, the computer directly connected to a Phidget could create and change keys for additional events on top of (or even instead of) those already thrown by the Phidget device API.  The dictionary API is very high-level and thus very flexible - essentially any application of adding keys, changing keys (and throwing events), and getting values of keys can be handled by the Dictionary.&lt;br /&gt;
&lt;br /&gt;
Note that you should never add or modify a key that starts with {{Code|/PSK/}} or {{Code|/PCK/}} as these are the keys that Phidgets use.  Unless, of course, you want to explicitly modify Phidget specific data - and this is highly discouraged, as it’s very easy to break things. Listening to these keys is fine if so desired.&lt;br /&gt;
&lt;br /&gt;
Refer to the API [[Software Overview#Language Support|for your specific language]] for the full Dictionary API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Long Term Code Maintenance===&lt;br /&gt;
&lt;br /&gt;
Thinking long term from the start is incredibly useful.  Phidgets as a company is constantly developing and inventing, and our API gets improved and changed to still work with older devices while adding support for new ones.  &lt;br /&gt;
&lt;br /&gt;
We release library updates - both for operating systems and languages - on a regular basis.  We &#039;&#039;&#039;strongly&#039;&#039;&#039; recommend updating your own libraries as we release them.  This goes for both the libraries and the WebService, as the versions must match.  &lt;br /&gt;
&lt;br /&gt;
This form of updating (did we mention that we strongly recommend it?) is the single most important thing you can do to reduce maintenance issues with your Phidget software down the road.&lt;br /&gt;
&lt;br /&gt;
Every so often, customers come to us having run the same code for years, without updating.  Then, for some reason, they have to update (say, for an operating system migration).  And their code no longer works. What do to then?  We can work with these customers to find out which of the many updates was the one to cause the problem - a difficult and very time consuming process.  And over the course of multiple years, we may no longer stock or even manufacture that particular Phidget.  You can imagine that a process with these limitations can take a very long time to resolve, if it can be resolved at all.&lt;br /&gt;
&lt;br /&gt;
Conversely, if you update every time, this time frame is greatly reduced.  We make a serious effort to test every library update, and although some backwards-compatibility problems do (rarely) get through, we have a fresh memory of what was changed and can work with you to quickly either debug the new libraries or get you a working version.&lt;br /&gt;
&lt;br /&gt;
In addition to library updates, here are a few other tips and tricks to reduce your maintenance time:&lt;br /&gt;
* If you are using [[#Logging|Logging]], don&#039;t remove the logging code when you finalize your release.  Simply comment it out so you can turn it on again later and debug quickly.&lt;br /&gt;
* Some long-term problems can be detected early by listening to library messages and errors.  Handling [[#Exceptions and Errors|Exceptions and Errors]] will allow your code to run silently until something is wrong, in which case you&#039;ll know right away.&lt;br /&gt;
&lt;br /&gt;
If you are looking for more help on how to work with our library updating, please feel welcome to [[Contact Us|contact us]].&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
This page has gone through [[#The Basic Functions|basic]] to [[#Advanced Concepts|advanced]] uses of the Phidget API.  We&#039;ve used C and Java here as example languages.  If you&#039;re using a different language, we include similar snippets of code (without the in-depth description) in the documentation [[Software Overview#Language Support|for your language]].&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve read this far and are still hungry for more, try learning more about your hardware; we have a number of [[Primers|high level teaching pages]] about hardware as well.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=InterfaceKit_Digital_Outputs&amp;diff=20663</id>
		<title>InterfaceKit Digital Outputs</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=InterfaceKit_Digital_Outputs&amp;diff=20663"/>
		<updated>2012-06-29T15:27:28Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Digital Outputs can be used to drive LEDs, solid state relays, and transistors (or anything that will accept a CMOS signal).&lt;br /&gt;
Digital outputs can be used to control devices that accept a +5V control signal.&lt;br /&gt;
With transistors and some electronics experience, other devices can be controlled, such as buzzers, lights, larger LEDs, relays.&lt;br /&gt;
&lt;br /&gt;
==Specifications and Features==&lt;br /&gt;
&lt;br /&gt;
[[Image:digital_output.jpg|right|thumb|A Phidgets digital output.]]&lt;br /&gt;
&lt;br /&gt;
The 250 ohm resistance is internal to the PhidgetInterfaceKit 8/8/8, and limits the current that can flow through the output. &lt;br /&gt;
This is intended to protect the device from being damaged if there is a short to ground or if an LED is used. &lt;br /&gt;
Ultimately this means the maximum current output of the digital outputs is 16mA.  In practice you should not try to draw 16mA from the outputs for extended periods of time though as this can lead to damaged components.  You should try to limit your current draw to less than 5mA though up to 10 would not cause any immediate concerns.&lt;br /&gt;
The output is intended to drive TTL or CMOS inputs; it is not designed to provide power to an external circuit.&lt;br /&gt;
&lt;br /&gt;
In practice the frequency at which these outputs can be switched is highly dependent on system properties such as OS, USB hardware, and cabling.  However, it is a good bet that the majority of systems will be able to achieve 1kHz.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Ground Protection===&lt;br /&gt;
Ground terminals on the InterfaceKit share a common ground with USB ground.  &lt;br /&gt;
Because they are not internally isolated, these terminals will expose the USB ground potential of the PC to which they are connected.  &lt;br /&gt;
Be sure you are completely familiar with any circuit you intend to connect to the InterfaceKit before it is connected.  &lt;br /&gt;
If a reverse voltage or dangerously high voltage is applied to the input or output terminals, damage to the Phidget or the PC may result.&lt;br /&gt;
&lt;br /&gt;
===5 Volt Terminal Block===&lt;br /&gt;
For users who need it, we provide 5V on the terminal block next to Digital Output 7.&lt;br /&gt;
&lt;br /&gt;
==Using the Digital Outputs==&lt;br /&gt;
Here are some circuit diagrams that illustrate how to connect various devices to the digital outputs on your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Driving an LED with the Digital Output===&lt;br /&gt;
&lt;br /&gt;
[[Image:LED_digital_output.jpg|right|thumb|Schematic for connecting to an LED.]]&lt;br /&gt;
&lt;br /&gt;
Connecting an LED to a digital output is simple. Wire the anode to a digital output labeled 0 to 7 on the Interface Kit, and the cathode to a supplied ground, labeled G.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a 3052 SSR Board with a Digital Output===&lt;br /&gt;
&lt;br /&gt;
[[Image:3052_digital_output.jpg|right|thumb|Schematic for connecting a 3052 board.]]&lt;br /&gt;
&lt;br /&gt;
Setting the digital output to true causes the output of the 3052 to turn on. &lt;br /&gt;
This can be used to control AC or DC devices. &lt;br /&gt;
&lt;br /&gt;
The load can also be switched with the 3052 on the high side.  &lt;br /&gt;
High side switching is helpful for powering more complicated circuitry that cannot tolerate having multiple grounds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Output with a MOSFET based SSR===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_output_ssr.jpg|right|thumb|Schematic for isolating a digital input with an SSR.]]&lt;br /&gt;
&lt;br /&gt;
It’s possible to wire up your own Solid State Relay to the digital output.  &lt;br /&gt;
MOSFET based SSRs have the advantage that they can be understood as being a simple switch.  &lt;br /&gt;
&lt;br /&gt;
There are many other types of SSRs that are more suitable for controlling higher power, higher voltage AC devices that can also be controlled in the same fashion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Output with an Optocoupler===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_output_optocoupler.jpg|right|thumb|Schematic for isolating a digital input with an optocoupler.]]&lt;br /&gt;
&lt;br /&gt;
In some applications, particularly where there is a lot of electrical noise (automotive), or where you want maximum protection of the circuitry (interactive installations, kiosks), electrical isolation buys you a huge margin of protection.&lt;br /&gt;
Driving the LED causes the output transistor to sink current.  &lt;br /&gt;
&lt;br /&gt;
The maximum current through the transistor will depend in part on the characteristics of the optocoupler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Controlling a Relay with a N-Channel MOSFET===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_nmos.jpg|right|thumb|Schematic for using a relay with an NMOS transistor.]]&lt;br /&gt;
&lt;br /&gt;
A inexpensive mosfet and flyback diode can be used to control larger loads - relays for example - directly from the digital output.&lt;br /&gt;
Be sure to use a Logic-Level MOSFET so that the +5V Digital Output is able to turn it on.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Controlling a Relay with a NPN Transistor===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_npn.jpg|right|thumb|Schematic for using a relay with an NPN transistor.]]&lt;br /&gt;
&lt;br /&gt;
This circuit is very similar to the N-channel mosfet - but you may already have NPN transistors on hand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a 3051 Dual Relay Board with one or two Digital Outputs===&lt;br /&gt;
&lt;br /&gt;
[[Image:3051_digital_outputs.jpg|right|thumb|Schematic for using a 3051 board.]]&lt;br /&gt;
&lt;br /&gt;
The 3051 Dual Relay Board is designed to be used with the PhidgetInterfaceKit 8/8/8.  &lt;br /&gt;
An Analog Input can be used to supply power to the relays, and one or two digital outputs used to control the relays.  &lt;br /&gt;
The 3051 is a good option if you need a couple relays in your project.&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Update Rate==&lt;br /&gt;
&lt;br /&gt;
Please check the specification for the maximum rate of sampling that the Digital input can measure.  This is often slower than your program can change it.  So, if you change the output one way and then flip it back immediately in your code, the interface kit may not register the change.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20662</id>
		<title>Digital Input Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20662"/>
		<updated>2012-06-29T15:24:38Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.&lt;br /&gt;
They have two states: Low (or TRUE), and High (or FALSE).&lt;br /&gt;
Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input.  &lt;br /&gt;
&lt;br /&gt;
Digital inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.&lt;br /&gt;
&lt;br /&gt;
==Specifications==&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hardware Filter===&lt;br /&gt;
There is built-in filtering on the digital input, to eliminate false triggering from electrical noise.		&lt;br /&gt;
The digital input is first RC filtered by a 15K/100nF node, which will reject noise of higher frequency than 1Khz. &lt;br /&gt;
This filter generally eliminates the need to shield the digital input from inductive and capacitive coupling likely to occur in wiring harnesses.&lt;br /&gt;
You can further reduce noise by externally filtering the input signal, but you will lose sensitivity in the process.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hysteresis===&lt;br /&gt;
The digital input has hysteresis - that is, it will hold its current state (false or true), unless a large change occurs.  &lt;br /&gt;
To guarantee FALSE, the digital input must be at least 3.75V, and to guarantee TRUE, the digital input must be less than 1.25V.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Sampling Characteristics===&lt;br /&gt;
The state of the digital inputs are reported back to the PC periodically.  &lt;br /&gt;
During this sampling period, if a digital input was true for greater than 4.0ms, the digital input is guaranteed to be reported as true in software.  &lt;br /&gt;
This makes the digital input much more sensitive to reporting TRUE state, and makes it useful to watch for short events.  &lt;br /&gt;
Any Digital Input True events of less than 1.5ms are never reported.&lt;br /&gt;
&lt;br /&gt;
===Electrical Specifications===&lt;br /&gt;
&lt;br /&gt;
[[Image:digital_input.jpg|right|thumb|Schematic for a Phidgets digital input.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs have a built in 15K pull-up resistor.  &lt;br /&gt;
By connecting external circuitry, and forcing the input to Ground, the Digital Input in software will read as TRUE.  &lt;br /&gt;
The default state is FALSE - when you have nothing connected, or your circuitry (switch, etc) is not pulling the input to ground.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using the Digital Inputs==&lt;br /&gt;
Here are some circuit diagrams that illustrate how to connect various devices to the digital inputs on your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Wiring a switch to a Digital Input===&lt;br /&gt;
&lt;br /&gt;
[[Image:switch_digital_input.jpg|right|thumb|Schematic for connecting a switch to a digital input.]]&lt;br /&gt;
&lt;br /&gt;
Closing the switch causes the digital input to report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Monitoring the Position of a Relay===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_position.jpg|right|thumb|Schematic for connecting to a relay.]]&lt;br /&gt;
&lt;br /&gt;
The relay contact can be treated as a switch, and wired up similarly.  &lt;br /&gt;
When the relay contact is closed, the Digital Input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an N-Channel MOSFET===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_mosfet.jpg|right|thumb|Schematic for detecting voltage with a NMOS transistor.]]&lt;br /&gt;
&lt;br /&gt;
A MOSFET can be used to detect the presence of an external voltage.  &lt;br /&gt;
The external voltage will turn on the MOSFET, causing it to short the Digital Input to Ground.  &lt;br /&gt;
If the MOSFET is conducting &amp;gt; 270uA, the Digital Input is guaranteed to report TRUE.  &lt;br /&gt;
If the MOSFET is conducting &amp;lt; 67uA, the Digital Input is guaranteed to report FALSE.&lt;br /&gt;
The voltage level required to turn on the MOSFET depends on the make of of MOSFET you are using. Typical values are 2V-6V.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Input with an Optocoupler===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_input_optocoupler.jpg|right|thumb|Schematic showing isolation of a digital input with an optocoupler.]]&lt;br /&gt;
&lt;br /&gt;
When driving current through the LED, the Digital Input will report TRUE.  &lt;br /&gt;
The amount of current required will depend on the optocoupler used.  &lt;br /&gt;
Design to sink at least 270uA to cause the digital input to report TRUE, and less than 67uA to report FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an NPN Transistor===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_npn.jpg|right|thumb|Schematic for detecting voltage with an NPN transistor.]]&lt;br /&gt;
&lt;br /&gt;
This circuit can be used to measure if a battery is connected, or if 12V (for example) is on a wire.&lt;br /&gt;
By designing to have Collector-Emitter current &amp;gt; 270uA, the digital input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a Capacitive or Inductive Proximity Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:proximity_switch.jpg|right|thumb|Schematic for connecting to a proximity switch.]]&lt;br /&gt;
&lt;br /&gt;
Capacitive proximity switches can detect the presence of nearby non-metallic objects, whereas inductive proximity switches can detect only the presence of metallic objects.  &lt;br /&gt;
To properly interface one of these proximity switches to the digital inputs, a 3-wire proximity switch is required, as well as an external power supply.&lt;br /&gt;
We have checked the following switch from Automation Direct to verify that it works with the Digital Inputs.  &lt;br /&gt;
Similar capacitive or inductive proximity switches from other manufacturers should work just as well.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Switches&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
! Manufacturer &lt;br /&gt;
! Web Page &lt;br /&gt;
! Capacitive Part No. &lt;br /&gt;
! Inductive Part No.&lt;br /&gt;
|-&lt;br /&gt;
| Automation Direct &lt;br /&gt;
| www.automationdirect.com &lt;br /&gt;
| CT1 Series &lt;br /&gt;
| AM1 Series&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using an FSR or Variable Resistor as a Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:fsr_switch.jpg|right|thumb|Schematic for using an FSR as a switch.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs can be easily wired to use many variable resistors as switches.&lt;br /&gt;
If the resistance falls below 3.75k Ohms, the Digital Input will go TRUE.&lt;br /&gt;
If the resistance rises above 75k Ohms, the Digital Input will go FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Helpful Tips==&lt;br /&gt;
===Update Rate===&lt;br /&gt;
*125 samples/sec is for each individual channel, not split between all channels. &lt;br /&gt;
*You can&#039;t &amp;quot;turn off&amp;quot; unused channels to improve update rate on the active channels. &lt;br /&gt;
*This value is already close to the spec for our USB processor, so there isn&#039;t much room to tinker.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20661</id>
		<title>Digital Input Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20661"/>
		<updated>2012-06-29T15:24:24Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Helpful Tips */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.&lt;br /&gt;
They have two states: Low (or TRUE), and High (or FALSE).&lt;br /&gt;
Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input.  &lt;br /&gt;
&lt;br /&gt;
Digital inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.&lt;br /&gt;
&lt;br /&gt;
==Specifications==&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hardware Filter===&lt;br /&gt;
There is built-in filtering on the digital input, to eliminate false triggering from electrical noise.		&lt;br /&gt;
The digital input is first RC filtered by a 15K/100nF node, which will reject noise of higher frequency than 1Khz. &lt;br /&gt;
This filter generally eliminates the need to shield the digital input from inductive and capacitive coupling likely to occur in wiring harnesses.&lt;br /&gt;
You can further reduce noise by externally filtering the input signal, but you will lose sensitivity in the process.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hysteresis===&lt;br /&gt;
The digital input has hysteresis - that is, it will hold it’s current state (false or true), unless a large change occurs.  &lt;br /&gt;
To guarantee FALSE, the digital input must be at least 3.75V, and to guarantee TRUE, the digital input must be less than 1.25V.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Sampling Characteristics===&lt;br /&gt;
The state of the digital inputs are reported back to the PC periodically.  &lt;br /&gt;
During this sampling period, if a digital input was true for greater than 4.0ms, the digital input is guaranteed to be reported as true in software.  &lt;br /&gt;
This makes the digital input much more sensitive to reporting TRUE state, and makes it useful to watch for short events.  &lt;br /&gt;
Any Digital Input True events of less than 1.5ms are never reported.&lt;br /&gt;
&lt;br /&gt;
===Electrical Specifications===&lt;br /&gt;
&lt;br /&gt;
[[Image:digital_input.jpg|right|thumb|Schematic for a Phidgets digital input.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs have a built in 15K pull-up resistor.  &lt;br /&gt;
By connecting external circuitry, and forcing the input to Ground, the Digital Input in software will read as TRUE.  &lt;br /&gt;
The default state is FALSE - when you have nothing connected, or your circuitry (switch, etc) is not pulling the input to ground.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
==Using the Digital Inputs==&lt;br /&gt;
Here are some circuit diagrams that illustrate how to connect various devices to the digital inputs on your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Wiring a switch to a Digital Input===&lt;br /&gt;
&lt;br /&gt;
[[Image:switch_digital_input.jpg|right|thumb|Schematic for connecting a switch to a digital input.]]&lt;br /&gt;
&lt;br /&gt;
Closing the switch causes the digital input to report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Monitoring the Position of a Relay===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_position.jpg|right|thumb|Schematic for connecting to a relay.]]&lt;br /&gt;
&lt;br /&gt;
The relay contact can be treated as a switch, and wired up similarly.  &lt;br /&gt;
When the relay contact is closed, the Digital Input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an N-Channel MOSFET===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_mosfet.jpg|right|thumb|Schematic for detecting voltage with a NMOS transistor.]]&lt;br /&gt;
&lt;br /&gt;
A MOSFET can be used to detect the presence of an external voltage.  &lt;br /&gt;
The external voltage will turn on the MOSFET, causing it to short the Digital Input to Ground.  &lt;br /&gt;
If the MOSFET is conducting &amp;gt; 270uA, the Digital Input is guaranteed to report TRUE.  &lt;br /&gt;
If the MOSFET is conducting &amp;lt; 67uA, the Digital Input is guaranteed to report FALSE.&lt;br /&gt;
The voltage level required to turn on the MOSFET depends on the make of of MOSFET you are using. Typical values are 2V-6V.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Input with an Optocoupler===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_input_optocoupler.jpg|right|thumb|Schematic showing isolation of a digital input with an optocoupler.]]&lt;br /&gt;
&lt;br /&gt;
When driving current through the LED, the Digital Input will report TRUE.  &lt;br /&gt;
The amount of current required will depend on the optocoupler used.  &lt;br /&gt;
Design to sink at least 270uA to cause the digital input to report TRUE, and less than 67uA to report FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an NPN Transistor===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_npn.jpg|right|thumb|Schematic for detecting voltage with an NPN transistor.]]&lt;br /&gt;
&lt;br /&gt;
This circuit can be used to measure if a battery is connected, or if 12V (for example) is on a wire.&lt;br /&gt;
By designing to have Collector-Emitter current &amp;gt; 270uA, the digital input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a Capacitive or Inductive Proximity Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:proximity_switch.jpg|right|thumb|Schematic for connecting to a proximity switch.]]&lt;br /&gt;
&lt;br /&gt;
Capacitive proximity switches can detect the presence of nearby non-metallic objects, whereas inductive proximity switches can detect only the presence of metallic objects.  &lt;br /&gt;
To properly interface one of these proximity switches to the digital inputs, a 3-wire proximity switch is required, as well as an external power supply.&lt;br /&gt;
We have checked the following switch from Automation Direct to verify that it works with the Digital Inputs.  &lt;br /&gt;
Similar capacitive or inductive proximity switches from other manufacturers should work just as well.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Switches&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
! Manufacturer &lt;br /&gt;
! Web Page &lt;br /&gt;
! Capacitive Part No. &lt;br /&gt;
! Inductive Part No.&lt;br /&gt;
|-&lt;br /&gt;
| Automation Direct &lt;br /&gt;
| www.automationdirect.com &lt;br /&gt;
| CT1 Series &lt;br /&gt;
| AM1 Series&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using an FSR or Variable Resistor as a Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:fsr_switch.jpg|right|thumb|Schematic for using an FSR as a switch.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs can be easily wired to use many variable resistors as switches.&lt;br /&gt;
If the resistance falls below 3.75k Ohms, the Digital Input will go TRUE.&lt;br /&gt;
If the resistance rises above 75k Ohms, the Digital Input will go FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Helpful Tips==&lt;br /&gt;
===Update Rate===&lt;br /&gt;
*125 samples/sec is for each individual channel, not split between all channels. &lt;br /&gt;
*You can&#039;t &amp;quot;turn off&amp;quot; unused channels to improve update rate on the active channels. &lt;br /&gt;
*This value is already close to the spec for our USB processor, so there isn&#039;t much room to tinker.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20660</id>
		<title>Digital Input Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20660"/>
		<updated>2012-06-29T15:23:07Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Helpful Tips */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.&lt;br /&gt;
They have two states: Low (or TRUE), and High (or FALSE).&lt;br /&gt;
Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input.  &lt;br /&gt;
&lt;br /&gt;
Digital inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.&lt;br /&gt;
&lt;br /&gt;
==Specifications==&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hardware Filter===&lt;br /&gt;
There is built-in filtering on the digital input, to eliminate false triggering from electrical noise.		&lt;br /&gt;
The digital input is first RC filtered by a 15K/100nF node, which will reject noise of higher frequency than 1Khz. &lt;br /&gt;
This filter generally eliminates the need to shield the digital input from inductive and capacitive coupling likely to occur in wiring harnesses.&lt;br /&gt;
You can further reduce noise by externally filtering the input signal, but you will lose sensitivity in the process.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hysteresis===&lt;br /&gt;
The digital input has hysteresis - that is, it will hold it’s current state (false or true), unless a large change occurs.  &lt;br /&gt;
To guarantee FALSE, the digital input must be at least 3.75V, and to guarantee TRUE, the digital input must be less than 1.25V.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Sampling Characteristics===&lt;br /&gt;
The state of the digital inputs are reported back to the PC periodically.  &lt;br /&gt;
During this sampling period, if a digital input was true for greater than 4.0ms, the digital input is guaranteed to be reported as true in software.  &lt;br /&gt;
This makes the digital input much more sensitive to reporting TRUE state, and makes it useful to watch for short events.  &lt;br /&gt;
Any Digital Input True events of less than 1.5ms are never reported.&lt;br /&gt;
&lt;br /&gt;
===Electrical Specifications===&lt;br /&gt;
&lt;br /&gt;
[[Image:digital_input.jpg|right|thumb|Schematic for a Phidgets digital input.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs have a built in 15K pull-up resistor.  &lt;br /&gt;
By connecting external circuitry, and forcing the input to Ground, the Digital Input in software will read as TRUE.  &lt;br /&gt;
The default state is FALSE - when you have nothing connected, or your circuitry (switch, etc) is not pulling the input to ground.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
==Using the Digital Inputs==&lt;br /&gt;
Here are some circuit diagrams that illustrate how to connect various devices to the digital inputs on your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Wiring a switch to a Digital Input===&lt;br /&gt;
&lt;br /&gt;
[[Image:switch_digital_input.jpg|right|thumb|Schematic for connecting a switch to a digital input.]]&lt;br /&gt;
&lt;br /&gt;
Closing the switch causes the digital input to report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Monitoring the Position of a Relay===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_position.jpg|right|thumb|Schematic for connecting to a relay.]]&lt;br /&gt;
&lt;br /&gt;
The relay contact can be treated as a switch, and wired up similarly.  &lt;br /&gt;
When the relay contact is closed, the Digital Input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an N-Channel MOSFET===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_mosfet.jpg|right|thumb|Schematic for detecting voltage with a NMOS transistor.]]&lt;br /&gt;
&lt;br /&gt;
A MOSFET can be used to detect the presence of an external voltage.  &lt;br /&gt;
The external voltage will turn on the MOSFET, causing it to short the Digital Input to Ground.  &lt;br /&gt;
If the MOSFET is conducting &amp;gt; 270uA, the Digital Input is guaranteed to report TRUE.  &lt;br /&gt;
If the MOSFET is conducting &amp;lt; 67uA, the Digital Input is guaranteed to report FALSE.&lt;br /&gt;
The voltage level required to turn on the MOSFET depends on the make of of MOSFET you are using. Typical values are 2V-6V.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Input with an Optocoupler===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_input_optocoupler.jpg|right|thumb|Schematic showing isolation of a digital input with an optocoupler.]]&lt;br /&gt;
&lt;br /&gt;
When driving current through the LED, the Digital Input will report TRUE.  &lt;br /&gt;
The amount of current required will depend on the optocoupler used.  &lt;br /&gt;
Design to sink at least 270uA to cause the digital input to report TRUE, and less than 67uA to report FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an NPN Transistor===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_npn.jpg|right|thumb|Schematic for detecting voltage with an NPN transistor.]]&lt;br /&gt;
&lt;br /&gt;
This circuit can be used to measure if a battery is connected, or if 12V (for example) is on a wire.&lt;br /&gt;
By designing to have Collector-Emitter current &amp;gt; 270uA, the digital input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a Capacitive or Inductive Proximity Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:proximity_switch.jpg|right|thumb|Schematic for connecting to a proximity switch.]]&lt;br /&gt;
&lt;br /&gt;
Capacitive proximity switches can detect the presence of nearby non-metallic objects, whereas inductive proximity switches can detect only the presence of metallic objects.  &lt;br /&gt;
To properly interface one of these proximity switches to the digital inputs, a 3-wire proximity switch is required, as well as an external power supply.&lt;br /&gt;
We have checked the following switch from Automation Direct to verify that it works with the Digital Inputs.  &lt;br /&gt;
Similar capacitive or inductive proximity switches from other manufacturers should work just as well.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Switches&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
! Manufacturer &lt;br /&gt;
! Web Page &lt;br /&gt;
! Capacitive Part No. &lt;br /&gt;
! Inductive Part No.&lt;br /&gt;
|-&lt;br /&gt;
| Automation Direct &lt;br /&gt;
| www.automationdirect.com &lt;br /&gt;
| CT1 Series &lt;br /&gt;
| AM1 Series&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using an FSR or Variable Resistor as a Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:fsr_switch.jpg|right|thumb|Schematic for using an FSR as a switch.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs can be easily wired to use many variable resistors as switches.&lt;br /&gt;
If the resistance falls below 3.75k Ohms, the Digital Input will go TRUE.&lt;br /&gt;
If the resistance rises above 75k Ohms, the Digital Input will go FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Helpful Tips==&lt;br /&gt;
===Update Rate===&lt;br /&gt;
*125 samples/sec is for each individual channel, not split between all channels. &lt;br /&gt;
*You can&#039;t &amp;quot;turn off&amp;quot; unused channels to improve update rate on the active channels. &lt;br /&gt;
*This value is already close to the spec for our USB processor, so there isn&#039;t much room to tinker with this spec.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20659</id>
		<title>Digital Input Guide</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Digital_Input_Guide&amp;diff=20659"/>
		<updated>2012-06-29T15:22:54Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Glossary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Primer]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.&lt;br /&gt;
They have two states: Low (or TRUE), and High (or FALSE).&lt;br /&gt;
Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input.  &lt;br /&gt;
&lt;br /&gt;
Digital inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.&lt;br /&gt;
&lt;br /&gt;
==Specifications==&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hardware Filter===&lt;br /&gt;
There is built-in filtering on the digital input, to eliminate false triggering from electrical noise.		&lt;br /&gt;
The digital input is first RC filtered by a 15K/100nF node, which will reject noise of higher frequency than 1Khz. &lt;br /&gt;
This filter generally eliminates the need to shield the digital input from inductive and capacitive coupling likely to occur in wiring harnesses.&lt;br /&gt;
You can further reduce noise by externally filtering the input signal, but you will lose sensitivity in the process.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Hysteresis===&lt;br /&gt;
The digital input has hysteresis - that is, it will hold it’s current state (false or true), unless a large change occurs.  &lt;br /&gt;
To guarantee FALSE, the digital input must be at least 3.75V, and to guarantee TRUE, the digital input must be less than 1.25V.&lt;br /&gt;
&lt;br /&gt;
===Digital Input Sampling Characteristics===&lt;br /&gt;
The state of the digital inputs are reported back to the PC periodically.  &lt;br /&gt;
During this sampling period, if a digital input was true for greater than 4.0ms, the digital input is guaranteed to be reported as true in software.  &lt;br /&gt;
This makes the digital input much more sensitive to reporting TRUE state, and makes it useful to watch for short events.  &lt;br /&gt;
Any Digital Input True events of less than 1.5ms are never reported.&lt;br /&gt;
&lt;br /&gt;
===Electrical Specifications===&lt;br /&gt;
&lt;br /&gt;
[[Image:digital_input.jpg|right|thumb|Schematic for a Phidgets digital input.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs have a built in 15K pull-up resistor.  &lt;br /&gt;
By connecting external circuitry, and forcing the input to Ground, the Digital Input in software will read as TRUE.  &lt;br /&gt;
The default state is FALSE - when you have nothing connected, or your circuitry (switch, etc) is not pulling the input to ground.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
==Using the Digital Inputs==&lt;br /&gt;
Here are some circuit diagrams that illustrate how to connect various devices to the digital inputs on your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Wiring a switch to a Digital Input===&lt;br /&gt;
&lt;br /&gt;
[[Image:switch_digital_input.jpg|right|thumb|Schematic for connecting a switch to a digital input.]]&lt;br /&gt;
&lt;br /&gt;
Closing the switch causes the digital input to report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Monitoring the Position of a Relay===&lt;br /&gt;
&lt;br /&gt;
[[Image:relay_position.jpg|right|thumb|Schematic for connecting to a relay.]]&lt;br /&gt;
&lt;br /&gt;
The relay contact can be treated as a switch, and wired up similarly.  &lt;br /&gt;
When the relay contact is closed, the Digital Input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an N-Channel MOSFET===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_mosfet.jpg|right|thumb|Schematic for detecting voltage with a NMOS transistor.]]&lt;br /&gt;
&lt;br /&gt;
A MOSFET can be used to detect the presence of an external voltage.  &lt;br /&gt;
The external voltage will turn on the MOSFET, causing it to short the Digital Input to Ground.  &lt;br /&gt;
If the MOSFET is conducting &amp;gt; 270uA, the Digital Input is guaranteed to report TRUE.  &lt;br /&gt;
If the MOSFET is conducting &amp;lt; 67uA, the Digital Input is guaranteed to report FALSE.&lt;br /&gt;
The voltage level required to turn on the MOSFET depends on the make of of MOSFET you are using. Typical values are 2V-6V.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Isolating a Digital Input with an Optocoupler===&lt;br /&gt;
&lt;br /&gt;
[[Image:isolating_digital_input_optocoupler.jpg|right|thumb|Schematic showing isolation of a digital input with an optocoupler.]]&lt;br /&gt;
&lt;br /&gt;
When driving current through the LED, the Digital Input will report TRUE.  &lt;br /&gt;
The amount of current required will depend on the optocoupler used.  &lt;br /&gt;
Design to sink at least 270uA to cause the digital input to report TRUE, and less than 67uA to report FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Detecting an External Voltage with an NPN Transistor===&lt;br /&gt;
&lt;br /&gt;
[[Image:external_voltage_npn.jpg|right|thumb|Schematic for detecting voltage with an NPN transistor.]]&lt;br /&gt;
&lt;br /&gt;
This circuit can be used to measure if a battery is connected, or if 12V (for example) is on a wire.&lt;br /&gt;
By designing to have Collector-Emitter current &amp;gt; 270uA, the digital input will report TRUE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using a Capacitive or Inductive Proximity Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:proximity_switch.jpg|right|thumb|Schematic for connecting to a proximity switch.]]&lt;br /&gt;
&lt;br /&gt;
Capacitive proximity switches can detect the presence of nearby non-metallic objects, whereas inductive proximity switches can detect only the presence of metallic objects.  &lt;br /&gt;
To properly interface one of these proximity switches to the digital inputs, a 3-wire proximity switch is required, as well as an external power supply.&lt;br /&gt;
We have checked the following switch from Automation Direct to verify that it works with the Digital Inputs.  &lt;br /&gt;
Similar capacitive or inductive proximity switches from other manufacturers should work just as well.&lt;br /&gt;
&lt;br /&gt;
{|border=1&lt;br /&gt;
|+&#039;&#039;&#039;Switches&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
! Manufacturer &lt;br /&gt;
! Web Page &lt;br /&gt;
! Capacitive Part No. &lt;br /&gt;
! Inductive Part No.&lt;br /&gt;
|-&lt;br /&gt;
| Automation Direct &lt;br /&gt;
| www.automationdirect.com &lt;br /&gt;
| CT1 Series &lt;br /&gt;
| AM1 Series&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
===Using an FSR or Variable Resistor as a Switch===&lt;br /&gt;
&lt;br /&gt;
[[Image:fsr_switch.jpg|right|thumb|Schematic for using an FSR as a switch.]]&lt;br /&gt;
&lt;br /&gt;
The digital inputs can be easily wired to use many variable resistors as switches.&lt;br /&gt;
If the resistance falls below 3.75k Ohms, the Digital Input will go TRUE.&lt;br /&gt;
If the resistance rises above 75k Ohms, the Digital Input will go FALSE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Helpful Tips==&lt;br /&gt;
===Update Rate===&lt;br /&gt;
*125 samples/sec is for each individual channel, not split between all channels. &lt;br /&gt;
*You can&#039;t &amp;quot;turn off&amp;quot; unused channels to improve update rate on the active channels. &lt;br /&gt;
*This value is already close to the spec for our USB processor, so there isn&#039;t much room for users to tinker with this spec.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
</feed>