Saturday, September 17, 2011

Using a Joystick With NETMF and the NETMFx Joystick Library

JoystickOnPandaII
As I’m working on the Omnimote, I decided the next article in the NETMF for Electronics Noobs series should be about how to interface a joystick with a NETMF device.
For this example, I’m using a Parallax joystick from Adafruit.comSparkfun has a similar joystick which should work using the same directions although the labels for the pinouts are slightly different.  I prefer the one from Adafruit because it has a nice rubber feel to it and it’s pin headers fit in a breadboard.  The one from SparkFun is a slippery hard plastic and requires you to buy a separate PCB in order to make it breadboard friendly.  It does have the advantage of an additional push button selector built-in that the one from Adafruit does not.  They both have convex tops.  I would have much rather had concave tops such as you get with an XBox 360 controller but these were not carried.

A joystick controller is simply a stick connected to two small potentiometers – one for the left-right (X) motion and one for the up-down (Y) motion.  To connect the joystick to the board, we will need two analog pins plus +5V and ground connections.  The following table will show the labels and pins for these two joysticks.
Adafruit Joystick Sparkfun Joystick Arduino Compatible Pin
L/R+ VCC +5V
L/R HOR Analog*
U/D+ VCC +5V
U/D VER Analog*
GND GND GND
Any two analog pins can be used for L/R and U/D.  For this tutorial, I am using Analog0 for L/R and Analog1 for U/D.


image
This post also serves as an announcement of a new open source NETMF library I’ve created called NETMFx.  This will serve as a place for me (and anyone else who wants to contribute) to put custom drivers and anything NETMF related.  My goal is to make anything in it compatible with both GHI and netduino so that the greater NETMF community can make use of it.  I’ve done this by using conditional compile symbols when necessary.  Be sure and check out the progress made so far in NETMFx.Joystick and NETMFx.Math projects in the NETMFx source code download.

There is also a “Samples” project in the NETMFx solution where I’ve posted a sample project called “Joystick Tutorial” that is specific to this post.  I’ve done a fairly complete job of documenting the project from the code so I will not bother going into detail in this post.  Feel free to contact me if you need further clarification of how to run the code once you have everything wired up.

0 comments:

Post a Comment