Intro: Stackers Arcade Game
Hi guys, today I want to share with you this amazing arcade game that you can make with a bunch Ws2812b LEDs and a microcontroller/FPGA. Behold Stack Overflow - our hardware implementation of a classic arcade game. What begun as a school project quickly became a labour of love as we began to spend more and more time in developing our game and learning more from it (and neglecting our studies in the process xD). In the end, our game was so well-built and well received by our school that it was confiscated (as demo material for the next batch of student). Well, we can always build a second one. Let's get started!
Online version of the game: http://online.brothergames.com/flash-games/stacker.html
Step 1: What Do You Need?
1. a Microcontroller/Microcomputer/FPGA - The FPGA is used to implement the logic of our game. Pick your board, for our project we are required to use the Mojo FPGA board. For the uninitiated, it is a type of board that uses hardware to implement its functions rather than codes. Hence, I would say its rather low level and completely different than if you're using Arduino or Pi. If you use other boards, you have to write your own code, but this game is pretty easy to code and hey! Now you can learn coding too!
2. Ws2812b LEDs - Here we are using the LEDs to construct the display for our game. Can't be a maker if you haven't touch Ws2812b's before xD. It is single addressable meaning that you can cut off single LEDs and paste them into any formation that you like. And it is RGB meaning that you can output any colour you like. Furthermore, FastLED - the Arduino library for controlling Ws2812b is very well developed. I would recommend people to use Arduino in place of the FPGA if you don't have one. You can purchase the LEDs from Taobao/Amazon but we bought ours from Sim Lim tower in Singapore.
3. Wood - For the external casing we used 1cm-thick plywood and for the LED matrix we used 0.3cm-thick plywood. We found our supply of scrap wood from our school's fab lab.
4. Light diffusing Acrylic - For our screen, we tried different types of acrylic and we found this frosted acrylic called PL-422 which is really good for diffusing light. If you can't find the exact model try looking out for frosted acrylics. We bought ours at Dama Plastics in Singapore.
5. Foam Board - In order to separate each individual pixels of light, we needed a grid structure and this foam is the ideal material to do so. We bought 0.5cm-thick foam board at our school bookstore.
6. Big Red Button - Ok, it isn't necessary for us to have such a big red button but its always good to have a button for people to slam! xD We bought it at Sim Lim tower in Singapore.
1. Wood Glue
2. Soldering Iron
4. Wires. Its best if you have soft wires as compared to the stiffer ones. And single core compared to multicore.
5. Wire stripper
6. Wire cutter
7. Drill with 1mm drill bits
8. Scroll saw
9. Band saw
1. Variable Power Supply Unit
Step 2: Rapid Prototyping
For our project, we employed rapid prototyping before building our LED matrix and programming our game. The reason for doing so is that we don't want to build the LED matrix just to realize our codes doesn't work or our game logic is flawed is some way.
On the hardware side, at the first stage we just tested our logic on shifting the light patterns on our own simple LED matrix. Once we tested that the logic works out fine, we then went out to cut out strips of 5 Ws2812b LEDs just to test our game logic with different rows. Once that works out, we then proceed to fabricate the LED matrix on full scale.
We also tested out different acrylics samples with the LED before settling for PL-422 as the best light diffuser. And for the separator structure we also tested out different heights for the LED to fully diffuse. In the end we realized 3cm*3cm square with 4cm height to be the best for diffusion. Based on this optimal size, we also decided what is the size of plywood needed for a 5 x 11 LED matrix by leaving 0.5cm gap for the foam between the squares..
On the software side, we try to be as modular as possible - we first test whether the LEDs can be lit up before proceeding to add the shift function, and then others.The results could be catastrophic if you don't do this. We learnt this the hard way as we tried coding out the whole game in a big chunk before realizing we couldn't debug it. Ouch!
Step 3: Making the Casing
For our casing, we went with classic arcade machine feels and looks. First, we cut some thin plywood to quickly prototype the shape as it is easier and faster to cut thin plywood and test. Once we were satisfied with our dimensions and shape, we started using thicker plywood to build the casing. We used a band saw to cut through the thicker plywood and a scroll saw to cut through the thinner ones. After that, we used wood glue to glue them together.
For the back of the plywood, we wanted to easily access the electronics inside hence we made it into a lock-in-place piece that you can easily remove whenever you want.
To attach the button, we first drew a circle the size of the button's microswitch diameter (the bottom long part of the button). We then drilled a hole near the edge and used the scroll saw to saw a circle through. Then we placed the button and screwed it in.
We also cut a thin piece of plywood as the base of our LED matrix according to the sizes we calculated before.
Note: I apologize for lack of step-by-step process. We didn't document the steps all the way and by the time we realized that we need to document the steps, the casing was already done. The diagram is also not the final dimensions.
Step 4: Making the LED Matrix
Using the thin piece we cut out earlier, we first mark out the position of each LED by drawing a square based on our foam structure and drawing a cross in the middle of the square as the place where we should stick the LED. Then we also drill 3 small holes on each side of the LED for the wires to come through and solder them to each LED.
We daisy-chain each row of LED by their Data In and Data Out pins and we solder each GND and VCC to a common wire. The leading Data In will generate the light patterns for each row and we connected it to the pinout of the microcontroller/FPGA. You can also solder the last Data Out of one row to the leading Data In of another row. The way the Ws2812b LED works is that each LED contains an IC that will take the required data from the wire and pass the rest down the chain. We based our LED on another fantastic Instructables (In fact, we copied it exactly! xD)
Here we would also like to stress on the importance of using soft wires. If you use rigid, hard wires for the leading Data In pin, what happens is every time you tug on the wire it might pull out the copper padding on your Ws2812b which will destroy it. In this project, before we changed to soft wires, we destroyed a total of 40 LEDs which is 1/3 of the LEDs needed for our project.
Step 5: Writing the Game Codes and Debugging Hardware
Mojo runs on Lucid HDL, which isn't the most popular language out there. We can't find any Ws2812b LED libraries in Lucid hence we resorted to writing our own library, which is a very interesting experience. To do that, we first analysed the signal that is passed out by using Arduino's FastLED library and wrote codes to replicate that. Here is a trick of hardware debugging, the oscilloscope is very, very useful to analyse signals, be it debugging your own signal that you aren't sure of or checking and copying other signals.
After writing the library for the Ws2812b, we then proceed to code for the game, we used the Bit shift functions to move each block to the left and to the right and used Bitwise AND to AND the squares of each row to the previous row. You can also think of implementing that in Arduino, which should not be that hard. We even coded game screens for the fun of it!
Our game had 2 levels, which is the visible stacking game (Green) and the second level invisible stacking game (Blue).
Even after we had a working codes and working LED matrix, sometimes we still face problems such as lights flickering or lights lighting up when they shouldn't. The problem is usually because of improper grounding, power supply level or interference. This is where you will need other hardware debugging tools such as variable power supply unit to check whether the Mojo/Arduino's power supply is sufficient or too high. In my experience, the Ws2812b has a pretty wide range of working voltages from 2.8v - 5v. Here I have a video that shows the lights going all crazy after I increase the power.
However, further checking revealed that we had some improper solder, after re-soldering them once again, our problem was solved. There could also be a problem with interference or cross-talking, but thankfully enough, we never faced any of them.
Github codes: https://github.com/ericywl/CompStruct-1D
Arduino Bitwise Shift: https://www.arduino.cc/reference/en/language/struc...
Arduino Bitwise AND: https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitwiseand/
Step 6: Putting Everything Together
You have the casing and the LED matrix. It is now time to put everything together. First we place the foam on the front and the LED matrix behind it and adjusted the position. Because foam has very high friction it was just friction mounted while the LED matrix is hot glued in place. After that we placed the screen in front of the grid. We then plugged each row's pin to the microcontroller and started playing! :D
One thing I like about this project is its flexibility, you can always reprogram the microcontroller to be part of another game and try something such as making animation or a reaction game. Hope you guys enjoy making this and learn something for making this. GgEz!