Saturday 30 August 2014

Raspberry Pi installed into an old broken NES

First blog post!


Hi all, this is my first blog post, I set this blog up to document some of my projects (only one of which is "complete" thus far) because I thought they might be of interest to others.  Certainly other people's blogs have been invaluable for both inspiration and information for my own projects.

Why put a Raspberry Pi in a NES?


This first project is my Raspberry Pi inside an old NES.  Why did I do this?  I'm really into retro games, yet I never owned a NES, instead I had a SEGA Master System (an awesome console).  Recently I really started to fee like I'd missed out on a whole lot of gaming cultural touch stones, so many often discussed games that I'd never even played.  So I thought I would buy a NES, and then I thought about how many cartridges I would have to buy and how expensive it would be and how much space it would take up (incidentally I am trying to reduce the amount of stuff that I own right now).  So my solution was to buy a NES that was broken beyond repair and put a Raspberry Pi in it.

My approach and goals with this project


Given that's where I'm coming from, just a few notes on how I approached this project.  I wanted to experience the NES as close to what it was really like as possible.  That meant doing this project in a way that kept the gameplay experience and the operation and appearance of the console as authentic as possible.  There are quite a lot of these projects around, and without meaning to offend anyone I think most of them are pretty clumsy implementations.  E.g. many use a dremel to gouge ugly holes in the side of the case to put in HDMI or Ethernet ports or even replace the controller ports on the front with USB ports.  At that point, to me I feel like "what's the point?"  This is of course only my own opinion and relates to what I want to get out of the experience, those other projects are still great and without reading about them I'd never have gotten anywhere with my own.

So my goal with this project was that from the outside there would be no telltale signs that this was a modified NES, it had to look completely original (at least with the cartridge slot lid closed).  That meant using all the original AV ports and original controllers.

Other projects that really helped


Probably the two most helpful blogs along the way were Igor's (http://www.igorkromin.net/index.php/2013/01/08/raspberry-pi-in-a-nes-case-part-1-wiring-up-the-front-panel-and-external-connectors/), who's project achieves the same goal as mine, using all the original ports, and James' (http://jamesparsons.com/2013/11/raspberry-nes-project), who's project had a couple of great features that I also implemented in mine.  Now, on with the show...

The Project


This isn't a proper build blog because I didn't document the process as I went, so I've just photographed everything as I was implementing one of the final features and will try to explain how I went about it.

Software


I won't say too much about the software, I'm using the retropie SD card image, you can find plenty of information about it elsewhere.  I barely understand electronics and I understand Linux even less so thankfully Retropie is very easy to get up and running.  Very unlikely that I can help with any questions regarding it's setup beyond the most basic, I followed the instructions of others.

Mounting the components



Because I didn't want to alter the actual NES case by drilling any holes in it or anything I cut a small sheet of perspex upon which to mount everything.  This sheet then screws onto the mounting posts that the original NES motherboard and other internals were attached to using the same screws, so I just had to drill a few holes in it in the right places.  The Pi is attached to the perspex via the bottom half of a case (you can see the top half of the case in the background in the image above and below) which has been screwed down.  The powered USB hub that I'm using (7 ports) sits on top of a platform at the right height to place it in the cartridge slot, it's attached to the perspex with adhesive velcro and the platform posts are some long screws and the barrel of a ball point pen.


Underneath is a keyboard encoder (I-Pac 2 VE from ultimarc.com) which is also screwed in (I'll explain it's purpose later)


You can see here that sticking out the front of the hub is a WiFi USB dongle, this one is really small and works out of the box with the Raspberry Pi so I'm really pleased with it.


The AV and Power ports



This is the small chassis that houses all the AV ports, I've removed the PCB that was attached to it and soldered a composite video cable to the video port, and a 3.5mm stereo cable with one channel soldered to the audio out port and the other channel soldered to the RF port, so the option for stereo sound is there if you are running something that needs it.  I've also soldered the power cable from the USB hub to the DC in port.  I then added a compatible male plug to the DC adapter for the hub so that it would plug into the DC port on the NES just like the original power supply (not pictured).

The power and reset buttons


I haven't taken a picture of it specifically but the power buttons and power LED are attached to a small PCB with 5 wires coming off it, this is convenient, all you have to do is remove the blue connector from the end of the 5 wires and then you can hook those wires up to whatever.  Take note of the colours, or just look underneath the board and trace their connections to the various components.


Here's the keyboard encoder, this is basically a keyboard, where you can hook any switch up to the terminals to simulate a keyboard stroke.  These are sold for the purpose of setting up a MAME machine so that you can get arcade controls working with ease on a PC.  This is a bit of an overkill way to implement this but I'm using this so that the reset button functions as the escape key, this is so that I can exit games and get back to the game select screen.  The two original wires from the reset switch just screw into the terminal for the escape key and the ground terminal.  Another option is to just use a specific button combination on the controller to exit the emulator, that can be setup easily, but I didn't like this idea because there's only 4 button ons a NES pad and I wasn't convinced that I wouldn't press the combination by accident or when throwing a tantrum because I died. 


The power switch utilises a small board from Mausberry Circuits.  You can see it between the black and orange usb cables, i've just hot glued it to the perspex sheet.  The two original wires from the power switch are soldered to this switch, and then it has two wires (blue and white) that connect to the GPIO pins.  All the instructions for setting it up are on the Mausberry Circuits website and it's very straight forward.  When you press the power button the Pi boots up, when you press it again it sends a shutdown command to the Pi and then cuts power after a few seconds, very cool.

I originally had this setup by just splicing the power switch into the wire providing power to the hub, which was fine for booting up, but then I had to shut down the Pi from the menu in emulationstation and then press the power button again once it shut down to return it to the off position - a bit clumsy.

Controller ports


This image is from a bit later in the build, but it shows the control port setup.  There are chips you can buy from Retrousb.com that have usb cables already attached to them, and all you have to do is solder wires from the back of the control ports to the chip.  Then when you plug an original nes controller into the control port the raspberry pi will recognise this as a normal USB controller.  This is a really great option.  Another way to go is wiring the ports directly to the GPIO pins, and using SNESdev which is included with Retropie.  This is the approach that Igor used and is what I originally tried to do.  I could NEVER get this to work properly, it drove me insane.  I could get one controller working fine but the other never would, and I couldn't get anyone to give me any kind of solution.  I even bought a second Raspberry Pi in case it was a hardware problem.  I also experienced control delay when I did have one controller running like that, something that isn't present at all using the USB chips. I'd save yourself the headache and do this instead, unless your much more comfortable with linux than I am (there is a good chance you might be).  Using these chips didn't require any setup, it just worked and there is no response delay.  I believe it may also add less overhead to the whole thing than using SNESdev does, and you won't run into any problems where something has been updated and breaks SNESdev.  In the picture below the chips are covered in electrical tape cause having them floating around like that makes me a tad nervous.


The full setup, almost done!


Here's a couple of pics just showing the whole layout



Up and running with the lid on and hooked up to a small 9" CRT.  The nintendo logo is one that I made to replace the default Retropie bootscreen.


Running SMB, of course.


Power LED and casing the Raspberry Pi


The last thing I wanted to do was hook up the power LED.  I left this till last because I had no idea what resistors I needed or how to find out.  I simply used the advice of others.  One blog said they used a 10k resistor, another one said they used 170, but two others said 330 so I went with that.  I desoldered a 100 and a 220 from the original broken NES motherboard and put them inline.  It's a little confusing here because there are two sets of blue and white wires, but the blue and white ones that are running along side each other are the ones that connect to the Mausberry circuit and are on side by side pins (see second image), while the other white wire on the right is from the power switch PCB and connects one side of the LED to a ground GPIO pin.  The blue wire on the left connects the other side of the LED (which I detached from the PCB) to the 3.3V GPIO pin - you can see the red heatshrink in the middle which covers the two resistors.


Showing where these wires connect to the Pi


I drilled a few holes in the appropriate places and put the case on the Pi now that there will be no more GPIO connections.


Here you can see where the blue wire connects to the LED on the powerswitch PCB, and you can see the five wires I spoke of earlier disappearing out the other end.


Power LED working


More pics


All done! The usb cable connecting the Mausberry circuits shutdown switch is missing in these pics so that you can see the detail a bit better (need to replace it with a shorter cable that isn't all coiled up in there)



Here you can see the AV ports


Power port and RF port.  One thing to note here, the gap in between had a small switch but it wasn't attached to the same chassis as the AV ports, it was attached to the PCB that I removed.  I'm considering either glueing it back on for aesthetics, or actually mounting a micro HDMI port here (that's right, you can have HDMI without butchering the case!).  I play this on a CRT TV (obviously, that's how it's supposed to be played!)  so it's not something I'm in a hurry to do, but I may do it at some point.


Here you can see the two black USB cables connecting the control port chips to the hub.  These were really long so I cut and resoldered them, hence the red heatshrink.  In hindsight it would have been a thousand times easier to desolder them from the chip and shorten the cable, rather than having to rejoin the five wires inside each cable.






I'm not completely happy with how this looks with the cartridge slot open, the screws and velcro tape don't look very neat or polished, I may put some kind of facade over this to hide everything but the USB ports, but it doesn't really bother me too much right now.


Conclusion


What's left to do?


It's pretty much complete.  The only two further modifications I'd like to make is as mentioned above putting something over the front of the USB hub to make it look neater, maybe a grey piece of plastic with the shape of the hub cut out.  Also still tossing up whether to add a micro HDMI port where the channel switch used to be at the back.

What could I have done better?


I'm pretty happy with the whole thing, I didn't want to permanently alter the Case itself, and I've implemented all the functionality I wanted without doing that, so I'm happy about that.  If someone one day wanted to use this case to restore an original NES they could, and it would be free of blemishes (except those imposed by a hard life of gaming).  I originally wanted to leave the cartridge spring mechanism inside so that you had to push down on the top of the USB hub to make it pop up, but the mechanism was too large and didn't leave me enough space for everything else.  It probably could have been done but would have been cramped.  It also made it problematic to access the back of the hub without drilling holes in the mechanism, which goes against one of my goals with the project.

Can you help me?


One thing I'm not happy about is using a 40 dollar keyboard encoder just to turn the reset button into an escape key.  I'm also building a MAME cabinet so I would like to use the encoder for that and not have to buy another one.  The Mausberry circuit works by activating a bash script (is that the right term?  it's a *.sh file)  that you have to install on the system.  There's a second set of terminals on the circuit for a reset switch which by default resets the whole system.  I'm wondering if by altering the script, a switch hooked up to the circuit's reset terminals could be made to either simulate a keyboard stroke or send the exit emulator command to Retroarch or Emulationstation (whichever handles that function).  If anyone knows how to implement that or has any other suggestions of how to elegantly implement this functionality please get in contact.

Happy to answer any questions you have regarding this project, I'll do my best to help with my EXTREMELY limited knowledge :)

22 comments:

  1. Can I get a list of items that are required to build this or recommendations? I've been trying to figure it out on my own but I'm having some trouble. Thank you in advance

    ReplyDelete
    Replies
    1. Sure thing. There are many ways you could do a project like this and get a similar result. If you want to make it the same as mine you’ll need the following things. I’ve split this into essential parts, which you more or less need, and non-essential parts, which are things that I used but could be substituted for any number of things that achieve the same result

      ESSENTIAL:

      Parts:
      NES (non functional)
      2x NES control pads
      2x RetroKit Control chips from retrousb.com
      Small sheet of clear acrylic
      ATXRapsi (or a mausberry circut)
      Keyboard encoder
      Raspberry Pi
      SD card
      Powered USB hub
      USB wifi dongle
      Bunch of coloured insulated wires
      Pin header connectors
      Heat shrink
      mini USB cable
      2x Micro USB cable
      Composite video cable
      2xRCA to 3.5mm stereo cable
      Various smalls screws and nuts to secure parts to the acrylic such as the keyboard encoder, power switch circuit and the raspberry pi (or it’s case)
      Solder

      Tools:
      Soldering iron
      Screw driver
      Hacksaw (for cutting the acrylic)
      Drill (for drilling holes in the acrylic and the Rpi case)
      Cigarette lighter (or heat gun) for shrinking the heatshrink


      NON-ESSENTIAL:

      Parts:
      A pen (for the legs of the hub platform)
      4x long screws with nuts (for the legs of the hub platform)
      Piece of black plastic (for cartridge slot facade)
      Velcro tape (to attach the hub to the platform)
      Electrical tape (wrapped around the retro USB chips)
      Raspberry Pi Case

      I'm pretty sure that's everything! If I think of anything I've forgotten I'll update the list. Any other queries don't hesitate to ask :)

      Delete
    2. Oh, and a 330 ohm resistor (or one of similar value)

      Delete
  2. Did you use the original dc in port? If so, any recommendations on a dc male plug? Thanks for posting this. It' seen super helpful!

    ReplyDelete
    Replies
    1. Yes, I did use the original dc port. I just checked my ebay history and the plug size I purchased to fit into this was a 5.5mm (outer diameter) x 2.5mm (inner diameter).

      I do wonder if the dc port could possibly vary by region, so I recommend you find a plug that fits (I assume most people would have a lot of DC power supplies in their house) and use a multimeter to test that it's making a connection on both the positive and ground pins of the port. If you find one that works, just measure it and order another one off ebay, they only cost a couple of bucks. Hope that helps.

      Delete
  3. Hi im building a same machine :) How do you soldered the Video and Audio ports?

    ReplyDelete
    Replies
    1. Hi, if you open up the NES you will find a piece of metal framing that has all the AV ports attached to it (fourth picture on this page shows what I'm referring to). On the inside the RCA jacks have an extension from the centre that is soldered to a small circuit board. I removed the board by des-oldering those connections. Once that was done I just took audio and video cables that connected to the raspberry pi and cut off the connector on one end. Then I soldered the signal wire to the centre pin on the RCA jacks (the part that was previously soldered to the circuit board) and soldered the cable shielding to the metal framing that holds all the AV ports. I hope that is helpful, if you need further clarification just ask :)

      Delete
    2. Oh! Thanks! its the same that I think, solder the "ground" wire to the metal :D

      Delete
  4. I know that this question is rather late but I'm making my own set up and I'm lost as to how I can connect to the existing AC Adapter. I'm trying to find pictures of your build and other people's but I can never get a detail on how they connect to the existing. If you have any answers that would be amazing.

    ReplyDelete
    Replies
    1. Hi Tim,

      Happy to help out. Can you clarify what you're trying to achieve? Are you trying to power this with the original nintendo power supply or do you want to power it with a power supply that came with your usb hub? Or some other power supply?

      Delete
    2. I'm going to power it with the recommended settings of 5v/2.5A but I've seen it where they are using the original ac adapter (5.5mm x 2.1mm). I was wondering how I would connect the wires of a micro usb to the back of the original adapter. I hope this makes a little more sense. Sorry, very new at this.

      Delete
    3. No worries, I'm new at this too :)

      When you say ac adapter, I'm assuming you mean the socket at the back of the nintendo. If I'm assuming incorrectly then let me know.

      Only two wires are used to supply power in a usb cable, so if you want to have a micro USB cable coming from the back of nintendo's power socket when you need to strip one end of a micro USB cable and solder the 5v (usually red) and ground (usually black) wires to the correct pins on the back of the socket. Then you'll be able to plug a power supply into the socket and power the Pi. Does that make sense?

      If you're powering the pi via a usb hub mounted inside (as I have) just cut the power cable for the hub, take the bit that plugs into the hub and solder the exposed wires to the back of the power socket, then solder a new plug onto the exposed wires of the power supply that will fit into the socket on the back of the nintendo.

      If that isn't clear, let me know and I'll do up a diagram and post it.

      Delete
    4. A diagram would be extremely helpful to me if it's not to much for you. I'm just trying to solder a USB to the back of the existing power socket of the NES but I don't see anything that I would connect it to.

      Delete
    5. Hi Tim, finally got round to doing this. If you want to take the approach of going directly from the power jack to a microUSB cable then here is a diagram that should help:

      http://i.imgur.com/yAye7ro.png

      This shows where you should solder the wires of your usb cable to the power jack. But there are a few important points to note

      1. The two pins coming from the power jack are originally soldered to a circuit board, as are the pins from all the AV ports. You would need to remove this circuit board first. Or, you would need to solder the wires carefully to the circuit board in the appropriate places.

      2. Which pin is positive and which is ground depends entirely on your power supply. Sometimes the centre pin of the jack is positive and sometimes it is negative. You must look at the specification of your power supply.

      3. From memory the rear-most pin of the jack is connected to the centre pin inside the jack, and the other pin is connected to the outer contact inside the socket. But you should always check this with a multi meter to be sure. Hope that helps.

      Delete
    6. Thanks for the reply! Just got this done by soldering it to the circuit board because removing it was becoming a hassle for me. Just need to double check now if I get power or not.

      Delete
  5. I'm trying to make this based on yours. I was wondering instead of using the NES controller chips, can I wire the controller ports directly to the keyboard encoder?

    ReplyDelete
    Replies
    1. Unfortunately not. A keyboard encoder will only accept a simple on off switches, so you need a wire for each button. That's not how the nes controller works. It has 8 contacts (up, down, left, right, start, select, A and B) but only 5 wires in the cable. The signal that the controller sends in more complicated than simple on/off switches. Unfortunately I can't explain it any better than that because I don't understand exactly how it works.

      If you don't want to buy the controller chips you can look into the solution that I first tried, which is wiring the ports directly to the GPIO pins. It uses a utility called SNESdev. I could never get this to work, I kept having problems and there was a bit of a language barrier when I was trying to communicate with the guy that made that utility. However, that was two years ago, it might work fine now, or someone might have written a new utility to accomplish this. Definitely do some research first, that way you might be able to save some money.

      Hope that helps :)

      Delete
  6. A teensy is able to emulate a keyboard and would be an affordable solution instead of the encoder. They're quite inexpensive for the earlier models, and can also be used to make an original NES Controller work over USB. They're extremely versatile and useful for all sorts of projects.

    ReplyDelete
    Replies
    1. Thanks for your reply! I actually bought a teensy for use in an upcoming gameboy pi project (haven't tinkered with it yet), it hadn't occurred to me that I could use it here. Do you have a link you could provide where I could find out how to program the teensy to translate the NES controller inputs to USB?

      Delete
    2. Hey BMOC, Great article! I'm glad your project was a success! To answer your question .sh is a shell script, and a .bh is a bash script (so many scripting languages!). You can emulate a keypress using xdotool and there is also another one tool. Search around for "Simulate key presses on Linux". xdotool is a command line tool so that means you just need to connect a button to a GPIO Pin on your pin and then program the PI. Again great job with this project, I hope this helps, and saves you money ;). Good luck!

      Delete
  7. (Re-posted since I posted as a reply the last time by mistake):
    --
    Hey BMOC, Great article! I'm glad your project was a success! To answer your question .sh is a shell script, and a .bh is a bash script (so many scripting languages!). You can emulate a keypress using xdotool and there is also another one tool. Search around for "Simulate key presses on Linux". xdotool is a command line tool so that means you just need to connect a button to a GPIO Pin on your pin and then program the PI. Again great job with this project, I hope this helps, and saves you money ;). Good luck!

    ReplyDelete
  8. Maaaaan , this is awesome so complete compared to what im tryna do. I just want to use the power and reset buttons to do exactly that turn on and reset . What i ve read just to solder the reset button to the RUN holes on the RBpi and conect Power to gpio and 0v usea a script but what about the led . Im not using a hub or something more im gonna be using a NES 30 Bluetooth Controller, maybe in a future would like to usea a joystick for Mame. But man yours looks awesome

    ReplyDelete