Arduino Project 7: Build a Retro Gamebox

 

APC Arduino-based Retro Gamebox
Our Retro Gamebox is built into a see-through container.

The games market may well dwarf the music and movie industries combined in global revenue and new-release games offer lighting effects and texture detail that make you forget you’re in a game and not a movie. But there’s always something that tugs us back to retro gaming – the blocky graphics corny 8-bit sound and those golden memories.

Our Arduino microcontroller doesn’t come with a video output although we showed you in the TV Weather Channel Station Project how you could hook it up to the composite video input of your TV and display your own TV weather channel.

So for this project we’re combining all this knowledge and putting together our very own retro arcade games console we’re calling the Retro Gamebox.

 

What you need

Apart from the Arduino Uno board the main components you’ll need are the arcade-grade joystick and fire pushbutton. They look impressive but they’re not expensive. We picked up ours from eBay – the joystick for $8.79 and the pushbutton just $3.50 both including shipping.

How the single-fire pushbutton works is pretty straightforward: the button plunger operates a normally open (NO) microswitch which closes when the button is pressed. A nice extra is that many also have an LED inside the button top.

The joystick is a little more complex – it has four NO microswitches one for each compass direction which operate as you pull the central control around. Some arcade joysticks have a mechanical locking mechanism that will lock off one axis (X or Y) so you can use it more easily; for example locking off the Y axis so the controller becomes a side-to-side type for playing Space Invaders.

Whether you’re building a full-on replica arcade gaming machine or just our little Gamebox the joystick switches do the same job: they connect to the circuit board and when activated cause the software to change operation based on the switch(es) pressed.

So that you can see the insides of our design more easily we’ve gone for a basic see-through food container. If you’re really keen you could put the whole thing together into your own full-scale retro arcade machine.

Parts list

Part Cost Source
Arduino Uno R3 $13.20 eBay
Eight-way arcade joystick $8.79 eBay
Arcade pushbutton $3.50 eBay
Dupont wires $2.55 eBay
Red RCA socket $0.95 Jaycar
Black RCA socket $0.95 Jaycar
900ml kitchen food container $2 Local $2 shop
2 x 470ohm 0.5W metal resistor $0.46 Jaycar
1 x 1kohm 0.5W metal resistor $0.46 Jaycar
TOTAL COST $32.86

 

Games

The inspiration for this project of ours came from the Hackvision system developed by Nootropic Design. It’s a basic cut-down custom Arduino with four direction buttons and a fire button all built onto a single printed circuit board. You can buy it as a prebuilt device ($44) or a kit you put together yourself ($34). However since the Arduino code for a number of games – including Space Invaders Asteroid Tetris and Sudoku – has been released to open source we decided a game box with existing Arduino hardware would be a worthy inclusion into our project list.

The main problem with the Hackvision system is the lack of USB connectivity requiring you to come up with your own USB-to-TTL adapter cable to program it. By using a standard Arduino in our Retro Gamebox changing games is as simple as plugging the Gamebox into your PC’s USB port and compiling the new Arduino sketch.

 

How it works

Our Retro Gamebox is surprisingly simple when it comes to hardware: five switches three resistors a couple of RCA sockets and that’s about it. Well it’s a little more complicated than that but when you boil it down that’s all there is from an electronics viewpoint.

How the arcade joystick works

Four of the five switches belong to the arcade joystick. Mechanically an arcade joystick is just a centre bolt that pushes the actuators of four microswitches wrapped around the outside. Each switch has two connectors: the contacts are the NO type that close when you move the joystick and actuate the switch. The trick with arcade joysticks is they operate the opposite switch to the direction of movement. So pushing the bar up activates the bottom switch; pushing it left operates the right switch and so on.

Arcade-grade controllers
Arcade-grade controllers use four microswitches around a central control lever.

Electrically the switches are used to effectively create an interrupt pulse within the Arduino and cause it to perform a function based on which switch is pressed; for example when we want our rocket ship to move in a certain direction.

In the Gamebox the digital inputs these switches are wired to are set to activate when the switch pulls that input to ground (the 0V rail). That means we can join one connector of each microswitch together and wire it to ground creating what’s called a common ground. This allows us to use just five wires from the joystick to the Arduino (one for each switch and the common ground) instead of eight (two for each switch).

How the fire button works

The fire button works slightly differently – it has just the one switch but two modes of operation. The switch has three connectors: a common connector plus one that’s NO and one that’s normally closed (NC). With the switch resting the common pin is electrically connected to the NC pin. When you press the switch that common pin then connects to the NO pin and disconnects from the NC pin.

The switch we’ve used here also has a built-in LED and current-limiting resistor. What we’ve done is hook up the anode side of the LED to the Arduino’s 5V pin and the cathode side to the pin that connects the switch to the Arduino (D10). The result is that the LED lights up whenever the fire button is pressed. Combine that with the blue power LED on the Arduino board and you get a neat little light show.

Fire button
A good-sized fire button is a must-have for any games console!

Video/audio output

Thanks to some impressive coding from Myles Metzler and others the video and audio output that connects to your TV requires only three resistors and one of those is optional. We won’t cover how it works here but briefly composite video requires two electronic signals: the analogue video data plus the synchronisation pulses that tell the telly where the data is meant to be on the screen. Two resistors are all that’s required to combine the signals into one composite video output with the correct voltage ratios your TV will understand.

Composite Video out
The Gamebox features composite video out and 8-bit sound via its two RCA ports.

The audio output is really simple. The Arduino creates genuine 8-bit pulse-width modulated (PWM) sounds straight out of pin D11. We’ve added a simple 470ohm current-limiting resistor to ensure that output pin doesn’t blow up if it’s accidently grounded. That output goes directly to your TV’s audio input and gets blasted out the speakers.

No power switch required

Once you’ve programmed the Arduino with your choice of game it’ll launch it straight away. High scores are saved in the Arduino’s small EEPROM memory so they’re saved even when the power goes off. We’ve not bothered with a power switch although you could integrate one into the build if you wish.

 

Putting it together

You can put the Retro Gamebox into any container you want so we’ve chosen a food container for its low cost and transparency. Full-size arcade games are impressive but we wanted you to see what’s going on inside and hopefully give you the idea that it’s not that complicated.

Using a food container

We’ve used a 900mL food container from the local $2 shop and if you follow this route you need to take care when drilling into plastic. First set your drill speed to slow otherwise you’ll tear the plastic to shreds. Second don’t push too hard against the plastic to get the drill bit to bite otherwise you’ll split the plastic. Don’t use cheap takeaway containers but a sturdy microwaveable type. You could also use a Jaycar ‘jiffy box’ although we like the see-through look. The other thing we’d do differently next time is mount the RCA sockets towards the edge of the container where the plastic is a little stronger (it’ll handle connecting and removing cables much more easily).

Mounting the components

We’ve used standard M4 machine screws on the joystick with washers on either side of the plastic lid (one under the bolt head another before the nut). You can pick these up from any hardware store. We ended up using a tapered reamer to size the hole for the joystick rod. However the fire button requires a sizeable 24mm hole for the centre shaft. If you don’t have a hole saw the easiest way is to pick your centre point and measure 10mm out to eight points around in the circle. You then drill pilot holes at each point and expand them out using a 3mm drill bit. You then snip around the outer perimeter of the plastic joining those holes with a pair of side cutters (food container plastic is soft enough for this). After that you’ll find you can just push out the centre piece leaving a 24mm hole you can push the fire button shaft through.

Place washers directly against the plastic
Place washers directly against the plastic so you don’t split it.

The fire button itself comes apart – grab hold of the microswitch bottom section twist and pull it to unlock. That’ll give you the top shaft section which you can feed through your case and anchor with the large plastic collar nut. There are different types of arcade pushbutton switches so your mileage may vary.

We raised the Arduino board off the bottom of the container using 5mm spacers (Jaycar) and 15mm M3 bolts (Bunnings) which fit into the Arduino’s four mounting holes. Don’t forget the washers on either side of the plastic before you add in those spacers. Using a see-through container makes it easy to mark out the mounting hole positions with a Sharpie before you drill. Finally don’t forget the holes for the DC power socket and the USB port.

Wiring up the components

Our build method requires no direct soldering to the Arduino board. Instead we used Dupont male wires cutting off one end soldering it into position and pushing the pin on the other end into the appropriate header hole on the Arduino board. The Arduino header sockets grab Dupont pins pretty well so you shouldn’t have to worry about them falling out unless you start drop-kicking the Gamebox around. We also used a small amount of standard hook-up wire to connect the common ground on the joystick and the fire button LED to the fire button’s NO contact.

use proper spade lugs
You can use proper spade lugs to solder the joystick and fire button switches or solder direct as we did.

Just make sure you don’t wire everything so short that you can’t take the lid off easily. Really how you build it is up to you – as long as you follow the circuit diagram you can build it on a lump of wood if you like and it should still do the job.

The Retro Gamebox's circuit diagram
The Retro Gamebox’s circuit diagram is pretty simple.

 

Programming it & hooking it up

Although these classic games were originally ported to work on the Nootropic Design Hackvision board we’ve designed the Gamebox so they’ll happily work here too. Provided you’ve followed the circuit diagram when building your Gamebox all you have to do is download the required files and libraries for each game onto your PC compile the Arduino sketch and upload it to your Gamebox – no game code needs to be harmed in the making of this project.

To make it easier we’ve put each game together with a package of libraries your Arduino IDE will need in order to compile it. They’re based around Myles Metzler’s excellent Arduino TVout library Nootropic Design’s controller library which handles the joystick and fire button plus other libraries where appropriate.

For all games other than Space Invaders just copy the contents of the ‘libraries’ folder across to your Arduino IDE’s libraries folder and overwrite any existing files. With Space Invaders you especially need to delete any existing TVout folder and replace it with the one bundled with the Space Invaders code. You then need to compile the sketch code and program your Arduino. The Space Invaders port was written for an older version of TVout and won’t work with the current release – that’s why you need to delete any previous version and use the specific version including the ZIP file.

We used the latest version 1.0.3 of the Arduino IDE available from arduino.cc/en/main/software.

Hooking it up to your TV

This is the fun bit. Use a standard stereo pair RCA cable and connect one side into the Retro Gamebox and the other end into the composite video and audio inputs of your TV or monitor. Go with a 3m or 5m cable to give you enough length that you’re not sitting on top of the telly to play. Powering the Gamebox you’ll need a 9VDC or 12VDC power brick with the centre pin positive and the other ring negative. The Arduino pulls no more than 50mA so just about any correct voltage/polarity power brick should work. You could also power the Gamebox with a USB power adapter from your smartphone or tablet and plug a USB cable into the Arduino – we’ve tested this and it works just fine.

soldered the output resistors directly to the RCA sockets
We’ve soldered the output resistors directly to the RCA sockets. It’s not ideal but it’s quick.

PAL or NTSC?

By default Gamebox is set to deliver US-based NTSC-standard video. That’s not a problem for modern TVs as they all handle NTSC and Australia’s PAL video system but if you’re planning to run this on an older CRT TV that’s PAL only add a wire from D12 to ground to tell the Arduino you want PAL video output. Apparently this also speeds up gameplay for some reason we haven’t figured out yet; most likely due to the change in video frame rate from 60Hz to 50Hz. Arduino only does monochrome video so don’t expect to see flashy colours.

Turn the TV volume down a bit before you start as the Arduino’s audio output can be a maximum 5V peak to peak and don’t forget to select the appropriate TV input to see the video.

To reset the Gamebox just pull the power out and plug it back in again. You could add in a small pushbutton switch that pulls the RESET pin to ground but that’s entirely optional.

Writing your own games

Once you’ve had a play for a while why not have a bash at writing your own games? If you’re thinking about gaming a simple setup like the Retro Gamebox will help you understand what makes good gameplay without getting sidetracked with producing eye-popping graphics.

Peer through the Arduino sketches for each game to glean ideas and head to the Nootropic Design web site for more details. Don’t forget the Arduino web site for more on coding the Arduino.

classic Space Invaders game
The classic Space Invaders still rocks!

Hackvision Arduino game sketches

You can find the original games available at nootropicdesign.com/hackvision/. To make it easier we’ve put together each game as a separate ZIP pack with all the required libraries included. You can grab them from the APC web site at apcmag.com/arduino.htm under Project 07. Note: Make sure you read through ‘Programming it & hooking it up’ section of this article for special information on uploading Space Invaders to your Retro Gamebox.

For a list of Arduino projects we’ve created (more to come) go to Arduino Projects – APC Master Class Series.

 

  • Robert Smith

    I’ve built the game box but I can’t get space invaders to work. No video or sound on the TV. I loaded the old TVOut library, compiles, and loads onto the uno. I can get the other games to work, change to the new TVout library of course. Can you help as I really want to get space invaders going.

  • Well, it sounds like you’ve got the hardware side of things working. One tip would be to make sure you restart the Arduino IDE after swapping back to the old TVout library, otherwise, it may still be compiling the new one.
    Cheers,
    Darren.

    • Robert Smith

      Thanks Darren. I’ve done that. If you don’t, you get compilation errors. The library versions have different names for some routines, different constants and fonts. Also found that some of the older libraries used D8 instead of D7 for video. Tried swapping wires, nothing. 🙁

      • Okay, been a while since I’ve used that code… 🙂 I still have my original version of the gamebox shown in the pics, so I’ll see if I can nut out what’s going wrong and report back. I know other people have got this working too, so I’m pretty certain it’s something to do with the TVout library.
        Can you tell which versions of the TVout library you’re using?
        Thanks,
        Darren.

        • Robert Smith

          BTW was using the TVout library that I downloaded from this website. “R6 (June 2010) (Currently Beta at 5.9)” according to “version history.txt” file.

        • Robert Smith

          Found the solution.

          On noontropicdesign website under Games (won’t let me put in link) just under the videos of Space Invaders and Pong there is –

          NOTE: This original firmware no longer works with the newer versions of Arduino and the Uno bootloader.
          You can use the standalone Space Invaders and Pong games. These are to be used with the TVout library at Google Code and the Hackvision Controllers library.

          There are links to the software and libraries.

          Tested Space Invaders and works fine with the latest TVout and Controller libraries