This mapping skips the SPI pins used by the SPI TFT screens as well as the analog audio out pins so that it may be used with those screens attached and analog audio.

First of all you will need to solder the required pins to the GPIO of your Pi Zero. Here is a map of where to solder the pins. solder the ground to any of the ground pins on the GPIO.

ltd7B84 - Copy

Then Type:


make retrogame

This should build the executable retrogame utility. If you instead get an error message, there’s a problem in the edited table most likely a missing curly brace, comma or semicolon.
One more step is to create a custom udev rule which will allow retrogame input events to be visible to applications built using the latest SDL2 library. Some applications like the latest version of RetroPie's EmulationStation frontend require SDL2 and can't see input events from retrogame without this rule. It can't hurt to add this rule even if you aren't using EmulationStation or other SDL2 apps.

To add the rule, run the following command to create and edit the file /etc/udev/rules.d/10-retrogame.rules in the nano text editor:


sudo nano /etc/udev/rules.d/10-retrogame.rules

Now copy in the following line exactly as shown (this should all be on a single line in the rules file, i.e. don't put in any linebreaks):


SUBSYSTEM=="input", ATTRS{name}=="retrogame", ENV{ID_INPUT_KEYBOARD}="1"

Save the file by pressing Ctrl-O and pressing enter, then exit nano by pressing Ctrl-X.

Restart your Raspberry Pi to make sure the new configuration is loaded.

sudo reboot

Now we’re in good shape to test it!

Navigate back to the Adafruit-Retrogame directory


cd /home/pi/Adafruit-Retrogame

Retrogame needs to be run as root, i.e.:


sudo ./retrogame

Give it a try. If it seems to be working, press control+C to stop the program and we’ll then set up the system to launch this automatically in the background at startup.


sudo nano /etc/rc.local

Before the final exit€ line, insert this line:


/home/pi/Adafruit-Retrogame/retrogame &

Save the file by pressing Ctrl-O and pressing enter, then exit nano by pressing Ctrl-X

If you placed the software in a different location, this line should be changed accordingly. sudo  isn’t necessary here because the rc.local script is already run as root.

Reboot the system to test the startup function:


sudo reboot

The software will now be patiently waiting in the background, ready for use with any emulators.

Each emulator will have its own method for configuring keyboard input. Set them up so the keys match your controller outputs. Up/down/left/right from the arrow keys is a pretty common default among these programs, but the rest will usually require some tweaking.


Select interfacing options >> SSH >> Enable >> reboot your pi

In the middle of this wiki it will show you how to FTP into retropie ... rring-Roms

In your FTP Client make sure you are in the pi directory then right click and click new then folder and name it Adafruit-Retrogame

Copy the retrogame.c file to the /home/pi/Adafruit-Retrogame directory on the SD Card using your preferred method. I found that FTP was the easiest for me

At this point you will need a terminal connection. I highly suggest using SSH as this will allow you to test run retrogame with the gui running on your device for button mapping testing.

Here is the wiki on how to SSH into retropie. Your pi zero will need to have a network connection for this to work.


I suggest starting with a fresh image of retropie as this will use a certain set of keyboard keys that I preselected. With a fresh retropie install you will be able to map these key presses on first startup. map the following table of keys with your keyboard so that things will work with my Code. Then you can get in and setup network so you can use SSH and FTP.

Up - up
Down - down
left - left
right - right
start - enter
select - s
A - a
B - b
X - x
Y - y
L - l
R - r

Download the retrogame.c file at the google drive link below and place in a directory on your Pi Zero SD card. ... EhKUFJOb2M

I used FTP to get to my pi zero and made the Adafruit-Retrogame directory in the /home/pi directory. This is the directory referenced later in code in this tutorial. So its best to stick to this.

as of retropie 4.2 SSH is now disabled by default. to enable
press F4 on a keyboard then.


sudo raspi-config


cd /home/pi/Adafruit-Retrogame