Raspberry Pi projects part 1 – A working NES in just the controller

Anyone who knows me personally knows I’ve recently become a father. This is obviously fantastic news, and loads more on that coming up in a future post. A nice side effect is the four weeks I had off work for paternity leave…

4 weeks at home…

I managed to use up my entire stock of Raspberry Pis. This ‘mini series’ of posts is going to walk you thorough the fun I had building stuff when I wasn’t learning how to be a dad.

 

The first project – building a game console

With a drawer full of Raspberry Pis (or RPis as I’ll be calling them from now on) , I turned to the RPi subreddit for some inspiration. Let’s look at the top post of all time:

rpi

Cool, guess we’re doing that then. I’ve been meaning to do this for years anyway. I’ve never been a huge gamer but I do like retro games, and having worked at a games company for a year it feels like the sort of thing I should do (I quit recently and now work for the British Geological Survey for anyone who cares btw)

Design Requirements

Before starting I came up with the following requirements:

  1. I want to emulate a NES. I’m too young for this to be my childhood console, but I do remember playing a lot of NES games at my friends’ houses. I even owned a NES while I was at uni.
  2. The entire thing has to fit inside an original NES controller. None of this plugging it into a little box which goes in the TV.
  3. The controller has to be an original NES controller. No knock-off USB controllers here, I want the original experience!
  4. It needs to support HDMI out and should be plug and play – ie you plug in the power, plug in the HDMI and you are good to go.
  5. It has to be able to support a second controller for two-player games.
  6. It should be easy to upload new games.
  7. It needs to be as cheap as possible. I had a Pi Zero and two NES controllers already lying around the house – so the project was essentially free for me but can be done for under $30 for someone without the kit already.

There are various versions of this project knocking around but I intend to walk through exactly how I achieved my version. I won’t focus too much on why we do all the steps, more how to do them because I suspect most readers just want to know how to make one (links at the end for those who want to know more). It did not necessarily go as easily as I expected – taking 2 days altogether.

Equipment list

1 X Raspberry Pi Zero W

1X micro SD card (min 8GB)

1 X original NES controller

1 X mini HDMI to HDMI converter

1 X HDMI cable

1 X micro USB lead

6 X 8mm M2.5 hex self tapping screws (can manage without if you don;t strip the original screws)

1 X USB NES controller (only needed for two player mode)

1 X 5mm LED (optional) – you choose the colour

1 X corresponding resistor for that LED (calculator here)

 

Required software (for Windows users – all free)

WinSCP

Putty

Win32 Disk Imager

 

Installing emulators to the RPi

In keeping with pretty much any RPi retro gaming project, we’ll be using Retropie for all the emulation. This is installed by downloading the free disc image from the Retropie website . Full instructions are given at the site but it’s pretty simple. I just downloaded the image for the Pi Zero and wrote it to a 16Gb SD Micro card using Win32 disk imager (also free to download).

 

Setting up the RPi for headless access

This step isn’t completely mandatory but makes life a lot easier later on. The conventional way to us a RPi is to plug it into a monitor/tv, plug in a keyboard and power it on. However, it’s easier to set it up for remote access so we can do the setup remotely via another computer.

To do this we need to tell the Pi which wifi network to connect to, and we need to allow SSH access (basically network access via the command line – don’t worry about the details if you’re not familiar with this).

Network access setup: to set this up, open the SD card we just wrote to in your file system and create a new file in the home folder (the folder is called ‘boot’) in a text editor . Call the file ‘wpa_supplicant.conf’. This file should consist of the following text – change the bits in caps as appropriate and delete the ” symbols:

country=
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid=""
 psk=""
}

Save the file as ‘wpa_supplicant.conf’, being sure to remove the .txt extension after it.

SSH setup: In the same folder (ie the boot folder of the SD card) create a file in a text editor. The file should be empty but the filename should be ‘ssh’ with no extension (ie, remove the .txt)

Now insert the SD card to the RPi and in the power and go to your routers home page. That’s usually found by entering either ‘192.168.1.1’ or ‘192.168.0.1’ into your browser. Once there and logged in (you can find the default password for your router online by googling your ISP and ‘router default login’) you should be able to see a list of connected clients. One will be called ‘retropie’. Note down the IP address of this client.

Now download putty (more free software) and enter that IP address. You should get a login prompt (the username is ‘pi’ and the password is ‘raspberry’). If so, you’ve successfully set the RPi up for headless access. We’ll be using it later to transfer games across.

 

Getting the Pi in the controller

Unlike most projects on this blog which are coding heavy, the main challenge here was the physical build. The Pi Zero W, for those unfamiliar is the teeny shrunk down version of the Raspberry Pi. It has onboard wifi which, although not essential for this project, makes it a lot easier. Although the Pi is tiny, the NES controller isn’t exactly huge so I had to do some surgery.

My NES controller was in pretty good condition so it didn’t need that much cleaning up (my upcoming SNES model will need some cleaning up). So, the first thing to do was to take it apart. I cut and stripped back the controller cable to about 10cm to reveal the five wires inside:

inside NES

NES controller with the back removed – the front (ie the buttons) are face down here.

 

Before going any further, I soldered the GPIO pins (the 40 pins on the side of the RPi) on the pi to the wires in the controller. Documentation is available at the Retropi Github pages explaining why each wire goes to its respective pin, but all you need to know is to solder as follows:

NES wire RPi Header pin #
white 1
orange 23
red 19
brown 6
yellow 7

Let’s be absolutely clear on the above. The header pin # refers to the physical pin number. I’m sick of guides being ambiguous with pin naming conventions so when I say ‘header pin #’ I mean the physical pin location. On the diagram at this page, the header pin #s are the small numbers written closest to the pin locations (ie not the big bold numbers).

If you want a power LED (a 5mm LED fits nicely set back into the hole left by the lead), also solder the -ive side of a LED to header pin 14 and the +ive side to pin 2, via the required resistor, feel free to splice to nasa standards!

With the Pi soldered up and the controller disassembled we see a basic controller board with a microcontroller. This microcontroller prevents us from simply putting the RPi under the board as it sticks up too high. So my only option was to remove the board and see if we can get the RPi above the board (ie between the board and the front panel).

rpi controller

The Pi is to sit above the control board at the top of the controller. Note, I didn’t have a power LED attached at this point – I added it later and forgot to take a photo.

Since the Pi is slightly larger than the shown space, it is necessary to remove some material from the inside of the controller. I used a scalpel to do this, but a dremel would be easier. Removing the black/white button membranes I removed plastic as shown below:

nes before

controller front before I started removing material

Using a scalpel I removed:

  1. The upper central screw post.
  2. The upper left plastic tab.
  3. About 2mm from top of the ring of grey plastic around the A and B buttons.
  4. Inserted notches in the plastic ring to turn the A and B buttons around by 90 degrees.
  5. The two plastic posts to the immediate upper right of the ‘B’ button.

The changes are shown below for comparison with the above photo:

nes after

Controller with plastic removed. Note the gunk around the D-pad – I cleaned this off with some rubbing alcohol.

With that done, the Pi fits snugly in place. It doesn’t need gluing or screwing down or anything:

pi in controller

The Pi sitting snugly in the controller. The buttons and membranes were replaced and the controller re-assembled.

At this stage I cut holes in the casing for the two USB micro ports and the HDMI port. Annoyingly I forgot to take a photo, but take my word for it, you can just make them out in the photo above. I then screwed the whole thing back together (using new M2.5 hex screws). Through trial and error I also ended up removing some plastic from the back of the controller as shown here:

CONT BACK

Plastic removed from the back of the controller – basically the 3 rings. It may be necessary to remove one or more of the screw posts too depending on your individual controller.

I recommend following the step below before removing plastic from the back of the controller as the buttons are pretty sensitive to pressure from the back piece of the controller so it’s worth removing just a bit at a time until they all work properly (yeah it’s tedious and is why this took 2 days).

Finally, the controller was re-assembled. Before screwing the back plate back on again, the wires were routed as shown below:

IMG_1828

Ignore the duct tape – I couldn’t find my electrical tape!

Configuring Retropie

With the controller reassembled, it’s time to get Retropie setup to use the actual controls.

To do this, plug in a USB keyboard to the free USB slot, plug in the HDMI to a display and power up the pi. Retropie will automatically start up and ask you to map various keys to the keyboard. Just map the keys as necessary (you only need to map the directional buttons and ‘A’, ‘B’, ‘start’ and ‘select’ for this to work, so make sure you map them to something sensible).

Then, select Retropie (by pressing ‘A’ on the homescreen). From here select retropie setup -> manage packages -> manage driver packages. Select option gamecon driver. This will take some time to install but will configure Retropie to use the NES controls. When it asks about configuring SNES controls, select ‘No’.

Then, using putty on your Windows computer (or equivalent on a Mac), SSH into the Pi, as described above and run the following:

sudo sh -c 'echo "gamecon_gpio_rpi" >> /etc/modules && echo "options gamecon_gpio_rpi map=0,0,2,0,0,0" > /etc/modprobe.d/gamecon.conf && reboot'

Now reboot the Pi and, using the keyboard we have plugged in, hit ‘start’ (ie whichever key you mapped to start) and go to ‘configure input’. It should state ‘1 gamepad detected’ and you can map the keys on the NES controller. If any keys don’t work you’ll need to unscrew it and consider removing more plastic as discussed above.

 

Uploading some games

To add games to your console you’ll need to source ROMs of the games you want. They are usually found in .zip files and don’t need to be unziped – you can just upload the zipped files as is. I can’t say where to get the ROM files because if you don’t already own the original games, it’s illegal to download ROMs, so I’ll leave it there.

To add a ROM to the console you’ll need WinSCP, which is yet another free piece of software. Open WinSCP and connect to the pi by entering its IP address (from earlier), username (default: pi) and password (default:raspberry). You’ll see two windows – the left is the file system on your computer, the right is the file system on the RPi. In the left window, navigate to the folder where your ROMs are saved. In the right window navigate to retropie -> roms -> NES. Then you can simply drag the games across from the left to the right window. That’s it – any time you want to add a new game, just power up the controller, it’ll automatically connect to your wifi can you can transfer the ROMs across. Reboot the controller and you’ll see the games under the NES icon!

By the way, I thoroughly recommend backing up the SD card. I always clone my Pi project cards but on this particular project the card actually corrupted before I made a backup. I wasn’t happy.

 

Adding a second player

In an ideal world, I’d make a custom connector to connect an original NES controller to the respective GPIO pins on the RPi However, I really couldn’t be bothered doing this, especially when it’s incredibly simple to add a USB controller.

So, I bought a cheap USB NES controller (just £2.49!). All you need to do is plug it into the remaining micro USB port, hit start (on the original controller) and go to ‘configure input’ – then you can configure the inputs for the new controller. That’s it – Retropie allows plug and play USB with no faffing around with drivers.

 

Enjoy your new toy!

IMG_1836

Here it is all connected up and with player 2 plugged in. Note my cool blue LED not shown in earlier photos

That’s it, a fully functioning NES in just the controller. The method I’ve presented is about the cheapest way of doing it. Potential improvements would include:

  1. Adding battery power. It’d be challenging but certainly possible to cram a battery and the necessary charging circuit it, thus removing the need to be plugged in while playing (I plan to do this on the SNES model in the future so watch this space).
  2. Add wireless HDMI. This would be expensive but wireless HDMI dongles do exist. I guess this would be the ‘Rolls Royce’ of NES emulaters with no wires. Part of this project was to make something cheaper than Nintendo’s NES classic so doing this would make a train-wreck of that objective.
  3. Use a bluetooth controller for player 2. The pi zero W has a bluetooth chip and it’s almost effortless to pair a second controller. Expensive though (about £30 for a controller here in the UK).
  4. Use an original NES controller for player two, as discussed above. Is this worth the effort? Maybe if you have the time.

 

Links and More Info

The RetroPie site provides more info and gives full install instructions:

https://retropie.org.uk/

 

Likewise, the Github page for Retropie gives way more info regarding technical details:

https://github.com/RetroPie

 

Here is a similar project which involves 3D printing a new back rather than doing surgery to an existing one:

https://howchoo.com/g/zdqxnzblmzm/gamepad-zero-a-raspberry-pi-retro-gaming-rig-in-an-nes-controller

 

Here is someone else getting a Pi zero into the controller in much the same way I did (this is where I got the idea to rotate the A and B buttons):

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s