<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.phidgets.com/docs21/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cora</id>
	<title>Phidgets Legacy Support - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.phidgets.com/docs21/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cora"/>
	<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/Special:Contributions/Cora"/>
	<updated>2026-04-10T07:50:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Software_Overview&amp;diff=20734</id>
		<title>Software Overview</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Solid_State_Relay_Primer&amp;diff=20733</id>
		<title>Solid State Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Solid_State_Relay_Primer&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/docs21/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/docs21/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/docs21/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/docs21/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/docs21/index.php?title=Template:StepperFAQ&amp;diff=20728</id>
		<title>Template:StepperFAQ</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Template:StepperFAQ&amp;diff=20728"/>
		<updated>2012-06-29T21:44:25Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:FAQ]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==General Stepper Motor FAQ==&lt;br /&gt;
&lt;br /&gt;
{{FAQ|What kind of motor should I buy for my project?|There are many factors to consider when selecting the proper motor. Please refer to our [[Motor Selection Guide]] for more information.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Is my stepper motor compatible with the Phidgets 1062 or 1063 stepper controller?|The first thing you should do is check the data sheet of your motor to find the amount of current it is rated for. The 1062 can provide a maximum of 1A of current, and the 1063 can provide 2.5A of current. These figures are absolute maxima- running at the maximum current constantly will effect the life of the controller. As long as our controllers can provide the current your motor is rated for, there is a high likelihood that it is compatible. Keep in mind that you can always drive your motor with less than the rated current, however, the torque and speed of the motor will be less than expected.&lt;br /&gt;
&lt;br /&gt;
:Another important specification is the power supply the motor requires. The 1062 has a maximum power supply voltage of 12V, while the 1063 has a maximum of 30V. If your motor requires significantly more power, it is likely incompatible. &lt;br /&gt;
&lt;br /&gt;
:The last specification you should check is the coil inductance of the motor. If a motor needs to stop quickly or change directions, all of the energy associated with the momentum of the motor is flushed back to the controller. If the inductance of the motor is high enough (&amp;gt;10mH), this can quickly destroy the controller. This limitation only applies to the 1063, as the 1062 runs slow enough to avoid such a problem.&lt;br /&gt;
&lt;br /&gt;
:If you are still unsure, you can [[Contact Us]].}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Is my stepper controller compatible with the motors sold by Phidgets?|As long as your controller is able to provide the appropriate current and voltage specifications as mentioned in the previous answer, and uses a chopper drive, it should be compatible with any of the motors of the appropriate type (unipolar/bipolar) that we sell. &lt;br /&gt;
&lt;br /&gt;
:If you are still unsure, you can [[Contact Us]].}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Can I use a unipolar controller to run a bipolar stepper? Or a bipolar controller to run a unipolar stepper?|It is possible to use a unipolar controller to run a 6 or 8-wire bipolar stepper motor (but not a 4-wire, since it has no common &amp;quot;+&amp;quot; wire), but you will only get roughly half as much torque and speed because only half of each motor coil is energized at any given time. You could use a bipolar controller to control a 6 or 8-wire unipolar stepper (but not a 5-wire, since the coils are connected internally by the common &amp;quot;+&amp;quot; wire), as long as the motor&#039;s current and voltage specifications match up with what&#039;s being provided by the controller. In most cases it&#039;s just easier to select the appropriate type of motor and controller ahead of time.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Precisely how much torque does a specific motor provide?|Giving an accurate, meaningful figure for the torque of a motor is difficult because it varies depending on the current provided to the motor and the speed at which it’s presently rotating. The easiest way to compare the torque of motors is by using the holding torque- that is, the torque of the motor at standstill with the rated current applied to the coils. The holding torque is equal to the output torque specified by the manufacturer plus the detent torque. &lt;br /&gt;
&lt;br /&gt;
:At low speeds, the operating torque of the motor will be roughly equal to the holding torque minus twice the detent, since the motor is working against the detent torque while in motion. At high speeds, the torque will decrease significantly. }}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Can I simultaneously use multiple stepper controllers with the same computer?|Yes, you can use as many controllers as you can connect to your computer via USB (you can use a USB hub if you run out of ports). Simply create a unique object for each controller and open them using each board’s unique serial number.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Can your stepper motors and controllers allow the motor to be driven in forward and reverse without changing the wiring?|Yes, you can make a stepper rotate forward by setting a target position greater than the current position, and you can cause it to rotate in reverse by setting a target position less than the current position (negative values are acceptable). The wiring merely determines whether “forward” in this case means clockwise or counterclockwise rotation.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Can I set the stepper motor to rotate continuously?|By setting the target position to a very large number, you can effectively cause the motor to rotate continuously. The maximum value for target position is ±239, which is long enough to keep a unipolar motor on the 1062 rotating at maximum velocity for 45 years, or a bipolar motor on the 1063 for 194 days.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|How do I connect a stepper motor to the Phidgets 1062 or 1063 controller?|Please refer to the 1062 or 1063 product page for a guide on connecting 4,5,6 and 8-wire stepper motors.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Can a stepper controller keep track of the number of steps made if the motor is turned by an external force (for example, rotated by hand)?|Stepper controllers are typically open-loop, meaning that the controller receives no feedback from the motor. If the motor is turned by an external force, or misses steps due to a heavy load, the controller will not count these steps and will lose track of the motor’s position. This could be corrected by including an encoder on the shaft of the motor to confirm the position, thus creating a closed-loop system.}}&lt;br /&gt;
&lt;br /&gt;
{{FAQ|Why is my stepper motor running with much less speed or torque than anticipated?|Ensure that you are supplying the proper rated current to the motor, and if the motor still under-performs, try using a higher voltage power supply.}}&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Weather_Station&amp;diff=20727</id>
		<title>Weather Station</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Weather_Station&amp;diff=20727"/>
		<updated>2012-06-29T21:43:43Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- CATEGORIES --&amp;gt;&lt;br /&gt;
[[Category:batteryPower]]&lt;br /&gt;
[[Category:solarPower]]&lt;br /&gt;
[[Category:phidgetsSBC]]&lt;br /&gt;
[[Category:fileIO]]&lt;br /&gt;
[[Category:removableStorage]]&lt;br /&gt;
[[Category:scheduler]]&lt;br /&gt;
[[Category:weatherproofing]]&lt;br /&gt;
[[Category:mounting]]&lt;br /&gt;
[[Category:Application Guides]]&lt;br /&gt;
The project described here is a simple weather station that measures air temperature, humidity, and surface temperature of the ground below the weather station.  &lt;br /&gt;
{|&lt;br /&gt;
|Practical concepts covered are (click on links to see other projects on that topic):&lt;br /&gt;
* Powering your Phidget&lt;br /&gt;
** [[:Category:BatteryPower|Battery power]]&lt;br /&gt;
** [[:Category:SolarPower|Solar power]]&lt;br /&gt;
* [[:Category:PhidgetsSBC|Using the SBC]]&lt;br /&gt;
** Using analog sensors&lt;br /&gt;
** Using LEDs&lt;br /&gt;
** Using USB sensors&lt;br /&gt;
* Data Logging&lt;br /&gt;
** Recording samples at a certain time&lt;br /&gt;
** [[:Category:FileIO|Writing to a text file]]&lt;br /&gt;
** [[:Category:RemovableStorage|Writing to a removable USB key]]&lt;br /&gt;
** [[:Category:Scheduler|Using the SBC cron scheduler]]&lt;br /&gt;
** Using Phidgets with Python&lt;br /&gt;
* Fixed Structures&lt;br /&gt;
** [[:Category:Weatherproofing|Weather resistance]]&lt;br /&gt;
** [[:Category:Mounting|General planning and assembly]]&lt;br /&gt;
|width=&amp;quot;45px&amp;quot;|&amp;amp;nbsp;&lt;br /&gt;
|[[Image:app_guide_weatherstn_introphoto.jpg|500px|link=|alt=]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;5px;&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Time:&#039;&#039;&#039; &lt;br /&gt;
| About 6 full days of work, including gathering components, writing code, and drilling/assembling&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Special Needed Tools:&#039;&#039;&#039; &lt;br /&gt;
|Drill, soldering iron, small screwdriver, socket and wrench set&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Other Useful Tools:&#039;&#039;&#039; &lt;br /&gt;
|Hammer, tin snips for pipe strapping&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Materials and Phidgets:&#039;&#039;&#039;&lt;br /&gt;
|Extensive lists are provided in this guide&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As with any of our [[:Category:Application Guides|described projects]], Phidgets takes care of the electrical component design.  Still, a project of this magnitude require a time investment in addition to a monetary investment.  Designing projects like these is hard. &lt;br /&gt;
&lt;br /&gt;
But the reward is deep - and very real.  A full, functional outdoor sensor system that you can build to whatever specifications you like... ask any hobbyist and you may see their eyes light up remembering their latest project.  Building such things is a special kind of freedom!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
A remote station project can monitor and log weather and other environmental conditions using Phidgets.  &lt;br /&gt;
&lt;br /&gt;
On this page, we describe this particular setup to get you started:&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_station.png|900px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
We start with all of the pieces (the Phidgets, the power supply, the main structure, and the code) and then put it all together.&lt;br /&gt;
&lt;br /&gt;
==Phidgets==&lt;br /&gt;
&lt;br /&gt;
At the core of this weather logging station is the [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer (SBC)].  The sensors and other attachments from Phidgets could include:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;5px;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;background: #c0c0c0;&amp;quot;&lt;br /&gt;
!Task&lt;br /&gt;
!Phidget&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Schedule the samples &lt;br /&gt;
* Split and Provide power to devices &lt;br /&gt;
* Control the USB Phidget (IR sensor)&lt;br /&gt;
* Run the code&lt;br /&gt;
|[{{SERVER}}/products.php?product_id=1072 1072 - PhidgetSBC2]&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Read surface temperature of ground, without touching it&lt;br /&gt;
* Provide ambient air temperature at board location&lt;br /&gt;
|[{{SERVER}}/products.php?product_id=1045 1045 - PhidgetTemperatureSensor IR]&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Measure ambient air temperature&lt;br /&gt;
* Measure ambient air humidity&lt;br /&gt;
|[{{SERVER}}/products.php?product_id=1125 1125 - Humidity/Temperature Sensor]&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Read the analog-in [{{SERVER}}/products.php?product_id=1125 Humidity/Temperature Sensor]&lt;br /&gt;
* Control LEDs to display status&lt;br /&gt;
|&lt;br /&gt;
[{{SERVER}}/products.php?product_id=1018 PhidgetInterfaceKit 8/8/8] &amp;lt;br&amp;gt;&lt;br /&gt;
(included on-board with the [{{SERVER}}/products.php?product_id=1072 1072 PhidgetSBC2])&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Take pictures&lt;br /&gt;
|[{{SERVER}}/products.php?product_id=3402 3402 USB Webcam]&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Display Status&lt;br /&gt;
| [{{SERVER}}/products.php?product_id=3601 3601 - 10mm Green LED] / [{{SERVER}}/products.php?product_id=3600 3600 - 10mm Red LED]&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
* Allow for far sensor placement&lt;br /&gt;
| 3004 - Sensor Cable 350cm&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SBC has the ability to run both USB-based Phidgets (such as the [{{SERVER}}/products.php?product_id=1045 1045 - PhidgetTemperatureSensor IR]) and analog-based Phidgets (such as the [{{SERVER}}/products.php?product_id=1125 1125 - Humidity/Temperature Sensor]).  But we have a variety of different environmental sensors that you could use on your system.  The included [{{SERVER}}/products.php?product_id=1018 1018 - PhidgetInterfaceKit 8/8/8] on board the SBC can handle up to 8 analog sensors, and 8 digital in sensors like switches.&lt;br /&gt;
&lt;br /&gt;
Using these components requires a bit of care, so the next sections give some suggestions on how to use each Phidget.&lt;br /&gt;
&lt;br /&gt;
===Phidget Infrared Temperature Sensor (IR Sensor)===&lt;br /&gt;
&lt;br /&gt;
Measuring the temperature of the ground is useful for things such as highway temperature in the summer, or snow surface temperature in the winter.  The IR board can face downward to do this without contacting the surface itself.&lt;br /&gt;
&lt;br /&gt;
The IR board should be:&lt;br /&gt;
* Encased and sealed (such as with a Phidget Enclosure and low-temperature caulk) against the weather&lt;br /&gt;
* Suspended at the right height for the sample size of ground needed (see the [{{SERVER}}/products.php?product_id=1045 1045 - PhidgetTemperatureSensor IR] specifications for the degrees of view you have)&lt;br /&gt;
* Suspended far enough away from the station that it is measuring only ground, and not measuring the base of the station&lt;br /&gt;
* Reasonably protected from solar heating (having a large station arm above it and shading it will probably do it)&lt;br /&gt;
&lt;br /&gt;
Note that you will need to calibrate the data received from this sensor.  When you can control all of the variables around what you are using the IR board to measure, you can get very accurate measurements.  But in the out-of-doors with a weather station, you will use the board temperature, any shaded temperatures you get from the [[#Phidget Temperature and Humidity Sensor|second temperature sensor]], and thermal measurement theory to correct the value the sensor receives.  Error includes:&lt;br /&gt;
* Warming of the IR board itself (i.e. you may need corrections based on board temperature)&lt;br /&gt;
* Emissivity of your subject being less than 1.0 (for more information on emissivity, see the [{{SERVER}}/products.php?product_id=1045 1045 - PhidgetTemperatureSensor IR] product page)&lt;br /&gt;
* Measurement of any reflected heat in addition to emitted heat (this also depends on the emissivity)&lt;br /&gt;
&lt;br /&gt;
These concepts and terms should help you get started in your research on how to correct the data specific to your needs - or if you need to do so at all - but a full course in correction is beyond our scope here.&lt;br /&gt;
&lt;br /&gt;
===Phidget Temperature and Humidity Sensor===&lt;br /&gt;
&lt;br /&gt;
Temperature sensors need to be protected from heating by the sun.  Both humidity and temperature sensors need to be protected from snow accumulating on them so that they can interact with the ambient air.&lt;br /&gt;
&lt;br /&gt;
A standard, suspended, white plastic Stephenson-type screen can provide this kind of protection.  Plastic ones are inexpensive, and available from specialized weather stores.  The photo in the [[#Introduction|Introduction]] shows a typical shield screen of this type.&lt;br /&gt;
&lt;br /&gt;
===Webcam===&lt;br /&gt;
&lt;br /&gt;
Whatever webcam you choose, you should test it outside to properly set the exposure and focus.  Most webcams are not weatherproof.  Your webcam can either be housed in a weather resistant housing such as those designed for outdoor floodlights, or sealed directly (except the lens) with thick, low-temperature caulk.&lt;br /&gt;
&lt;br /&gt;
===Communication===&lt;br /&gt;
&lt;br /&gt;
Because of the power requirements (as discussed further in the [[#Power|power]] section), we chose not to include a wireless connection to transfer data and check on status.  Rather, this task can be split up into two parts:&lt;br /&gt;
* LEDs can provide visible status&lt;br /&gt;
* USB keys can store and transfer data&lt;br /&gt;
Performing both of these tasks during normal field operation is covered in the [[#Code|code section]].  However, for development and debugging, we did use a wireless connection:&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_table_devel.jpg|800px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
==Power==&lt;br /&gt;
&lt;br /&gt;
From the Phidget documentation, we know that the Single Board Computer (SBC) will run at 1.2 watts with no power consumed by devices in its USB ports, and 2.5 watts maximum if all USB port devices are drawing power to maximum specification.  Because the power to all sensors and USB devices is included in this estimate, this is what we use to pick a battery and a solar panel.  &lt;br /&gt;
&lt;br /&gt;
Although we chose our Phidgets first, and are now designing a power system to support them, the Phidget selection also included some power concerns.  With a little forethought, we can guess that the wireless internet adaptor is probably the most power hungry thing that we can plug into a Phidget SBC.  A wireless adaptor has two important benefits:&lt;br /&gt;
# You can download data over the network&lt;br /&gt;
# You can change code, settings, and scheduling of data gathering as the station is operating&lt;br /&gt;
You don&#039;t necessarily need an internet connection to use the wireless, as you can connect to it via its {{Code|phidgetsbc.local}} local link address.  &lt;br /&gt;
&lt;br /&gt;
On the other hand, without a wireless adaptor, the SBC is essentially running autonomously.  You can save a lot of power this way, but if the SBC gets into an undesirable state (extreme weather causes it to reboot, a USB Phidget wiggles loose and doesn&#039;t properly attach in software, etc) your only options are to either reboot, or add a network connection to log in and change things.&lt;br /&gt;
&lt;br /&gt;
As we do not use wireless here, but do use a webcam, we use an estimate of 2.0 watts to run the SBC.&lt;br /&gt;
&lt;br /&gt;
===Solar Panel===&lt;br /&gt;
&lt;br /&gt;
We would like to have a power setup that will operate continuously, rather than having to replace the battery.  This involves solar power, and it also involves knowing something about the expected weather (namely, the sunshine) in the installation location.  Your solar watt capacity should be big enough that in periods of sun it can recharge the battery much faster than the SBC will drain it.&lt;br /&gt;
&lt;br /&gt;
To take an example as to why this matters, imagine installing a 2.0 watt solar panel into your system.  If there were sunshine 100% of the time, this would be a closed, self-refreshing system because the SBC would draw 2.0 watts from the battery, and the solar panel would put 2.0 watts back in. But with only a short period of dark, the battery will be drained slightly and never refreshed.  So we need to consider all of the factors that could cause darkness (or relative darkness) and determine from them how big a solar panel we need.&lt;br /&gt;
&lt;br /&gt;
We start with choosing amorphous solar panels because of their low cost, and (more importantly) their ability to charge a battery in low or indirect light conditions.&lt;br /&gt;
&lt;br /&gt;
Then, we account for nightfall.  This at least doubles our solar needs, especially in winter when nights are long.  We assume 3/5 dark time, as twilight conditions are poor for power generation, and the station will be installed in a valley with high ridges blocking the sun for morning and evening.  So even assuming every day is sunny, we will only receive 2/5 charge time, and will need 5/2 (5 watts) of power via the solar cell simply due to location and season.&lt;br /&gt;
&lt;br /&gt;
Then, we account for weather. An average long storm for the interior Rocky mountains is about two weeks.  Although we chose amorphous solar panels for their low-light performance, the conservative assumption is that the battery will get little recharge during such a storm.  Therefore, we want to recharge quickly between storms.  In late winter, the mountain sky is cloudy about 2/3 of the time, leaving us one week to top off the battery after two weeks of drain.  From our [[Electricity Primer#Power Needs|more general power needs section]], we can learn that our 2.0 watt SBC will draw 0.17 amps if [[#Battery|we use a 12 V battery]]. So our drain - at worst - will be:&lt;br /&gt;
*Two weeks = 24 hours per day x 14 days = 336 hours&lt;br /&gt;
*336 hours at 0.17 amps = 57 amp-hours&lt;br /&gt;
&lt;br /&gt;
To recharge 57 amps at 12 V, with a 10 watt panel this would take (the concepts are from the [[Electricity Primer#Power Needs|more general power needs section]]):&lt;br /&gt;
* 57 amps * N hours = 10 watts / 12 V&lt;br /&gt;
* N = 68&lt;br /&gt;
...68 hours.  At 2/5 charge time from the nightfall calculation (giving ten hours a day of charge), a 10 watt panel would recharge in the expected week (6.8 days).  This gives us an idea of what class of solar panel we are looking for, and from here we can examine 10 watt and larger panels with respect to cost and size.&lt;br /&gt;
&lt;br /&gt;
After examining cost, a 10-watt panel was nearly the same size and cost as an 18-watt panel ($80), and so an 18-watt panel was used here. The 18-watt panel also would help add a buffer when - even on non-storm days - high mountain clouds form and further reduce the available sun.&lt;br /&gt;
&lt;br /&gt;
Whatever you choose for your solar panel, you should include a charge limiter, and a way to reliably attach the wires to a battery (clips are for testing only, the post clamps are a more permanent install).  The cable on the right is outdoor grade power hookup wire:&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_battery_wires.jpg|800px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
===Battery===&lt;br /&gt;
&lt;br /&gt;
Your battery amp capacity should be big enough that the SBC can run continuously, with reserves, in times of cloudy weather.  Even with a proper type of battery, if your SBC completely drains your battery, depending on the battery type it has a chance of dying completely (which is called &#039;&#039;bricking&#039;&#039;) and will lose its capacity to recharge.&lt;br /&gt;
&lt;br /&gt;
We have an in-depth description of how to choose batteries [[Electricity Primer#Power Needs|in a more general power needs section]]. From the information in that section, we can determine that we will probably be using a 12 V battery, and that the SBC will draw 0.17 amps with a 12 V battery.&lt;br /&gt;
&lt;br /&gt;
Using this in the [[#Solar Panel|solar power section]], we calculated that the drain on the battery during a long storm would be, at worst, 57 amp-hours, and so this is the minimum usable capacity we need for the battery.  &lt;br /&gt;
&lt;br /&gt;
At more than about 30 amp-hours, the [[Electricity Primer#Power Needs|battery that makes the most sense]] is the large car-battery type lead acid battery.  However, typical car batteries won&#039;t work as they are not &#039;&#039;deep cycle&#039;&#039; that is, they are designed to stay fully charged most of the time.  Drawing current from this type of battery continuously will only damage and eventually destroy it.  Batteries for RVs, boats, electric golf carts, and the like are designed to be used up through most of their amperage capacity, recharged, and used again and again - these batteries are deep cycle batteries.&lt;br /&gt;
&lt;br /&gt;
Most batteries list this usable capacity for their specification, but if not, consider only 60% of the capacity to be usable.  Some example specifications are:&lt;br /&gt;
* &#039;&#039;70 Amp-hours (110 reserve)&#039;&#039; - this battery has 70 usable amp hours&lt;br /&gt;
* &#039;&#039;70 Amp hours&#039;&#039; - this battery probably only has 42 amp hours, but you can call the manufacturer to make sure&lt;br /&gt;
&lt;br /&gt;
The battery will probably be a higher cost than the solar panel.   A 60-70 usable amp-hour lead acid battery will be about $100 and 50 lbs.  When choosing a battery, the &#039;buy in bulk&#039; philosophy can come into play.  For example, this station ended up using a 110 amp-hour battery, which was $115 and 65 lbs.  This is not much weight or price difference for nearly double the power capacity.  And extra power capacity will give you extra buffer when you are testing your system at the beginning.&lt;br /&gt;
&lt;br /&gt;
There are many different types of deep cycle batteries - not just lead acid - and they vary in price significantly.  There are resources all over the Internet about different battery types to use with solar panels (as well as [[Electricity Primer#Battery Power|a primer that we have]]), so we will not describe them here.  The key deciding factor is how long the installation is designed to last.  Lead acid batteries have a lifespan of about three years.  Longer than that, and you will need to purchase a more expensive battery.&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_battery.jpg|800px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
==Structural System==&lt;br /&gt;
&lt;br /&gt;
The list of major components for this weather station is:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;5px;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;background: #c0c0c0;&amp;quot;&lt;br /&gt;
! Components&lt;br /&gt;
|- &lt;br /&gt;
| Station Tripod&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Commercial lightweight tripod&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Extension masts&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Protective screen for temperature and humidity sensor&lt;br /&gt;
|- &lt;br /&gt;
| Wires&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Exterior-grade power cable&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Hookup wire for LEDs and Long Phidget Sensor wires&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Solder and heatshrink&lt;br /&gt;
|- &lt;br /&gt;
| Misc Hardware&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Horizontal arm for measuring surface temperature (Pipe plus U-bolts and pipe strapping)&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Solar panel and SBC case mounting (Metal frame or wide clamps with locks, with U-bolts)&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Battery box to keep snow off the terminals&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Pelican 1200 waterproof case for SBC&lt;br /&gt;
|- style=&amp;quot;background: #efefef;&amp;quot;&lt;br /&gt;
| Battery post mounts, protectors, and charge limiter&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Although most of these components individually are inexpensive, put them together and the Phidgets are only a small portion of the overall system cost.&lt;br /&gt;
&lt;br /&gt;
With these types of projects, it is easy to lose track of all the little details.  Even in something contained like a weather station there are lots, including: &lt;br /&gt;
* Zip ties (black exterior type) for cable management&lt;br /&gt;
* Cold weather silicone caulk for sealing the case wire holes &lt;br /&gt;
* Silica gel packets for desiccant within the SBC case&lt;br /&gt;
* Penetrating oil (WD-40) and a hammer for working with the tripod and masts&lt;br /&gt;
* Foam to pad the U-bolt ends from the solar panel&lt;br /&gt;
* Bolts and angle brackets for the Pelican case mounting&lt;br /&gt;
And so on.  So plan to spend a while working your particular system out with diagrams, lists, or whatever works for you.  &lt;br /&gt;
&lt;br /&gt;
The details of each major connecting part (e.g. mounting the solar panel on the mast, mounting the SBC within the case and to the mast, mounting the horizontal arm, etc) will depend on many different details specific to your application, such as:&lt;br /&gt;
* Snow depth, expected winds, and primary weather&lt;br /&gt;
* Length of the horizontal arm and any sensors also on the end&lt;br /&gt;
We found U-bolts to be sufficient for most mounting needs, and quick grip clamps to be sufficient for the solar panel (a person could hang on them), which made the station easier to maintain.  This station was designed to be run for a few months and then moved or taken down; a more permanent installation may have a different design.&lt;br /&gt;
&lt;br /&gt;
Depending on your expected forces, you can enhance this basic system design.  For example, adding some stakes and plastic coated galvanized guy wires can enable your weather station masts to withstand winds of 70 kph with minimal vibration:&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_guyhardware.jpg|800px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
We will be writing our Phidget code in Python.  This code will then be scheduled to run - via [[OS - Phidget SBC#Via Cron|cron]] on the SBC - to sample data once per minute and take a webcam photo once every thirty minutes.&lt;br /&gt;
&lt;br /&gt;
Since the weather station runs autonomously - on its own, in the wild - you will need to write code that runs on the SBC itself, as you will have no external computer to control the SBC.  This depends on the SBC being set up as described in the [[1072 - Getting Started]] page, and then additionally as described in the [[OS - Phidget SBC]] page.  Namely, to follow along with this particular station design, you will need:&lt;br /&gt;
* [[OS - Phidget SBC#SSH|SSH]] enabled&lt;br /&gt;
* [[OS - Phidget SBC#Installing Python|Python installed]]&lt;br /&gt;
&lt;br /&gt;
Of course, there are many, many other ways to design this code - in Java, to run at boot rather than as a cron job, and so on - and many of these alternatives are outlined on the [[OS - Phidget SBC]] page.&lt;br /&gt;
&lt;br /&gt;
For this example, we have two [[Language - Python|Python scripts]]: {{Code|station.py}} which runs the sensors once per minute and saves the data, and {{Code|webcam.py}} which saves a webcam picture once per minute.&lt;br /&gt;
&lt;br /&gt;
===Station===&lt;br /&gt;
&lt;br /&gt;
The station code in {{Code|station.py}} has three jobs:&lt;br /&gt;
* Reading data, which is the gathering and saving of the weather data,&lt;br /&gt;
* Displaying status via the Interface Kit and LEDs, and&lt;br /&gt;
* Moving data onto a second USB key (optional)&lt;br /&gt;
&lt;br /&gt;
====Reading and Recording Data====&lt;br /&gt;
&lt;br /&gt;
This station handles two USB Phidgets (the Interface Kit on the SBC board, and the IR Temperature sensor), and two analog Phidgets (air temperature, and humidity).&lt;br /&gt;
&lt;br /&gt;
We have code snippets for using more than one USB Phidget on the [[General Phidget Programming#Using Multiple Phidgets|General Phidget Programming page]].  To use more than one analog sensor, you simply use the port number it is plugged in to.  As shown on the general programming page, you can automatically detect which USB Phidgets are attached, without knowing their serial number.  But you cannot detect which analog ports are being used, unless create an ad-hoc method, such as assuming a value of 0 means no sensor is attached, and any other value indicates an attached sensor.&lt;br /&gt;
&lt;br /&gt;
After we read the data from the Phidgets, we want to save it on the USB data key.  We can either hard-code the location or automatically detect where the key is plugged in.  Using USB keys with the SBC is discussed in detail on the [[OS - Phidget SBC#Using USB Data Keys|SBC operating system page]].  We will hard-code the location in this section&#039;s code, but we show how to automatically detect a USB key in the [[#Moving USB Data|Moving USB Data]] section.&lt;br /&gt;
&lt;br /&gt;
Here we open the two USB Phidgets, read the IR temperature state, read the two analog in sensors, write the data to an existing file on the USB data key, and turn on and off an LED looks 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=python&amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
from Phidgets.Devices.TemperatureSensor import *&lt;br /&gt;
from time import sleep&lt;br /&gt;
from datetime import *&lt;br /&gt;
&lt;br /&gt;
errors = &amp;quot;&amp;quot;&lt;br /&gt;
fileLocation = &amp;quot;/media/usb0/data.txt&amp;quot;&lt;br /&gt;
weatherLED = 0  # Digital out port position&lt;br /&gt;
&lt;br /&gt;
def close():&lt;br /&gt;
    global interfaceKit&lt;br /&gt;
    global temperatureSensor&lt;br /&gt;
    global errors&lt;br /&gt;
    try:&lt;br /&gt;
        interfaceKit.setOutputState(weatherLED,0)&lt;br /&gt;
    except PhidgetException as e:&lt;br /&gt;
        errors = errors + &amp;quot;Phidget Exception on turning off LED\n&amp;quot;&lt;br /&gt;
    temperatureSensor.closePhidget()&lt;br /&gt;
    interfaceKit.closePhidget()&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    temperatureSensor = TemperatureSensor()&lt;br /&gt;
    interfaceKit = InterfaceKit()&lt;br /&gt;
except RuntimeError as e:&lt;br /&gt;
    errors = errors + &amp;quot;Runtime Exception on object creation\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    # Replace these serial numbers with your own&lt;br /&gt;
    temperatureSensor.openPhidget(142768)&lt;br /&gt;
    interfaceKit.openPhidget(48498)&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
    errors = errors + &amp;quot;Phidget Exception on Open\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    interfaceKit.waitForAttach(1000)&lt;br /&gt;
    temperatureSensor.waitForAttach(1000)&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
    errors = errors + &amp;quot;Phidget Exception on Attach\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    # Turn the LED on&lt;br /&gt;
    interfaceKit.setOutputState(weatherLED,1)&lt;br /&gt;
    # Temperature and humidity are both ratiometric&lt;br /&gt;
    interfaceKit.setRatiometric(1)&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
    errors = errors + &amp;quot;Phidget Exception on Ratiometric turn on\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# To let the LED stay on for a visually detectable amount of time&lt;br /&gt;
sleep(0.5)&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    # These conversions are in the product manual&lt;br /&gt;
    currentTemp = (interfaceKit.getSensorValue(0) * 0.22222) - 61.11&lt;br /&gt;
    currentRH = (interfaceKit.getSensorValue(1) * 0.1906) - 40.2&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
    errors = errors + &amp;quot;Phidget Exception on reading Temperature and RH\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    currentIRTemp = temperatureSensor.getTemperature(0)&lt;br /&gt;
    boardTemp = temperatureSensor.getAmbientTemperature()&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
    errors = errors + &amp;quot;Phidget Exception on reading IR Temperature&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
outputLine = &amp;quot;&amp;quot;&lt;br /&gt;
outputLine = outputLine + str(datetime.now()) + &amp;quot;,&amp;quot;&lt;br /&gt;
outputLine = outputLine + &amp;quot;T=&amp;quot; + str(currentTemp) + &amp;quot;,&amp;quot;&lt;br /&gt;
outputLine = outputLine + &amp;quot;RH=&amp;quot; + str(currentRH) + &amp;quot;,&amp;quot;&lt;br /&gt;
outputLine = outputLine + &amp;quot;IR-T=&amp;quot; + str(currentIRTemp) + &amp;quot;,&amp;quot;&lt;br /&gt;
outputLine = outputLine + &amp;quot;IR-Brd=&amp;quot; + str(boardTemp) + &amp;quot;\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
appendFile = open(fileLocation, &#039;a&#039;)&lt;br /&gt;
appendFile.write(outputLine)&lt;br /&gt;
if errors is not &amp;quot;&amp;quot;:&lt;br /&gt;
    appendFile.write(str(datetime.now()) + &amp;quot;:\n&amp;quot; + errors)&lt;br /&gt;
appendFile.close()&lt;br /&gt;
&lt;br /&gt;
close()&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;
This code snippet shows only one LED in use to show status, attached to digital output port 0 (short LED wire goes into the ground &#039;&#039;&#039;G&#039;&#039;&#039; terminal).  For ideas on using other LEDs to display the status of the SBC and your program, see the [[#Status|status section]].&lt;br /&gt;
&lt;br /&gt;
After running this a number of times, you will have a file {{Code|data.txt}} full of lines that 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=text&amp;gt;&lt;br /&gt;
2012-03-10 08:37:02.776500,T=-1.77726,RH=40.2,IR-T=-1.01,IR-Brd=-1.09&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be written differently to start with, or parsed later into whatever data analysis program you want to use.&lt;br /&gt;
&lt;br /&gt;
====Moving USB Data====&lt;br /&gt;
&lt;br /&gt;
The station was visited once per week to obtain the data.  On these visits, we would simply change out the old USB key for a new one on every visit, and reboot the SBC.&lt;br /&gt;
&lt;br /&gt;
We also considered the alternative of writing some extra code to detect when a second USB key is plugged in and copy all of the latest data to it.&lt;br /&gt;
&lt;br /&gt;
After experimenting with both, it turned out that the change-and-reboot option worked well and was the simplest.  Rebooting the station at every visit was no problem because the cron job simply restarts as soon as the SBC restarts.  Having only one key with the data on it for the week, and then installing a fresh one, created only one key to keep track of at a time.&lt;br /&gt;
&lt;br /&gt;
However, the copy method may be useful in other instances.  You can use the mount table to detect a second USB key and write to it like this (the mount  and cp shell commands are discussed on the [[OS - Phidget SBC]] page):&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;
#! /usr/bin/python&lt;br /&gt;
from time import sleep&lt;br /&gt;
from datetime import *&lt;br /&gt;
import shlex, subprocess&lt;br /&gt;
&lt;br /&gt;
# If this code might start again via cron, we want to ensure only one process writing to the USB key&lt;br /&gt;
# The file contains a &amp;quot;1&amp;quot; to denote a process is using the second key, and &amp;quot;0&amp;quot; otherwise&lt;br /&gt;
lockFile = &amp;quot;/root/WeatherStation/semaphore.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# The shell command to check the location of a second USB key&lt;br /&gt;
checkUSBcommand = &amp;quot;mount | grep sdb1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Spawn a command line process, and obtain the output (e.g. the lines from &amp;quot;mount&amp;quot; with &amp;quot;sdb1&amp;quot; in them)&lt;br /&gt;
checkUSBprocess = subprocess.Popen(checkUSBcommand, shell=True,&lt;br /&gt;
                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)&lt;br /&gt;
output = checkUSBprocess.communicate()[0]&lt;br /&gt;
&lt;br /&gt;
usbLocation = None  # A default value&lt;br /&gt;
&lt;br /&gt;
if len(output) &amp;gt; 3:  # If we have more than a newline, key is attached&lt;br /&gt;
    outputArray = output.split(&amp;quot;usb&amp;quot;)&lt;br /&gt;
    usbLocation = outputArray[1][0]  # Get the number right after &amp;quot;usb&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# If there is no usb key, remove any locks - especially useful for multiple cron processes&lt;br /&gt;
if usbLocation is None:&lt;br /&gt;
    file = open(lockFile, &amp;quot;w&amp;quot;)&lt;br /&gt;
    file.write(&amp;quot;0\n&amp;quot;)&lt;br /&gt;
    file.flush()&lt;br /&gt;
    file.close&lt;br /&gt;
    exit(0)&lt;br /&gt;
&lt;br /&gt;
file = open(lockFile, &amp;quot;r&amp;quot;)&lt;br /&gt;
lock = file.readline().rstrip()&lt;br /&gt;
if lock is not &amp;quot;0&amp;quot;:  # If another process is already writing&lt;br /&gt;
    exit(0)&lt;br /&gt;
&lt;br /&gt;
# If we&#039;ve gotten this far, there is a key and we need to write to it.&lt;br /&gt;
&lt;br /&gt;
# Lock the semaphore&lt;br /&gt;
file = open(lockFile, &amp;quot;w&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;1\n&amp;quot;)&lt;br /&gt;
file.flush()&lt;br /&gt;
file.close&lt;br /&gt;
&lt;br /&gt;
usbLocation = &amp;quot;/media/usb&amp;quot; + usbLocation + &amp;quot;/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Copy the data file via a spawned shell process&lt;br /&gt;
copyDataCommand = &amp;quot;cp /media/usb0/data.txt &amp;quot; + usbLocation&lt;br /&gt;
dataProcess = subprocess.Popen(copyDataCommand, &lt;br /&gt;
			shell=True, stdout=subprocess.PIPE)&lt;br /&gt;
# The copy might take a while, so check every so often and sleep until done&lt;br /&gt;
while dataProcess.poll() != 0:&lt;br /&gt;
        sleep(0.1)&lt;br /&gt;
&lt;br /&gt;
# Copy any webcam images via a spawned shell process&lt;br /&gt;
copyImagesCommand = &amp;quot;cp /media/usb0/*.jpg &amp;quot; + usbLocation&lt;br /&gt;
imageProcess = subprocess.Popen(copyImagesCommand,&lt;br /&gt;
                        shell=True, stdout=subprocess.PIPE)&lt;br /&gt;
&lt;br /&gt;
# Again, the copy might take a while, so check every so often and sleep until done&lt;br /&gt;
while imageProcess.poll() != 0:&lt;br /&gt;
        sleep(0.1)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Unlock the semaphore&lt;br /&gt;
file = open(lockFile, &amp;quot;w&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;0\n&amp;quot;)&lt;br /&gt;
file.close&lt;br /&gt;
&lt;br /&gt;
exit(0)&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;
====Status====&lt;br /&gt;
&lt;br /&gt;
There are many ways to use LEDs to communicate status, but a key way is to have the LEDs turn on when reading data, and turn off when finished successfully.  Then, if they remain on at your next visit, you will know an error was triggered.  &lt;br /&gt;
&lt;br /&gt;
This shows that an error occurred, but not what error.  You can also consider writing the details of the error to your data file along with time and date information so you know what surrounding conditions may have caused it.  But depending on your method of moving (or copying) the USB data off of the board, you may want to have many LEDs for different states:&lt;br /&gt;
* Data being measured&lt;br /&gt;
* Data being copied&lt;br /&gt;
* Error generated&lt;br /&gt;
* Program exited normally&lt;br /&gt;
&lt;br /&gt;
If you use more than one LED, especially of the same colour, make sure to label them!  &lt;br /&gt;
&lt;br /&gt;
The LED setup that was used in this particular station turned an LED on for measurement, and then off on successful program exit.  Then, when the station SBC was rebooted in the field, a briefly flashing LED once per minute means the reboot of the station and software was successful.&lt;br /&gt;
&lt;br /&gt;
===Webcam===&lt;br /&gt;
&lt;br /&gt;
There is a lot of information on the [[#OS - Phidget SBC#Taking Pictures With the Webcam|SBC operating system page]] on using UVC compatible webcams. That section describes how to install the {{Code|opencv}} supporting library, which was used to control the webcam.&lt;br /&gt;
&lt;br /&gt;
The code {{Code|webcam.py}} run once every 30 minutes to take a picture was:&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;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
import cv&lt;br /&gt;
from datetime import *&lt;br /&gt;
&lt;br /&gt;
webcam = cv.CaptureFromCAM(0)&lt;br /&gt;
&lt;br /&gt;
image = cv.QueryFrame(webcam)&lt;br /&gt;
&lt;br /&gt;
# Compose a fixed-width date label for the file&lt;br /&gt;
now = datetime.now()&lt;br /&gt;
filename = str(now.year)&lt;br /&gt;
if len(str(now.month)) == 1:&lt;br /&gt;
    filename += &amp;quot;0&amp;quot; + str(now.month) &lt;br /&gt;
else: &lt;br /&gt;
    filename += str(now.month)&lt;br /&gt;
if len(str(now.day)) == 1:&lt;br /&gt;
    filename += &amp;quot;0&amp;quot; + str(now.day)&lt;br /&gt;
else:&lt;br /&gt;
    filename += str(now.day)&lt;br /&gt;
filename += &amp;quot;-&amp;quot; + str(now.hour) + &amp;quot;-&amp;quot; + str(now.minute) + &amp;quot;.jpg&amp;quot; &lt;br /&gt;
&lt;br /&gt;
# This results in something like /media/usb0/20120224-30.jpg&lt;br /&gt;
filename = &amp;quot;/media/usb0/&amp;quot; + filename&lt;br /&gt;
&lt;br /&gt;
if image:&lt;br /&gt;
    cv.SaveImage(filename, image)&lt;br /&gt;
    print filename&lt;br /&gt;
else:&lt;br /&gt;
    # Throw an error, now just an empty placeholder&lt;br /&gt;
    print &amp;quot;&amp;quot;&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;
===Scheduling===&lt;br /&gt;
&lt;br /&gt;
You can schedule your Python scripts the same way we did - as cron jobs by following the [[OS - Phidget SBC#Via Cron|cron section]] on the SBC operating system page.  Both files were saved in the default home directory {{Code|/root}}.&lt;br /&gt;
&lt;br /&gt;
The line used to schedule the weather station every minute was:&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;
* * * * * /root/station.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line used to schedule the webcam every thirty minutes was:&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;
0,30 * * * * /root/webcam.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Data===&lt;br /&gt;
&lt;br /&gt;
When visiting this weather station, we could perform any upkeep.  Then, as above, we could get the data off the weather station by simply removing the USB key drive from the SBC and rebooting the SBC.  As mentioned earlier, the reboot helped keep our code stable over time by resetting and fully cleaning out any script instances which had hung due to unforeseen circumstances. The USB key would then have a week of data on it at a time.  Here is a week with air temperature in &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;green&amp;lt;/span&amp;gt; and (partially corrected) snow surface temperature in &amp;lt;span style=&amp;quot;color:blue;&amp;quot;&amp;gt;blue&amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_plot.jpg|800px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
==Putting it All Together==&lt;br /&gt;
&lt;br /&gt;
Field installation will always be harder than you think.  But at the same time it will be fun, seeing your hard work come together.  Make sure you have permission to set up your station in its new home if the land is not yours.  Some day-of-assembly tips:&lt;br /&gt;
* Pick a day with reasonable weather for the installation, so you can slow down and do things carefully.  &lt;br /&gt;
* Assemble the pieces for practice at home, or better yet run them in your backyard before installing elsewhere&lt;br /&gt;
* Bring basic tools into the field with you when you install (a solar setup tester, hammer, penetrating oil, some wrenches and sockets, caulk) &lt;br /&gt;
&lt;br /&gt;
It is good to check your code very carefully before installing, but if something doesn&#039;t go right, you can always remove the SBC, transport it home, fix it, and reinstall relatively easily.&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_sbc_box_lables.png|800px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
When you check on the station, things you may not expect can happen in the interim, so consider bringing a small repair kit each time as you work the bugs out.&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_snow.jpg|500px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
==Extra Credit==&lt;br /&gt;
&lt;br /&gt;
===Faster Sampling===&lt;br /&gt;
&lt;br /&gt;
The ports can sample at any time interval up to the maximum data rate of the [{{SERVER}}/products.php?product_id=1018 Phidget Interface Kit] attached to the SBC.  So you can also write fast-sampling code that runs constantly from [[OS - Phidget SBC#Via a Boot Script|the SBC boot time]] and samples very quickly.  With fewer than four analog sensors, you can sample up to 1000 times per second.&lt;br /&gt;
&lt;br /&gt;
===A Smarter Station===&lt;br /&gt;
&lt;br /&gt;
The Single Board Computer is just that - a computer!  So you could install something like the [http://www.r-project.org R Statistical Package] (you can do this by using [[OS - Phidget SBC#apt|apt-get install r-base]] over [[OS - Phidget SBC#SSH|SSH]] on the SBC) and do analysis on the data as it comes in.&lt;br /&gt;
&lt;br /&gt;
[[File:app_guide_weatherstn_farshot.jpg|500px|link=|alt=]]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Solid_State_Relay_Primer&amp;diff=20725</id>
		<title>Solid State Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Solid_State_Relay_Primer&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/docs21/index.php?title=OS_-_Linux&amp;diff=20723</id>
		<title>OS - Linux</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Mechanical_Relay_Primer&amp;diff=20722</id>
		<title>Mechanical Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Mechanical_Relay_Primer&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/docs21/index.php?title=Mechanical_Relay_Primer&amp;diff=20721</id>
		<title>Mechanical Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Mechanical_Relay_Primer&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/docs21/index.php?title=Mechanical_Relay_Primer&amp;diff=20720</id>
		<title>Mechanical Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Mechanical_Relay_Primer&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/docs21/index.php?title=Mechanical_Relay_Primer&amp;diff=20719</id>
		<title>Mechanical Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Mechanical_Relay_Primer&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/docs21/index.php?title=Digital_Output_Primer&amp;diff=20718</id>
		<title>Digital Output Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Digital_Output_Primer&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/docs21/index.php?title=Template:HiddenNeeds&amp;diff=20717</id>
		<title>Template:HiddenNeeds</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Template:HiddenNeeds&amp;diff=20717"/>
		<updated>2012-06-29T21:32:51Z</updated>

		<summary type="html">&lt;p&gt;Cora: Created page with &amp;quot;&amp;lt;!--- This is to hide content needed notifications on published webpages {{{1}}}---&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--- This is to hide content needed notifications on published webpages {{{1}}}---&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Solid_State_Relay_Primer&amp;diff=20716</id>
		<title>Solid State Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Solid_State_Relay_Primer&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/docs21/index.php?title=Solid_State_Relay_Primer&amp;diff=20715</id>
		<title>Solid State Relay Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Solid_State_Relay_Primer&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/docs21/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/docs21/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/docs21/index.php?title=OS_-_OS_X&amp;diff=20713</id>
		<title>OS - OS X</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=OS_-_OS_X&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/docs21/index.php?title=OS_-_Windows&amp;diff=20712</id>
		<title>OS - Windows</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Language_-_Python&amp;diff=20711</id>
		<title>Language - Python</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Language_-_LabVIEW&amp;diff=20710</id>
		<title>Language - LabVIEW</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Language_-_LabVIEW&amp;diff=20709</id>
		<title>Language - LabVIEW</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Language_-_Flash_AS3&amp;diff=20708</id>
		<title>Language - Flash AS3</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Language_-_Flash_AS3&amp;diff=20708"/>
		<updated>2012-06-29T20:30:51Z</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-Flash AS3.png|64x64px|link=|alt=]]|Flash, developed by [http://www.adobe.com Adobe Systems] is used to build and deploy dynamic multimedia applications to the Internet.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Flash ActionScript|Phidgets &amp;lt;i&amp;gt;only&amp;lt;/i&amp;gt; over the Phidget WebService, and it is unlike the majority of the other programming languages we support where the device can be used without the Phidget WebService. The complete Phidget API, including events are supported|all Phidget devices.|[[#Windows | Windows]] and [[#OS X | OS X]]|&lt;br /&gt;
&lt;br /&gt;
Only ActionScript 3 is supported. Interaction with Phidgets is made possible as the library uses web sockets to communicate with Phidgets over the PhidgetWebService.}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Flash ActionScript|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21Flash_doc.zip ActionScript 3}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/flashdoc/index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/Flash.zip| (same file as ActionScript Libraries below)}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/examples/Flash.zip|ActionScript| (same file as Examples above)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Flash ActionScript==&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;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Flash ActionScript on Windows depend on the following files and folders. The installers in the [[#Libraries and Drivers | Quick Downloads]] section put only the {{Code|phidget21.dll}} and {{Code|PhidgetWebservice21.exe}} into your system. You will need to manually put the {{Code|com}} folder 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.  This needs to be installed on the computer that the Phidget is connected. By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebservice21.exe}}&amp;lt;/b&amp;gt; allows for controlling Phidgets remotely across the network. This needs to be installed on the computer that the Phidget is connected.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|com}}&amp;lt;/b&amp;gt; folder is the Phidget ActionScript library. The computer that is used for Flash development will need this folder. It is to be manually placed in the same directory as your project root.&lt;br /&gt;
&lt;br /&gt;
Unlike the majority of the [[Software_Overview#Language_Support |programming languages]] we support (where applications can directly connect to the Phidgets), Flash can only connect to the Phidgets over the PhidgetWebService. There are potentially three roles that a computer can act as: host, developer, and an end user. It is possible for a single computer to act as more than one of these roles at the same time:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Host&amp;lt;/b&amp;gt;: The computer that the Phidget is attached to, and can broadcast device information to any computer over the network. The {{Code|phidget21.dll}} and {{Code|PhidgetWebservice21.exe}} must be installed on the host. The host must also have the PhidgetWebService started in order for it and other computers to connect to the Phidgets attached to the host.&lt;br /&gt;
* &amp;lt;b&amp;gt;Developer&amp;lt;/b&amp;gt;: The computer that is used to develop Flash applications. This computer needs the {{Code|com}} folder in the root directory of your project. The {{Code|phidget21.dll}} and {{Code|PhidgetWebservice21.exe}} are only needed if the Phidget is directly attached to the computer.&lt;br /&gt;
* &amp;lt;b&amp;gt;End user&amp;lt;/b&amp;gt;: The computer that is used to run the compiled flash application (i.e., {{Code|.swf}}).The {{Code|phidget21.dll}} and {{Code|PhidgetWebservice21.exe}} are only needed if the Phidget is directly connected to the computer. If the computer is used for developing Flash applications, then it will need the {{Code|com}} folder in the root directory of your project.&lt;br /&gt;
&lt;br /&gt;
Here is a table summarizing what files/folders are needed for each computer role:&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;
! Computer Role&lt;br /&gt;
! {{Code|phidget21.dll}}&lt;br /&gt;
! {{Code|Phidget21WebService.dll}}&lt;br /&gt;
! {{Code|com}} folder&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|Host&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|[[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|[[Image:Checkmark.png|link=]]&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|Developer&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|[[Image:Checkmark.png|link=]]&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|End User&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|&lt;br /&gt;
|style=&amp;quot;background: #5EC155&amp;quot; align=center|&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Please see the [[Phidget WebService | Phidget WebService]] page for a high-level introduction to our WebService.&lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer on Windows, you can download the [{{SERVER}}/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
===Flash Professional===&lt;br /&gt;
&lt;br /&gt;
Adobe Flash professional allows you to develop in ActionScript and control Phidgets over the WebService.  We support ActionScript 3.0.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
This section will assume that the device is plugged into the host computer, and that the development computer has Flash Professional installed.&lt;br /&gt;
&lt;br /&gt;
As the Flash ActionScript library only supports communication with Phidgets through the PhidgetWebService, begin by [[Phidget WebService#Using The WebService|starting the WebService]] on the host computer with the default port (5001).&lt;br /&gt;
&lt;br /&gt;
To run the examples on a development computer, download the [{{SERVER}}/downloads/examples/Flash.zip Flash examples] and unpack them into a folder.  Here, you will find a HelloWorld example which is very basic but which will run with any Phidget.  You will also find more in-depth example programs for all devices.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
When you have found your example, open that {{Code|.fla}} file in the Adobe Professional Flash environment. The only thing left to do is to run the examples! Click on Control &amp;amp;rarr; Test Movie. &lt;br /&gt;
&lt;br /&gt;
[[File:Flash Test Movie.png|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Flash ActionScript examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
You may also run the examples by navigating to Control &amp;amp;rarr; Test Scene. If you are running the examples with Debug &amp;amp;rarr; Debug Movie, you will have to change the Flash Global Security Settings in order for the example to run. More information will be provided about the Flash Global Security Settings in the [[#Running Compiled Code | Running Compiled Code]] 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 ActionScript library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Place a copy of the [{{SERVER}}/downloads/examples/Flash.zip {{Code|com}}] folder in the root directory of your Flash project.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new ActionScript 3 Flash file.&lt;br /&gt;
&lt;br /&gt;
[[File:Flash New Project.png|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Then, in your code, you will need to include the Phidget ActionScript library. Navigate to Window &amp;amp;rarr; Actions to bring up the Actions window and enter in the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=actionscript&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.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;
====Running Compiled Code====&lt;br /&gt;
&lt;br /&gt;
Running a compiled {{Code|.swf}} application on an end user computer will prompt the Flash player to display a dialog box mentioning that the application will block all communications with the Internet.&lt;br /&gt;
&lt;br /&gt;
[[File:Flash Player Security Warning.png|link=|alt=Flash Player Security Warning]]&lt;br /&gt;
&lt;br /&gt;
1. Click on the {{Code|Settings}} button to bring up the Flash Global Security Settings Manager in your default web browser. Alternatively, you can access the manager with the following URL: [http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html].&lt;br /&gt;
&lt;br /&gt;
[[File:Flash Global Security Settings 1.png|link=|alt=Flash Global Security Settings]]&lt;br /&gt;
&lt;br /&gt;
2. In the Global Security Settings tab, navigate to {{Code|Edit locations ...}} &amp;amp;rarr; {{Code|Add locations}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Flash Global Security Settings 2.png|link=|alt=Browse for File/Folder]]&lt;br /&gt;
&lt;br /&gt;
3. Then, browse and add the application or the folder containing the application. &lt;br /&gt;
&lt;br /&gt;
[[File:Flash Global Security Settings 3.png|link=|alt=Added file to the trusted locations]]&lt;br /&gt;
&lt;br /&gt;
This will allow the Flash Player to allow the application to accept any communication with the Internet.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
Flash ActionScript has excellent support on OS X over the PhidgetWebService.&lt;br /&gt;
&lt;br /&gt;
The first step in using Flash ActionScript on Mac is to install Adobe Flash Professional.&lt;br /&gt;
&lt;br /&gt;
Once you have the Flash environment installed, setting up a project is exactly the same as on Widows.  Please refer to the [[#Windows (2000/XP/Vista/7)|Windows]] section for more information on this subject.&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 [[#Follow the Examples|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 ActionScript code will be our ActionScript 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/Phidget21Flash_doc.zip ActionScript API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in ActionScript 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 ActionScript 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.  Remember that Actionscript cannot open Phidgets directly - rather, it must use a form of remote open to use the WebService.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
Before you can use the Phidget, you must include a reference to the library in the action frame (Window | Actions). In Actionscript 3.0, the inclusion code would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=actionscript3&amp;gt;&lt;br /&gt;
import com.phidgets.PhidgetInterfaceKit;&lt;br /&gt;
import com.phidgets.events.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you are ready to declare, initialize, and open your Phidget. For example, we can declare and initialize a Phidget Interface Kit with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=actionscript3&amp;gt;&lt;br /&gt;
public var phid:com.phidgets.PhidgetInterfaceKit;&lt;br /&gt;
phid = new PhidgetInterfaceKit();&lt;br /&gt;
phid.open(&amp;quot;localhost&amp;quot;, 5001);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The object name for any type of Phidget is listed in the API manual. Every type of Phidget (Interface Kit, Temperature Sensor, Spatial, etc.) also inherits functionality from the Phidget base class.&lt;br /&gt;
&lt;br /&gt;
The Open function will continuously try to connect to a Phidget, based on the parameters given, even trying to reconnect if it gets disconnected. The [[Phidget WebService]] as used by ActionScript allows a single Phidget to be opened by multiple applications - this is something that cannot be done with the regular, direct interface. &lt;br /&gt;
&lt;br /&gt;
The API manual lists all of the available modes that open provides. In Flash, the parameters can be used to open the first Phidget of a type it can find or based on its serial number.&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
Simply calling open does not guarantee you can use the Phidget immediately. It needs to be plugged in (attached). If it becomes unplugged, it will be &#039;detached&#039;.  We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or checking the isAttached property and waiting until it is true.&lt;br /&gt;
&lt;br /&gt;
Our examples provide code snippets for attach event functions and how to hook them in to the Phidget for use.&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of [[General Phidget Programming#Event Driven Code|event driven programming]] when working with Phidgets. In Actionscript 3.0, we hook an event handler with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=actionscript3&amp;gt;&lt;br /&gt;
phid.addEventListener(PhidgetDataEvent.SENSOR_CHANGE, onSensorChange);	&lt;br /&gt;
    function onSensorChange(evt:PhidgetDataEvent):void{	&lt;br /&gt;
    trace (evt.Data); //Echo	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this method, the code inside the {{Code|onSensorChange}} function (which you also need to define - check out our examples for ways to do this) will get executed every time the PhidgetInterfaceKit reports a change on one of its analog inputs. &lt;br /&gt;
&lt;br /&gt;
The values from the report can be accessed from the PhidgetDataEvent object properties. Some events such as [[#Step Two: Wait for Attachment (plugging in) of the Phidget|Attach and Detach as discussed above]] belong to the base Phidget object and thus are common to all types of Phidgets.  Others, like this one for the analog sensor change on the Interface Kit, are specific to the Phidget board.  Please refer to the API manual for a full list of events and their usage.&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget and used as an alternative to event driven programming. Simply use the instance properties or call member functions such as {{Code|getSensorValue(index: int)}} or {{Code|setOutputState(index: int, val: Boolean)}} for Phidget Interface Kits, for example.&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
Just like the open call from Step One, you can close the Phidget when you are finished with it in your code.&lt;br /&gt;
&lt;br /&gt;
====Flash Security Settings====&lt;br /&gt;
&lt;br /&gt;
During debugging or after publishing the project, you may encounter some difficulties with Flash network security settings either inside or outside of the development environment with Phidgets.&lt;br /&gt;
&lt;br /&gt;
Permissions for your project folder can be added through the settings manager at [http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html], under “Always trust files in these locations” &amp;amp;rarr; “Edit locations...” &amp;amp;rarr; “Add location...”.&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
Problem: My compiled application is experiencing the following security error upon launching: &amp;quot;SecurityError: Error #2010: Local-with-filesystem SWF files are not permitted to use sockets&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:Socket Runtime Error.png|link=|alt=Socket Error]]&lt;br /&gt;
&lt;br /&gt;
Solution: The symptom of this problem is similar to the one that is discussed in steps 1 - 3 of the [[#Running Compiled Code | Running Compiled Code]] section. Please see that section for a remedy. To access the Flash Global Security Settings Manager, go to [http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html].&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Language_-_Visual_Basic_(.NET_Compact_Framework)&amp;diff=20707</id>
		<title>Language - Visual Basic (.NET Compact Framework)</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Language_-_Visual_Basic_(.NET_Compact_Framework)&amp;diff=20707"/>
		<updated>2012-06-29T20:29:39Z</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 Compact Framework) is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft] intended for developing applications for smart devices.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Visual Basic (.NET Compact Framework)|the complete Phidget API, including events|all Phidget devices.|the .NET Compact Framework. This framework is supported on devices with the Windows CE operating system. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Visual Basic (.NET Compact Framework)|&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/CE.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip|Phidget Windows CE| (all architectures)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21ARMV4I.CAB|Windows CE|Installer (ARMV4I)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21x86.CAB|Windows CE|Installer (x86)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21MIPSII.CAB|Windows CE|Installer (MIPSII)}}&lt;br /&gt;
}}&lt;br /&gt;
The source code for the Phidget Kernel driver for Windows CE is also provided:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21CEkernalsource.zip Kernel Driver Source(all architectures)]&lt;br /&gt;
&lt;br /&gt;
==Getting started with Visual Basic (.NET Compact Framework)==&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;
To develop applications on Windows CE, you will need a Windows(2000/XP/Vista/7) system in order to perform development on. The drivers can be easily installed onto the Windows CE system by using the installers in the [[#Libraries and Drivers | Libraries and Drivers]] section. You will also need the (.NET Compact Framework Libraries) on your development system to code against.&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 Compact Framework) 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.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21CE.NET.dll}}&amp;lt;/b&amp;gt; is the .NET(Compact Framework) Phidgets library.&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 [[Phidget WebService | Phidget Web Service]].&lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip files]. Inside the zip file, please use the files that pertain to your architecture. These files should be placed in the {{Code|\Windows}} folder.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
We will start by downloading the examples and building an executable for them on the development machine. Visual Studio will be used for development. We will then transfer the executable onto the Windows CE machine to run.&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/CE.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2008, Visual Studio 2010 will easily open and upgrade them. Please note that we do not have examples for Visual Studio 2005. &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 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}} Visual Basic(.NET Compact Framework) example.&lt;br /&gt;
&lt;br /&gt;
Next, build the example project. Right click the {{Code|HelloWorld}} project and select {{Code|Build}} to create an executable. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2008 VBNETCompact Build.PNG|link=|alt=Build]]&lt;br /&gt;
&lt;br /&gt;
Then in Windows Explorer, navigate to the {{Code|project directory\bin\Debug}} folder if you are targeting a debug configuration. The folder will be {{Code|project directory\bin\Release}} if you are targeting a release configuration. Regardless of whether you are targeting debug or release, you will find an executable named {{Code|HelloWorld.exe}}. Transfer this file onto the Windows CE system. &lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Double click on the executable on the Windows CE system to run it. &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! &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}} Currently, the only devices we have example code is for the PhidgetInterfaceKit, PhidgetRFID, PhidgetTextLCD. 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 Visual Basic(.NET Compact Framework) 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;
On the development computer, 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 Visual Basic(.NET Compact Framework) libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new smart device Visual Basic Console Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2008 VBNETCompact New Project 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2008 VBNETCompact New Project 2.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:VS2008 VBNETCompact Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Download the [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip {{Code|Phidget21CE.NET.dll}}] file. The file is contained in the zip file. &lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21CE.NET.dll}}.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2008 VBNETCompact Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. 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;
==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 .NET 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;
===Code Snippets and Further Help===&lt;br /&gt;
&lt;br /&gt;
Coding in Visual Basic .NET Compact Framework is very similar to coding in [[Language - Visual Basic .NET | Visual Basic .NET]].  We have a huge section on that page which includes pseudo-code and code snippets for developing with Phidgets.  These resources are also applicable to .NET Compact:&lt;br /&gt;
&lt;br /&gt;
* [[Language - Visual Basic .NET#Follow the Examples|Follow the Examples in Visual Basic .NET]]&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None specific to .NET Compact at this time, but please also refer to the [[Language - Visual Basic .NET#Common Problems and Solutions/Workarounds|Common Problems and Solutions/Workarounds]] section on the main Visual Basic .NET page.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Language_-_C_Sharp_(.NET_Compact_Framework)&amp;diff=20706</id>
		<title>Language - C Sharp (.NET Compact Framework)</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Language_-_C_Sharp_(.NET_Compact_Framework)&amp;diff=20706"/>
		<updated>2012-06-29T20:29:26Z</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#(.NET Compact Framework) is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft] intended for developing applications for smart devices.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C# (.NET Compact Framework)|the complete Phidget API, including events|all Phidget devices.|the .NET Compact Framework. This framework is supported on devices with the Windows CE operating system. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#(.NET Compact Framework)|&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/CE.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip|Phidget Windows CE|(all architectures)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21ARMV4I.CAB|Windows CE|Installer(ARMV4I)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21x86.CAB|Windows CE|Installer(x86)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Phidget21MIPSII.CAB|Windows CE|Installer(MIPSII)}}&lt;br /&gt;
}}&lt;br /&gt;
The source code for the Phidget Kernel driver for Windows CE is also provided:&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21CEkernalsource.zip Kernel Driver Source(all architectures)]&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#(.NET Compact Framework)==&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;
To develop applications on Windows CE, you will need a Windows(2000/XP/Vista/7) system in order to perform development on. The drivers can be easily installed onto the Windows CE system by using the installers in the [[#Libraries and Drivers | Libraries and Drivers]] section. You will also need the (.NET Compact Framework Libraries) on your development system to code against.&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#(.NET Compact Framework) 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.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21CE.NET.dll}}&amp;lt;/b&amp;gt; is the .NET(Compact Framework) Phidgets library.&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 [[Phidget WebService | Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip files]. Inside the zip file, please use the files that pertain to your architecture. These files should be placed in the {{Code|\Windows}} folder.&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;
We will start by downloading the examples and building an executable for them on the development machine. Visual Studio will be used for development. We will then transfer the executable onto the Windows CE machine to run.&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [{{SERVER}}/downloads/examples/CE.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|WindowsCE.NET Examples.sln}} or {{Code|WindowsCE.NET Examples_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# (.NET Compact Framework) 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;
Next, build the example project. Right click the {{Code|HelloWorld}} project and select {{Code|Build}} to create an executable. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 CSharpCompact Build.PNG|link=|alt=Build]]&lt;br /&gt;
&lt;br /&gt;
Then in Windows Explorer, navigate to the {{Code|project directory\bin\Debug}} folder if you are targeting a debug configuration. The folder will be {{Code|project directory\bin\Release}} if you are targeting a release configuration. Regardless of whether you are targeting debug or release, you will find an executable named {{Code|HelloWorld.exe}}. Transfer this file onto the Windows CE system. &lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Double click on the executable on the Windows CE system to run it. &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! &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}} Currently, the only devices we have example code is for the PhidgetInterfaceKit, PhidgetRFID, PhidgetTextLCD. 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# (.NET Compact Framework) 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;
On the development computer, 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#(.NET Compact Framework) libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new smart device Windows CE C# Console Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 CSharpCompact 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:VS2005 CSharpCompact Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Download the [{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip {{Code|Phidget21CE.NET.dll}}] file. The file is contained in the zip file. &lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21CE.NET.dll}}.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 CSharpCompact Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. 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;
==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 .NET 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;
===Code Snippets and Further Help===&lt;br /&gt;
&lt;br /&gt;
Coding in C# .NET Compact Framework is very similar to coding in [[Language - C Sharp | C# .NET]].  We have a huge section on that page which includes pseudo-code and code snippets for developing with Phidgets.  These resources are also applicable to .NET Compact:&lt;br /&gt;
&lt;br /&gt;
* [[Language - C Sharp#Follow the Examples|Follow the Examples in C Sharp]]&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None specific to .NET Compact at this time, but please also refer to the [[Language - C Sharp#Common Problems and Solutions/Workarounds|Common Problems and Solutions/Workarounds]] section on the main C# page.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Language_-_Visual_Basic_.NET&amp;diff=20705</id>
		<title>Language - Visual Basic .NET</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Language_-_Visual_Basic_.NET&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/docs21/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/docs21/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/docs21/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/docs21/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/docs21/index.php?title=LED_Primer&amp;diff=20701</id>
		<title>LED Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=LED_Primer&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/docs21/index.php?title=User:Cora&amp;diff=20700</id>
		<title>User:Cora</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=User:Cora&amp;diff=20700"/>
		<updated>2012-06-29T20:07:30Z</updated>

		<summary type="html">&lt;p&gt;Cora: Replaced content with &amp;quot;You&amp;#039;re probably looking for [http://sl/wiki/index.php/User:Cora the old wiki]&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;You&#039;re probably looking for [http://sl/wiki/index.php/User:Cora the old wiki]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=OS_-_iOS&amp;diff=20699</id>
		<title>OS - iOS</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=OS_-_Android&amp;diff=20698</id>
		<title>OS - Android</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Language_-_MATLAB&amp;diff=20697</id>
		<title>Language - MATLAB</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Language_-_MATLAB&amp;diff=20697"/>
		<updated>2012-06-29T20:04:40Z</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-Matlab.png|64x64px]]|MATLAB is a scientific and numerical analysis oriented language, with many graphical libraries and a wide user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|MATLAB|the non-[[General Phidget Programming#Event Driven Code|event driven]] part of the Phidget API|AdvancedServo, Encoder, InterfaceKit, Servo and Stepper.|any operating system that can run MATLAB code|}}&lt;br /&gt;
&lt;br /&gt;
If you want to use the events provided by the Phidget library (for, say, collecting sensor data as it changes) then consider using Python as a wrapper.  Python has many libraries which can provide MATLAB-like functionality, such as:&lt;br /&gt;
* MatplotLib (plotting functions very similar to MATLAB)&lt;br /&gt;
* NumPy (array functions similar to MATLAB)&lt;br /&gt;
* SciPy (scientific functions similar to MATLAB libraries)&lt;br /&gt;
&lt;br /&gt;
For Windows and Mac users who do not want to manage individual packages, there is [http://www.enthought.com/products/epd.php Enthought] which includes all of the above in addition to wxPython for graphing and other GUI-type programming.  For Linux users, matplotlib may be downloaded from [http://matplotlib.sourceforge.net/ its website], and the other packages are in the Debian package and other package repositories.&lt;br /&gt;
&lt;br /&gt;
There is also Pytave, which interfaces with Octave, which can read .m files.  Using the list of libraries above would &#039;&#039;&#039;mimic&#039;&#039;&#039; MATLAB abilities in Python.  Using Pytave would allow you to open most MATLAB code directly, as long as it works on Octave.  In both of these cases, you would use the [[Language - Python | Python Phidget libraries]], and Python as your main Phidget programming language, not MATLAB.  Python has excellent [http://python.org/ web documentation], and we even have an application guide to use [[Live Data Graphing|Python graphics instead of MATLAB graphics]].&lt;br /&gt;
&lt;br /&gt;
We do not support Octave.  Phidgets in MATLAB depend on the &amp;lt;code&amp;gt;calllib()&amp;lt;/code&amp;gt; function, which Octave does not have.  For workarounds, see our [[#Common Problems and Solutions|common problems]] section.  Also, the {{Code|calllib}} library uses our C libraries, so programming in MATLAB for Phidgets uses the C API.&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|MATLAB|&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/Matlab.zip MATLAB|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|{{SERVER}}/downloads/libraries/Matlab.zip|MATLAB (Windows and Mac)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting Started with MATLAB==&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]]&lt;br /&gt;
&lt;br /&gt;
==Windows 2000/XP/Vista/7==&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
Start by using and modifying existing examples.  You can find the MATLAB example code here:&lt;br /&gt;
&lt;br /&gt;
*[{{SERVER}}/downloads/examples/Matlab.zip MATLAB Examples]&lt;br /&gt;
&lt;br /&gt;
If you are using a 64 bit version of Windows, a small modification to the {{Code|phidget21Matlab.h}} will be required to use our examples or writing your own code. Please add the following lines to the beginning of 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=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #ifndef WIN32 &lt;br /&gt;
  #define __stdcall&lt;br /&gt;
  #endif&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 run the example code, you&#039;ll need to unpack the download and find the source code &#039;&#039;for your specific device&#039;&#039; within the example package.  The file you need will be named something similar to your device name.  Once you have found the file that runs your device, copy that .m source file &#039;&#039;&#039;and&#039;&#039;&#039; phidget21Matlab.h from the examples folder to your project directory.   Then, run the code within MATLAB as you would any .m file.  For example, from the MATLAB command line, to run the example that reads the analog input from a Phidget Interface Kit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  run analogin.m&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;
This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
If you receive an error regarding that the selected compiler cannot be found.&lt;br /&gt;
&lt;br /&gt;
[[File:MATLAB Win Compiler Error.png|link=|alt=Compile cannot be found]]&lt;br /&gt;
&lt;br /&gt;
You will have to to configure your compiler for MATLAB by entering the following command in the MATLAB command window:&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #f3f3f3; border-color: #1c9edb; border-width:1px; border-style: dashed;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;font size=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;source lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  mex -setup&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:MATLAB Win Mex Setup.png|link=|alt=Mex Setup]]&lt;br /&gt;
&lt;br /&gt;
Next, select {{Code|y}} to view all installed compilers.&lt;br /&gt;
&lt;br /&gt;
[[File:MATLAB Win Choose Your Compiler.png|link=|alt=Choose your Compiler]]&lt;br /&gt;
&lt;br /&gt;
Finally, select the compiler you wish MATLAB to use. &lt;br /&gt;
&lt;br /&gt;
[[File:MATLAB Win Mex Setup Output.png|link=|alt=Mex Setup Output]]&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
You can write your MATLAB code the same way you usually do, whether within a text editor or within MATLAB itself.  However, to use Phidget calls within your code, you must include a reference to the Phidget library in your main body of code, before any Phidget calls:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  function phidgettest(n)&lt;br /&gt;
     loadlibrary phidget21 phidget21Matlab.h;&lt;br /&gt;
      % More code goes here&lt;br /&gt;
  end&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;
Also, before running your code, remember to &#039;&#039;&#039;copy phidget21Matlab.h to your project directory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Mac OS==&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;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
Due to different library naming conventions, as well as different compiler support for the behind-the-scenes libraries, you will have to make two small modifications to our MATLAB examples to run them on Mac OS.&lt;br /&gt;
&lt;br /&gt;
Instructions will differ depending on whether you are using a 32 or 64 bit system.  &lt;br /&gt;
&lt;br /&gt;
For, &amp;lt;b&amp;gt;32 bit systems&amp;lt;/b&amp;gt;, you need to make one change to {{Code|phidget21Matlab.h}}, by adding the following to the top of 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=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #ifndef WIN32 &lt;br /&gt;
  #define __stdcall&lt;br /&gt;
  #endif&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;
Save the file and keep it in the same folder where you will run the example.&lt;br /&gt;
&lt;br /&gt;
This change simply defines __stdcall to be nothing. The __stdcall function is not supported on a Mac because it is not supported by the library compiler gcc. Removing the __stdcall definition will simply call the Phidget functions in a raw manner rather than having the stack managed by the function itself. &lt;br /&gt;
&lt;br /&gt;
The next change is to the example {{Code|.m}} source code file you are using.  In all of the example code {{Code|.m}} files, there is a line near the very top (line 4 or so) that says:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary phidget21 phidget21Matlab.h;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary (&#039;phidget21&#039;, &#039;phidget21Matlab.h&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Mac OS, this needs to be changed to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary /Library/frameworks/Phidget21.framework/Versions/Current/Phidget21 phidget21Matlab.h alias phidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The location of {{Code|Phidget21}} should be the actual location of the Phidget libraries on your system.  If you just did a default install, the locations as written above should be fine.  Otherwise, find the libraries (use a search or locate function from the command line or operating system) and substitute their actual location.&lt;br /&gt;
&lt;br /&gt;
These changes are needed because the Phidget libraries are named differently on Mac OS than they are on Windows.  On Windows, the {{Code|loadlibrary}} function looks for a &#039;&#039;phidget21&#039;&#039;.dll file and links it to the phidget21 alias used throughout the MATLAB program.  This alias linking happens automatically because the library and the alias have the same name, including capitalization.&lt;br /&gt;
&lt;br /&gt;
On Mac OS, however, the library to be linked is the executable {{Code|Phidget21}}.  Because it does not have exactly the same name as &#039;&#039;phidget21&#039;&#039; (which is used as the alias in the rest of the {{Code|.m}} code), you have to link it and alias it explicitly.&lt;br /&gt;
&lt;br /&gt;
Without these changes, the errors that appear can be quite strange.  They show up as file-not-found errors, ELF-header errors, or simply {{Code|evalin()}} errors, depending on whether you&#039;ve changed the phidget21Matlab.h file, the path, the file, or none of the above.  The file-not-found error looks 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=text&amp;gt;&lt;br /&gt;
Error in ==&amp;gt; digitalout at 3&lt;br /&gt;
loadlibrary phidget21 phidget21Matlab.h;&lt;br /&gt;
&lt;br /&gt;
Error in ==&amp;gt; run at 74&lt;br /&gt;
    evalin(&#039;caller&#039;,[script &#039;;&#039;]);&lt;br /&gt;
&lt;br /&gt;
Caused by:&lt;br /&gt;
    Error using ==&amp;gt; loaddefinedlibrary&lt;br /&gt;
    phidget21.so: cannot open shared object file: 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;
The phidget21Matlab.h file should be either in the current project directory, or in a MATLAB path (type {{Code|path}} in MATLAB to see the current setup).  If you prefer to use parentheses and quotations for aliasing (to keep your formatting strict), you can read about the various syntax options for the {{Code|loadlibrary}} function on the [http://www.mathworks.com/help/techdoc/ref/loadlibrary.html MathWorks website].&lt;br /&gt;
&lt;br /&gt;
Once you have made the changes above to both the {{Code|phidget21Matlab.h}} file and the {{Code|*.m}} example file you want to run, running the example you want is easy.  Just put the {{Code|*.m}} example and the {{Code|phidget21Matlab.h}} file into your current directory in Matlab, and type the example name.&lt;br /&gt;
&lt;br /&gt;
For instance, to use the {{Code|analogin.m}} example to read analog in data from a Phidget Interface Kit, you can just type it on the MATLAB command line:&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; M A T L A B (R) &amp;gt;&lt;br /&gt;
Copyright 1984-2012 The MathWorks, Inc.&lt;br /&gt;
R2012a (7.14.0.739) 64-bit (glnxa64)&lt;br /&gt;
February 9, 2012&lt;br /&gt;
 &lt;br /&gt;
To get started, type one of these: helpwin, helpdesk, or demo.&lt;br /&gt;
For product information, visit www.mathworks.com.&lt;br /&gt;
 &lt;br /&gt;
&amp;gt;&amp;gt; analogin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;b&amp;gt;64 bit systems&amp;lt;/b&amp;gt;, the {{Code|phidget21Matlab.h}} will differ slightly from the 32 bit version. Download the 64 bit version of {{Code|phidget21Matlab.h}}, and change the following line:&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;
  typedef void* CPhidgetHandle;&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;
with:&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;
  typedef long long CPhidgetHandle;&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 next change is to the example {{Code|.m}} source code file you are using.  In all of the example code {{Code|.m}} files, there is a line near the very top (line 4 or so) that says:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary phidget21 phidget21Matlab.h;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary (&#039;phidget21&#039;, &#039;phidget21Matlab.h&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Mac OS, this needs to be changed to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary /Library/frameworks/Phidget21.framework/Versions/Current/Phidget21 phidget21Matlab.h alias phidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The location of {{Code|Phidget21}} should be the actual location of the Phidget libraries on your system.  If you just did a default install, the locations as written above should be fine.  Otherwise, find the libraries (use a search or locate function from the command line or operating system) and substitute their actual location.&lt;br /&gt;
&lt;br /&gt;
The pointer data type of the PhidgetHandle will also need to be changed. Replace the following:&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;
  ptr = libpointer(&#039;int32Ptr&#039;,0);&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;
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=c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  ptr = libpointer(&#039;int64Ptr&#039;,0);&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 phidget21Matlab.h file should be either in the current project directory, or in a MATLAB path (type {{Code|path}} in MATLAB to see the current setup).  If you prefer to use parentheses and quotations for aliasing (to keep your formatting strict), you can read about the various syntax options for the {{Code|loadlibrary}} function on the [http://www.mathworks.com/help/techdoc/ref/loadlibrary.html MathWorks website].&lt;br /&gt;
&lt;br /&gt;
Once you have made the changes above to both the {{Code|phidget21Matlab.h}} file and the {{Code|*.m}} example file you want to run, running the example you want is easy.  Just put the {{Code|*.m}} example and the {{Code|phidget21Matlab.h}} file into your current directory in Matlab, and type the example name.&lt;br /&gt;
&lt;br /&gt;
For instance, to use the {{Code|analogin.m}} example to read analog in data from a Phidget Interface Kit, you can just type it on the MATLAB command line:&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;
 &lt;br /&gt;
  &amp;gt;&amp;gt; analogin&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;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
You can write your MATLAB code the same way you usually do, whether within a text editor or within MATLAB itself.  However, to use Phidget calls within your code, you must include a reference to the Phidget library in your main body of code, before any Phidget calls.&lt;br /&gt;
&lt;br /&gt;
On Mac OS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  function phidgettest(n)&lt;br /&gt;
     loadlibrary /Library/framework/Phidget21.framework/Versions/Current/Phidget21 phidget21Matlab.h alias phidget21&lt;br /&gt;
      % More code goes here&lt;br /&gt;
  end&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;
==Linux==&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;
===Use our Examples===&lt;br /&gt;
&lt;br /&gt;
====Step 1: Compile the MATLAB Library====&lt;br /&gt;
&lt;br /&gt;
In the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Linux libraries] (not the MATLAB libraries) you have already have compiled the {{Code|phidget21.h}} for running all Phidgets on Linux.  There is &#039;&#039;another&#039;&#039; make target in those libraries to make the MATLAB library header file for your Linux system.&lt;br /&gt;
&lt;br /&gt;
To make this MATLAB library:&lt;br /&gt;
# Re-download the [{{SERVER}}/downloads/libraries/libphidget.tar.gz Phidget Linux libraries] if you have deleted the Phidget Library source code&lt;br /&gt;
#* If you re-download, also make the main {{Code|phidget21.h}} Phidget library as described on the [[OS - Linux]] page so the MATLAB library matches&lt;br /&gt;
#Then, in the source code directory where you ran {{Code|./configure}}, {{Code|make}}, and {{Code|make install}} for the main libraries, also run:&lt;br /&gt;
#:{{Code|make phidget21matlab.h}}&lt;br /&gt;
&lt;br /&gt;
This will generate a file called {{Code|phidget21matlab.h}} which you can rename to {{Code|phidget21Matlab.h}} so that it works with our examples:&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;
mv phidget21matlab.h phidget21Matlab.h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, if you have an older library, you may have to add one line at the top of {{Code|phidget21Matlab.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;
typedef long long __int64;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you try running the examples as below, and something similar to this is not already in the {{Code|phidget21Matlab.h}} file, MATLAB will give you a series of fairly descriptive errors involving {{Code|__int64}}.  So you can also try running the examples and adding this if needed.&lt;br /&gt;
&lt;br /&gt;
And, on &#039;&#039;&#039;64-bit Linux systems&#039;&#039;&#039; with older libraries, you will need to change the line that says {{Code|typedef long CPhidgetHandle;}} to say either:&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;
typedef long long CPhidgetHandle;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or:&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;
typedef void* CPhidgetHandle;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
....depending on how you want to typecast your Phidget handle within your code (if you are not sure, the first one should work fine).&lt;br /&gt;
&lt;br /&gt;
This changes the pointer type for the Phidget software object to be 64 bits, which is what your 64 bit machine will naturally create.&lt;br /&gt;
&lt;br /&gt;
====Step 2: Modify the Examples====&lt;br /&gt;
&lt;br /&gt;
Download the and unzip the [{{SERVER}}/downloads/examples/Matlab.zip Phidget examples for MATLAB].  Put the {{Code|phidget21Matlab.h}} header file that you just compiled into the unzipped example directory, overwriting the existing Windows/Mac {{Code|phidget21Matlab.h}} file that came with the examples.&lt;br /&gt;
&lt;br /&gt;
The next change is to the example {{Code|.m}} source code file you are using.  In all of the example code {{Code|.m}} files, there is a line near the very top (line 4 or so) that says:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary phidget21 phidget21Matlab.h;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary (&#039;phidget21&#039;, &#039;phidget21Matlab.h&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs to be changed to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
loadlibrary /usr/lib/libphidget21.so phidget21Matlab.h alias phidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The location of {{Code|libphidget21.so}} should be the actual location of the Phidget libraries on your system.  If you just did a default install, the location as written above should be fine.  Otherwise, find the libraries (use a search or locate function from the command line or operating system) and substitute the actual location.&lt;br /&gt;
&lt;br /&gt;
These changes are needed because the Phidget libraries are named differently on Linux than they are on Windows.  On Windows, the {{Code|loadlibrary}} function looks for a &#039;&#039;phidget21&#039;&#039;.dll file and links it to the phidget21 alias used throughout the MATLAB program.  This alias linking happens automatically because the library and the alias have the same name, including capitalization.&lt;br /&gt;
&lt;br /&gt;
On Linux, however, the library to be linked is the executable {{Code|libphidget21.so}}.  Because it does not have exactly the same name as &#039;&#039;phidget21&#039;&#039; (which is used as the alias in the rest of the {{Code|.m}} code), you have to link it and alias it explicitly.&lt;br /&gt;
&lt;br /&gt;
Without these changes, the errors that appear can be quite strange.  They show up as file-not-found errors, ELF-header errors, or simply {{Code|evalin()}} errors, depending on whether you&#039;ve changed the phidget21Matlab.h file, the path, the file, or none of the above.  The file-not-found error looks 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=text&amp;gt;&lt;br /&gt;
Error in ==&amp;gt; digitalout at 3&lt;br /&gt;
loadlibrary phidget21 phidget21Matlab.h;&lt;br /&gt;
&lt;br /&gt;
Error in ==&amp;gt; run at 74&lt;br /&gt;
    evalin(&#039;caller&#039;,[script &#039;;&#039;]);&lt;br /&gt;
&lt;br /&gt;
Caused by:&lt;br /&gt;
    Error using ==&amp;gt; loaddefinedlibrary&lt;br /&gt;
    phidget21.so: cannot open shared object file: 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;
On a &#039;&#039;&#039;64-bit Linux&#039;&#039;&#039; system, you will need to change the Phidget handle within the example to be a 64 bit pointer, matching the {{Code|phidget21Matlab.h}} file.  For example, in the {{Code|analogin.m}} example, the line that says &amp;lt;code&amp;gt;ptr = libpointer(&#039;int32Ptr&#039;,0);&amp;lt;/code&amp;gt; to say:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
ptr = libpointer(&#039;int64Ptr&#039;,0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step 3: Run the Examples====&lt;br /&gt;
&lt;br /&gt;
The compiled and edited {{Code|phidget21Matlab.h}} file should be either in the current project directory, or in a MATLAB path (type {{Code|path}} in MATLAB to see the current setup).  If you prefer to use parentheses and quotations for aliasing (to keep your formatting strict), you can read about the various syntax options for the {{Code|loadlibrary}} function on the [http://www.mathworks.com/help/techdoc/ref/loadlibrary.html MathWorks website].&lt;br /&gt;
&lt;br /&gt;
Once you have made the changes above to both the {{Code|phidget21Matlab.h}} file and the {{Code|*.m}} example file you want to run, running the example you want is easy.  Just put the {{Code|*.m}} example and the {{Code|phidget21Matlab.h}} file into your current directory in Matlab, and type the example name.&lt;br /&gt;
&lt;br /&gt;
For instance, to use the {{Code|analogin.m}} example to read analog in data from a Phidget Interface Kit, you can just type it on the MATLAB command line:&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; M A T L A B (R) &amp;gt;&lt;br /&gt;
Copyright 1984-2012 The MathWorks, Inc.&lt;br /&gt;
R2012a (7.14.0.739) 64-bit (glnxa64)&lt;br /&gt;
February 9, 2012&lt;br /&gt;
 &lt;br /&gt;
To get started, type one of these: helpwin, helpdesk, or demo.&lt;br /&gt;
For product information, visit www.mathworks.com.&lt;br /&gt;
 &lt;br /&gt;
&amp;gt;&amp;gt; analogin&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 can write your MATLAB code the same way you usually do, whether within a text editor or within MATLAB itself.  However, to use Phidget calls within your code, you must include a reference to the Phidget library in your main body of code, before any Phidget calls.&lt;br /&gt;
&lt;br /&gt;
And on Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  function phidgettest(n)&lt;br /&gt;
     loadlibrary /usr/lib/libphidget21.so phidget21Matlab.h alias phidget21&lt;br /&gt;
      % More code goes here&lt;br /&gt;
  end&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;
Also, before running your code, remember to &#039;&#039;&#039;copy phidget21Matlab.h to your project directory&#039;&#039;&#039;.&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 MATLAB makes extensive use of the &#039;&#039;&#039;calllib()&#039;&#039;&#039; function to the C/C++ library, so your main reference for coding will be the C/C++ API reference:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|although you can only use the logic code type design in MATLAB|[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
If you find yourself wanting to use event functions in the API (which are not available in MATLAB), try using Python as described in the [[#Support | support]] section at the top of this page.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in MATLAB 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 MATLAB 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=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  devicePointer = libpointer(&#039;int32Ptr&#039;,0);&lt;br /&gt;
  calllib(&#039;phidget21&#039;, &#039;CPhidgetInterfaceKit_create&#039;, devicePointer);&lt;br /&gt;
  device = get(devicePointer, &#039;Value&#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;
The devicePointer is converted to the handle &#039;&#039;&#039;device&#039;&#039;&#039; as a handle for the Phidget.  This example is &#039;&#039;specific to the Interface Kit&#039;&#039; because the call CPhidgetInterfaceKit_create is used.  For another device, use the correspondingly named call in the C/C++ API. &lt;br /&gt;
&lt;br /&gt;
The handle &#039;&#039;&#039;device&#039;&#039;&#039; is then used for all the C function calls where CPhidgetHandle phid is used in the C/C++ API.  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.&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 all of the available modes that open provides. &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 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=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  calllib(&#039;phidget21&#039;, &#039;CPhidget_open&#039;, device, -1);&lt;br /&gt;
  if calllib(&#039;phidget21&#039;, &#039;CPhidget_waitForAttachment&#039;, device, 2500) == 0&lt;br /&gt;
     % Insert your code here&lt;br /&gt;
  end&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 Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
MATLAB does not support event handling, so all data must be read and sent directly. &lt;br /&gt;
&lt;br /&gt;
The most common thing you might want to do is read data from sensors.  For example, in the code below, we might want to read data from a sensor on the [{{SERVER}}/products.php?product_id=1018 Phidget Interface Kit].&lt;br /&gt;
&lt;br /&gt;
Simply use the C API functions such as CPhidgetInterfaceKit_getSensorValue() or CPhidgetInterfaceKit_setOutState() for Interface Kits.  The following reads and displays data from a sensor ten times as quickly as the while loop can execute: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  while n&amp;lt;10&lt;br /&gt;
    dataPointer = libpointer(&#039;int32Ptr&#039;,0);&lt;br /&gt;
    calllib(&#039;phidget21&#039;, &#039;CPhidgetInterfaceKit_getSensorValue&#039;, device, 0, dataPointer)&lt;br /&gt;
    disp(get(dataPointer, &#039;Value&#039;));&lt;br /&gt;
    n=n+1;&lt;br /&gt;
  end&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;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=matlab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  calllib(&#039;phidget21&#039;, &#039;CPhidget_close&#039;, ikhandle);&lt;br /&gt;
  calllib(&#039;phidget21&#039;, &#039;CPhidget_delete&#039;, ikhandle);&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;
At the end of your program, don’t forget to call close to free any locks on the Phidget that the open() call put in place!&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_C_Doc.zip C/C++ API].  Note, however, MATLAB does not make use of the event functions in the C/C++ 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==&lt;br /&gt;
&lt;br /&gt;
===Octave Problem: The function calls loadlibrary() and callib() are not supported in Octave===&lt;br /&gt;
&lt;br /&gt;
Likely Fix: As use of Phidgets in MATLAB requires these calls, the best is probably to choose a programming language that is not MATLAB.  You can choose [[Software Overview#Language Support|from many languages]] that we support.&lt;br /&gt;
&lt;br /&gt;
However, this may not be possible if, for example, you already have a lot of external code written in MATLAB that you would like to interface your Phidget with.  Here are a few suggestions to help you find a way to use your existing MATLAB code:&lt;br /&gt;
* Write your overall program in Python.  Python natively controls Phidgets, and you can use Pytave to interface between the Python Phidget code and your Octave code.  &lt;br /&gt;
* If you are using a version of Octave that Pytave does not support, write your program in Python as above.  Then, you can try reading your matlab code through R, and using RPy to interface with Python.&lt;br /&gt;
* External foreign linking libraries (Swig, FFCall) might be made to work...&lt;br /&gt;
&lt;br /&gt;
===All Operating Systems: You get a warning &amp;quot;The library class &#039;libphidget21&#039; already exists.  Use a classname alias.&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
Note that the {{Code|phidget21}} library is not unloaded at the end of our example {{Code|.m}} files.  This is because rapidly unloading the library just after linking it can cause problems in short programs.&lt;br /&gt;
&lt;br /&gt;
So, when you run the program again within the same MATLAB session, you will get this warning. Your code will still work, it is just that running the same code again loads the library again without closing it first.&lt;br /&gt;
&lt;br /&gt;
===OS X: The examples do not run with Rosetta under OS X.}}===&lt;br /&gt;
&lt;br /&gt;
The example programs uses the MATLAB {{Code|timer()}} call, which relies on the Java Virtual Machine. Since Rosetta does not support Java, the examples will not operate as expected.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Language_-_Objective_C&amp;diff=20696</id>
		<title>Language - Objective C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Language_-_Objective_C&amp;diff=20696"/>
		<updated>2012-06-29T20:03: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-Cocoa.png|64x64px|alt=|link=]]|Cocoa is Apple&#039;s native object-oriented application programming interface (API) for the [http://www.apple.com/macosx Mac OS X] operating system.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Cocoa|the complete Phidget API, including events|all Phidget devices.|XCode on OS X|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Cocoa|&lt;br /&gt;
{{APIQuickDownloads|{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++}}&lt;br /&gt;
{{ExtraAPIQuickDownloads|{{SERVER}}/documentation/web/cdoc/index.html|HTML Version of}}|&lt;br /&gt;
{{ExampleQuickDownloads|{{SERVER}}/downloads/examples/Cocoa.zip|}}|&lt;br /&gt;
{{MacQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Cocoa==&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;
We offer support for developing Cocoa on [[#OS X |OS X]].&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The Phidget examples were written in Objective-C and Xcode 3.2.4, and this tutorial assumes their use. Other versions of Xcode should work as well and would be set up in a similar manner. &lt;br /&gt;
&lt;br /&gt;
===Description of Files===&lt;br /&gt;
&lt;br /&gt;
Any files we think are worth knowing about specifically, or at the minimum a note that the OS X install puts things in their proper place.&lt;br /&gt;
&lt;br /&gt;
===XCode===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
If Xcode is not already installed on your system then you will need to get it.  You can download it from the Mac app store free of charge.&lt;br /&gt;
&lt;br /&gt;
Once that is done, you need to download our [{{SERVER}}/downloads/examples/Cocoa.zip examples].  If this is your first time working with Phidgets we recommend using the HelloWorld example as it will work with every Phidget device and it fairly easy to understand.  &lt;br /&gt;
&lt;br /&gt;
Open the HelloWorld example and before anything, run it.  You should see a window that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[image:xcodehelloworld1.png|600px|link=]]&lt;br /&gt;
&lt;br /&gt;
The window will list every Phidgets device connected to the system.  In addition to this it will register when devices are connected or disconnected from the system.  Now go and find the example project for your specific device.  You can run this is the exact same way.  After that you can take a look at the code and see how things work.  While you are doing that you can refer to the [[#Follow The Examples|Follow the Examples]] section to guide you through all the parts of the example project.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
First, generate a new Cocoa project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
Then, add the Phidget21 Framework (Groups &amp;amp; Files &amp;amp;rarr; Frameworks &amp;amp;rarr; Other Frameworks).&lt;br /&gt;
&lt;br /&gt;
Then, create a new Objective-C class with a descriptive name. For the purpose of this guide, the class name will be PhidgetInterfaceKit. &lt;br /&gt;
&lt;br /&gt;
At this point, a header file(.h) as well as an implementation file(.m) will automatically be created. Open the header file for editing, and add a reference to phidget21.h: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
  #import &amp;lt;Phidget21/phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you want to use a text field to capture output. Add a text field outlet in the header file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
  @interface PhidgetInterfaceKit : NSObject{&lt;br /&gt;
    IBOutlet NSTextField *sensorValueTxt;&lt;br /&gt;
  }&lt;br /&gt;
  @end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, in Groups &amp;amp; Files &amp;amp;rarr; Resources, open up MainMenu.nib to bring up the Interface Builder. Drag a text field from the Library to the Window.  &lt;br /&gt;
&lt;br /&gt;
Now, an instance of the PhidgetInterfaceKit class will need to be created:&lt;br /&gt;
#In the Library, drag an object to the MainMenu.nib Window.  &lt;br /&gt;
#In the Identity tab of the Inspector for this object, add the PhidgetInterfaceKit class. &lt;br /&gt;
#Connect the PhidgetInterfaceKit class instance to the text field. &lt;br /&gt;
The project now has access to Phidgets and we 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 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 Cocoa 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 AppleScript|[{{SERVER}}/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Cocoa 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 Cocoa 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;
First, make sure you have given your program access to Phidgets as described in the [[#Write Your Own Code | Write Your Own Code]] section. Then, you will need to declare your Phidget variable in your code.  For example, we can declare a Phidget Interface Kit in the .m implementation file with:&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
  CPhidgetInterfaceKitHandle ifkit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The object name for any type of Phidget - Temperature Sensor, Spatial, Motor Controller, etc - is listed in the API manual. Every type of Phidget also inherits functionality from the Phidget base class.&lt;br /&gt;
&lt;br /&gt;
Next, the Phidget object needs to be initialized and the program needs to try and connect to the Phidget through a call to open(). Open 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. For example, we can connect to a Phidget Interface Kit in the .m implementation file with:&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
  @implementation PhidgetInterfaceKit&lt;br /&gt;
  - (void)awakeFromNib&lt;br /&gt;
  {&lt;br /&gt;
    CPhidgetInterfaceKit_create(&amp;amp;ifkit);   &lt;br /&gt;
    CPhidget_open((CPhidgetHandle)ifkit, -1);&lt;br /&gt;
  }&lt;br /&gt;
  @end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&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 all of the available modes that open provides. One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This prevents any other instances from retrieving data from the Phidget, including other programs. The one connection per device limit does not apply when exclusively using the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
Simply calling open does not guarantee you can use the Phidget immediately. 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 by calling waitForAttachment. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded. &lt;br /&gt;
&lt;br /&gt;
To instead use events to handle attachment, first you declare the function that will be called when an Attach event is fired - in this case we call the function {{Code|gotAttach}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
int gotAttach(CPhidgetHandle phid, void *context) {&lt;br /&gt;
	[(id)context performSelectorOnMainThread:@selector(phidgetAdded:) withObject:nil waitUntilDone:NO];&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after our {{Code|create}} call [[#Step One: Initialize and Open|in the Step One code snippet]], but before our {{Code|open}} call, we hook our {{Code|gotAttach}} event function into our Phidget software object with the {{Code|CPhidget_set_OnAttach_Handler}} function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifkit, gotAttach, self);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check our examples for putting these attachment calls into the context of your larger program.&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 a similar way to [[#Step Two: Wait for Attachment (plugging in) of the Phidget|handling an attach event]] as described above, we can hook an event handler at loading with the following code:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
  CPhidgetInterfaceKit_set_OnSensorChange_Handler(ifkit, gotSensorChange, self);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
A call like this connects a function and an event.  In this case, the {{Code|CPhidgetInterfaceKit_set_OnSensorChange_Handler}} hook connects the {{Code|gotSensorChange}} function to the event of a sensor (black analog input port) changing value on a Phidget Interface Kit.  Next, the callback method {{Code|gotSensorChange}} needs to be set up before it can be used. For example,&lt;br /&gt;
     &lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
int gotSensorChange(CPhidgetInterfaceKitHandle phid, void *context, int ind, int val)&lt;br /&gt;
  {&lt;br /&gt;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];&lt;br /&gt;
    [(id)context performSelectorOnMainThread:@selector(SensorChange:)&lt;br /&gt;
    withObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:ind], [NSNumber numberWithInt:val], nil] waitUntilDone:NO];&lt;br /&gt;
    [pool release];&lt;br /&gt;
    return 0;&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Above, the SensorChange method is invoked on the main thread. Event data is stored in a {{Code|NSArray}}, which in turn is sent as a single argument to the SensorChange method.  The {{Code|NSAutoreleasePool}} object is created to clean up released objects on the event thread, and is released at the end of the method. &lt;br /&gt;
&lt;br /&gt;
The method calls selector on the SensorChange method, which is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  - (void)SensorChange:(NSArray *)sensorChangeData&lt;br /&gt;
  {&lt;br /&gt;
    int sensorIndex, sensorValue;&lt;br /&gt;
    sensorIndex = [[sensorChangeData objectAtIndex:0] intValue];&lt;br /&gt;
    sensorValue = [[sensorChangeData objectAtIndex:1] intValue];&lt;br /&gt;
    [sensorValueTxt setStringValue:[NSString stringWithFormat:@&amp;quot;Sensor: %d, Value: &lt;br /&gt;
    %d&amp;quot;, sensorIndex, sensorValue]];&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;
With this series of declarations and functions, the code inside SensorChange will get executed every time the PhidgetInterfaceKit reports a change on one of its analog inputs. 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;
Please refer to the API manual and the Cocoa examples for a list of events and their usage. &lt;br /&gt;
&lt;br /&gt;
Some values can be read and sent directly to the Phidget, simply use the C API functions such as CPhidgetInterfaceKit_getSensorValue() for PhidgetInterfaceKits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  int sensorValue;&lt;br /&gt;
  CPhidgetInterfaceKit_getSensorValue(ifkit, 0, &amp;amp;sensorValue);&lt;br /&gt;
  [sensorValueTxt setintValue: sensorValue];&lt;br /&gt;
    &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
These functions can be used inside a polling loop as an alternative to event driven programming.&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;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&amp;lt;syntaxhighlight lang=objc&amp;gt;&lt;br /&gt;
  CPhidget_close((CPhidgetHandle)ifkit);&lt;br /&gt;
  CPhidget_delete((CPhidgetHandle)ifkit);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&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/docs21/index.php?title=Language_-_Java&amp;diff=20695</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/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/docs21/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/docs21/index.php?title=OS_-_Windows_CE&amp;diff=20693</id>
		<title>OS - Windows CE</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=OS_-_Windows_CE&amp;diff=20693"/>
		<updated>2012-06-29T19:59:35Z</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 CE.png‎|64x64px|link=]]|On Windows CE, 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;
Phidgets are designed to run on &#039;&#039;&#039;Windows CE 5.0 or newer&#039;&#039;&#039;. &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].&lt;br /&gt;
&lt;br /&gt;
If you are already a pro, and just want the Windows CE installer:&lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21ARMV4I.CAB ARM4VI Installer]&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21x86.CAB x86 Installer]&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21MIPSII.CAB MIPSII Installer]&lt;br /&gt;
&lt;br /&gt;
The above installers are intended for the target Windows CE system. &lt;br /&gt;
&lt;br /&gt;
* [{{SERVER}}/downloads/examples/CE.zip CE Example Code]&lt;br /&gt;
&lt;br /&gt;
In addition to owning a Windows CE system, you will also need a Windows (2000/XP/Vista/7) system for developing and deploying Windows CE applications. (View our page on [[OS - Windows|Phidgets with Windows (2000/XP/Vista/7)]])&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. You will also have to download the Windows CE Libraries on your development machine.&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget21-wincedevel.zip Phidget21 Windows CE Libraries] (All architectures)&lt;br /&gt;
*[{{SERVER}}/downloads/libraries/Phidget21CEkernalsource.zip Kernel Driver Source]&lt;br /&gt;
*[{{SERVER}}/Drivers_Info.html#wince Software License]&lt;br /&gt;
&lt;br /&gt;
==Getting Started with Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
&lt;br /&gt;
To install the libraries on the Windows CE machine, 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 ARM4VI, x86, or MIPSII.&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21ARMV4I.CAB ARM4VI]&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21x86.CAB x86]&lt;br /&gt;
* [{{SERVER}}/downloads/libraries/Phidget21MIPSII.CAB MIPSII]&lt;br /&gt;
&lt;br /&gt;
2. Open up the {{Code|CAB}} installer, and proceed through the wizard. If you have installed the Phidgets library before on the same system, it may mention that the Phidget libraries are already installed. This is safe to ignore. Please note that by default, the installer places the [[#Description of Library files | Phidget libraries]] in {{Code|\Program Files\Phidgets}}. &lt;br /&gt;
&lt;br /&gt;
3. Once the installation is complete, you are ready to program with Phidgets.&lt;br /&gt;
&lt;br /&gt;
For a description of what was installed onto your system, please see the [[#Description of Library files | Description of Library Files]] section. &lt;br /&gt;
&lt;br /&gt;
Proceed onto to the [[#Phidget Control Panel | next]] section where an example program will be run to confirm that the libraries were installed correctly.&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 if the software component works.&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 running the {{Code|\Program Files\Phidgets\HelloWorld.exe}} application and seeing if the Phidget device is listed in the output. You can run the application by simply double clicking on it in Windows Explorer. Note that if the Phidget is already plugged into the system, you will have to re-attach it after the Phidget libraries are installed.&lt;br /&gt;
&lt;br /&gt;
If the Phidget is plugged into an USB port and you are not able to see that the Phidget is in the list, there may be a hardware issue. &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 CE 5.0 or greater.&lt;br /&gt;
* You have the correct package installed according to your system&#039;s architecture.&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| getting started 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;
&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;
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;
On Windows CE, we recommend the following languages:&lt;br /&gt;
&lt;br /&gt;
*[[Language - C Sharp (.NET Compact Framework)|C Sharp (.NET Compact Framework)]]&lt;br /&gt;
*[[Language - C/C++|C/C++]]&lt;br /&gt;
*[[Language - Visual Basic (.NET Compact Framework)|Visual Basic (.NET Compact Framework)]]&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 Windows CE are already included in the [[#Quick Downloads | Drivers]] above. The WebService is started with the {{Code|PhidgetWebservice21.exe}} application. &lt;br /&gt;
&lt;br /&gt;
You can connect to a Phidget hosted on another computer if you know the IP address/host name of the host computer. &lt;br /&gt;
&lt;br /&gt;
This section helps you install, check, and use the WebService on Windows CE, 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;
The WebService can be turned on and off using command line.  If you used our installer, the WebService utility is automatically installed in {{Code|\Program Files\Phidgets}}. &lt;br /&gt;
&lt;br /&gt;
You can get command line help with {{Code|PhidgetWebservice21.exe}} 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;
Please note that as Windows CE does not support the use of mDNS, the -n option cannot be used. &lt;br /&gt;
&lt;br /&gt;
To find the defaults used by {{Code|phidget21webservice}}, the command line is the fastest way to learn the IP address of your computer:&lt;br /&gt;
*For your IP address, type {{Code|ipconfig}} in the command line.&lt;br /&gt;
**A line in the return text, will say something like {{Code|IP Address ........ 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|\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 on port 5002:&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 -p 5002&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;
&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 CE is simply to start the WebService and run the Phidget program on the same computer.  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, we will need to modify the example code. We will go over how to modify the C#(.NET Compact Framework) in Visual Studio. Please go ahead and download the [{{SERVER}}/downloads/examples/CE.zip example code]. Extract it, and open up the {{Code|\CE\HelloWorld\HelloWorld.sln}} in Visual Studio. &lt;br /&gt;
&lt;br /&gt;
Find the line in our {{Code|HelloWorld}} example that says:&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;
 manager.open();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&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;
 manager.open(&amp;quot;127.0.0.1&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;
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. &lt;br /&gt;
&lt;br /&gt;
Build the project in Visual Studio. This will create an executable in the {{Code|Project Folder\bin\Debug}}(if you are running in debug mode).&lt;br /&gt;
&lt;br /&gt;
1. Start a command line window to run this test.  First, traverse to the {{Code|\Program Files\Phidgets}} directory and start the WebService.&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. Transfer the newly created executable onto the Windows CE system. Double click on the application to run it. &lt;br /&gt;
&lt;br /&gt;
3. Now, plug in the Phidget to the Windows CE system!  The {{Code|Phidget21webservice}} program captures the {{Code|Attach}} event and other events and sends them out over the network and the example application will receive them.&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. Simply, in the command line window, press {{Code|Ctrl}} and {{Code|c}} at the same time.&lt;br /&gt;
&lt;br /&gt;
Note that since Windows CE does not have mDNS and cannot be detected using the Windows Control Panel or the OS X Preference Pane.&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 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.&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. Please take a look at the [[#Description of Installer files | Description of Installer files]] sections to see which files you will need to install yourself. &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|\WINDOWS}} 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;
===Deploying the Program===&lt;br /&gt;
&lt;br /&gt;
For simple programs in .NET, if the compiled Windows CE program runs on the development machine, then it should behave the same way on the target machine with the exception of the need for Invokes. It is also recommended that the program be debugged over a remote connection to the device. Make sure to include the {{Code|phidget21CE.NET.dll}} with your distribution.&lt;br /&gt;
&lt;br /&gt;
If you receive a {{Code|Can&#039;t find PInvoke DLL}} error on deployment, check to make sure that the Phidget Framework {{Code|.dlls}} are installed to the device (normally in the Windows folder). Running the {{Code|CAB}} installer is the easiest way to ensure the files are installed and registered correctly.  &lt;br /&gt;
&lt;br /&gt;
You can use the Phidget WebService to connect to remote Phidgets if USB ports are not available. Note that Windows CE does not support mDNS and by extension some {{Code|open()}} calls. In .NET, use {{Code|open(serial,&amp;quot;IPAddress&amp;quot;, port, &amp;quot;pass&amp;quot;)}}.&lt;br /&gt;
&lt;br /&gt;
===Deploying the Program on an Emulator===&lt;br /&gt;
&lt;br /&gt;
Your success for running Phidgets on an emulator may vary based on the type of the device being emulated, and whether it supports USB devices or the installation of the Phidget Framework. Here, if you receive a {{Code|Can&#039;t find PInvoke DLL}} error during execution, this means the emulator image does not have the Phidget Framework installed. One approach installing it &lt;br /&gt;
on an emulator is to set up a shared folder (File &amp;amp;rarr; Configure... &amp;amp;rarr; General &amp;amp;rarr; Shared folder) with the ARMV4I or x86 Framework inside, then browse to its location and run the installer. Also, if you’re running the Phidget WebService, you may want to have the network connection shared between the PC and device through ActiveSync.&lt;br /&gt;
&lt;br /&gt;
===Compiling Your Own OS Build===&lt;br /&gt;
&lt;br /&gt;
Often you’ll also find that after power cycling the device, the state of the operating system is reset and the Phidget drivers are lost. As a matter of convenience, it’s possible to include the Phidget drivers into the OS build so that they do not need to be reloaded every time. Building an OS image is often a complicated task and is not covered in detail here. However, if you are going to try this process it will involve using the SDK for the device, including the ARMV4I or x86 .dlls, and inserting entries into the registry for USB detection of Phidgets. The easiest way of getting the .dlls and registry entries is to copy them off the device after installing the {{Code|CAB}} file. The CE kernel source can also be found at the [#Quick Downloads | beginning] of this page&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions==&lt;br /&gt;
&lt;br /&gt;
===Issue: The Phidget Windows CE libraries need to be installed everytime the system restarts===&lt;br /&gt;
This is discussed in the [[#Compiling Your Own OS Build | Compiling Your Own OS Build]] section.&lt;br /&gt;
&lt;br /&gt;
===Issue: The Phidget is not attaching to my Program===&lt;br /&gt;
If the Phidgets are already plugged into the USB port of the Windows CE device, the Phidgets will need to be re-attached to the device once the Phidget libraries are installed. This is so that the drivers can detect that the Phidgets are connected.&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 that is distributed through the iOS drivers.&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]].&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;
* &amp;lt;b&amp;gt;{{Code|Phidget21CE.NET.dll}}&amp;lt;/b&amp;gt; is the .NET(Compact Framework) Phidgets library. It is placed in {{Code|\Windows}}.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=OS_-_Linux&amp;diff=20692</id>
		<title>OS - Linux</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=OS_-_OS_X&amp;diff=20691</id>
		<title>OS - OS X</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=OS_-_OS_X&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/docs21/index.php?title=Template:ExtraAPIQuickDownloads&amp;diff=20690</id>
		<title>Template:ExtraAPIQuickDownloads</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Template:ExtraAPIQuickDownloads&amp;diff=20690"/>
		<updated>2012-06-29T19:53:31Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[{{{1}}} {{{2}}} API Manual]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Language_-_C&amp;diff=20689</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Template:ExtraAPIQuickDownloads&amp;diff=20688</id>
		<title>Template:ExtraAPIQuickDownloads</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Template:ExtraAPIQuickDownloads&amp;diff=20688"/>
		<updated>2012-06-29T19:53:01Z</updated>

		<summary type="html">&lt;p&gt;Cora: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[{{{1}}} {{{2}}} API Manual]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Template:ExtraAPIQuickDownloads&amp;diff=20687</id>
		<title>Template:ExtraAPIQuickDownloads</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Template:ExtraAPIQuickDownloads&amp;diff=20687"/>
		<updated>2012-06-29T19:52:54Z</updated>

		<summary type="html">&lt;p&gt;Cora: Created page with &amp;quot;[{{{1}}} {{2}} API Manual]&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[{{{1}}} {{2}} API Manual]&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs21/index.php?title=Language_-_C&amp;diff=20686</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=Language_-_C&amp;diff=20685</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/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/docs21/index.php?title=LED_Primer&amp;diff=20684</id>
		<title>LED Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=LED_Primer&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/docs21/index.php?title=LED_Primer&amp;diff=20683</id>
		<title>LED Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=LED_Primer&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/docs21/index.php?title=LED_Primer&amp;diff=20682</id>
		<title>LED Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=LED_Primer&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/docs21/index.php?title=LED_Primer&amp;diff=20681</id>
		<title>LED Primer</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=LED_Primer&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/docs21/index.php?title=Use_Phidgets_Wirelessly_with_the_SBC&amp;diff=20680</id>
		<title>Use Phidgets Wirelessly with the SBC</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs21/index.php?title=Use_Phidgets_Wirelessly_with_the_SBC&amp;diff=20680"/>
		<updated>2012-06-29T18:05:42Z</updated>

		<summary type="html">&lt;p&gt;Cora: /* Phidgets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- CATEGORIES --&amp;gt;&lt;br /&gt;
[[Category:phidgetsSBC]]&lt;br /&gt;
[[Category:Application Guides]]&lt;br /&gt;
The project described here is a basic network control program for an LED plugged in to an SBC.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Practical concepts covered are (click on links to see other projects on that topic):&lt;br /&gt;
* Using the Phidget SBC&lt;br /&gt;
** Using [[:Category:PhidgetsSBC|Phidgets over the Webservice]]&lt;br /&gt;
* Using Phidgets with C/C++&lt;br /&gt;
|width=&amp;quot;45px&amp;quot;|&amp;amp;nbsp;&lt;br /&gt;
|[[Image:app_guide_sbcweb_sbc_image.jpg|200px|link=|alt=]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As with any of our [[:Category:Application Guides|described projects]], Phidgets takes care of the electrical component design.  This project demonstrates what the SBC already does naturally from the time it ships.  If you want something more powerful and flexible to control Phidgets over a network, you may be interested in these other Application Guides:&lt;br /&gt;
* [[Web Page on the SBC]] - Controlling Phidgets over the web using CGI&lt;br /&gt;
* {{LinksNeeded|Web Server on the SBC|[[Web Server on the SBC]]}} (coming soon) - Controlling Phidgets over the web using a full self-contained webserver embedded in C code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border:1px solid darkgray;&amp;quot; cellpadding=&amp;quot;5px;&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Time:&#039;&#039;&#039; &lt;br /&gt;
| About an hour&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Special Needed Tools:&#039;&#039;&#039; &lt;br /&gt;
|None&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Materials and Phidgets:&#039;&#039;&#039;&lt;br /&gt;
|A Phidget SBC, Ethernet and power cords (or Wireless), an LED, and your computer&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should have already worked through the [[1072 - Getting Started]] page to have set up the network on your SBC and obtained its IP or local link address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
When the SBC is powered on and connected to a network, it automatically handles any network requests for the Phidgets attached to it.  All sensor and other Phidget data is broadcast over the local network as it changes, and all incoming Phidget control requests to the SBC over the local network are directed to the appropriate Phidgets.&lt;br /&gt;
&lt;br /&gt;
This Webservice system looks something like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:app_guide_sbcweb_webservice_flow.png|500px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
To create these requests to control the attached Phidgets, or to receive incoming sensor data, we write code on the controlling and receiving computer.  This application guide simply blinks an LED plugged in to the SBC, and does so over the network.&lt;br /&gt;
&lt;br /&gt;
==Phidgets==&lt;br /&gt;
&lt;br /&gt;
For this, you will need:&lt;br /&gt;
* A [{{SERVER}}/products.php?product_id=1072 Phidget Single Board Computer], set up as per the [[1072 - Getting Started]] guide&lt;br /&gt;
** This is the SBC that this guide used; others will probably work fine as well&lt;br /&gt;
* An LED, such as one of the ones from Phidgets (many part numbers starting at 3600), attached to digital output port 0 (long wire) and ground (short wire)&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
On your external computer, you can use this code to control the Interface Kit (which is attached to the SBC) over the network:&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=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;quot;phidget21.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]) {&lt;br /&gt;
 &lt;br /&gt;
    int result;&lt;br /&gt;
    int outputState;&lt;br /&gt;
    int i; &lt;br /&gt;
&lt;br /&gt;
    CPhidgetInterfaceKitHandle interfaceKit = 0;&lt;br /&gt;
    CPhidgetInterfaceKit_create(&amp;amp;interfaceKit);&lt;br /&gt;
 &lt;br /&gt;
    CPhidget_openRemoteIP((CPhidgetHandle)interfaceKit, -1, &amp;quot;phidgetsbc.local&amp;quot;, 5001, NULL);&lt;br /&gt;
 &lt;br /&gt;
    result = CPhidget_waitForAttachment((CPhidgetHandle)interfaceKit, 10000);&lt;br /&gt;
    if (result) {&lt;br /&gt;
        printf(&amp;quot;No Device!\n&amp;quot;);&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    outputState = 1;&lt;br /&gt;
    CPhidgetInterfaceKit_setOutputState(interfaceKit, 0, outputState);&lt;br /&gt;
&lt;br /&gt;
    for (i = 0; i &amp;lt; 1000; i++) {&lt;br /&gt;
    &lt;br /&gt;
        if (outputState) { outputState = 0; }&lt;br /&gt;
        else { outputState = 1; }&lt;br /&gt;
&lt;br /&gt;
        CPhidgetInterfaceKit_setOutputState(interfaceKit, 0, outputState);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CPhidgetInterfaceKit_setOutputState(interfaceKit, 0, 0);&lt;br /&gt;
&lt;br /&gt;
    CPhidget_close((CPhidgetHandle)interfaceKit);&lt;br /&gt;
    CPhidget_delete((CPhidgetHandle)interfaceKit);&lt;br /&gt;
&lt;br /&gt;
    return 0;&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;
Some highlights:&lt;br /&gt;
* Line 14 is the line that actually opens the Interface Kit over the network.  &lt;br /&gt;
** Notice that there is no mention of the SBC, or any SBC object.  &lt;br /&gt;
** The SBC will simply act as a transparent pipe between the Phidget and your computer.&lt;br /&gt;
** The local link address ({{Code|phidgetsbc.local}}) and the port (5001) are the defaults, make sure to change them to what you have set in the Getting Started guide.&lt;br /&gt;
* Lines 25-31 blink the LED quickly; however, the flashing will barely be visible and the LED will simply appear to be on&lt;br /&gt;
&lt;br /&gt;
==Putting it All Together==&lt;br /&gt;
&lt;br /&gt;
Compile your C file using the instructions for our examples on the Language - C/C++ page.&lt;br /&gt;
*This code was written for gcc, so you&#039;ll either have to use a gcc compiler (Cygwin, Mac OSX, or Linux) or modify the code to work with your favourite platform.&lt;br /&gt;
*The code has been tested on Linux, and Cygwin on Windows.&lt;br /&gt;
*Make sure to copy the last blank line return at the end of the file - many Windows compilers insist on this being present.&lt;br /&gt;
&lt;br /&gt;
Then, run the program and watch the LED on the SBC!&lt;br /&gt;
&lt;br /&gt;
[[Image:app_guide_sbcweb_sbcled.jpg|300px|link=|alt=]]&lt;br /&gt;
&lt;br /&gt;
==Extra Credit==&lt;br /&gt;
&lt;br /&gt;
# Phidgets attached to the USB ports on the SBC will be opened the same way as the Interface Kit in code, except with different software objects.&lt;br /&gt;
#* Plug a USB Phidget in (if you have one) to one of the SBC&#039;s USB ports, and add that Phidget&#039;s object and some functionality to the code above&lt;br /&gt;
# Sensors attached to the analog ports will be opened via a port on the Interface Kit.&lt;br /&gt;
#* Try using the function {{Code|CPhidgetInterfaceKit_getSensorValue}} on the different Interface Kit analog ports to read them.&lt;/div&gt;</summary>
		<author><name>Cora</name></author>
	</entry>
</feed>