Arduino Space Invaders – Making on Stripboard

Let’s move our project from the breadboard to strip-board to give it a more permanent home. You will need 30×30 hole strip-board (30 width is a common size). Strip-board is the prototyping board that has rows of copper strips as apposed to perf-board which just has copper pads. I prefer strip-board also sometimes referred to as veroboard (veroboard is a large manufacturer of strip-board). If you want to use perf-board then you will have to adopt the design below accordingly.

A video has been created to support this article

Below are three diagrams of the the same board (click to make full size). I’ve labeled the rows and columns with numbers to make it easier to transfer to you own board. We are going to build and test this in stages to hopefully minimise any errors. The first shows the track side of the board and where you need to make cuts. the second and third are the component (none track/solder side), with the middle showing just the wiring (solder them underneath where they go through the board).

 

 

Cutting the tracks
First job is to cut the tracks where indicated by the white circles. Turn you board so that you are looking at the copper tracks facing you. See this picture of the board I’m using (click to enlarge);

Cut the board to 30 holes across and 30 down. Orientate the board so the tracks are running vertically downwards as shown in the left most picture above (and in the photo just above). Cut the tracks where shown, being careful to double check you are doing it in the correct place. A track cutter is a good tool purpose built for this job but you can get by with a craft knife if required. After you’ve finished check every cut track to ensure there is NO continuity across the cuts (sometimes tiny bits of copper can remain). Here’s mine after completion.

Adding the jumper wires
Next we add the jumper wires on the reverse side to the one where you’ve just cut the tracks in the copper, this is called the component side. Look at the middle picture which shows where to place them. Again, care should be taken over their placement and double checked as errors here could result in the system not working or even the breaking of parts in the system. Here’s my board after adding the tracks;

Note : Due to last minute alterations the board shown here is a little bit different from the designs further up, follow the earlier designs and not these progress pictures.

Adding the components – Arduino Nano
Solder in the Arduino Nano taking care on the placement – see the right most image above. You need not solder every pin, only the ones being used, so for this it would be GND, 5V (Vcc), D10, D6, D5, D4, A4, A5. But by all means solder them all if you wish. Once the Nano has been added you should upload a test sketch to blink the on-board LED to ensure all is currently working. Here’s the blink test for a Arduino Nano, upload and test.

Adding the OLED screen
Position and solder in the OLED screen. To test we will need to bring in some libraries to our Arduino IDE. The first is the driver for 1306 OLED displays. Go to the Arduibo IDE library manager, “Sketch->Include Library->Manage Libraries”. Type “Adafruit SSD1306” into the search field. The first result should be the one you require titled “Adafruit SSD1306 by Adafruit”. Install this. The second library is an altered version of the Adafruit graphics library that I modified to work with graphics stored in dynamic rather than static RAM. I believe Adafruit have added this capability in since I wrote this addition but I’ve not had time to look into this and check if my Space Invaders code would work with it, so I’m sticking with what I know works. If you’ve already added the normal standard Adafruit Graphics library for other projects then you will need to remove whilst you install this version and use it in this project, here’s the link to the download, download and install into your IDE;

Adafruit-GFX-Library-master

Altering the screen size definition in the Adafruit driver library
OLED screens come in various pixel definitions for both width and height, the  library supports three different sizes at time of writing. Open Adafruit_SSD1306.h , which should be located within the libraries folder in the folder where your Arduino projects are stored, for example mine is located here;

My Documents\Arduino\libraries\Adafruit_SSD1306-master

At around line 70 you will see the following lines

 

By default #define SSD1306_128_32 is un-commented and the others commented out. For our purposes we have a 64 pixel height screen and this is the line we need to uncomment, so change the code to look as follows;

 

Ready to demo (still might not work!)

Enter or copy and paste the following code into a new Arduino Sketch. Ensure your port is set correctly and you have selected the correct board to upload to (in my case it’s the Nano).

Compile and upload the code. If it works then great, you’ve done it, if not then the most likely culprit(apart from bad wiring – please check!) is the I²C address of your display. These tend to be either 0x3C or 0x3D. So first try changing the line

#define OLED_Address 0x3C

to

#define OLED_Address 0x3D

and recompile/upload. If this doesn’t work it may be that your screen has an even different address to the most common ones.  In this case you need to load a  I²C address scanner onto your Arduino to get the screen to return its address and use that one in the code above. See this Link for a suitable scanner.

Once this is done you should be able to run the above code and see the message. As a further test to ensure all the screen is being written to correctly, open an example from Adafruit and upload it, use “File->Examples->Adafruit SSD1306->ssd1306_128x64_i2c”. When this is run you should see it going through several graphical demo’s and then stop at the end.

Adding the Space Invaders Code
Next we are going to upload the actual code, but before we do we need to add in the sound library otherwise it will give a compilation error. Download and add the following library to your Arduino IDE;

toneAC

This is a modified version of the toneAC library to add in functionality I needed for this game.

The full space invaders code can now be uploaded and is available below, just expand the area and copy and paste into your IDE. When ran you should see the Space Invaders start screen but you currently have no way of starting a game, see after the code below.

Adding Controls
Solder in the three buttons below the Nano, making sure that they are orientated so that the push connection is made connecting the left hand side of the button to the right, use a multi-meter if you are unsure or sometimes it is marked on the bottom of the switches with some sort of diagram. Test by playing the game, the fire (far right) should start a game and the others are left and right direction control.

Adding Sound
Add the two resistors (ensure they are in the correct locations or you will probably damage something) and then the PAM8403 module and speaker itself. The last item is the volume control, which I mounted as shown and connected the three outputs to the tracks. You may have to be inventive in mounting yours due to difference in what I’ve got and what you have, just ensure the three connections go to the correct track.

The completed project
Here’s my completed board, note that at time of the build the correct speaker was unavailable so I made do with a temporary one that is slightly oversized but will be replaced when the correct one arrives.

Power Up
Power up again and now you should have sound with volume control. That’s it for this article, next time in this series we’ll present an actual printed circuit board design that you can use for home production or indeed send off to be manufactured. It may even be able to purchase it from this site if I get the shop up and running but files will be available for download so that you don’t have to purchase it to have it.

4 Comments

  1. Hi Sorvad (Stardot friend), I saw your post there which lead me here.
    I have now built your space invadershardware and compiled the .ino with the libraries as you havve described them. I have it working 95%, but the screen is only showing the invaders, but not the lower third, ie the baracades, nor the launcher. I suspect the error is in changes to the adafruit Adafruit SSD1306 library (in the last 20 days), do you have an complete ino file with the libries you used attached (in tabs) ? Or any other help you can offer ? cheers, Roger

    • Yes, you are correct in the fact that since this code was originally written (over a year ago now) the Adafruit library did change. All you need to do is either alter the “.h” header file for the SS1306 library to un-comment the 128×64 screen size an comment out the 128×32 default setting. Or change the line that creates the screen object to

      Adafruit_SSD1306 oled(128, 64); // create our screen object setting resolution to 128×64

      They changed it to above as so many people didn’t remember or know to change the header file for the appropriate display, You should be good to go once you’ve done this.

Comments are closed.