A Raspberry Pi power button connected to a Pi

Build an Emergency RetroPie (RetroArch/ EmulationStation) Controller Configuration Reset Button

Screw up your controller settings? Reset them with a single press!
  • by Zach (173)
  • Time to complete: 30 minutes

It seems that every time a friend comes over to play games on RetroPie, they invariably screw up the controller settings somehow. Sometimes they'll accidentally press [any] button when a game is loading, panic, and then change the controller settings for a specific ROM. Other times, they'll plug a new controller in and map it incorrectly.

Suddenly, you can't even use the controller to navigate the RetroPie interface correctly. Either way, resetting controller settings for a specific ROM or controller often requires SSHing into the Pi, pulling out the old keyboard, or hoping another controller will work. Not anymore!

Now you can reset all controls, restoring RetroArch/EmulationStation controller mappings to default, with the press of a physical button. :)

How it works

In a nutshell, a normally open (NO) button is connected to the Pi's 40-pin GPIO header. When pressed, it triggers a script that removes your existing controller configuration/mapping files and reboots your Pi. When the Pi reboots, the controller configuration prompt will reappear and all ROM controller configurations will have reset. Nice!

Note: This is meant to be a fun, novel project; there are many other ways to handle and backup your controller configurations.

1

Raspberry Pi shutdown button wiring

First, we need to create the button that will connect to the Pi. To do this, we'll solder some wires to a normally open (NO) push button, forming a "pigtail". This type of button is an open circuit until it is pressed. You can use any size button you wish, just make sure it's normally open and is a push (not toggle) button.

howchooer Tyler wrote an excellent guide on building a Raspberry Pi power button. We'll use that guide as a base for building our button.

If you have a breadboard, you can use it to prototype and test your button and scripts. If not, no worries; this is a super simple circuit.

Cut the ends off of two jumper wires and solder one of each to each button terminal. Then, use heat-shrink tubing to secure the soldered connections.

2

Connecting the button to the Pi

Connect one end of the Pi button pigtail to pin 5 (SCL), and the other to pin 6 (GND). If pin 6 is already taken by something else, you can use any other ground pin instead. Pinout.xyz is a great resource for identifying other ground pins.

3

Now we'll need to create a few scripts:

  1. The listen script, which will watch for button presses and call the reset script if the button is pressed, and
  2. The reset script, which essentially runs the following commands to reset RetroArch config and reboot the Pi:
rm /opt/retropie/configs/all/emulationstation/es_input.cfg
rm /opt/retropie/configs/all/retroarch-joypads/*
sudo reboot

I'll walk you through the process of creating these scripts.

4

SSH into your Pi and create the reset script:

sudo nano listen-for-reset.py

Then, paste the following into that file:

#!/usr/bin/env python

import RPi.GPIO as GPIO
import subprocess


GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(3, GPIO.FALLING)

subprocess.call(['rm', '/opt/retropie/configs/all/emulationstation/es_input.cfg'], shell=False)
subprocess.call(['rm', '/opt/retropie/configs/all/retroarch-joypads/*'], shell=False)
subprocess.call(['shutdown', '-r', 'now'], shell=False)

Save and exit. Finally, make the script executable and set it to start on boot:

sudo mv listen-for-reset.py /usr/local/bin/
sudo chmod +x /usr/local/bin/listen-for-reset.py
5

Now we'll create the listen script that will start/stop our service and watch for button presses. To create the script:

sudo nano listen-for-reset.sh

Enter the following:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          listen-for-reset.py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting listen-for-reset.py"
    /usr/local/bin/listen-for-reset.py &
    ;;
  stop)
    echo "Stopping listen-for-reset.py"
    pkill -f /usr/local/bin/listen-for-reset.py
    ;;
  *)
    echo "Usage: /etc/init.d/listen-for-reset.sh {start|stop}"
    exit 1
    ;;
esac

exit 0

Save and exit. Then, move the file into /etc/init.d and make it executable:

sudo mv listen-for-reset.sh /etc/init.d/
sudo chmod +x /etc/init.d/listen-for-reset.sh

Finally, tell the script to run on boot:

sudo update-rc.d listen-for-reset.sh defaults

Now, you can reboot your Pi to start the script or start it manually:

sudo /etc/init.d/listen-for-reset.sh start
6

A Raspberry Pi power button mounted in a plastic housing

Find a good place to mount your button. For example, if you built a Retrobox, you can drill a hole on the back for mounting; if you built a Pi Cart, use a tiny reset button and embed it right in the case.

Or, let it hang.

7

A Raspberry Pi power button connected to a Pi

To test your setup, configure a controller and/or change its configuration from within a ROM. Press the button and after your Pi reboots you will be prompted to configure the connected controller from scratch.

Now your friends (or kids) can mess around with the controller settings all they want and, poof, reset button.

Questions? Comments?

Post in the comments section below and I'll do my best to help you out!