Overview

I love Tetris! Nothing could compare with the satisfaction I get from clearing a line after another. So in this guide, we are going to build a handheld game that plays not only Tetris, but Snake and more!

Menu

When the Tiny Tetris is first turned on, you can use the left/right buttons to select between Tetris, Snake, and the Paint program, then press the center button to enter the program. Once you're inside a program, you can switch to the previous/next one by holding down the center button and press the brightness adjustment buttons on the left side.

Brightness Adjust

Tetris

  • Up - Rotate
  • Left/Right/Down - Move to left/right/down
  • Center - Drop

Snake

  • Left/Right/Up/Down - Change direction
  • Center - N/A

Paint

  • Left/Right/Up/Down - Move cursor
  • Center - Draw/Clear dot
  • Hold center for 3s - Clear canvas

Parts & Tools

Parts

  • 7 x 10kΩ Through Hole Resistors
  • 5 x M2x5/6mm Flat Socket Head Cap Screw
  • 8 x Neodymium Magnets 1/4 x 1/16 Inch

3D Printing

The enclosure is designed in SolidWorks, and printed on a Makerbot Replicator 2 but will fit in nearly any small 3D printer bed. Customize it with your favorite logo!

Makerbot Desktop Print Settings:

  • Infill: 15%
  • Shells: 2
  • Layer Height: 0.10mm
  • Extruder Temperature: 230°C
  • Speed while Extruding: 90 mm/s
  • Speed while Traveling: 150mm/s
  • With raft but no support

Circuit Diagram

Bottom

This first circuit diagram contains all parts mounted on the bottom half of enclosure. The JST connector on the PowerBoost 500 Charger goes to the LiPo battery, which is not shown in the picture. The four wires that connect to the 16x8 LED Matrix Backpack are the only ones that connect between the bottom and top half of the enclosure.

Top

The second circuit diagram contains everything mounted on the top half of the enclosure. This is a view from the inside of the enclosure, which means that both the LED Matrix Backpack and the joystick are facing away from us. If it seems confusing, the assembly guide on the next page will definitely help you understand better. All seven resistors shown in this circuit diagram have a value of 10kΩ.

At this point, you might be asking why we're wiring the buttons to the LED Matrix Backpack instead of the Pro Trinket. There are a couple good reasons why we're doing this. One is that we don't need to connect so many wires between the top and bottom half of the enclosure, which makes the assembly much easier. But the underlying reason has to do with the HT16K33 chip located on the LED Matrix Backpack. Let me explain more on the next page.

HT16K33 Explained

So what is the HT16K33? It's the name of the chip on the LED Matrix Backpack. 

It's a wonderful chip! Not only is it capable of driving a 16x8 LED Matrix, but reading a pushbutton matrix with a maximum size of 13x3. In fact, this is how HT16K33 is used on the Adafruit Trellis to read the 16 pushbuttons.

The HT16K33 refreshes the LED matrix with a frequency of about 100Hz. In each of the 10ms frame, it first refreshes the display, and then scans the button matrix for the state of every single one of those 13x3=39 buttons. But it's gets more interesting! The HT16K33 does not immediately tell you when any of the buttons is pressed. Instead, it waits for one additional cycle, which is a total of 20ms, to confirm the reading on all the buttons, and store the confirmed readings in its internal registers. 

It debounces the buttons for you! How cool is that?

So instead of writing code for debouncing the buttons on the Pro Trinket, we can ask the HT16K33 over I2C about the state of all buttons once every 20ms (50Hz). That's exactly what we are doing in this tutorial!

Assembly

Now let's start to put these components together to build our Tiny Tetris! The entire assembly process consists of three parts: the top half of the enclosure, the bottom half, and the interconnection. 

Let's start with the soldering the LED matrices to the Backpack. After all 32 pins have been soldered, carefully trim the pins with a flush cutter.

Use a pair of pliers to straighten the legs of the two pushbuttons and then insert them into the cavities on the left side of the enclosure.

Be careful when soldering inside the enclosure. Your soldering iron will deform the PLA plastic if they come in contact with each other (see the burn mark in the picture below.)

On the inside, you should be able to see all four pins of the pushbuttons. Bend the inner two and join them together with some solder.

Now prepare two resistors and two short piece of wires - approximately 4cm and 5cm respectively - and solder each wire to a resistor.

Then solder each of them to the outer two pins of the pushbuttons. The 4cm wire on the left, 5cm on the right.

To prepare the joystick for soldering/mounting, straighten its legs, bend them 90 degrees outward, and then cut them to about half the length.

Put a little bit of solder on all six pins.  

Make sure the joystick is in the correct orientation. The distance between the top and middle pins should be smaller than the distance between the middle and bottom pins.

Prepare 5 pairs of resistors and short wires (about 8cm each). We'll cut them to the exact lengths needed later.

Solder the five resistors to the five pins on the joystick. Make sure the solder makes firm connections between the resistors and the joystick.

Push the joystick into the square opening. It should be a tight fit. If not, put a little bit of super glue along the seam to fix the joytick in place.

Now push the LED matrix backpack into the largest opening, and use four M2 screws to secure it in place. Make sure that the I2C pins (VCC, GND, SCL, SDA) are near the top of the device.

Solder the two white wires from the pushbutton resistors to the 1st and 2nd pins on the left side of the top LED matrix. 

Then use a yellow wire to connect the joystick to the solder joint between the two pushbuttons, and another to connect the solder joint to the 3rd pin on the left side of the top LED matrix. 

Solder a white wire to each of the resistors on the left side of the joystick, and make the connections shown in the picture above. If the picture looks confusing, please refer to the circuit diagram on the previous page.

Then we can solder the last set of wires to connect the two resistors on the right side of the joystick to the backpack. Again, please refer to the circuit diagram on the previous page if the picture looks confusing.

Now we have the top half of the Tiny Tetris with all components assembled and wires soldered. 

Bottom

Start by putting the Pro Trinket and the PowerBoost 500 Charger into the enclosure. Use a M2 screw to secure the Pro Trinket. Gently push the PowerBoost into the cavity to fix it in place. It should be more or less a friction fit.

Push the SPDT switch into the cavity at the top of the enclosure, and the pushbutton on the right side of the enclosure. You should be able to see the pins of the switch and pushbutton on the inside of the enclosure.

Use three short wires to connect the power lines between the PowerBoost and the Pro Trinket.

Pro Trinket --- Powerboost

  • BAT --- +
  • G --- GND
  • BUS --- USB 

These connections allow us to recharge the battery through the micro USB port on the Pro Trinket in addition to the one on the PowerBoost 500 Charger, and have the Pro Trinket powered by the boosted 5V source from the PowerBoost. 

Then use two more short wires to connect the reset button to the Pro Trinket. 

Connect the RST pin to the left side of the pushbutton, and one of the GND pins to the right side of the pushbutton.

Now connect the EN and GND pins on the PowerBoost to the left and middle pins on the SPDT switch. Be sure to run the wires on the side instead of going straight to the switch. We want to leave some space for the LiPo battery.

Finally we can connect the battery to the JST connector on the PowerBoost to test the circuit. If you slide the SPDT switch to the right, the boost converter will be enabled, and the system will power on. Make sure that you see both the blue LED on the PowerBoost and the green LED on the Pro Trinket light up. 

Also, you can test the reset button as well by pressing the pushbutton and see if the Pro Trinket reset itself.

If everything is working as expected, we can move on to make the connections between the top and bottom half of the Tiny Tetris.

Interconnection

Solder four wires to the I2C pins on the Backpack. The colors I used in the picture above are the same as the ones in the circuit diagram on the previous page.

  • Red: VCC
  • Black: GND
  • Blue: SDA
  • Yellow: SCL

Connect the four wires to the Pro Trinket and PowerBoost as listed below:

  • Red: 5V on the PowerBoost
  • Black: GND on the Pro Trinket
  • Blue: A4 on the Pro Trinket
  • Yellow: A5 on the Pro Trinket

Finally use some super glue to secure the eight magnets to the cavities on the enclosure. Wait for a little bit to allow the glue to dry completely.

The two pieces snap together easily, and we've finally finished the entire assembly process!

Source Code

You can browse the source code on the GitHub repository here

Click the button below to just download the whole thing in a zip file. Uncompress and be sure to change the name of the folder to Mini_LED_Gamer after download.

The code for this project doesn't use any external libraries. Instead of using Wire.h to talk to the HT16K33 chip on the LED Matrix Backpack, it uses the i2c.h for the I2C interface.

The reason is that a timer interrupt is used to both refresh the LED matrix and read the state of all the buttons at approximately 50Hz. However, Wire.h uses the timer interrupt for the I2C interface, and you can't have two timer interrupts running inside of each other. The i2c.h does not use any timer interrupt, thus avoiding the conflict. 

It's a little more advanced but works well!

HT16K33.cpp is similar to the Adafruit_LEDBackpack library, but it works with i2c.h instead of Wire.h, and it not only drives the LED matrix but also checks the state of the pushbuttons.

Tetris.cpp, Snake.cpp, and Paint.cpp are each responsible for an individual program that runs on the Tiny Tetris.

This guide was first published on Sep 04, 2014. It was last updated on Sep 04, 2014.