It all started with the Nintendo Classic craze. I had a friend that was rambling about one the other day. I mentioned that I could totally make him one but better because it would emulate more than just Nintendo. Enter RetroPie. I was looking at putting the bill of materials together and thinking of cases for the mini NES, then I realized why not just print one! So BAM and BAM.
https://www.thingiverse.com/thing:1887826
then this https://www.thingiverse.com/thing:2011955
Then this for giggles
https://www.thingiverse.com/thing:1710104
Here’s what we are doing
- Flashing RetroPie to an SD card for a Raspberry Pi
- Soldering header pins to the RUN pin holes on the RPi
- Soldering wires to some push buttons
- Soldering some wires to an LED
- 3D Printing a mini NES case for the RPi
- 3D Printing a bracket for the NES case
- Glueing push buttons, LED and bracket into the printed case
- Wiring the LED and buttons to the RPi
- Testing it all
Here’s what you need
- Raspberry Pi (save yourself a headache, get a RPi 3!)
- RPi power supply MINIMUM of 2.5A!
- SD card 8gb+ class 10
- HDMI cable
- USB keyboard
- Network cable (even though the RPi 3 has wifi you will at least need to do the initial wifi setup with a LAN connection)
- A 3D Printer to print the case and the bracket
- (2) push buttons
- (2) male header pins
- Super glue and hot glue
- (1) red LED
- (1) 100 ohm resistor
- (6) pieces of jumper wire with connections (you can cut some in half if long enough)
Whats Up
I will assume you have a network connection (non wifi) a USB keyboard a TV or Monitor or tv with an HDMI connection and that you have active internet. You will need to know how to solder, and be somewhat comfortable with a terminal and hopefully the Linux environment. I also assume you have and know how to use a 3D printer. I will also assume that you know and are comfortable with Raspberry Pies. Lots of ASSumptions.
This post is not designed as a how to install RetroPie but more of a how to get RetroPie installed and create the scripts for shutdown the Pi and lighting the LED, then you can follow the first install guide by RetroPie to get you going with the actual RetroPie software.
If you want to use WiFi
With a keyboard and TV/Monitor connected follow this https://github.com/RetroPie/RetroPie-Setup/wiki/Wifi, otherwise…
Let’s Get Started
3D print the case and button/LED bracket. Solder up some of the jumper wires to the push buttons and then solder the resistor to the LED and some wires. Glue this all together in the bottom of the case). Check the Thingiverse page for more information on all this as well.
Go download the newest version of RetroPie. Once that is downloaded you need to flash the image to an SD card, preferably 8gb or higher, class 10. There are a few ways to get the image on the SD card. Apple-Pi Baker, Etcher, or use the dd command or Win32DiskImager.
RetroPie first installation
https://www.raspberrypi.org/documentation/installation/installing-images/windows.md
https://www.raspberrypi.org/documentation/installation/installing-images/mac.md
https://etcher.io/
https://www.tweaking4all.com/downloads/#Raspberrypi
Once you got the image on the SD slap it in the RPi and boot. You will need to have the unit connected to a TV/Monitor and you will need a controller. A keyboard connected to the Pi is required (at least momentarily). Once the unit boots it will want you to map the keyboard keys to the buttons. Just hit F4 or Shift+F4 to get a terminal. From there we need to set up some defaults and turn on auto login on the Pi so the script runs on boot.
sudo raspi-config
How do I change the default password
- Select option “1. Change User Password”
- Follow the prompts to set the new password. The default password is raspberry.
How do user auto login
- Select option “3. Boot Options”
- Select option “B1. Desktop / CLI”
- Select option “B2. Desktop Auto login”
- Don’t quit or reboot yet, go back to the main menu
How do I extend the available space when upgrading to a larger SD card
- Select option “7. Advanced Options”
- Select option “A1. Expand Filesystem”
- Reboot your Raspberry Pi (or do the optional SSH)
How do I enable SSH on RetroPie?
- Select option “5. Interfacing Options”
- Select option “P2. SSH”
- Select YES
- Reboot your Raspberry Pi
Once it reboots you can then SSH into the Pi or continue to use the keyboard attached.
See RetroPie first installation for more info on installing RetroPie. See https://retropie.org.uk/docs/FAQ/ for more answers to questions.
Check out the directions on https://www.thingiverse.com/thing:2011955, they are pretty decent and should get you most of the way through as well. Most if not all of this information is compiled from there. First things first, from the terminal:
1 2 |
sudo apt-get update sudo apt-get upgrade |
Install wiringPi
Taken from http://wiringpi.com/download-and-install/Let’s check to make sure you don’t have wiringPi already (if you used the RetroPie image you do NOT). If it spits back a version number, you do. If you do then (we need to purge it, to update to the newest):
1 2 |
sudo apt-get purge wiringpi hash -r |
You will need GIT installed to install wiringPi. If you are using the RetroPie image you already have it. To install GIT:
sudo apt-get install git-coreThen pull a copy of wiringPi:
git clone git://git.drogon.net/wiringPiCheck to see if you have the most recent version of wiringPi (which you should):
1 2 |
cd ~/wiringPi git pull origin |
Now build:
sudo ./buildYou should have wiringPi, to check:
gpio -vReboot.
Making the LED work, and run on boot
Check here for more information. From a terminal:
1 2 3 |
cd ~/ sudo mkdir Scripts sudo nano Scripts/LEDon.py |
Paste this into the new file:
1 2 3 4 5 6 7 |
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO.OUT) print "LED on" GPIO.output(18,GPIO.HIGH) |
ctrl+o to save ctrl+x to quit, then let’s create another file to turn off the LED:
sudo nano Scripts/LEDoff.pyPaste this into the new file:
1 2 3 4 5 6 7 |
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO.OUT) print "LED off" GPIO.output(18,GPIO.LOW) |
Of course change the pin (18 in this example) to whatever GPIO you are using. You can test the scripts by using:
sudo python ~/Scripts/LEDon.py or sudo python ~/Scripts/LEDoff.py . Now let’s make it turn on when the Pi boots.Making the LED illuminate on boot
We need to edit rc.local:
sudo nano /etc/rc.localAdd this to the file before the end of the loop:
sudo python /home/pi/Scripts/LEDon.py &The “&” is important, don’t forget to have that there. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" sudo python /home/pi/Scripts/LEDon.py & fi exit 0 |
ctrl+o to save, ctrl+x to quit. The LED should automatically turn off when the Pi shuts down (unknown what will happen if the Pi just freezes, I imagine it would stay lit).
Making the RUN (reset) pins work
- Solder some male header pins to the empty spot marked RUN on the RPi board
- Simply connect the reset button to the RUN pins and done.
- Anytime you press the reset the Pi should, well, reset.
Making the shutdown button work
Check out https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b for more information on all this.
The python script
We need to create a new directory and a shutdown script:
1 2 |
cd ~/ sudo nano Scripts/shutdown.py |
Paste this in the new file you just created:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/python # Simple script for shutting down the raspberry Pi at the press of a button. # by Inderpreet Singh import RPi.GPIO as GPIO import time import os # Use the Broadcom SOC Pin numbers # Setup the Pin with Internal pullups enabled and PIN in reading mode. GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP) # Our function on what to do when the button is pressed def Shutdown(channel): os.system("sudo shutdown -h now") # Add our function to execute when the button pressed event happens GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000) # Now wait! while 1: time.sleep(1) |
Edit the above and change the GPIO (18 in the example) to whatever pin you are using. Then save (ctrl+o) and exit (ctrl+x). You can test the new script by running (it should shutdown, if you already did the reset/RUN pin then you can use that to reboot):
sudo python Scripts/shutdown.pyMaking it run on start
We need to edit rc.local:
sudo nano /etc/rc.localAdd this to the file before the end of the loop:
sudo python /home/pi/Scripts/shutdown.py &The “&” is important, don’t forget to have that there. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" sudo python /home/pi/Scripts/shutdown.py & fi exit 0 |
Then you are good to go, reboot for the changes to take effect. The script you created should start automatically upon reboot.
The LED should light on when RetroPie starts, the shutdown button should power down the RPi and kill the LED and the reset button should reboot the Pi from its shutdown state. Let me know if I missed anything.
Discover more from Its_All.Lost
Subscribe to get the latest posts sent to your email.