Most of us used to play video games using joystick either on PlayStation or PC. When I started tinkering with Arduino, when I built a robot or a vehicle, I also wanted to control it with a similar joystick, so I got the Sparkfun joystick shield.
Today I will make a detailed comparison between our 1Sheeld gamepad shield and the SparkFun joystick shield, I will take you in a step by step tutorial till we can control 4 LEDs lightening to indicate the direction of the joystick. Let’s get started!
1- SparkFun Joystick Shield
The first shield we are going to cover is the SparkFun joystick shield. It is a nice shield which gives you the feeling of the old Atari Joystick, you can get it directly from SparkFun website, it comes with the whole package of Joystick and pushbuttons withR3 stackable headers but it’s all unsoldered and you have to solder it yourself.
The joystick internally consists of two potentiometers, one of them measures the vertical resistance and the other measure the horizontal one, they are connected to both pins A0 and A1 and a small push button under it is connected to pin 2.
Regarding the other push buttons, the smaller one is the shield reset button and the other 4 push buttons are action button connected to pins 3, 4, 5 and 6.
Now let’s go to the step by step tutorial.
Step 1: Adjust the shield
As I said that the shield is not pre-assembled so we have to solder the joystick and the headers into it, so we have to get a soldering iron and solder like this.
Actually, SparkFun is providing a very simple Assembly guide especially for this shield.
The first thing to be soldered is the joystick and the push buttons but be careful while soldering the joystick cause it has so many pins.
Then solder the headers to it.
Voila!! That’s how it supposed to be like after soldering the pin headers.
Step 2: Mount the shield on the Arduino board
The shield can be mounted over the Arduino board but there are two drawbacks in it, the first thing is that in Arduino UNO case which am using the shield is hitting the USB interface of the Arduino board where if I forced the shield to completely mounted on the board the shield may be broken or I may harm the USB interface so please be careful.
The other thing is that mounting another shield over the joystick shield is impossible, understandably because you need to use the buttons on it, so if you are using multiple shields, you have to keep that on the top.
Step 3: Write the code
In this example I will control 4 LEDs depending on the direction I pressed on whether using the joystick or the normal pushbutton and when am using the joystick I can turn two LEDs at the same time if it lays in between two different directions like the “up right”,“up left” and so on
// Store the Arduino pin associated with each input
// Specify each pin connected to a pushbutton as an input.
// Also enable the Arduino's internal "pull-up" resistors
// for each pushbutton we want to read--this means the shield
// doesn't need to have resistors on it.
// Note that when a pull-up resistor is used on a pin the
// meaning of the values read are reversed compared to their
// usual meanings:
// * HIGH = the button is not pressed
// * LOW = the button is pressed
// y_direction == 1
// y_direction == 1
// x_direction == 1
// y_direction == 1
Step 4: Build the hardware
I have connected 4 LEDs of 4 different colors on pins(9, 10, 11 and 12) to indicate the direction I pressed.
At the end of this tutorial, I want to say that using this good looking shield gives you the feeling of the old Atari games feeling but actually with some bad user experience cause you should hold the whole system in your hand with all the cables, wires and even batteries, and when you use it for a long time you will feel the heat coming from the system due to long use.
2- 1Sheeld Gamepad Shield
Now it’s time to show our awesome 1Sheeld gamepad shield.
For anyone who does not know about 1Sheeld, it is a board that connects your smartphone’s sensors and peripherals to the Arduino, allowing your smartphone to control Arduino and Arduino to control anything on your phone.
The most important thing in 1Sheeld is that you can make a lot of amazing things with only 1 line of code!
So, here we are going to control 4 LEDS lightening using a gamepad on your smartphone which will give you the feeling of mobile app games controlling.
You will find two versions of it the 1Sheeld for Android phones and the 1Sheeld+ for iOS and Android phones from 4.3 and above.
Now let’s get started with the 1Sheeld!
Step 1: Adjust 1Sheeld
Warning! If you have an Arduino that works on 3.3V then you must make your 1Sheeld to work on the 3.3V mode since it may damage your board.
Step 2: Mount the 1Sheeld over the Arduino board
In my case am using Arduino UNO board if you have a different board you can check how to mount 1Sheeld to different Arduino board from this tutorial.
Step 3: Install Arduino library
Download the 1Sheeld library from here and after unzipping it, copy the folder to your libraries directory or you can manage any libraries from Arduino’s IDE .. just click Sketch >> Include library >> Manage libraries >> type “The library name” >> then click install and you are good to go.
This code simply is controlling the 4LEDs lightening with the Arrows and the buttons of the shield, each LED is representing one of these directions ( Up, Down, Right and Left) so i combine each two corresponding arrow and button to control each LED.
After writing the code, make sure to set 1Sheeld UART switch to the uploading mode before you upload your code to Arduino.
After uploading the code, the 1Sheeld is not ready to work until you switch it back to the operating mode.
Operating mode is turned on when the UART switch is pushed towards 1Sheeld logo.
Step 6: Use the 1Sheeld application
Open 1Sheeld application on your Android phone or iOS device.
The application will first scan over Bluetooth for your 1Sheeld, it will take a few seconds and the phone will find it.
Once it appears on your screen as 1Sheeld #xxxx, you will be required to enter the pairing code (the default pairing code is 1234) and connect to 1Sheeld via bluetooth.
Step 7: Access the shield
Select the shields you would like to use in your Arduino sketch and press on the multiple shields icon at the top right of the app.
In this case, use Gamepad shield.
As you see in the above image it has 4 arrows and 4 colored buttons which gives you the ability to make lots of applications, and thanks to our open source community, one of our Github repo contributors Mustafa Shaarawi developed the gamepad shield arrows to be an analog joystick, he finished the mobile app and the Arduino library and now it’s under testing so stay tuned for our coming release! Here is an image for the shield and how it will be displayed.
There will be two options which are the arrows mode and the joystick mode, just press the mode button and it will toggle to the other state.
Arduino makers …. you can connect your Arduino to MQTT brokers(servers) and launch your IoT with Arduino IoT Shield! It’s the 1Sheeld IoT shield that will do the job for you. It’s one of the most important but recent Arduino shields in 1Sheeld. Simply, it turns your Arduino into MQTT client where you can publish and …
Monitor my home environmental parameters remotely is one of the most desirable things I have ever wanted to make. It’s not about purchasing such a system that can get the job done for me. But, passion to create it myself. So, today, I am going to connect the popular DHT sensor to an online MQTT …
“Oh God! … It seems like I have forgotten the door lock open, again” … the normal saying whenever I am in hurry to go out! Have you encountered this problem before? It always confuses me since I may even think that I have left the door lock opened, and once I go back, …
Here I am with another IoT-based home automation project; Arduino IoT Fan Control. Every day, I get back from work tired and feeling hot. No air conditioner here and the fan takes much time to start cooling the room, sadly! So, I was thinking why not controlling the fan from outside my home with my …
Have you ever forgotten to turn your home lights off when you got outside? Sadly, it happens to me all the time. And this causes confusion once I get my bills! Furthermore, here is one secret about me; I am a lazy man. I always want to control my room lamp from my sweet bed. …
Welcome to our home automation hacks series #3, for so many times I had problems with watering my plants while traveling abroad and I have always needed a way to control it remotely, then I decided to do it with one of the fanciest ways you may ever hear off, cause I’m gonna water my …