Saturday, December 31, 2016

Making a Custom PC Gamepad with Arduino



What: Making a simple gamepad from an Arduino that you can use on the computer

Why: I wrote another article earlier this year about using the RXTX java library involving basic communication with a computer and finally got a free weekend to make an even better project using that same tech. Furthermore, a Twitch streamer by the handle 'Rudeism' has become well known for using a 'Makey Makey' microcontroller in video games, and it should be noted that he inspired me to finally get working on my own fun game controller.

Required: 
- Arduino, Arduino IDE
- Switches, buttons, and/or joysticks
- Computer
- Java
- RXTX Java Library
- Code available on my Github

Notes: For this tutorial, I am using an old analog computer joystick. It used a gameport adapter, but I have since cut it off so I can get at the wires directly. The important take away is that I have wired the outputs from the potentiometers of the joystick directly into the analog input pins of the Arduino. Further, the buttons from the joystick are also wired directly into the digital input pins. The program files available for this tutorial assume only two axes and two buttons. If you want to make a more complicated gamepad, I encourage you to do so; the concept is the same. 

I am using an Arduino Uno R3. The Uno does not have native HID support which is why we need the Java program on the computer. The joystick I am using an old InterAct Raider Pro Digital that I found while thrifting. This tutorial does not require flashing the Uno’s core firmware.

Brief: The basic idea is that the Arduino will receive the inputs (either digital or analog) from a button or joystick you have and send it over the serial connection to your PC. The PC will then parse that input into something actionable. Using the Java ‘Robot’ class, your Java application will move the mouse, click a button, or enter a keystroke. Here is an abstract diagram for how it should work:



Steps:

1. Connect your switches, buttons, and potentiometers to the Arduino


[x-axis potentiometer signal] -> [analogPin0]
[y-axis potentiometer signal] -> [analogPin1]
[trigger button] -> [digitalPin3]
[thumb button] -> [digitalPin4]
[GND] -> [GND]
[5v] -> [5v]

2. Upload the Arduino sketch
     View my sketch example video HERE.

3. Run the Java application
     That's it! Your potentiometer inputs now drive your mouse, the trigger button is a left click, and the thumb button is a right click.

Troubleshooting:

-If you need more help with the RXTX library specifically, please refer to my previous article on using the library HERE.

-If you have questions about the process or this project in particular, post a comment and I'll try to help you out.

More process photos:
(Testing direct connections)

(Connections soldered and labeled)

(Ready for game testing)

No comments:

Post a Comment