Introduction: Arduino VGA Console With Five Games
In my previous Instructables, I have reproduced simple versions of some of the most famous classical arcade games, by means of a bare Arduino and few other components. Later on I joined four of them together in a single sketch. Now I have finally added a fifth one, thus you can build a simple console that can to play Pong, Breakout, Bomber, Tetris and a drawing toy inspired to Etch-a-Sketch.
The main feature is the generation of a VGA signal, thanks to the VGAx library, thus the console needs a VGA monitor. My goal, as usual, is to avoid any "special component" to build it, you don't need then any supporting IC or shields! The only components are two potentiometers, five buttons, few resistors and a DSUB15 (VGA) connector. A piezo speaker is optional. You can see how these games look in the pictures in this page.
The VGAx library allows to use four color with a resolution of 120 x 60 pixels, not many but enough for this retro-game console. The graphic is raw but, thanks to the use of the potentiometers, the games run smoothly. Simple sound effects are available too.
Step 1: How to Build Your Own Arduino VGA Console
First download ArduinoVGAgame.ino code at the bottom of this page and copy it on your PC in a directory with the same name. Download the VGAx library from this link on GitHub. The easiest way is to copy it in the Arduino software subfolder named "libraries", to be immediately recognized.
IMPORTANT: this library works for Arduno IDE 1.6.4 but it is not fully compatible with elder or newer versions.
Upload the code in your Arduino board (I tested both Uno and Nano). A warning for low available memory is normal. If you do not have other errors everything is ok and you can immediately start to build your own console.
For this you need:
- an Arduino Uno Rev. 3 or Arduino Nano 3.x (ATmega328)
- a DSUB15 Connector, i.e. a VGA female connector or a VGA cable to be cut.
- resistors: 2 x 68 Ohm and 2 x 470 Ohm and 5 x 1 to 2 kOhm
- two 10 kOhm linear potentiometers (similar values are fine too)
- five buttons
- some piece of cable
- one or two nice boxes to put all the components.
- a breadboard or a strip board
- a piezo speaker
The schematic is reported at the top of this step, together with an example of a finished “console”.
the schematic shows how to connect a button and a potentiometer. More specifically, you need to connect five buttons to pins 5, 10, 11, 12 and 13 respectively. The action performed by each button is described in the upper right table in the schematic. On the left it is shown how to connect a potentiometer (you need two potentiometers to pins A1 and A2). The speaker must be connected to analog pin A0.
I placed the Arduino board with the VGA connector in a wood box, which holds also the first player potentiometer and four buttons, while the second player potentiometer and his start button are in a separate and smaller box.
If you like this toy and you decide to reproduce it, I appreciate if you write a comment or send a picture in the comment section below.
Step 2: Appendix 1: More Details About How to Build the Controllers
You can realize the controller in many different ways, depending on the available material and your taste.
I like to realize them with wood boxes (see the pictures in this page). A main box for the Arduino, the VGA connector and the first player buttons and potenziometer; a second (smaller) one just for the second player button and wheel (needed for Pong and the drawing toy). Another possibility is to put everything in a single larger box.
First I reccomand to connect the VGA port. In the first and second pictures you can see some details: note the two 470 Ohm resistors for Red and Green connected to pins 6 and 7 respectively, and two 68 Ohm to pins 3 and 9 for horizontal and vertical synchronization signal.
You can choose different color combinations depending on wich pins you connect on the VGA DSUB15 connector, the pins 1, 2 and 3 represent Red, Green, Blue (RGB) respectively. I connected the pins 1 and 2, thus I have the following color combination: (0, 0) = black; (1, 0) = red; (0, 1) = green; (1, 1) = yellow.
For all different possibilities, I suggest to read the details in the page where you download the VGAx libraries.
As soon as the VGA connector is ready, you can prepare all the other cables for the buttons, wheels and speaker (see picture 2).
Now just put everything together: remember that each button pin need to be connectet to ground through a 1 or 2 kOhm resistor, otherwise when the button is open the state of the pin may be undefined. This means that if the pin is left disconnected you can have a random (static) voltage on it that can activate it. See for more deteils the schematic in the second step of this instructable.
The last step is to fix everything in place. I used the hot-glue-gun, but you can use your preferred method.
Step 3: Appendix 2: Some Considerations About the Memory Limits
It is amazing that a simple Arduino is able to generate a VGA signal and all these games together. The real bottle-neck is the lack of SRAM. The AVR microcontroller has only 2048 bytes available to store and manipulate the variables, and the VGAx library stores the screen variables in a 120x60 pixels framebuffer where each pixel needs 2 bits (4 colors), for a total of 1800 bytes. This means that there are only 248 bytes left for the sketch variables. Furthermore, in my experience, one should leave at least 100 bytes free to avoid instabilities. Using above 1950 bytes of dynamic memory, the microcontroller begin to show odd and unpredictable behaviour.
This means that all the variables must be shared among the different games, and this makes the code quite unreadable and hard to debug. It is not just a matter to "add a new game" to the previous sketch, but all the code must be deeply modified and optimized.
Furthermore, I had to use the minimum possible variable format: for instance, for all the coordinates I had to use "byte" instead of "int" or, in other cases, I had to prefer "int" instead of "float".
Finally, my aknowledgement goes to Sandro Maffiodo aka Smaffer, the creator of the VGAx library. Without it this project could not have been realized.