Analog Joystick on RetroPie

I’ve been working on this one for a really long time, and I’m quite proud of the end result. Let’s add an analog joystick to the Raspberry Pi.

The module at the center of this is the ADS1015. It’s an analog to digital converter that works over the I2C interface, and is the same chip that’s going to be used in PSPI Version 4 when it’s released. You can buy the module here on my site if you want, or you can get it on eBay if you don’t mind shipping from China. It provides 4 12-bit analog inputs over the I2C interface. There’s a few pins that have to get attached to the Pi to get up and running. Basically SDA on the module goes to SDA (for I2C-0 BCM pin 0, physical pin 27) on the Pi, SCL goes to SCL (for I2C-0, BCM pin 1, physical pin 28), VCC (power) goes to a 3.3v pin, GND goes to a GND pin, and ADDR (address) goes to a GND pin. The other 4 pins are for the analog input, but only channels 0 and 1 are needed for a joystick. You’re also going to be using one pin on the Raspberry Pi as a button during setup, and GPIO 27 (physical pin 13) is preset as this pin. When the time comes, you’ll need to run a jumper from this pin to a GND pin to simulate pressing a button on the joystick. If your joystick actually has a button then you’ll just run the joystick button to this pin permanently.

Lets start with the software installation. I’m starting with a fresh image of RetroPie on the SD card, so if you have problems you should do the same. I’ve got all this set up for an offline installation since not everyone has internet on their Pi. You’ll need to go to Github and download and extract the zip file. Open the zipped folder and copy the contents to your RetroPie SD card. You’ll need to overwrite the config.txt on your SD card and make sure that all the other folders copy correctly. A couple really important files will copy to the overlays folder.

Boot up your system with a keyboard, let RetroPie do it’s thing (again, assuming fresh install), and do the controller configuration. Use your keyboard to do the configuration initially, it’ll make the next part easier.

After the keyboard is configured as input, press F4 to exit RetroPie. Then type the following commands.
cd /boot/uinput/ (then press enter)
sudo python setup.py install (press enter)
cd /boot/examples/
sudo python joystick.py & (press enter)
jstest /dev/input/js0 (press enter)

Then wiggle the joystick around and make sure it is picked up.
press CTRL and C on the keyboard to exit

Type the following to set the joystick software to load on bootup (I’m assuming you’re still in /boot/examples):
sudo bash install.sh (press enter)
exit (press enter, and you’ll be taken back to RetroPie)

Use the keyboard to restart the controller configuration. It should already say there is a controller attached. Press the joystick button (or simulate pressing the button by connecting GPIO 27 to GND for a few seconds), and the configuration will start. Use the keyboard to press down until you reach the one called “LEFT ANALOG UP”, and this is where you do that motion on the joystick to get it to detect. Then go through the other three and use the keyboard to arrow down and hit OK. You’re done. Some extra configuration might be needed in Retroarch, but that’s for another day and another guide.

Share this with others

Leave a Reply