While building yet another RetroBox arcade I got to work to see if I could add some awesome illuminated buttons.
Since I was really pleased with my previous build, I decided to continue to use RetroPie as a foundation and add my own modifications on top of it. For the most part I was just making minor changes such as changing the way EmulationStation handles gamelists, adding Xin-Mo controller support and customizing the overall theme. For the next build I wanted to add something special. After giving it some thought I settles on adding illuminated buttons that would toggle on/off depending on which one are in use by the emulator or rom.
Collecting the parts
For this project I bought a USB Interface & Chrome effect Joystick set similar to the one I used in my previous build but with illuminated buttons support. One of the biggest drawbacks with this set is that it only contains 14 buttons while my build needs 16, so I had to buy two additional buttons and I also got two dead bulbs I’m waiting to get replaced. According to the specs the buttons are supposed to use 12V but even with only 5V they are actually quite bright. Since the screen I’m going to use already features a 5V USB port I may use that for power instead of a 12V power supply. At least for testing purposes 5V will do just fine. If you are interested to see the difference in brightness based on voltage values, take a look at my video on YouTube.
In addition to the joystick set, I needed some electronic components in order to be able to control all lights individually. Since the Raspberry Pi only provides 3.3V and about 15mA from the GPIO ports I needed to make a simple circuit using MOSFET N-CH transistors. In order to be able to control all LED’s individually I had to use 16 transistors. For information on how I assembled the circuit take a look at the schematic. Please note that the resistors are only there for the simulation because the buttons have them builtin.
Writing the code
My main purpose for this project was to make the buttons indicate which buttons are in use for any given emulator or rom. While console emulators such for SNES and GameBoy do not have much information about button configurations on a per game basis (unless scraped from the web), MAME is a completely different story. Thanks to files such as controls.xml and nplayer.ini it’s quite easy to determine which buttons are in use and how many players a specified game supports. Using these two files and the config files residing in /opt/retropie/configs I pretty much have all I need to get started.
I’m still writing the script but the main idea is inject two lines of code into runcommand.sh because this file is executed before and after all emulators. The other big advantage of this file is that it already has variables that contain information about the system, emulator and rom being launched. The only thing I need to do is to write a small python script that would take these variables as an argument and interpret the supporting files.
The script would need to map the GPIO pins and the physical buttons and configure the GPIO pins so we can control them. Using the system variable it should then look for a config file in /opt/retropie/configs/ and parse the button configuration if found. In case the system is set to MAME we also want to parse controls.xml and nplayer.ini for additional information before turning on the correct LED’s.
Stay tuned for updates!