Arduino Joystick Shield – Revised Primer

If you want to make your Arduino project more compact, an Arduino Shield is the answer. The Arduino Shield is a neat piece of hardware that sits on top of your Arduino board. It is typically designed for a specific purpose. An Arduino Shield lets you to employ your Arduino for more than one project and to change the hardware setup easily.

This little post is about a common (and cheap) Arduino Joystick Shield – the Funduino Joystick Shield (V1.A). This Arduino Uno Joystick shield has all the functions of a standard game controller on a single circuit board. It provides not only four main pushbuttons to assign various functions, but also an integrated pushbutton switch in the joystick mechanism itself. With the ergonomic joystick you can smoothly move through the X and Y axis to perform movements with moderate accuracy.

Key features of the Funduino Joystick Shield are listed below:

  • Supports both 3.3V and 5V Arduino platforms (Slide Switch Selector)
  • Total 7 Momentary Push buttons (4 main + 2 sub + 1 in joystick)
  • 2-Axis Joystick
  • Additional Ports/Headers for LCD module (Nokia 5110), RF module (NRF24L01), and Bluetooth module (HC-05 & HC-06)
  • Extra I2C Header for further expansion

Now to her pin assignments:

The X-Axis potentiometer of the joystick is connected to A0, while the Y-Axis potentiometer is connected to A1. The joystick pushbutton is connected to D8.

There’s a total of 6 tactile buttons labelled AF. The 4 large buttons are typically used for up/down/left/right or similar functions. The two buttons are typically used for less commonly used functions since they’re not easily accessible/less likely to be pressed accidentally. All buttons have onboard pull-up resistors.

  • Button A (UP) – D2
  • Button B (RIGHT) – D3
  • Button C (DOWN) – D4
  • Button D (LEFT) – D5
  • Button E (E) – D6
  • Button F (F) – D7

The dual-row yellow male header connector (interface connector) provides another way to access all the pushbuttons, joystick potentiometers, 3.3V, 5V and 0V (GND) rails. The pinout of this interface connector is clearly labeled on the shield.

Moreover, the Rx/Tx lines are brought out to a separate 4-pin female header along with 3.3V and GND for connecting a 4-pin 3.3V Bluetooth module or a TTL serial device. Likewise, the I2C SDA and SCL lines are brought out to a separate 4-pin male header along with 5V and GND. This is in addition to the normal A4/A5 location of these I/Os. This allows easy interaction with external I2C modules.

Below figure shows pin assignments of the Nokia 5110 LCD module and NRF24L01 module connectors.

In short, this joystick shield (V1.A) has a neat user interface perfect for gaming and navigating through menu options quickly. Its onboard headers for display and radio modules lets communication and readout tasks perform in easy ways.

It’s always a good idea to spend some time testing a new piece of hardware before embarking on a real project. Do a physical inspection first to ensure that the joystick shield is clean with no dirty solder residues between the header pins. Make sure there are no short circuits with micro solder blobs between the solder joints of those header pins. Also, make sure there’re no broken/dry solder joints.

When you’re satisfied with the visual inspection, carefully plug your Funduino Joystick shield onto the Arduino Uno, and connect the setup to your computer thru an Arduino USB cable.

Thereafter you can upload the below Arduino Sketch to test your Arduino + Funduino Joystick Shield setup through Arduino Serial Monitor. Note that the given code is an example code (retouched a bit by me) that comes with the “Joystick Shield” Library. This is the GitHub link to download it https://github.com/sudar/JoystickShield.

[code]

#include //
JoystickShield Library

joystickShield joystickShield; //
Create an instance of JoystickShield object

void setup() {


Serial.begin(9600);


delay(100);


// New calibration function


joystickShield.calibrateJoystick();


// Predefined Joystick to Pins 0 and 1.


// Change it if you are using a different joystick shield


// SetJoystickPins(0, 1);


// Predefined buttons to the following pins.


// Change it if you’re using a different joystick shield.


// setButtonPins(pinJoystickButton, pinUp, pinRight, pinDown, pinLeft,
pinF, pinE); // K,A,B,C,D,F,E


// To deactivate a button, use a pin outside of the range of the Arduino
eg 255, but not the above!


// setButtonPins(8, 2, 3, 4, 5, 7, 6);

}

void loop() {


joystickShield.processEvents(); // Process events


if (joystickShield.isUp()) {


Serial.println(“Up”) ;


}


if (joystickShield.isRightUp()) {


Serial.println(“RightUp”) ;


}


if (joystickShield.isRight()) {


Serial.println(“Right”) ;


}


if (joystickShield.isRightDown()) {


Serial.println(“RightDown”) ;


}


if (joystickShield.isDown()) {


Serial.println(“Down”) ;


}


if (joystickShield.isLeftDown()) {


Serial.println(“LeftDown”) ;


}


if (joystickShield.isLeft()) {


Serial.println(“Left”) ;


}


if (joystickShield.isLeftUp()) {


Serial.println(“LeftUp”) ;


}


if (joystickShield.isJoystickButton()) {


Serial.println(“Joystick Clicked”) ;


}


if (joystickShield.isUpButton()) {


Serial.println(“Up Button Clicked”) ;


}


if (joystickShield.isRightButton()) {


Serial.println(“Right Button Clicked”) ;


}


if (joystickShield.isDownButton()) {


Serial.println(“Down Button Clicked”) ;


}


if (joystickShield.isLeftButton()) {


Serial.println(“Left Button Clicked”) ;


}


// new eventfunctions


if (joystickShield.isEButton()) {


Serial.println(“E Button Clicked”) ;


}


if (joystickShield.isFButton()) {


Serial.println(“F Button Clicked”) ;


}


if (joystickShield.isNotCenter()) {


Serial.println(“NotCenter”) ;


}


// New position functions


Serial.print(“x”); Serial.print(joystickShield.xAmplitude()));
Serial.print(“y”);


Serial.println(joystickShield.yAmplitude()));


delay(500);

}

[/code]

This code checks the status of all pushbuttons and the joystick loop-the-loop and displays the results in the serial monitor window. So, you can see how it works!

The serial monitor read out will look something like this when you press the push buttons and move the joystick handle:

Keep in mind, I had the same problem mentioned here while using the Joystick Shield library https://github.com/sudar/JoystickShield/issues/3 , but not yet resolved. Give this a try for yourself.

Now see a casual pic of my quick test hardware setup below.

Now let’s move to a funny do it yourself project (good for a novice) using the Funduino Joystick Shield, an Arduino Uno, and one RYG Traffic Light LED Module. You can use an RGB LED module (of course with series resistors) in lieu of the proposed traffic light LED module. This utterly simple code snippet will help you to control the RYG LEDs in the traffic light LED module through the joystick and its pushbutton switch. Since this well-commented code is straightforward and self-explanatory, I will not go into the details of how it works.

[code]

const int SW_pin = 8;

const int X_pin = A0;

const int Y_pin = A1;

int greenPin = 11;

int yellowPin = 12;

int redPin = 13;

int YPIN;

int XPIN;

int SWPIN;

void setup() {


pinMode(SW_pin, INPUT);


digitalWrite(SW_pin, HIGH);


pinMode(redPin, OUTPUT);


pinMode(greenPin, OUTPUT);


pinMode(yellowPin, OUTPUT);

}

void setColor(int green, int yellow,
int red)

{


analogWrite(greenPin, green);


analogWrite(yellowPin, yellow);


analogWrite(redPin, red);

}

void loop() {


int YPIN = analogRead(Y_pin);


int XPIN = analogRead(X_pin);


int SWPIN = digitalRead(SW_pin);


if (YPIN == 0) {


setColor(225, 0, 0);//Down = Green


delay(100);


}


else {


setColor(0, 0, 0);


}


if (YPIN == 1023) {


setColor(0, 0, 255);//Up = Red


delay(100);


}


else {


setColor(0, 0, 0);


}


if (XPIN == 0) {


setColor(0, 225, 0);//Left = Yellow


delay(100);


}


else {


setColor(0, 0, 0);


}


if (XPIN == 1023) {


setColor(0, 0, 255);//Right = Red


delay(100);


}


else {


setColor(0, 0, 0);


}


if (SWPIN == LOW) {


setColor(255, 255, 255);//Push = R+Y+G


delay(100);


}


else {


setColor(0, 0, 0);


}

}

[/code]

Here’s the wiring pointer of the traffic light LED module. Just insert it in the 5110 LCD connector of the joystick shield in the right way. That’s it!

And a candid shot of my quick test setup:

Overall, this joystick shield would be a welcome choice for adding joystick and button control features to a project without having to worry about how to set up a bunch of discrete parts in a small protoboard. However, when plugging in an Arduino Uno, you need to add appropriate PCB standoffs to the pushbutton side of the joystick shield to maintain the required mechanical stability.

Well, next time I will use this joystick shield for some minuscule transceiver modules. See, many Arduino-compatible RF modules can be configured as transmitters and receivers. As the name implies, a transceiver module can transmit and receive radio frequency signals. Stay tuned!

Leave a Comment