Monday, May 23, 2016

Part 4: Preparation

In this part of the build, I start fitting everything in the case. Some of the parts required serious modification to get everything to fit. It was slightly nerve-wracking at times, but I pushed forward, confident after the extensive testing performed in the previous sections.

Screen and RPi Board Fitting

The 2.8" PiTFT screen was too wide to fit in the case. I knew this when ordering it and was just lucky there was a side of the PCB with nothing important on it that I could trim down. I used a cutting wheel on my dremel to trim of 1-2mm from the side opposite of the connector. This was enough to get it to fit snuggly in the case. Following that, I removed the top-most screw posts with a burr and was able to fit both the RPi board and screen in the case, at least partially.
I had been putting it off until this point, but I finally trimmed back the battery compartment as well. The RPi board extended enough that it would just reach into this area. Again, I tried to be conservative with what I removed because the battery compartment is a pretty vital part of the structure. After finishing the build, I realized I could have removed less, but I haven't noticed any issue because of it.


Screen and GPIO Cable

Originally, I bought both the 40-pin and 26-pin cables from Adafruit.com. This turned out to be a good decision as I ended up splicing the connectors together, leaving a 26-pin connector one end with 14 free wires and a 40-pin connector on the other. As another stroke of luck, the 2.8" PiTFT screen has two connectors on the back, one male and one female. The male connector is vertically aligned and with a trimmed back ribbon cable it was perfectly aligned for the RPi board to be mounted portrait style and the screen mounted in a landscape orientation. I did cut the first cable too short and the second one too long.

Desoldering USB and Network Ports

It was really important to have all the software and everything else in place at this point as I would be depending on the Wifi for a network connection and be unable to connect a keyboard if there was an issue. It was probably the most nerve-wracking portion of the build. Desoldering components from a board is never fun and I was a little worried about over-heating the board and burning something out. Obviously, it all worked out in the end, but it was time consuming and is a pretty good argument for using a Pi Zero if you can get your hands on one. I tried a couple of tricks to get the ports to come out easily, but I don't own a re-work station to really take the effort out of it. What ended up working the best was trimming the excess leads on the components, then globbing on a bunch of excess solder. Then it was just a matter of yanking on the port with pliers while constantly moving the iron around on the pins.

Replacing a USB Connection

I had thought about cutting down micro USB connectors for both the Pro Micro and power, but only ended up doing it for the Pro Micro. The connector for power would have stuck out too far and I don't have any right-connectors on hand. For the Pro Micro, I just cut off one end, stripped all of the insulation and soldered it directly to the RPi board, making a direct plug-in cable for it. Looking back, I should have soldered it on at the right-side port instead of the middle as it kind of interfered with the battery later. It was nice, however that I was able to unplug the gamepad and screen while I still working everything out.

Hardwiring Power

I tacked on leads to the bottom of the RPi board to provide power directly. During testing I still used the micro USB plug until the final assembly when I patched it into the Power Boost board. Helpfully, the RPi designers have included a number of test points on the bottom of the board that are very easy to solder to.



Gamepad Wiring

I soldered some rainbow ribbon cable to the gamepad PCB and then connected it to the I/O pins on the Pro Micro. The rainbow colors were useful for tracing which pad corresponded to which pin, but overall was kind of annoying to work with because the wires were so thin. I opted to leave the left and right trigger buttons disconnected until final assembly as they will be later installed in the back of the case. This was useful during the build as I was able to keep the front and back detached from each other while still working on it. I did have to reprogram the pin out code in the Pro Micro because I wired the pins differently from the original testing and development.

Saturday, May 21, 2016

Part 3: Final Testing and Demolition

This first bit probably should have been in the last video, but it was getting a little long. All that really did was make this section longer. Starting off, I put together all the components from the last video. The only thing I didn't wire up was the power switch which would have made continued testing harder.


Final Testing

I wasn't quite sure how the auto-disconnect headphone jack was intended to work. The datasheet isn't that helpful and slightly cryptic, but that's what breadboards are for, I guess. The audio amplifier is connected to power via the Power Boost Charger, gets audio input from the RPi board. Output is connected to the headphone jack which is also connected to the small speaker. The test controller is plugged in via USB and the RPi is powered off the Boost Charger. As a last test, the 3.7v LIPO battery is connected and main power disconnected.
The only missing feature here is the power switch with an orderly shutdown, which was one of the last things I figured out.
Here you can see the two points on the back of the RPi board where the audio connections are made. On the other side of the board, below the red wire, is the headphone jack. It was simpler, and saved more space, to just tack on these wires instead of using a 3.5mm jack wire tail.

Assembling all the test components together was pretty easy. Originally, I had too many grounds connecting everything which produced some static coming out of the speaker. The audio amplifier has a small adjustment pot for volume. I tweaked it until the rest of the static went away, and later adjusted the system volume within Emulation Station. This was also the first time I tried running it all off of the 3.7v LIPO battery. After some fiddling, everything worked as expected.

Demolition

Cutting into the case is where this project gets serious. I put off doing this until I had everything and a better idea of how it would all fit together. Gutting the back of the case was an easy decision. There were several screw posts and ridges for supporting the logic board of the GAMEBOY, most, if not all, were removed. Another key piece to remove was the backing for the game cartridge area. This was in the direct way of the RPi board, and it still didn't completely fit with it removed. I made sure to conserve the supporting plastic for the power switch and leave a little bit of a rim around the cartridge area to attach the acrylic cover I made. Later on, I cut away some of the battery compartment near where the dremel tool is in the picture above. I put this off until I knew it had to happen. The battery compartment on the GAMEBOY case is actually pretty important structurally. Two of the case screws are attached through it, as well as reinforcement support for the gamepad area. These supports can be seen in the picture above to the left and right of my thumb. They keep the PCB from flexing and eventually breaking from jamming on the buttons.
Around this time in recording, the PCBs arrived from the fab house. They weren't perfect to, but work great. Some of the mounting holes required minor drilling or filing out. Next up was drilling holes for the x/y buttons. I used the DXF file from the previous section to create a template for where to drill the holes. Again, I was really nervous about this because it was the front of the GAMEBOY and didn't want to mess it up. The template lined up perfectly with the PCB. I under-drilled the button holes, routed them out with the dremel most of the way, and then finished with files and sandpaper until the buttons moved in them easily.

Installing the Buttons

I spent a lot of time on mounting the new buttons because they are probably one of the most important features of the build. To both retain the x/y buttons and ensure they moved only up and down in the slot, I cut out the supports from the SNES controller. Cutting off the excess plastic and supergluing them in place was the next step. I only had a slight issue with alignment on one of the buttons which was fixed by running a tube of sandpaper through the hole until the button moved freely. Then I reinforced all of the supports with super glue. The end result almost looks like it was made that way.
There's a molded depression around the A/B buttons on the case. I couldn't think of any reasonable way to reproduce this without messing it up, so I didn't bother. The end result is very natural and has thrown off a few people I've shown the finished product to.

Sunday, May 15, 2016

Part 2b: Installing and Configuring RetroPie

Installing RetroPie and getting it to work with the Adafruit 2.8" PiTFT LCD Screen ($34.95) was kind of a convoluted process. For one reason, the Raspberry Pi 3 was very new when I started and the wonderful folks at Adafruit.com had only just updated some of there documentation and images to work with the RPi 3 update. Initially, I had purchased a 3.2" PiTFT LCD Screen, but couldn't get it to work with RPi 3 and EmulationStation/RetroPie combo. I worked on it for 6+ hours, trying everything I could find online. During that attempt, I also butchered the header pins on the screen which may have also caused an issue. I really don't know. I gave up and ordered the 2.8" PiTFT as a replacement because I found a couple of threads on the Adafruit forum confirming they got it working with the RPi 3.

RetroPie

Overall, I'm very impressed with this distribution. It's simple, it works, and has a nice user interface. I'm not going to break down all the instructions for installation here as it would be just a poor facsimile of what others have already done.


To actually get the image on the SD card, I used ApplePi Baker for Mac OS X. I'm sure there are similar tools for Windows, but I'll be damned if I know what they are.
So you followed the directions and have an SD card all baked up, next you're going to want to plug in a keyboard and HDMI connected to a monitor or TV. Power up the RPi with a USB adapter and you'll be presented with the Emulation Station boot screen. It's probably easiest to just plug-in a network cable to the RPi and your router. This is helpful later when transferring ROMs as they will transport faster.
Hitting F4 on the keyboard will take you to the command line. If you're not familiar with the command line, you might want to do some reading as a large part of the rest of this tutorial is all done in the via text editors and such.
First thing to do is to discover your IP address so we can login via SSH (see WinSCP or Putty for weendows users). Type in the command `ip addr sh` and look for en0 with an IP address.
Back on your computer, use a terminal window to ssh into the RPi.
 ssh pi@192.168.11.158  
Replace '192.168.11.158' with the IP address you found above. The password is "raspberry" by default.

PiTFT LCD Screen

Follow these instructions from Adafruit.com and that will get you some output on the screen when attached. To get the EmulationStation/RetroPie to display correctly follow these additional instructions. The only thing I did differently was used the following line for dtoverlay= in /boot/config.txt
 dtoverlay=pitft28r,rotate=270,speed=64000000,fps=60  
I installed my screen upside to get everything to fit better, thus "rotate=270", the speed=64000000 and fps=60 for smoother graphics. After making these changes I could no longer use my HDMI cable on my monitor. This is normal as far as I understand because my monitor doesn't support HDMI with such a low resolution. At this point I was working entirely in SSH anyways so it didn't make much of a difference.

With all of that done, I was about at the point in the end of Part 2 video.

Part 2: Building Test Rigs

This section covers wiring up some of the individual modules - audio amplifier, power boost charger, and Arduino Pro Micro - for testing purposes. I thought it was important to breadboard up as much as possible because I sourced ideas for this build from numerous places and wasn't entirely sure if it would all work together. As a result of this decision, I ended up soldering on several pin headers and connectors that I would later de-solder for final assembly. This ended up adding extra work to the build, but I was able to move ahead with programming the Arduino Pro Micro while waiting for the GamePad PCB to be manufactured.


Audio Amplifier

 This audio amplifier from Adafruit.com ($3.95) is a nice little piece of kit. The power coming out of the RPi 3 audio port isn't really enough to produce any sort of reasonable sound from the attached speaker, so this just kicks it up a notch. Here I'm just tacking on red/black wires to the positive and negative connections. Although not shown in the video, I connected these to pin headers to make them easy to plug into the breadboard. All of the wires added in this step were kept intentionally long, anticipating final assembly later on.
Here you can see the audio with it's other intended connections. On the left side, two wires are connected to the RPi board for sound output. The Vin and GND pins are connected to 5V and GND on the 1000C Power Boost board. The output on the right side is connected to a disconnecting headphone jack which in turn has a speaker connected to it.
The audio amp does have a shutdown pin, but after the power switch is configured, all power to the amplifier will be cut when it's turned off.

PowerBoost Charger

I thought I was going to need the PowerBoost Charger for the Pro Micro, but it turns out it's powered via USB. For some applications without being connected to USB it would need external power. In the video, I soldered on the USB connector and pin header for testing later.

Arduino Pro Micro

After counting up the number of GPIO pins I would need for the controller, I decided to just add in the Arduino Pro Micro (Amazon: $8.70). It's a pretty low cost solution to making a USB HID that will just be accepted by the RetroPie/EmulationStation install. It also has some useful analog-to-digital converters that may provide for some interesting add-ons later, like a volume control knob or low battery warning. I realized during this build you could make some pretty cool custom controllers/joystick/control panel using one of these.
Looking around on the net, I found a few confusing tutorials for turning a Pro Micro into a gamepad. Finally, I came across this library (ArduinoJoystickLibrary) by MHeironimus. Looking at the options included in the library API, it's a little overwhelming at first, but then realize you only need to catch button input as we're only creating a gamepad and nothing as complex as a joystick.

Arduino IDE

You'll need to download the Arduino IDE, if you don't have it already. Follow these instructions to get the Joystick library installed with the accompanying USBAPI.h and HID.cpp files. After the library is in place, in the Arduino IDE select Tools -> Board -> Arduino Leonardo, and then Tools -> Port -> USB modem. (Note: this will only show up when you connect the Pro Micro via USB)

Code

Courtesy of Sparkfun.com
Below is the code I used to program my Pro Micro. You will probably need to change the pins connected to each button. Reference the pin out diagram to determine the number for each pin. Avoid using Pin 0 and 1. There's nothing spectacular about this code, but it works with good reaction times. My choice of pins was determined more by wire organization than logic. Copy the code below, paste it into the Arduino IDE, save it. Click the verify button to make sure everything checks out, then you can upload it to the Pro Micro. To test the controller, I used Controllers Lite app (free) from the Apple store. Based on the tutorial linked above, you should be able to test it with built-in tools on Windows.
 #include <Joystick.h>  
 int A=5;  
 int B=4;  
 int X=3;  
 int Y=2;  
 int L1=21;  
 int R1=20;  
 int Up=14;  
 int Down=10;  
 int Left=15;  
 int Right=16;  
 int Start=6;  
 int Select=7;  
 int led=13;
 int BTN_UP=0;  
 int BTN_DOWN=1;  
 int BTN_LEFT=2;  
 int BTN_RIGHT=3;  
 int BTN_SELECT=4;  
 int BTN_START=5;  
 int BTN_A=6;  
 int BTN_B=7;  
 int BTN_X=8;  
 int BTN_Y=9;  
 int BTN_L1=10;  
 int BTN_R1=11;  
 int AState=0;  
 int BState=0;  
 int XState=0;  
 int YState=0;  
 int L1State=0;  
 int R1State=0;  
 int UpState=0;  
 int DownState=0;  
 int LeftState=0;  
 int RightState=0;  
 int StartState=0;  
 int SelectState=0;  
 bool pressed = false;  
 void setup(){  
  pinMode(A,INPUT_PULLUP);  
  pinMode(B,INPUT_PULLUP);  
  pinMode(X,INPUT_PULLUP);  
  pinMode(Y,INPUT_PULLUP);  
  pinMode(L1,INPUT_PULLUP);  
  pinMode(R1,INPUT_PULLUP);  
  pinMode(Up,INPUT_PULLUP);   
  pinMode(Down,INPUT_PULLUP);  
  pinMode(Left,INPUT_PULLUP);  
  pinMode(Right,INPUT_PULLUP);  
  pinMode(Start,INPUT_PULLUP);   
  pinMode(Select,INPUT_PULLUP);  
  pinMode(led,OUTPUT);  
  digitalWrite(led,LOW);  
  Joystick.begin(true);  
 }  
 void loop(){  
  AState=digitalRead(A);  
  BState=digitalRead(B);  
  XState=digitalRead(X);  
  YState=digitalRead(Y);  
  L1State=digitalRead(L1);  
  R1State=digitalRead(R1);  
  UpState=digitalRead(Up);  
  DownState=digitalRead(Down);  
  LeftState=digitalRead(Left);  
  RightState=digitalRead(Right);  
  StartState=digitalRead(Start);  
  SelectState=digitalRead(Select);  
  if(AState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_A);  
  } else {  
   Joystick.releaseButton(BTN_A);  
  }  
  if(BState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_B);  
  } else {  
   Joystick.releaseButton(BTN_B);  
  }  
  if(XState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_X);  
  } else {  
   Joystick.releaseButton(BTN_X);  
  }  
  if(YState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_Y);  
  } else {  
   Joystick.releaseButton(BTN_Y);  
  }  
  if(L1State==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_L1);  
  } else {  
   Joystick.releaseButton(BTN_L1);  
  }  
  if(R1State==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_R1);  
  } else {  
   Joystick.releaseButton(BTN_R1);  
  }  
  if(UpState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_UP);  
  } else {  
   Joystick.releaseButton(BTN_UP);  
  }  
  if(DownState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_DOWN);  
  } else {  
   Joystick.releaseButton(BTN_DOWN);  
  }  
  if(LeftState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_LEFT);  
  } else {  
   Joystick.releaseButton(BTN_LEFT);  
  }  
  if(RightState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_RIGHT);  
  } else {  
   Joystick.releaseButton(BTN_RIGHT);  
  }  
  if(StartState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_START);  
  } else {  
   Joystick.releaseButton(BTN_START);  
  }  
  if(SelectState==LOW){  
   pressed = true;  
   Joystick.pressButton(BTN_SELECT);  
  } else {  
   Joystick.releaseButton(BTN_SELECT);  
  }  
 }  

Game Pad

At this point in the build and video recording, I didn't have the gamepad PCB back from manufacturing yet. First, I'll cover the test controller I made and then I'll go over the creation and design of the gamepad PCB.

Test Controller

Here is the test controller I came up with. A while ago I ordered 100 tactile buttons to have on hand for stuff, but I read the serial number wrong and ended up ordering brown buttons. *sigh* Great for testing, but not much else. The test controller is very simple. One side of each button is connected to a common ground (the top rail on the breadboard). The other side connected to its own pin on the Pro Micro. Each pin corresponds to the above code. I was actually able to play an entire level of Super Mario and Tetris using just this game pad. One very nice feature about the Joystick library, versus something like simulating a keyboard, is you can hold down buttons and they will be continuously read by the Pro Micro. This is kind of important for playing some games.

GamePad PCB

Front Case Layout
Originally, I purchased an SNES knock-off controller to part out for this project. I guess some part of me was hoping Nintendo used relatively the same layout for buttons. After tearing down the controller and looking at the measurements, I realized cutting up the circuit board wasn't really going to work for the build I wanted. Both because it would be pretty janky and because the button pads didn't exactly line up with the existing holes in the GAMEBOY case. I did find an existing gamepad PCB for sale by kitsch-bent.com, and now that I actually look at their site I see that they also have an A/B/X/Y version (facepalm). Had I seen that before, I would have just ordered it instead of designing my own. But since I went through all the work, I'll post what I created here.

Note: the Front Case Layout below is probably not going to match the kitsch-bent.com PCB. Just looking at it, my buttons are a little closer together and skewed slightly where the kitsch-bent.com PCB has more square tangents.

If you would like to order the PCBs I designed, they can be ordered directly from OSHPark.com (my favorite PCB fab house) from here:

Order from OSH Park
You will have to order three (3) PCBs as a minimum order which comes to about $37.05 with shipping and wait about 2 weeks for shipping and manufacturing.

Files

Saturday, May 14, 2016

Part 1: Disassembly and Bleaching

Disassembly

Tearing down the GAMEBOY is pretty simple, but requires one special tool, a Tri-Wing Security Driver. It's cheap, but next to impossible to remove the six screws in the back of the case without it. Out of shear impatience, I tried grinding a drill bit to fit the screw. It didn't particularly work well. Other than that, all the internal screws are phillips drive. Remove all the guts, save the buttons and pads. There are a couple of parts on the circuit board you can reuse - like the power switch and headphone jack, if you're so inclined.

Bleaching

As you can see from the image above, most older GAMEBOY cases have a yellow tint due to aging. To make the cases, a fire retardant (some sort of bromine) was included in the plastic mixture. Over time, this causes the case to yellow. It is relatively simple to reverse this process, and all you really need is some concentrated hydrogen peroxide (H2O2). You can find this at most beauty supply stores as "developer" for bleaching hair. For this build, I used 40 volume which is about 13% H2O2. 
Warning: Wear gloves and eye protection
The eye pro is a good idea when scrubbing off the baked on crud. You really don't want this stuff getting your eyes. Even though this mixture is used for bleaching hair, it is still an irritant and you should avoid getting it on your skin.
Previously, I had seen this on www.retr0bright.com. Basically, you mix hydrogen peroxide with some Oxiclean, spread it on to the case, and let it sit in the sun. The gallon jug I bought happened to be the "creme" version which is a bit thicker than the normal stuff. I think this helped keep it on the case while it was baking in the sun.
If you can't find the creme mixture, adding a little cornstarch and microwaving it for 30 seconds will turn it into a nice gel. After I had completed this portion of the project, I saw video of somebody spreading on the H2O2 and wrapping it in clear saran wrap, then leaving it on in the sun. I kind of wish I had discovered it earlier as I ended applying 8-9 treatments and even purchased a UV pet light in an attempt to accelerate the process. After it stopped raining for several days in a row, I just left it in the sun for a few hours.

Basic Recipe

  • 2 cups Developer Creme (H2O2)
  • 1 tbspn Oxiclean
  • 1 tbpsn Cornstarch (optional)
Spread it on the case, wrap in plastic, let sit in sun for 1-3 hours. Repeat until desired result.

Next: Part 2: Building Test Rigs

Introduction


Building a Raspberry Pi GAMEBOY isn't a new idea by far, but after seeing a few posts kicking around the internet where people had built their own, I thought it would be a fun project. One post that really caught my interest, by wermy, used a Raspberry Pi Zero. Unfortunately, when I started this build they were nigh impossible to buy anywhere. I did discover that the new Raspberry Pi 3 has built-in Wifi and Bluetooth which is kind of a bonus. Given what I ended up doing to the RPi board in this project, that was probably the biggest help as the RPi 3 is much larger than the RPi Zero. An image of RetroPie was used for the operating system, and numerous emulation packages installed with it.
Overall, this is more of a "build log" than it is a how-to. If I were to redo all of this, there would be a lot less experimenting and more straighten forward, linear instructions. As it was, I spent a lot of time planning and researching all the different parts and how they fit together.

Part List

Item
Price
Source
Used Gameboy
$17.49
Ebay
$39.95
Adafruit
$14.95
Adafruit
$19.95
Adafruit
$3.95
Adafruit
$2.95
Adafruit
$1.50
Adafruit
$9.99
Amazon
$34.95
Adafruit
$2.95
Adafruit
$8.70
Amazon
$6.99
Amazon
$6.59
Amazon
$5.00
Adafruit

Part Total: $170.91 + shipping



All said and done, the retro fitted GAMEBOY has an impressive list of features:
  • Raspberry Pi 3 with all its impressive specs
  • 2.8" PiTFT LCD Screen (320x240)
  • 32gb SD micro card (way too big)
  • USB Charging and 2500mah LIPO battery
  • Buttons and Controls for SNES games, including Left/Right trigger buttons
  • On-Board Speaker and headphone jack, and audio amplifier
  • Working On/Off switch with safe shutdown

Part 2: Building Test Rigs

Part 2b: Installing and Configuring RetroPie

Part 4: Preparation