The Raspberry Pi is an incredibly cool and fun little piece of hardware. I love it. I’ve wanted one for a while, and with the introduction of the new Raspberry Pi 2 Model B, I absolutely had to buy one.
How do I explain it’s coolness? Hmm. Like all good pieces of hardware let’s talk some specs. 900MHz quad-core ARM Cortex-A7. 1 GB RAM. 4 USB ports. HDMI. MicroSD. Ethernet. AUX. 40 pins providing 17x GPIO. Power. All of that comes on a board the size of a credit card. Some people might think these specs are terrible. Some might think they are amazing. The new Raspberry Pi 2 Model 2 has about as much power as a moderate smartphone. And you get it all for the wildly low price of $35.
For those who don’t deal with specs, here are just a few of the many cool projects that have been built with the Raspberry Pi.
Pi in the Sky – taking a Raspberry Pi, strapping it to a weather balloon, and launching it to the edge of space.
Make coffee – send a text message to make a cup of espresso
Time lapse video – shoot some dope time lapse that looks like this
Make a supercomputer – buy 64 of these and string them together to create a pretty powerful little supercomputer
Automated pet feeder – automatically dispense food for your pets from the internet
BeetBox – an instrument that allows users to play drum beats by touching actual beets
Car Touch Screen – install a touchscreen display in your car that stores your music, movies, pictures, etc.
Weather Station – collect data on wind speed and direction, rain, humidity, pressure, temperature, soil temperature, etc.
Blackstripes – convert a picture into a beautiful pencil drawing
Surveillance System – set up a surveillance system, record pictures, stream video, motion detection, etc.
Sync lights to music – sync your outside Christmas lights to music, sync lights in to club, etc.
Computer – this should probably be clear by now, but yes you can use it as a computer to browse the web, do photo editing in GIMP, etc.
Home Media Center YouTube, Spotify, Hulu, Netflix, Amazon VOD, HBO Go, your own movies, music, etc.
The Pi can be used in an infinite number of projects and it has some use in commercial application. Five million units have been sold. Although the Raspberry Pi Foundation created the little device to promote the teaching of basic computer science in schools, it has blown up in popularity. The community behind the Pi is immense. So even if you have no experience in programming you can probably find a step by step tutorial or the solution to your problem somewhere on the internet.
With all of these cool projects out there, I had to figure out what I first wanted to build. I figured I would start off with some old school video game emulation. It would be pretty cool to be able to play some of the old school games from my childhood on the Raspberry Pi. The process to get this up and running is pretty simple, and I’ll walk you through it here step by step.
Some hardware you will need:
- Raspberry Pi 2 Model B
- Raspberry Pi Power cord
- MicroSD card (I’m using SanDisk 32GB Extreme)
- Ethernet cable or USB WiFi dongle (I’m using the WiPi dongle)
- TV or monitor
- TV power cable
- HDMI cable
- USB Keyboard
- USB Mouse (not used but may be good for future products)
- Gaming controller (I’m using PS3 with USB wire)
A lot of these you likely have lying around the house. Once you set your Raspberry Pi up you don’t really need Ethernet, keyboard, or mouse. They are only used in the beginning to set the Pi up.
And a quick rambling before I continue. I went to Best Buy to try to get a cheap monitor. The cheapest I could find was about $90 but it didn’t have an HDMI input. The cheapest monitor with HDMI was $130. I looked for an HDMI to VGA adapter and found one for $30 dollars. I then realized something amazing. Instead of buying a computer monitor, you can just buy a cheap flatscreen tv. For $85 I picked up a 19 inch flatscreen (it was a floor model) and it came with 2x HDMI ports, VGA, Component, Antennae, Digital Output, USB, Audio Out, screws for wall mounting, speakers, and a remote control. That’s a ton of value that turns my cheap monitor into something much more versatile. Just something to consider if you are looking for a monitor and might be able to use any of the additional functionality of a tv.
There are really a million different ways to set game emulation up but this is one of the easier approaches.
We are going to use the RetroPie Project, which gives us emulators for a ton of old school gaming consoles. Emulators are a software version of a hardware gaming console. For example a Nintendo 64 emulator like Mupen64Plus let’s us play software versions of our N64 games. Just like the emulator is a piece of software that emulates the hardware console, we also need ROMs which are software versions of the physical video games. In the old days you took a cartridge or a CD and put it into a physical gaming device and played the game that way. In the modern day you install an emulator and you copy over some ROM files and you can now have multiple systems and multiple games available all on a small piece of hardware such as the Raspberry Pi. The RetroPie project includes emulators for many systems including:
- Amiga (UAE4ALL)
- Apple II (LinApple)
- Atari 800 (Atari800)
- Atari 2600 (RetroArch/Stella)
- Atari ST/STE/TT/Falcon (Hatari)
- Apple Macintosh (Basilisk II)
- C64 (VICE)
- Amstrad CPC (#CPC4Rpi)
- Final Burn Alpha (RetroArch/PiFBA, RetroArch/FBA)
- Game Boy (RetroArch/Gambatte)
- Game Boy Advance (GpSP)
- Game Boy Color (RetroArch/Gambatte)
- Sega Game Gear (Osmose)
- Intellivision (jzIntv)
- MAME (RetroArch/mame4all-pi, RetroArch/mame4all)
- MSX (openMSX)
- PC – x86 (rpix86)
- NeoGeo (PiFBA, GnGeo)
- Nintendo Entertainment System (RetroArch/FCEUmm)
- Nintendo 64 (Mupen64Plus-RPi)
- TurboGrafx 16 – PC Engine (RetroArch/Mednafen/pce_fast)
- CaveStory (RetroArch/NXEngine)
- Doom (RetroArch/PrBoom)
- Duke Nukem 3D (eDuke)
- Sega Master System / Mark III (RetroArch/Picodrive, Osmose, DGen)
- Sega Mega Drive / Genesis (RetroArch/Picodrive, DGen)
- Sega Mega-CD / CD (RetroArch/Picodrive, DGen)
- Sega 32X (RetroArch/Picodrive, DGen)
- Playstation 1 (RetroArch/PCSX ReARMed)
- Super Nintendo Entertainment System (RetroArch/Pocket SNES, snes9x-rpi)
- Sinclair ZX Spectrum (Fuse, FBZX)
Wow. RetroPie sounds like a sweet project. Let’s go grab that. It is possible that this link will change from time to time (it already has in the last few days). We want to download the newest version of the RetroPie SD Image available for our Raspberry Pi 2 device. Download the newest version of RetroPie. If this link is out of date then you should be able to find an updated link in the RetroPie Image Download at this link.
Once the download is complete you will have a file called something like retropie-v2.6.0-rpi2.img.gz. We have to unzip this file so that we only have the .img file. On most computers you can do this by simply double clicking the file. If that does not work then you should use a program like 7-Zip or WinRAR.
At this point we have to format the MicroSD card. We can do this by using SD Card Formatter. Download this program. Insert you MicroSD card into your computer. Run the program. You should see the following screen. Click quick format, give the card a name if you want and click Format.
The next step is to extract the downloaded RetroPie image file to the formatted MicroSD card. For Windows use Win32 Disk Imager or for Mac use RPi-SD Card Builder. If you love your linux use the dd command.
Here is what the process looks like for Mac using RPi-SD Card Builder. You will likely have to input admin password for your Mac while installing this software.
Select your RetroPie image file that you just unzipped. Click OK on the next pop up.
Select your card to write the image to.
Click OK and wait a little while.
Oh yea. RetroPie image is installed on our MicroSD card!
It is now time to remove the MicroSD and insert it into the Raspberry Pi. We also want to connect the mouse, keyboard, gaming controller, and WiPi dongle to the four USB ports. If we are using Ethernet instead of the WiPi then connect the Ethernet cable from your router to your Raspberry Pi’s Ethernet port. Connect the HDMI cable from the Raspberry Pi to the TV or monitor. Connect the TV’s power cable to your power source. Select the HDMI input on the TV for your Raspberry Pi. Finally, only after everything else is connected, connect your Raspberry Pi’s power cable from the Raspberry Pi to the power source.
If you did everything correctly you should see a screen that asks you to set your controller settings. If you do not see this screen then you can try removing the power cable from the Raspberry Pi and reinserting it. Enter the appropriate buttons when the screen asks you, ie. Up, Down, Left, Right, A, B, etc. This will sync your gaming controller with the RetroPie.
Once this is complete, press F4 on your USB keyboard that is connected to your Raspberry Pi. Pressing this button will get us out of the RetroPie’s main GUI which is called the Emulation Station and into the command line so that we can change some settings.
The first command we want to run is
Enter that command into the command line prompt as shown in this image.
Then press enter. You should see the following screen.
This allows us to change some settings on the Raspberry Pi. We first want to highlight Expand Filesystem and click Enter. This will ensure that all of the SD card storage is available for the operating system. Currently even though we have a 32 GB card, not all of that space is available. After clicking Enter we see a message telling us the filesystem will be enlarged at the next reboot, which we will do later.
Pressing enter returns us to the list of options. I personally don’t want to keep the stock password so click Enter on the second option. Enter a new password and press enter. Re-enter the new password and press enter. The password should change successfully.
Next we can go down to Overclock and press Enter. After the warning screen we see a screen where we can increase the performance of our Raspberry Pi. This may lead to the SD card becoming corrupted or to the Raspberry Pi unexpectedly crashing or possible failure of the Pi. I will choose to not overclock but if you want to do that then this would be the place to do it. You may find that you can get smoother gameplay and you will be able to have more processing power available to you by overclocking. Personally if I wanted a lot of power I would not by the Pi, but this is a nice option to know about.
Select your choice and hit enter or select cancel to get out of here. This is the last setting I would change so let’s select Finish and hit Enter. This will bring us back into the Emulation Station.
Once the Emulation Station loads, let’s hit F4 again on our USB keyboard connecting to the Raspberry Pi. If you notice towards the bottom we see a filesystem rootfs that now has 27GB available space. This has been increased over the initial amount.
We have to setup my WiPi to give the Raspberry Pi wireless internet access. Let’s enter:
sudo nano /etc/network/interfaces
and press Enter.
We should see the following in this file:
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet dhcp
iface default inet dhcp
If you do not see exactly this in this file then make the changes to the file until it is the same as what you see. Once the file looks exactly like this press Ctrl+X. We are asked if we want to save changes. Press Y and then press Enter to save the file.
Next let’s enter into the command line:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
and press Enter.
We likely will see the following in this file:
Below that we will want to enter:
Make sure to enter the double quotes. The SSID and PSK is the name and password that come from your router. These are the same you would enter to connect your phone or computer to your wireless router. Also make sure your settings are correct based on your router. Depending on your network settings you may want to change Protocol type to RSN (for WPA2) instead of WPA (for WPA1), key to WPA-EAP instead of WPA-PSK, pairwise to CCMP (for WPA2) instead of TKIP (for WPA1), and authorization option to SHARED or LEAP instead of OPEN (used for WPA1 and WPA2). Once these settings are added correctly to the file, press Ctrl+X. You will be asked if you want to save. Press Y and then press Enter.
Back in the console type:
and press Enter. This will again boot us back into the Emulation Station. Let’s press F4 again to get back into the command line. Hopefully our Raspberry Pi is now online. Let’s check that by entering:
ping -c 1 google.com
and pressing Enter.
If we did everything right then we should see something that says:
1 packets transmitted, 1 received, 0% packet loss.
If so, yay, our little Pi is on the internet. He sure is growing up fast.
At this point we need to find out the IP address of our Pi. You can do this by entering:
and pressing Enter.
Under wlan0 we should see an IP address under inet addr. This will be something like 192.168.1.4.
We will need this IP for later to add ROMs to the Raspberry Pi.
So, now it’s time for us to get our ROMs. About that. So we know emulators are software versions of the hardware console. An Nintendo emulator emulates the Nintendo console and allows you to play Nintendo ROMs. ROMs are software versions of the hardware catridge game that you used to have to blow air into to get to work. Emulators are all fine and dandy, but the use of ROMs is pretty much illegal. It is illegal to download and play a Nintendo ROM from the internet. This has to do with the U.S. copyright laws that state that copyrights owned by corporations are valid for 75 years from the date of first publication. So until the copyrights expire, it is illegal to download and play ROMs.
There is one semi-exception that you often hear quoted by people supporting emulation and ROMs but it doesn’t help us much. I’ll quote Nintendo’s legal response here. “There is a good deal of misinformation on the Internet regarding the backup/archival copy exception. It is not a “second copy” rule and is often mistakenly cited for the proposition that if you have one lawful copy of a copyrighted work, you are entitled to have a second copy of the copyrighted work even if that second copy is an infringing copy. The backup/archival copy exception is a very narrow limitation relating to a copy being made by the rightful owner of an authentic game to ensure he or she has one in the event of damage or destruction of the authentic. Therefore, whether you have an authentic game or not, or whether you have possession of a Nintendo ROM for a limited amount of time, i.e. 24 hours, it is illegal to download and play a Nintendo ROM from the Internet.” Read more about the topic at Nintendo’s Legal.
So yea, legally we can’t really proceed to add ROMs that aren’t part of the public domain. There are no Nintendo, SuperNES, N64, etc. games that are part of the public domain, so to legally continue with this tutorial you have to wait 50 years or so. If you do decide to wait that long and to continue, then you will need a copy of your ROMs. You can find ROMs today all over the internet by searching on your normal laptop or desktop computer. Note that this step is done not on your Pi, but on your computer that is connected to the same network that the Raspberry Pi is on. Searching your favorite torrent site like The Pirate Bay for terms like “nes,” “snes,” “n64,” etc. will allow you to download almost all of the ROMs for a system in a single shot. Often these ROMs are saved as .zip files. You will need to unzip all of these files and then add them to a new folder containing only these unzipped files. For example you want your filenames to be .nes for NES games, .smc for SNES games, .z64 or .v64 for N64 games, etc. and not .zip. These should be saved to folders named /nes, /snes, and /n64-mupen64plus. These folder names must be named this way. The full list of folders for this version of RetroPie are:
To get the full list of these folders in future releases of RetroPie you can run the following command on the Raspberry Pi:
and pressing Enter.
If you notice, there are sometimes more than one folder for the same system. Sometimes adding a ROM to a different folder will allow it to run better. For example I had better luck running some of the N64 games in the /n64-mupen64plus folder but I also had some titles run better in the /n64 folder. You may have to move these ROMs around to get the newer systems to run.
As you can see there are many gaming systems and many games available that you would have to download and unzip if you want to move them to the Raspberry Pi.
Once the ROMs are downloaded to laptop or desktop, unzipped, and added to folders based on their console, it is time to move them over to the Raspberry Pi. On Mac this can easily be done using the scp command in Terminal. Let’s open terminal (Command+Space and then typing terminal and pressing enter) and enter the following three commands. Note that you have to replace /Users/yourname/Desktop/ with the file path of where the files are saved on your computer.
scp -v -r /Users/yourname/Desktop/nes/ email@example.com:/home/pi/RetroPie/roms/
scp -v -r /Users/yourname/Desktop/snes/ firstname.lastname@example.org:/home/pi/RetroPie/roms/
scp -v -r /Users/yourname/Desktop/n64-mupen64plus/ email@example.com:/home/pi/RetroPie/roms/
After entering the command you will be asked to enter yes or no based on your Mac not knowing the Raspberry Pi device. You can enter Yes and press Enter. You will then be prompted for the password of the Raspberry Pi that we set earlier for every folder of ROMs that you upload. If you never changed your password in the earlier step then your password is “raspberry” (do not enter the quotes) which is not the most secure of passwords.
This may take some time based on your internet speeds, especially for larger folders, so you might want to find something to pass the time.
If you don’t have a Mac or you don’t want to use the scp command, you can use a GUI based file transferring program such as FileZilla. I will show a quick example of using FileZilla because a lot of people like to avoid the command line and use visual tools like this one. Start the program. Enter your host, username, password, and port and click Quickconnect. Your host is the IP address of the Raspberry Pi that we found earlier. The username is “pi”. The password is what we changed it to, or “raspberry” if you didn’t change it (do not enter the quotes). The port number is 22. After Quickconnect is clicked you will get a message saying Unknown host key and whether you want to trust the host. Check always trust this host and click OK.
To move the files from one place to another you simply drag and drop them. Before we drag and drop let’s make it easy by opening our folder with ROMs and our emulation folder on the Raspberry Pi. This should look like this.
Select all of the ROM files and drag them to the empty emulator folder. Depending upon your upload speed you should see files get added to your previously blank folder like so.
When the files are finally copied from your computer you are almost ready to play.
I had to make one final change to get sound to work with an HDMI monitor. You may or may not have to do this. This is caused by some computer monitors which select DVI mode even if an HDMI cable is connected. We have to alter the Raspberry-Pi Configuration File. Let’s enter:
sudo nano /boot/config.txt
and press Enter.
We need to take the line that says:
and change it to:
by removing the # sign. Once this is done press Ctrl+X. You will be asked if you want to save. Press Y and then press Enter.
and press Enter.
Again you may not have to do this step to get your sound to work, but it seems like you will need to do it if you are playing on an HDMI monitor with internal speakers.
Ok. Let’s try out some games. When you normally start your Raspberry Pi you will be in the Emulation Station. If you are at the command line and want to launch the Emulation Station then type:
and press Enter.
In the Emulation Station you select which console that you want to play. Note that consoles will only appear when you have ROMs installed for those consoles. Pick a game and get to playing. Here are some videos of some games running for various systems. I apologize for their terrible quality.
NES running Super Mario Brothers.
SNES running NBA Jam.
N64 running Mario Kart 64.
You may find that you have various problems with your RetroPie setup. Sometimes unplugging things and restarting can fix the problem. But if you have a serious problem that needs fixing I am sure there is a solution on the internet. If you made it through any part of this tutorial then have a little Linux command line skills. You likely can implement the fix to your problem. Google is your friend. In the worst case you can always wipe the card clean and start over from scratch.
Now that the RetroPie is up and running, I’ll hopefully be working on a more challenging Raspberry Pi project in the near future. The great thing about the Pi is you only have to take out the MicroSD card and replace it with another to have a totally different application. Feel free to drop a line if you need help.