27 July 2016

NESPi - my Mini NES Classic Raspberry Pi games console

It was inevitable... I have a Raspberry Pi, I have a 3D printer, I'm a huge nerd...

At some point I was going to print a case for it in the shape of the old Nintendo Entertainment System.

In the end, this project turned into more of a love-letter to the NES than just printing a case.
I learnt a lot of new things about Linux, 3D design, wrote my first Python program and had a blast doing it...
The NES was the first console I had growing up. I've got strong memories of playing Nintendo games with my brothers when we were younger.

The ergonomics of the whole experience are something I still remember very clearly 20+ years later...

The front-loading game slot... lifting the door and inserting the cartridge

Pushing it down with that satisfyingly-sprung *click*.

The tactility and sound of the power button when you turned it on...

...and of course blowing on the cartridges when they didn't work :)

Fond memories, and all of that is just as much part of my nostalgia for the system as playing the games themselves, and I had some ideas of how I could pay homage to it using the Raspberry Pi.

RetroPie. It's a collection of software that runs on the Raspberry Pi, integrating a bunch of retro gaming emulators into an easy-to-use package.

It's quite popular and loads of people have made some really great builds using it. Since I was just starting out with Raspberry Pi and Linux, I'd use RetroPie as the base software for my project.

So I dug out my old NES and took some measurements. I was going to design my case from scratch.

To make the case as compact as possible, I scaled down the real NES dimensions to 40% of actual size.

This gave me just about enough room for the Pi to sit transverse, USB and network ports on the left, power and HDMI at the back.

I could make a cut-out for the microSD card and would relocate two of the USB ports to the front where the controllers would be on a real NES.

As I got further along with the design and started to model the top half, I wondered if I could do anything to make the cartridge slot functional.

At first, I thought about making a NES cart-shaped caddy to hold the microSD card.

A guy called wermy did that with the SD card on his RetroPie build the "Game Boy Zero". It turned out really nicely but ultimately I came up with another idea that I hadn't seen done before.

NFC.

A while ago I picked up an NFC reader based on the PN532 from NXP, intending to play around with an Arduino and some tags to control room lighting.

My plan here would be to make a little replica NES cartridge with a tag inside and have the Raspberry Pi launch a game when it reads the tag.

Cool idea right?

'artist's' impression

It wasn't quite as easy as it sounds. I'm not much of a programmer, I can ctrl-c/ctrl-v with the best of them but tend to rely on tutorials and pre-written libraries for the most part and that's where I had trouble.

NFC has been done on the Raspberry Pi but I couldn't find much information. Adafruit has a rather sparse article about getting libnfc compiled, but I soon found it a bit more complicated than I thought.

I wanted to be able to write to the cartridges with my phone, and then have them read by the Pi. This meant starting with a universally compatible tag.

The tags I bought to experiment with, are NTAG216s. These are NFC Forum Type 2 tags from what I've read they're compatible with all Android phones. They also have plenty of writeable memory, with 888 bytes available.

On my phone I use NFC Tools Pro. It's pretty good, you can read/write tags with things like WiFi and Bluetooth pairing info, contact details etc. and it's all nice and easy to use.

Eventually I found that I'd only need to write the console and rom name to the tag and could use that to lookup and launch the game on the Raspberry Pi itself.

The issue I had trouble to start with, was actually reading that information in the first place.

NDEF, the structure of the writeable data, is fairly transparent and simple to use on Android. But I couldn't find anyone that had read these NDEF records with a Raspberry Pi.

All the documentation I found on the subject was a bit over my head and whilst I could read the tag's ID easily enough, I couldn't get any NDEF data.

After some searching, I came across "NDEF Library for Arduino". With this, the plan would be to read the NDEF records with an Arduino, then send them to the Raspberry Pi.

Not the most elegant solution I know, but I was probably going to need to use an Arduino at some point to run a shut-down/power switch for the Pi, so... two birds I suppose.

Speaking of shutdown switches... because the Raspberry Pi doesn't have any sort of power switch people have designedtheirown but they're all pretty expensive.

Since I'd decided to use an Arduino to read the NFC anyway, I would just have a go at writing my own program to do the power management.

Code time ; )

The software for this project is in two parts. An Arduino sketch to read the NFC tags and manage the power switching, and a Python script running on the Raspberry Pi to launch the games.

The two communicate over serial. I could have used I²C, but I was already familiar with serial on the Arduino and could also use it for debugging.

Arduino:

I'll post my code here because I've always found it useful to read other peoples programs.

However I can't vouch for it's quality, it works and I've written comments where I could, but I'm no expert.

The program listens to the serial port to find the console and rom information sent by the Arduino.

We look up the console name in list of valid emulators, then look for the rom to see if there's a file with the correct name stored on the SD card.

If it finds one, then when the power button is pushed down, it launches the emulator and game. If it doesn't then it tells the Arduino to light the indicator in red to show a read error.

In order to manage the power, on boot-up, it will set a GPIO pin HIGH. This is monitored by the Arduino so that it can tell if the Pi is running by checking the status of that pin.

The program also checks the serial port for a shut-down message and will safely shut-down the Pi when it hears one.

This means I can shut-down the Pi normally through software or by long-pressing the 'reset switch' and after it's finished shutting down the Arduino will detect it, and cut the power safely.

3D design:

I've used Tinkercad to design stuff in the past. For this project I'd 'graduate' to 123D Design. It's has a few more features, yet is still simple enough to get to grips with if you've got limited CAD experience like I do.

I started by blocking out the rough shape, transferring my scaled dimensions over to the computer.

I tried to keep as much of the design in proportion to the real NES. But made some concessions with details like the front switches being a bit larger than scale for ergonomic reasons.

One thing I was quite pleased with, is the snap-fit feature I incorporated. Noé Ruiz from Adafruit made a video that shows a really cool way to have a case snap closed.

You can see the little triangle-shaped tabs on the lip between the case halves. They click quite nicely and hold the case together really well, it means I don't have to waste space building in screw posts.

Because of the small design I was going for, I'd have to remove the USB sockets from the Raspberry Pi board in order to include the cartridge slot and keep all the proportions correct.

Since I intended to move two of them to the front anyway this wouldn't be too much of an issue.

For the final case I wanted to use filament match the colours. Faberdashery have a wide range of colours available, and their Monotone Mix Pack looked ideal to match the NES' shades.

Since that filament was a bit more(4x) expensive than the eBay PLA I normally use. I made all my test prints with cheap-o plastic.

Comically, I didn't have a screwdriver of the right size that was long enough to reach all the screws. So I couldn't take my own NES apart to see how the cart slot worked.

From tear-downphotos though, I could see the original cartridge latch mechanism would be too difficult to 3D print on a small scale and have work reliably.

After some idle searching of eBay, I uncovered an odd yet perfect solution.

3D Printing:

Printing all the parts took around 6.5 hours with all the colour changes.

Assembly:

I attached the black pieces with super-glue and apart from the screws holding the Raspberry Pi itself in the case, everything else snapped together.

The wiring for the switches wraps behind the cart slot and the NFC cable needs to be folded up into the roof of the case to allow it to move freely.

The front lid hinge is a couple of short lengths of filament. I printed a cosmetic piece to cover the opening and match the lines on the original NES.

The cartridges:

I'd make these at the same 40% scale as the rest of the case. I simplified some of the features but kept as true as I could to the originals, with indents for the labels on the front and back of the cart.

They're designed to be printed in two halves, this meant no support material was needed and both visible sides would have a consistent surface finish.

I need more practice shooting time-lapse :/

The carts are lined-up with little pegs and super glued together with an NFC tag embedded in the middle.

I printed the labels on slightly thicker than normal, 120g/m² paper. I 'laminated' them with clear packing tape and stuck them in place with super glue.

Controller:

Seeing my little replica next to it's full-scale counterpart, I couldn't help thinking about the controller.

The NES controller is a truly iconic piece of design. The silhouette alone pretty much represents video-games entirely by itself. I wanted to make one.

So I fired-up 123D again and plugged some scale measurements into it. Serendipitously, an Arduino Pro Micro knock-off, fits perfectly inside a 40% scale NES controller.

10 seconds of googling, and I found this library. I couldn't resist if it was going to be that easy...

Just 20 lines of code and the software was done. Since the buttons would get mapped in RetroPie anyway, it didn't matter which key presses the controller generated. This made the program very neat and tidy.

At such a small scale, finding room for everything in the controller would be tricky. I did have some small tactile switches on hand that would work, just 1.5mm high.

To accommodate them, I etched a simple little PCB to mount the buttons to the Arduino. This was easier than chopping up bits of perfboard to try and get the right spacing laid out.

Not the prettiest thing. To keep the proportions correct I even had to cut legs off some of the switches so it's definitely a bit ugly on the inside.

Initially, I transferred some graphics to the controller and they looked great, but I accidentally damaged the finish with an acetone thumbprint that marked the surface underneath.

I didn't have any more 'Architect's Stone' filament to make a replacement so I printed the graphics on sticker paper, laminated it with packing tape and used that to cover it up.

The USB plug cover was modelled after the shape of the original NES connector and recessed so it'd sit flush with the case.

It's even surprisingly playable. I won't be doing any marathon playthroughs with the dinky little pad, the tiny buttons are a little stiff, but it is perfectly serviceable and turned out to be one of my favourite parts of the build.

Conclusion:

This project took longer that I first thought, but I enjoyed it immensely. It sharpened up my Arduino coding, I learned some Python and used Linux properly for the first time.

I also really improved my 3D printing ability, both in CAD and the printing process itself.

In the end I'm very pleased with how this project turned out. I met all of my initial goals and finished with a cool, functional piece of hardware that's pretty unique*.

* Addendum:

D'oh. I've been working on this for weeks, and even wrote-up most of this post before this was announced...

I was thinking of making a few more units to sell. Oh well never mind, gg Nintendo.

Make the kit, or release instructions and drawings so we can copy. I wanted to do the same thing but would happily clone your design. I've been looking for a NES case for the Pi but only found 3D-printed stuff. Awesome project, great work!

I can't afford an investment as big as a 3d printer or the tools needed to put all the technical parts together (at least not for a single project that won't bring me any income) but I would pay handsomely for a kit for this! to get the parts premade and just be able to piece it together with my own hands, would be a dream come true!

Would buy one from you. Nintendo had us limited to 30 games and don't even have a Dragon Warrior/Quest game on it... I would buy a kit and the complete collection of Dragon Warrior on mini cartdridge haha :).

Far superior to Nintendo's effort, since one could add games if they want, and even emulate other consoles (or use it as a computer), since its a Raspberry Pi. I'm sure you'll still find plenty of buyers if you sold these, or even better sell kits with instructions.

Would seriously buy this in a heartbeat - not at all interested in the official Nintendo one due to the lack of upgradability. If you do decide to run a few please sign me up - alistairkirkland[at]gmail.com

I forgot to let you know earlier, I've submitted a pull request with the changes. There were some other things I'd like to go back and double check but unfortunately I don't have all of the hardware I would need, like the NFC reader lol

I think you can clearly see you've got something on your hands man. If you want to. There are a lot of others for sale, but yours by far is the best quality. Please let me know if you are up for it. warfidem@gmail.com

This is pretty sweet, Mike! In all honesty, I think the learning process from all this would make it a perfect project for those of us starting to make things with 3D printing, arduino and the like. If you ever feel like publishing the 3D print files, I'd love to try and make my own here in Barcelona :D

I was going to do this exactly as you did. Minus the NFC stuff. Just needed to put some time in modeling the case. Was even going to do the mini carts as well - just non functioning. But you beat me to it and clearly went the extra mile. Are you planning on adding the 3d files to the git repository? I would much appreciate not having to design it from scratch my self, since you have already done such a good job. Thanks

Just to add my voice to the chorus, please sell these! Whether as an easy-to-assemble kit or pre-made, I would buy it in a heartbeat! It's much better than Nintendo's offering, since it can play many systems and is upgradeable and whatnot. Though if you do, I'd personally prefer one utilising the RPi 3, though would still buy it if it used an RPi 2.

And I'd also buy some of those cartridges too! Perhaps a generic one for any game, and then a few of the classics too, if they were available. :)

Don't make a kit. As you said you enjoyed the project and learnt a lot from doing it. If any one else wants one they should put in the same amount of effects as you did. Not to mention that Nintendo would sue you ass off if you tried to sell these.

Absolutely amazing work! I would definitely be interested in a kit. Judging by the response here I think you'd sell quite a few! And a big thank you for going in to such great detail in this blog. A really good read :-)

Amazing project. I have been thinking about doing the exact same thing for months. But have not been able to work out the NFC side of things. What kind of arduino are you using? Is that a custom board underneath? Would love to try to replicate your work. But I cannot quite figure out what you did there;-)

Anyway, great writeup and great work. Love it when people include their code, so that others might have a look, and learn something in the process:-)

I would really like to own one. I can of course pay you. Hope it doesn't cost me a bomb but i would love to have one with some games. Please. My email is keithh8r@gmail.com if you would be making any more. Thanks a lot and such fantastic work.

How is the power to the RPi being managed by the Arduino? From the look of the photo the USB power plugs directly into the RPi, if that's the case how does the Pi not power on as soon as its plugged in and how does the Arduino cut it off?

Good eye... I removed the fuse F1 from the Raspberry Pi board and intercepted the 5v from the micro-USB input and routed it to the Arduino. It then controls the 5v to the RPi with a high-side MOSFET switch.

Hi Mike, It would be really awesome if you would release your design on thingiverse, but if not, I would totally be willing to pay for the design as well. This is by far the best nes pi case I have seen.

Another possible option would be to put in on shapeways.com so people can get it printed, but then still offer the stl's for free. Anyway, major props to you for this awesome project.

Hopefully you will release the stl's soon so I can build my own. I will totally be contributing back to the github python code as soon as I can get the time to start building the hardware to use it on.

Like so many above me I'd buy a kit or the full thing if you were willing to do it. I love the idea of the NES mini but I like yours so much more because of the ability to add my own games outside of the preloaded on the mini as well as being able to emulate other consoles.

Hello! Let me start by saying that this build is fantastic! Great work! I'll also throw my hat in the "make a tutorial" ring because this is fantastic!

Seeing your build really made me want to make a mini SNES, and after watching your update video, it makes me happy to see you have the interest as well. Was curious if you wanted any help at least with the NA version. I would love to help out in some way. (coding skills are not perfect, but my modeling skills are very good! =D) Let me know!

Excellent build. I am impressed with how well thought out this is. I built a similar project of the SNES with a raspberry pi 2 running retropi and mine turned out really nice but its nothing more than a case for the pi. A friend pointed me to your video and said i should check it out. I would love to see a complete build guide for this including a parts list and your custom code for the arduino. However you decide to proceed, I tip my hat to you.Norm

This is a fantastic build! I appreciate the time you've spent creating this, as well as the time spent documenting it for us to drool over. I have a few questions I hope you are able to answer, given the flood of traffic and comments. Thanks for sharing the video and code that you have so far!

1.) Do you have a compiled BOM? (bill of materials) I'm interested in seeing what things roughly ran to get a budget in mind for attempting this as well.

2.) Do you have a template for the cartridge labels? They turned out extremely well.

3.) This is probably the biggest request you've been getting... I'd love to get a copy of the .stl or .obj files. Like others have asked, have you considered uploading the a site like thingiverse? I know you put some time into this, and would be willing to "license" the files from you. My modelling skills are not up to snuff, I'm great at printing and assembly though...

Again this is so cool. Even in light of the NES Classic coming, I'm still really, really wanting to make one of these. Congrats daftmike, this is well done!

Saw the updated video. If you can, please post the 3d files for the cases and carts. I actually would love to try building one my self and even pushing it to see if I can't get a zipped full games stored into an RF Tag or similar tech (I do have coding/hw skills so I can resolve that end of it)

Your version of Mini-Nes is better than the official, because of the USB controller ports AND the cartridges. It would be amazing if nintendo could release classic games on tiny cartridges, people certainly would buy lots of it.

Hello daftmike! Your work for your Mini NES is pure genius! Can you make a portable version of your Mini NES? I know there has been lots of portable NESes nowadays, but your cartridges is about the same size as the Game Boy Color cartridges, only slightly bigger, and they can work well for portables.

Hey Mike, I'm completely new to 3d printing. I'm looking into getting a printer to make this my first project. How do I see what size the print will be to make sure I get a printer large enough? What is the minimum print area this project would require?

Seem's I'm just adding to the chorus here, but I'd buy one of these if they were for sale. Doubtful I have the skills or access to the equipment to create on on my own. Wondering what the legal ramifications would be in selling something like this? Without the Rasberry Pi, seems it's just another case. But in this sue happy world, wonder if Nintendo would get peeved about something like this for sale. In any case, count me in if you ever decide to market these things.

Just ordered the kit and I can't wait to get everything put together. Got the case already printed and have the raspberry pi 3 ready and waiting with retropie. Your kit is cheaper than buying the parts individually, plus I don't have to spend the time soldering everything together.

Do you plan on making your tiny nes controller available for people to make? I think that would be awesome!

It's a good idea to print such things! )) I want to try to print them too! Do you like to play roms? Yesterday I found site with free roms https://romsmania.com/ I have already downloaded some great games from it.

Ditto. I'm looking at building my own. While I don't need a working slot as I don't think I'm going to do RFID's. The reset with moving the USB slots and the working buttons on the front I am definitely interested in. Nintendo is a idiot for killing off the NES classic before fans could get their hands on one.

Can somebody help me? I'm trying to put together a complete Mini(er) NESPi with NFC reader and power management from the Arduino. My main question is how does the 'power on' works, if the USB power cable connects directly to the Raspberry Pi Zero?