Joystick Shield

Voltage warning, read this!

The Joystick shield normally works on 5V since it's designed for Arduinos and not for Netduinos.
The analog inputs of Netduinos don't like to get 5V and this could damage your device.

To solve this I created a work-around. First we replace the stackable pin headers by normal pins. A small but very important detail, one of the pins is removed. Also I took a small metal pin aside for later use:
288616
Now solder everything except for the power pins (both +3.3V and +5V):
288617
After that, take the small pin and make a nice half circle of it. Notice that one side is longer then the other!
288618
Then the only thing to do is to short the +3.3V and +5V holes with the small curved pin:
288619
Now, the shield is ready to go!

Shield connections

The shield contains 5 components:
  • Thumb joystick using pins A0 (horizontal movement), A1 (vertical movement) and D2 (push button)
  • Right button using pin D3
  • Top button using pin D4
  • Bottom button using pin D5
  • Left button using pin D6

Sample code in C#

// The thumb joystick is connected to analog pins 0 and 1, and digital pin 2
// On the Joystick shield, the thumb stick is rotated by 90° so we need to invert the horizontal value
ThumbJoystick Joystick = new ThumbJoystick(new Netduino.ADC(Pins.GPIO_PIN_A0), new Netduino.ADC(Pins.GPIO_PIN_A1), Pins.GPIO_PIN_D2, true);

// The other buttons are connected to digital pins 3, 4, 5 and 6
// The shield doesn't have pull-up resistors so we use the internal ones from the Netduino
InputPort ButtonRight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp);
InputPort ButtonUp = new InputPort(Pins.GPIO_PIN_D4, false, Port.ResistorMode.PullUp);
InputPort ButtonDown = new InputPort(Pins.GPIO_PIN_D5, false, Port.ResistorMode.PullUp);
InputPort ButtonLeft = new InputPort(Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);

// Infinite loop; so far Analog ports can't handle interrupts, so the Joystick driver can't as well
while (true)
{
    // Lets start with an empty string
    string OutputText = "";
    // Add the values of the thumb stick
    OutputText = "Horizontal: " + Joystick.HorizontalValue.ToString();
    OutputText += " Vertical: " + Joystick.VerticalValue.ToString();
    if (Joystick.PushValue) OutputText += " Thumbstick pushed";

    // Add button states to the output text (inverted with the ! because of the pull-up resistor)
    if (!ButtonDown.Read()) OutputText += " Button Down";
    if (!ButtonUp.Read()) OutputText += " Button Up";
    if (!ButtonLeft.Read()) OutputText += " Button Left";
    if (!ButtonRight.Read()) OutputText += " Button Right";

    // Displays the output text to the debug window
    Debug.Print(OutputText);

    // Wait 100ms to read the pins again
    Thread.Sleep(100);
}

Sample code in VB

' The thumb joystick is connected to analog pins 0 and 1, and digital pin 2
' On the Joystick shield, the thumb stick is rotated by 90° so we need to invert the horizontal value
Dim Joystick As ThumbJoystick = New ThumbJoystick(new Netduino.ADC(Pins.GPIO_PIN_A0), new Netduino.ADC(Pins.GPIO_PIN_A1), Pins.GPIO_PIN_D2, True)

' The other buttons are connected to digital pins 3, 4, 5 and 6
' The shield doesn't have pull-up resistors so we use the internal ones from the Netduino
Dim ButtonRight As InputPort = New InputPort(Pins.GPIO_PIN_D3, False, Port.ResistorMode.PullUp)
Dim ButtonUp As InputPort = New InputPort(Pins.GPIO_PIN_D4, False, Port.ResistorMode.PullUp)
Dim ButtonDown As InputPort = New InputPort(Pins.GPIO_PIN_D5, False, Port.ResistorMode.PullUp)
Dim ButtonLeft As InputPort = New InputPort(Pins.GPIO_PIN_D6, False, Port.ResistorMode.PullUp)

' Infinite loop; so far Analog ports can't handle interrupts, so the Joystick driver can't as well
Do
    ' Lets start with an empty string
    Dim OutputText As String = ""
    ' Add the values of the thumb stick
    OutputText = "Horizontal: " + Joystick.HorizontalValue.ToString()
    OutputText += " Vertical: " + Joystick.VerticalValue.ToString()
    If Joystick.PushValue Then OutputText += " Thumbstick pushed"

    ' Add button states to the output text (inverted with the NOT because of the pull-up resistor)
    If Not ButtonDown.Read() Then OutputText += " Button Down"
    If Not ButtonUp.Read() Then OutputText += " Button Up"
    If Not ButtonLeft.Read() Then OutputText += " Button Left"
    If Not ButtonRight.Read() Then OutputText += " Button Right"

    ' Displays the output text to the debug window
    Debug.Print(OutputText)

    ' Wait 100ms to read the pins again
    Thread.Sleep(100)
Loop

Last edited May 14, 2012 at 10:51 PM by Garrcomm, version 4