Here is how I arranged the circuit boards on the back of the control panel:
You can see by the location of the power cord for the Raspberry (and how it extends past the edge of the panel) that I wasn’t thinking about that when I decided where to place the raspberry. But it gets worse. Next to each set of button holes is a board that connects to the buttons and joystick. These boards connect to the Raspberry via USB cables. I ordered some short USB cables because the ones that came with the button kit are several feet long, and I have these boards pretty close to the Raspberry. But when I tried to connect the cables, I saw more effects of my poor location planning:
The USB cable goes right where one of the buttons is, and it’s still long enough to be a pain at the edge of the panel. As for the cable for the other joystick board:
The cable doesn’t even reach.
To fix all of this, I rotated the two joystick boards by 180 degrees (so they will no longer interfere with the buttons), and moved the Raspberry down so that it can reach both boards with the short cables.
I told a couple of coworkers about the problem I was having with using up the available memory in my Arduios. Later that day, one of them sent me the following two links:
From the first link, I learned that every time I added a case to the switch, I was adding all the characters in the filename into SRAM, which in my case (since the Pro Mini uses the ATMEGA 328P), was limited to 2048 bytes. That’s not very much, and it’s really easy to fill.
From the second link, I learned how to store an array of character arrays in PROGMEM, which is 32 kilobytes for my processor, and then retrieve only the one that I need into the SRAM. This worked, but I am now depending on the order of the games in the array to be what I expect them to be rather than directly associating each system or game with a number. Here is the result from the compile, with no low-memory warning. You can see that I didn’t really affect the program memory, but dramatically reduced the use of the dynamic memory.
My updated code is included in a comment on this post.
I also had to change the runcommand-onstart.sh script on the Raspberry, because all of the arcade games have the same system, and I was loading the images based on the system before. This is still appropriate for the consoles, but for the arcade games, I need to load based on the game.
I am using two MAME (Multiple Arcade Machine Emulator) modules for my system. The reason is that one of them supports all the roms I have except one. That one game is Altered Beast, which is the one that I dumped loads of quarters into a the 7-11 near my high school in the late 80s. So it’s worth having another MAME module just for that game.
In the updated script, I check to see whether the system name begins with “mame”. If it does, then I call the loadButtons.sh script with the game. Otherwise, I call it with the system. Here is the updated script:
#!/bin/bash
# ARGUMENTS, IN ORDER:
# 1: System (e.g., “arcade”)
# 2: Emulator (e.g., “lr-fba-next”)
# 3: Full path to the game (e.g., /home/pi/RetroPie/ropms/arcade/wjammers.zip)
if [ -z “$#” ]; then
exit 0
fi
system=$1
emulator=$2
# Gets the basename of the game (e.g., wjammers”)
game=$(basename “$3”)
game=${game%.*}
gamepath=$(dirname $3)
#echo “system is $system” >> /home/pi/bin/log.txt
echo “game is $game” >> /home/pi/bin/log.txt
#echo “gamepath is $gamepath” >> /home/pi/bin/log.txt
if [[ $system == mame* ]]
then
# echo “need to use the game, not system” >> /home/pi/bin/log.txt
# /home/pi/bin/loadButtons.sh “$game” >> /home/pi/bin/log.txt
/home/pi/bin/loadButtons.sh “$game”
else
/home/pi/bin/loadButtons.sh “$system” >> /home/pi/bin/log.txt
fi
I also had to add all the games to the file buttons.cfg. Here is the result:
In the switch statement in the code for the Arduinos, I had only put in the first 16 out of 70 options. Today I added the rest, and when I was uploading the program to the Arduino, I saw this message:
I hooked up the Arduino, and sure enough, it didn’t work. I kept removing cases from the switch statement until I didn’t see the low memory warning. Then it worked again.
So now I need to find a way to cover all the options with less code so I don’t blow the memory.
The rest of my arduinos came in the mail. I soldered on the comm pins, then the 90-degree pins for the LCDs. Then I added the stackable headers. Here are some in-progress photos:
Once I had those put together, I decided to finish up the wiring on the first of the two boards that the Arduinos will be mounted in. I already had the wiring for the first stack, but I had to run wires to the second stack. Here is what it looked like when (I thought) I was done:
I plugged in an Arduino with an LCD to the second stack, and it didn’t work. It took me a while to figure out that I had missed one of the control wires. Here’s what it looked like when it was actually done:
And here is a pulled-back view for context:
I tested it out by putting two full stacks of Arduinos on the board, and connecting an LCD to the top Arduino on the second stack. I ran the script that cycles through all the images that I have so far. In the video, the LED on one of the Arduinos keeps blinking. That’s because that Arduino has not been programmed yet.
Up until this point, I have not physically secured the Arduinos in any way. I had decided that in the final build, there would be four stacks of five. I wanted to mount each stack to a board that could also be used to connect the control and power wires to (instead of plugging into the top of the stack as I had done for testing). I also needed a way to connect the control wires to each stack. I found these proto-boards on eBay, and they seemed perfect:
They already had mounting holes, and they have the same layout as the breadboard that I was using for testing. I could use the outer strips for 5V and ground, which would give me room to provide power to the LCDs. These boards came in packs of 5, and I figured I could mount two stacks on each, so I would only need to use two of them.
I wanted to be able to remove any Arduino from the stack if need be, so I soldered headers onto the board:
In order to keep the headers from tilting while being soldered, I stuck them into the bottom of an Arduino stack before sticking them through the holes on the board:
These are the same headers that I am using to make the Arduinos stackable, so the leads stuck out of the bottom of the board pretty far:
Once both boards had all four headers soldered on, I trimmed the leads with diagonal cutters. I also found that since there is no solder mask on the board, it’s easy to get too much solder on the connection and cover up some of the holes.
It was a tight fit, but I can fit two stacks on one board:
Before going further with the mounting of the Arduinos, I decided to address an issue that I was having with my bank of relays. In most of the connections, I had more than one wire, and the design of the terminals does not work well with that. So I decided to solder together any multi-wire connections:
This was harder with the black wires than the red, since the black wire that I used was solid instead of stranded.
Since the Arduinos will need to be near the buttons and the LCDs (to save on wiring), I decided to mount them to the back of the control panel. Since there are 10 buttons for each player, and one board holds two stacks for a total of 10 Arduinos, I decided to put one just below the “Player 1” buttons, and one just below then”Player 2” buttons.
And since the relay bank has to be near the Arduinos, and the Raspberry has to be near the relay bank, it made sense to also mount those on the bottom of the control panel.
The stand-offs that I have do not have long enough shafts to go through both layers of the control panel. That is fine, since I don’t want nuts or screw-heads sticking up through the console anyway. So I drilled small holes through both layers, and then in the top layer, I used the small holes as pilot holes for a 3/8” drill.
This meant that I had to dis-assemble the control panel – removing the buttons, joysticks, and wiring – but I knew I would have to do this to cut the holes for the LCDs anyway.
I marked the locations of the holes by putting lipstick on the posts and then placing them on the back control panel piece:
The larger holes that I drilled in the first layer of the control panel had a lot of material hanging on the back that I trimmed with a utility knife:
I decided to put the Raspberry in the center near the top, and the relay bank half way between the two Arduino boards. The two boards that came with the jousticks and buttons would go between the joystick and the buttons on each side. Here it is with all that layed out and some of the wires from the relay bank to the Arduino soldered in (the Arduino boards are not currently mounted, so I can solder wires to them):
I began soldering wires between the relay bank and the two Arduino boards. The wires are not soldered to the relay board, but in each case there are two wires from each terminal (one per Arduino board), and the two wires are soldered together. Once I got all 7 control wires soldered to each Arduino board, and power connected to one of them, I decided to test the image loading again, to make sure I hadn’t made any mistakes in the soldering, like connecting the wrong wire or putting too much solder so that two wires were connected. The preliminary test was successful:
I still have more soldering to do before all four Arduino sockets will be working, but the progress is encouraging.
I was pretty disappointed at how poorly my first attempt at making a control panel went. I started thinking of other materials that would be sturdy enough to have so many holes so close together. I even looked at steel, and found I could buy a 1/4” x 12” x 30” piece of steel for about $70. Of course, I would still have to drill it.
I abandoned the idea of steel once I had calmed down. I went to the hardware store and bought a 2’ x 4’ x 1/4” piece of hardboard.
As I said before, I want the control panel to be 12” x 30”, so this was plenty big enough. In fact, it was big enough to cut two pieces that size, which meant I could double up on the thickness. I wanted to do that anyway, for the following reason: I had spent a lot of time trying to figure out how to mount the mini LCDs. I had lots of ideas that I gave up on for one reason or another. The solution that I finally settled on was to have two layers of the control panel, and the top layer would have holes for the LCDs, and the bottom layer would not. The bottom layer would still need holes for the wires for the LCDs, but it would provide a surface to mount the LCDs on in a way that they could be flush with the tops of the buttons.
As it turns out, when they say that the hardboard is 2’ wide, they really mean 23.75”. So the bottom panel is slightly smaller than the top one. No big deal, though. Here are the pieces after the first cut down the middle:
And after being trimmed to 30”:
I used the same template from slagcoin.com that I had used before, and marked the centers of the holes. Instead of using spade bits, I bought two hole saws. There are two different sizes of buttons in the set that I bought. For each color, there are two small buttons and eight large ones. I used some calipers to measure their outer diameter, and came up with 1-1/8” for the large buttons and 15/16” for the small ones. Seriously, 7/8” would not have been large enough, and 1” would have them falling through. The hardware store did not have a 15/16 hole saw, so I ordered one on Amazon.
I taped the template 1” from the top and 1-7/8” from the edge. I repeated that for player two. Once the centers were marked, I clamped the two pieces together and drilled pilot holes. That way I could drill all the bigger holes without the boards clamped together and the holes would still line up.
Here are the two pieces with all the pilot holes drilled:
Drilling the holes for the buttons went much better this time:
Before I went any further, I just had to see how it looked with the buttons all in it:
Of course, I had to take the buttons back out to continue. The next step was to cut a hole for the joystick. This would have to be a large square hole, centered around the pilot hole that I had drilled. I drilled slightly larger pilot holes to match the diameter of the joystick handle, which protrudes from the bottom of the assembly:
The idea was that I could set that into the pilot hole and then trace around the assembly so I would know where to cut the hole. Unfortunately, the mounting plate makes it hard to mark anything. Under the disc at the base of the joystick, there are four mounting screws:
I removed the knob and the disc, and then I could remove the four screws and the mounting plate.
Then I could trace and cut the holes. I used my square to ensure that the holes were lined up with each other. I didn’t trust any powered cutting tools to not chew up the edges, so I cut the squares with my utility knife.
Once you fit the assembly through the hole, there’s not much overlap for the mounting plate. I decided to use machine screws with nuts and washers so that they would be secure.
I still have to cut the holes for the LCDs, but at this point I wanted to try out the controllers. I wired them up with the wires that came in the kit. For the LEDs, they have two wires with a bunch of in-line terminals to hook them all up to one power source. This means that all buttons will be lit up all the time.
Here is what it looks like all wired up:
And here is what it looks like when it’s plugged in and powered up:
And here is me holding the control panel alike a proud daddy:
My son and I played a two-player game to test it out. The button locations were not consistent between the two players, which tells me that the configuration for each game is independent of the setup in EmulationStation. That is good, since I want full control over the per-game configuration. Also, it was really fun!
I got tired of waiting for the solder that I bought on eBay so I just went to Hobbytown and bought some. I was able to solder the pins to my second LCD, and connected the two LCDs to two Arduinos, all driven by the Raspberry/relay configuration. Instead of loading games, I ran a demo script to run through the consoles. The images for Atari 7800 and Commodire 64 are identical, so that’s why you see the same image twice in a row (red background with “left” and “right” written on it).
The glitches that you sometimes see between images is due to the fact that I am changing more than one input pin at a time on the Arduino, and since that doesn’t happen exactly simultaneously, there will be a brief moment when the Arduino displays the wrong image. When the transition is smooth, you know that only one pin was changed.
This will not be an issue in the actual build, since every time a new game is loaded, the Arduinos will be starting up from an off state instead of transitioning from another image.
In the video, the two LCDs occasionally appear to have different hues from each other. This is simply an artifact of trying to film an LCD screen. It looks better in person. You can see all of these images all together the the previous post called “Scaling up: Multiple LCDs.”
I have gone through a few iterations of what to do with the mini LCDs when their corresponding button is not in use. Clearly, I want them to be blank, but how to achieve that?
My first idea was the worst one (as usual). I would have an image file for every game for every button, and if a particular button was not used in a game, then its image for that game would just be a black rectangle.
One issue with that, besides the tedium of copying the same file over and over to all the different buttons, is that even though the display is black, the backlight would still be on, and it would therefore still glow a little.
Then I realized that the method that draws the images checks for the existence of the file, as I mentioned in a previous post. So now, instead of having a bunch of files that are just black, I could only have files for games that use a particular button, and when the button is not used, no file will be found, and I could just draw a black screen when that happened.
I still would have the issue of a slight glow from the unused LCDs, but the implementation would be a lot cleaner.
Then, when I came up with the solution for lighting the LEDs in the buttons, I thought that I could power the LCD with the same pin that lights up the LED. Then I realized that that wouldn’t work, because the LCD needs to be powered up while the Arduino is looking for the image file, since those are stored on the SD card of each LCD.
Then a discussion with a coworker reminded me that there is a pin on the LCD for controlling the backlight. If I could turn the backlight off, even if the LCD has power, then my glow problem would be solved. I looked up the info about the backlight pin and found this:
Lite – this is the PWM input for the backlight control. It is by default pulled high (backlight on) you can PWM at any frequency or pull down to turn the backlight off. Use 3-5V logic level
So I connected the Lite pin of the LCD to the A0 pin of the Arduino (which is the pin that will control the LED), and it worked like a charm. Now the LCDs next to any button not in use will be completely dark.
I finally ordered a couple of joysticks and a bunch of buttons:
I went to the hardware store and bought a plank of wood, 12” x 48” x 3/4”. I figured 12” would be wide enough for a player to be able to rest their wrist while reaching the buttons. I have concluded that I want the cabinet to be about 30” wide, so I planned to trim the board down to that. I used a printout from slagcoin.com and taped it to the board to mark the hole centers.
3/4” is a little too thick, so I decided that after drilling pilot holes, I would drill part way through from the bottom with a bigger spade bit, and then drill down from the top with a button-sized spade bit.
I was a little surprised by the spade bits that I bought. I didn’t think much of the “10x faster” claim on the packaging. I should have. The center parts of these bits are threaded, so it pulls the bit into the wood. These bits do not produce sawdust. As soon as the center of the bit touches the wood, chunks explode everywhere.
I was still able to cautiously drill part way through from the back:
But drilling from the top did not go so well:
I don’t think I’ll use a wooden plank for the control panel after all.
There are several images for the buttons that have stylized text (like the “B” button for NES). My original approach to these was to find an image of the actual controller, and try to create a nice image based on that, tracing it out in Photoshop and using color fill. Those turned out to look amateurish at best. Then it occurred to me that there might be fonts that match what was used on the actual games, and I was right. The images resulting from just typing the letters in the correct font came out much better.