The worlds smallest (S)NES emulator

From RevSpace
Jump to navigation Jump to search
Project (S)NES emulator
NES emulator prototype.JPG
A very tiny, (probably the smallest ever) but fully functional NES and SNES emulator based on a Raspberry PI Zero
Status In progress
Contact Mahjongg
Last Update 2017-03-21

I tried to buy the recently released NES Classic Mini system on its launch day (the 11th of November 2016), but failed because Nintendo distributed just a very few systems worldwide, creating an immediate shortage. The largest game shop chain in the large town den Hague where RevSpace is located received just one New classic Mini for their two shops! Thats how thinly Nintendo distributed these things.

I studied what the NES Classic Mini was based on, and discovered it was actually an emulator based system, (not a direct hardware re-creation) based on an ARM system (a quadcore all winner SoC). It could take many weeks before I will be able to buy one, but I knew that for Raspberry PI's there exists an emulation system called RetroPI that is able to do the exact same thing (and then some more).

I had a raspberry PI zero left unused, and thought it would be nice to install RetroPI on it, I also knew that it would be possible to control retroPI with buttons connected to the PI's GPIO's, and a piece of code from Adafruit that converts the buttons to a "Virtual USB keyboard". Looking at my zero I envisioned that it had a shape (but not size) resembling a NES controller, and had also seen YouTube movies that described a PI zero being built into a NES controller. I decided to see if I could place the joypad buttons on a piece of perfboard that had the same size as a Raspberry PI zero, and so this project was invented, (luckily I have small hands, so this joypad isn't too small for me). I decided to put some extra buttons on the PCB, so it resembled a SNES controller, and added one extra button, for special functions, which may come out handy later, perhaps to be able to easily exit a game (later I found out that this isn't necessary). Later I also added shoulder buttons.

the best way I initially thought was to combine the button board with the PCB would not be to put the button PCB on top of the zero, but on the bottom, this would make the "stack" of the PCB's and components much thinner, so the thickness of the whole would be more similar to a NES controller (later I found out that this wasn't really necessary).

First I would wire all buttons on one end to ground, with the other end of the button wired to one 10K pullup, all the other ends of the pullups would be wired together, so they could be wired to 3.3V. Each node between a button and Pullup will be wired to a single GPIO line (one not carrying a special function). A total of 11 Buttons are available, so I would need 11 GPIO's. But the zero has plenty of these. GND and 3V3 wiring was done on the bottom of the "keyboard PCB", wires running to GPIO's will be wired on top with thine wire wrap wire with at least four different colours (different from the black and red wires of the bottom.

I am planning to first solder a wire to all nodes, then to temporary wire up the GND and 3V3 wires, then use a multimeter to see if I can control each GPIO wire, so I know the wires on the bottom are Okay before soldering the PCB's together. I will place a piece of foam as isolation between the two PCB's.

This is a picture of the wiring on the bottom of the "keyboard" PCB, showing all the GND and 3V3 wiring, and the interconnects between pullups and buttons.

PTDC0012.JPG

note that it will be possible to also connect a full size retro NES USB controller, or a keyboard.

PTDC0004.JPG

December 6, 2016: keypad wired up and working with RetroPI

I managed to complete the wiring of the SNES compatible keypad, and got it working with RetroPI, using the Adafruit virtual keyboard driver for RetroPI, and a dedicated configuration file.

PTDC0017.JPG

I used another raspberry PI, a B+, in the process. Installed retroPI to a 8GB SD-card with the help of 7ZIP and WIn32Imager. When that worked (with a temporary keyboard to control it) I installed the adafruit keyboard driver, using a wired ethernet connection, and re-configured the retropi.cnf file with the GPIO ports I used for the direction keys, start, pause and A,B and X and Y keys, and an extra ESC key. Then I placed the SD-card in the zero, and configured the keyboard configurator with the assigned buttons. It took a while and I made some detours, and along the way discovered I forgot to solder a pinheader pin on the Zero GPIO side that caused the up-arrow-button to not work, but in the end it all functioned. Next Job is to get some ROM images on the sd-card, so the NES emulator is activated. For that I need to create a map on a memory stick, and put it on the booted up RetroPI system, so RetroPI can created directories for the ROM's where I can put my NES game ROM's in.

the keypad will get a white vinyl cover with lettering, to cover the wiring, and a black vinyl cross for the direction keys, and white vinyl backing over the IC's and card slot on the back, all to make it neat, and make it look like a NES controller (with extra buttons).

81b5dZtIPLL. SX522 .jpg


December 10, 2016: Emulator is working

Well, it works! I can play NES games using the Joypad I built. I tried six games from the list of 30 games from the NES Classic Mini, and they run fine. However playing it isn't really comfortable, with the heavy HDMI cable hanging off the keypad. The biggest reason for that is that the keypad is really very small, the exact same size as the RPI Zero. Also the hardware is now "naked", as I have not yet covered the keypad and RPI zero on the back. That will be the next thing I will do, in the process I will also cover the buttons with red, yellow, green and blue plastic dots for the A, B, X and Y buttons, and a black plastic cross from flexible plastic on the cross buttons. I will also try a few SNES games, partly to see if adding shoulder buttons, is useful.

I'm also considering to design a small PCB, with somewhat larger buttons, so you will get a full size SNES joypad that is easy to build, it will also be possible to use a mounting structure, so you have a complete enclosure around the joypad. Finally I will try adding a composite cable to see how well the emulator works with a PAL resolution. If that works well, I will add filter logic to a PWM GPIO so that mono analog sound is supported. With such few and thin cables the Joypad will be more pleasant to use.

December 18

added a composite cable, and shoulder buttons. The composite cable means I now have just two light cables hanging off the Zero/Joypad and the picture quality is surprising acceptable. Shoulder buttons work, but mechanically they are unacceptable. In fact the size as is is simply too small for me, and real gaming is awkward on this prototype. I really wanted to play these games, so I bought a "real joypad", a SNES30 from 8bitdo, but at €50, it was not exactly cheap, and it was hard (convoluted) to get it working. I think that I can do a better job with a PCB, and better buttons spread out to a similar size as the SNES30 joypad, and finding a solution for the still awkward cabling problem. I also need a better housing for proper shoulder button support.

January 17, 2017

My employer donated a few suitable enclosures to me, with a promise I could get a few more when I wanted. I have now mounted my contraption in such a case, and added acceptable shoulder buttons. It works fine and is mechanically much stabler. Although the buttons are a bit on the low (small) side to protrude through the plastic, its still acceptable, as I discovered I could remove all pull up resistors without negative side effects, this meant that the PCB could be glued closer to the plastic, meaning the buttons protruded higher above the surface of the enclosure. They are still somewhat small and cramped together though.

I also have added analog sound, by using the option to switch the PWM used to generate analog audio from the other PI's, to a set of (or a single for mono) GPIO pins, (which I was glad to see could be accomplished with a single line in config.txt) and adding my own "filter circuit".

This means I now have a usable setup with just three cables, one for audio, one for video and one for power.

Sound works fine if you turn up the audio settings in Retropie to the max. The software needed for direction PWM to GPIO's is just one simple line you add to config.txt, if you then connect a HDMI cable you still get HDMI audio and video automatically! Also the Video (which is NTSC I presume (no its actually PAL!)) works great, much sharper than an original NES. Perhaps I can switch the video to PAL, for an even better picture (its already PAL, as most monitors I tried work fine).

I'm now planning to design a small PCB that fits into this enclosure, and plan to use switches with long stalks, so that I only have to drill circular holes into the enclosure, so I don't have to make irregularly shaped holes in the case, which is a lot of work.

I'm planning to use thin four pole cable, with wires for 5V, GND, Video and Audio, which are wired to a very small PCB at the end which contains just a regular USB type B connector, and two RCA connectors, this can then be placed in a sub miniature copy of a NES. The cable doesn't have to be much thicker than a normal keypad cable.

January 18, 2017

Started on PCB design (with Ultiboard) created shape of PI-zero with GPIO pins and video pins, schematic symbol, and PCB shape. Also looked at an alternative enclosure that can be bought (the one I got could no longer be bought). Decided on PCB board size that fits in this enclosure and possible future one that is 30mm high, and 90mm wide. Thought about stereo sound, which needs an extra wire, but could be optional. Wire should be connected permanently to both controller and interface for simplicity, but I could use 1/10" header pitch connector for low cost, and possibly (to still add more connections) a 2x3 pins connector (later on I decided against this idea, and switched to a RJ-12 modular connector. I still have to choose buttons that are cheap but reliable and usable. Decided the PCB will be on the topside of the Zero for ease of layout (don't have to rotate the design in my head) and to protect the electronics beneath it. Use of single sided board is possible with copper layer on top side so you can solder the header on top, switches with PTH or SMT pins can be soldered on top, and filter components can be placed in between Zero and PCB (on underside PCB) when using PTH components, or on top when using SMT.

As single sided boards normally have copper on bottom, but my board needs copper on the top (so I can solder the pinheader pins, So I may have to mirror the layout afterward, or check gerbers/drillfiles carefully before ordering PCB's. If price difference isn't too big dual-sided PCB's might still be better for better mechanical reliability. I would prefer to Use PTH components ONLY for ease of build. So don't use micro-USB connector, but regular type B (square) connector. If PTH components on bottom are a problem, I might have to switch to SMT, but Ill use components that have a manageable size (1206).

February 7, 2017

I had built a version of my "NES console" prototype that used a single 4-wire cable, to a "micro NES" at the end, which is housing just the three connectors needed, an USB Type B power input, and two RCA output connectors, one for video, and one for audio. That worked, but I wasn't satisfied with it as the sound sounded awful, lots of hum, and switching sounds, and if you looked carefully you could also see intensity faults in the video signal.

I decided that combining the power and signal ground wires was a bad idea, and decided that adding a fifth wire was a necessity. So I made the change to try my theory, and also added a "connector" to the "micro NES". I am now considering a 6-pin modular jack,using six wire telephone cable for the final design, but for the prototype I used a simple six-pin angled pin header to female header structure with 5 wires, and that worked fine. I used a six pin angled header, so I could cut off the second pin of the six, and glued close the second hole in the corresponding female header, for reverse insertion protection. The 5 wire "cable" was made from a strand of band cable with 5 wires, which is cheap and works fine. Length was about 1.5 meter.

The result literally left nothing to desire, picture and sound are now excellent (for PAL composite video and Mono analog audio, that is).

Now that it works perfectly I feel that my prototype is finished, and I can start at designing the PCB knowing that the result will be satisfying.

February 14, 2017 prototype finished

Here is a picture of the finished prototype gamepad, which is actually the whole NES emulator, consisting of a Raspberry PI Zero with a support PCB for buttons and some analogue filters for audio. Power input, and AV output is connected through a 5-wire cable to the "NES console", which houses the USB-B 5V 200mA power input connector, and two RCA connectors one for audio, and one for PAL video.

the gamepad which houses the emulator
the "micro NES" is extremely small

To the right is the prototype "micro NES", at the end of the cable, which is extremely small, as it (almost) only consists of the power and A/V connectors.

These pictures show the prototype, the final version will have a PCB for the various A/V/power connectors (an USB-B connector for power, and three RCA connectors, one for video, and two for stereo audio) in the "back", and a single RJ-12 (6P6C) modular jack connector on the front, so you can (dis)connect the gamepad to the "NES", with six wire modular cable. The sixth wire means I can also add stereo capability. I will make 4-wire cable capability optional, when you add a wire link to the PCB to combine power and signal GND, and restrict to mono audio, but this is not recommended.

February 14, 2017 Now working on the PCB.

I started working on the PCB, with all the new ideas I gathered from the prototype.

February 28, 2017 Modifications to accommodate the PI Zero W.

To accommodate the new version of the Raspberry PI Zero W, and specifically its plastic case, I decided to come back from my decision to put the keypad PCB on top of the Zero, I realized that I could use the new enclosure, but it would be nicer when the keypad PCB would be rotated so that it could be mounted on the flatter back-side of the Zero. So I revised the component placement. This does mean that the pin-header connection between Zero and keypad PCB should be dis-connectable, as with the PCB soldered directly to the Zero the zero can no longer be removed from the case, and that means you cannot remove the SD-card from its holder (unless you make a hole in the case). This is doable with low profile female headers, and compatible pin-headers.

Its also possible to still fit the PI, and keypad PCB with a directly soldered PCB inside the originally planned enclosure.

With the new Wireless variant of the Raspberry PI zero, it is now possible to scrape for album art, and to upload content directly wirelessly. It is also possible now to use a wireless keyboard, and a wireless Joypad, such as the 8-bit DO (for a second player).


I also made last minute changes to the schematic based on the latest insights (switched the two audio channels to simplify the layout). The schematic can be downloaded here: File:Emulator schematics.pdf

March 7, 2017 printed the component setup, and modified it to look more like a real SNES controller

I had printed out the Gerber plot of my previous component setup and board size and compared it to a real SNES joypad. My conclusion was that the button placement was still far too small, and a larger size PCB was possible and necessary.

I noted that the enclosure, that I have about a dozen pieces off, was about the right width but not height compared to the real Joypad. I measured up the size of a PCB that would fit in it, and the location of two 5mm pillars for screws, for which I had to create holes in the PCB, tho other plastic structures I could cut away, but not the pillars for the screws.

I modified the size of the PCB, so it would fit in the case, and added the two holes in the right places. I spread out the buttons so their positioning more closely resembled that of the original, and made a new Gerber file to check the new positions and PCB size.

March 14, started with PCB layout

Started with layout work, trying to fit it all on a single sided board, making use of the fact that switches can also be used as "jumpers", which is a bit tricky. Its also hard to route it all on a single sided board, need to use my "bag of tricks". However its a nice challenge and will keep the cost of the PCB down. I will try to route the important traces (video + video GND) the shortest. Need to remember to add 4 mounting holes for a piece of perspex over the switches, which could also be used to replace the case. At the end of the evening I had managed to do a large part of the layout work, when someone found it necessary to switch off the power, and as my laptop doesn't have a battery I lost some work, (just 15 minutes or so, as I save often).

March 21, PCB Layout finished

Finished the layout, it looks like this: SNES EMULATOR JOYPAD PCB.PNG