The NeceMoon | Phidgets : First Steps In Robotics ?

Phidgets : First Steps In Robotics ?

by necemon 12. June 2012 21:55


Phidgets are a set of "plug and play" building blocks, some low-cost electronic components that you can control from your personal computer via USB. They provide you with some extra input/output methods beyond the classic mouse + keyboard + screen. 

As Harold Thimbleby mentioned in his book Press On, phidgets are a very nice way to get into hardware programming, as you may want to build real systems, not on screen or web browser simulations : phidgets are so-called because they are the physical equivalent of on-screen widgets (Windows Gadgets). 

Phidgets = Physical + Widgets
(Widgets =  Windows + Gadgets)

Where to find them ?
there are various official phidgets dealers spread across the world. For example, if you live in the UK, you can check out

Getting started
All the USB complexity is managed behind the Phidget API (Application Programming Interface). Applications can be developed quickly by programmers using their favorite language: C/C++, C#, Cocoa, Delphi, Flash AS3, Flex AS3, Java, LabVIEW, MATLAB, Max/MSP, MRS, Python, REALBasic, Visual Basic.NET, Visual Basic 6.0, Visual Basic for Applications, Visual Basic Script, Visual C/C++/Borland.NET, etc (If you can't code you can also use software such as Microsoft Robotics Studio or even Microsoft Excel).
All you need is the drivers that you can get by downloading the relevant installer. Similarly, you can access the various manuals, the samples and the API sorted by language from here 

For example, as a C# developer, just download those and you are ready to go:
2. Windows Installer (32-bit) 

A practical example
Allow me to introduce the Quick-&-Dirty-Pad (while I think of a better name), a "game controller" I built with my partner Daniel Williams, while we were back at University during the Interaction Technologies classes led by Dr Parisa Eslambolchilar

Yes I know, it looks horrible but hey, everyone needs to start somewhere...

We used it primarily to go along with a flight simulation game we programmed, we used force sensors for shooting, a joystick for direction, RFID tags for user authentication and a rotation sensor to regulate the game speed. The game events where reflected through a LCD screen and a few LED indicators. 

(Thanks for reading so far. The rest is for the nerds only. This is the part where we briefly discuss the key technical details.)

The game itself was written in C#. It was inspired from a Riemers XNA tutorial. The key parts of the code include the navigation system:

if (keys.IsKeyDown(Keys.Right))

                leftRightRot += turningSpeed;

            if (keys.IsKeyDown(Keys.Left))

                leftRightRot -= turningSpeed;

            float upDownRot = 0;

            if (keys.IsKeyDown(Keys.Down))

                upDownRot += turningSpeed;

            if (keys.IsKeyDown(Keys.Up))

                upDownRot -= turningSpeed;

The aircraft keeps moving forward automatically and the above code is used to control the rotational movements. One of our challenges was to incorporate the phidget code for the joystick into this part of the code such that the joystick behaves as arrow keys. 

First of all we created a new input wrapper which is the class that contains the sensor change handler to detect any changes in the movement of the joystick. The input wrapper class implements the interface kit object which detects any input from any phidget 

InputWrapper iw = new InputWrapper();

ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);

The first section of the next code controls the x axis of the joystick. The output values of the joystick are between 0 and 999, so for any value greater than 500 the plane would rotate to the right and any value less than 500 the plane would rotate to the left. The second part of the code is used to control the Y axis of the joystick. This time any value greater than 500 would rotate the plane so it's facing upwards while any value less than 500 will rotate the plane so it's facing downwards. 


                leftRightRot = (iw.XJoystick-500)/10000;

            if (iw.XJoystick < 450)

                leftRightRot = (iw.XJoystick-500)/ 10000;

if (iw.YJoystick > 550)

                upDownRot = (iw.YJoystick - 500)/10000;

            if (iw.YJoystick < 450)

                upDownRot = (iw.YJoystick - 500) / 10000;

The LCD screen was used to display the current player and their score. The user must scan their id to start the game or the game wouldn’t start. The RFID phidget was used to detect the identity of the current playing user. First of all we created a text LCD wrapper and an RFID wrapper which contain the various event handlers. The RFID detects if a tag is present; if not a message appears on the LCD screen asking the user for their tag 

TextLCDWrapper tlw = new TextLCDWrapper();

       RFIDWrapper rw = new RFIDWrapper();

while (rw.tag == null || rw.tag.Length < 2)


                tlw.JustTyped("Tag, Please!");


When the user scans their tag the RFID will detect if the user is registered to play the game or not and display the relevant message on the LCD screen 

private void DrawText()


           if(rw.tag != null && rw.tag.EndsWith("cb"))


                tlw.JustTyped("Necemon : " + score);

                spriteBatch.DrawString(font,"Necemon - score:" + score, new Vector2(20, 45), Color.White);


            else if (rw.tag != null && rw.tag.EndsWith("8a"))


                tlw.JustTyped("Daniel : " + score);

                spriteBatch.DrawString(font,"Daniel - score:" + score, new Vector2(20, 45), Color.White);


            else if (rw.tag != null)


                spriteBatch.DrawString(font, rw.tag + " - score:" + score, new Vector2(20, 45), Color.White);

                tlw.JustTyped("Unknown : " + score);



The rotation sensor will be used to control the speed of the plane. The values of the rotation sensor are obtained through the input wrapper class, previously mentioned when describing the joystick. The more you turn the rotation phidget the more the speed increases

gameSpeed = iw.RotationValue/100;

The following code creates a new bullet every time the space bar is pressed provided the previous bullet was fired more than 100 milliseconds ago

if (keys.IsKeyDown(Keys.Space))


            double currentTime = gameTime.TotalGameTime.TotalMilliseconds;

                if (currentTime - lastBulletTime > 100)


                    Bullet newBullet = new Bullet();

                    newBullet.position = xwingPosition;

                    newBullet.rotation = xwingRotation;


                    lastBulletTime = currentTime;



Our task was to implement four sensors to control the bullets being fired from the plane. The values of the force sensor are also obtained through the input wrapper class. The following code now creates a new bullet of type 3 every time the force sensors are pressed 

if (keys.IsKeyDown(Keys.C) || iw.Force3 > 25)


                //make the lights blink

                iw.ifKit.outputs[0] = (!iw.ifKit.outputs[0]);

                iw.ifKit.outputs[1] = (!iw.ifKit.outputs[1]);

                iw.ifKit.outputs[2] = (!iw.ifKit.outputs[2]);

                iw.ifKit.outputs[3] = (!iw.ifKit.outputs[3]);

                double currentTime = gameTime.TotalGameTime.TotalMilliseconds;

                //within a certain frequency

                if (currentTime - lastBulletTime > 300)


                    //Create the bullet and add it to the bulletlist

                    Bullet newBullet = new Bullet();

                    newBullet.position = xwingPosition;

                    newBullet.rotation = xwingRotation;


                    //play a sound


                    lastBulletTime = currentTime;



(Robotics picture from

Tags: , , , ,

English | Prototype | Technical

blog comments powered by Disqus



I am Necemon Yai. I am a .NET developer and a digital artist. Let's keep in touch via Twitter, LinkedIn or Facebook.

Je suis Necemon Yai. Je suis un développeur .NET et un artiste numérique. Restons en contact via Twitter, LinkedIn ou Facebook.