Architecture
There are 3 software components in the system:
- Arduino firmware for driving the WS2812 LED stripes
- ESP8266 firmware (Arduino sketch)
- Python scripts for the Raspberry Pi
This image gives an overview of the system:
WS2812
There exists an option to directly drive the WS2812 LEDs from a Pi with the dpi_ws281x library. But I decided to use an Arduino, so it is possible to use the LEDs even during the Pi's boot process or without booting the Pi. Arduino and Pi communicate via UART at a speed of 500kbit/s, which is quite enough for a smooth gameplay.
Text display
The MAX7219-Matrix displays (e.g. available at eBay or direct china import) are driven by a great existing library, which provides text scrolling and direct pixel access via Python. I used four 8x8 matrix displays in a cascaded setup. For the Tetris highscore display, I build my own small font for 6 digits and enough space for displaying the next piece for the game. 6 digits are needed to realize the original Gamboy Tetris scoring.
Audio
There is an integrated speaker driven by a mono amplifier (from Adafruit), which is connected to the analog audio output of the Pi.
Raspberry Pi
The Raspbian distribution includes a set of Python games in the folder python_games (doc of Python Games) which are based on the pygame lib. I replaced this library by my own display driver to directly drive the 20x10 LED matrix, but reused the gameplay for Tetris and Snake. For development purpose, I wrote a simulation version which still uses the pygame lib to write and test the code on a PC/Mac before transferring it to the Pi. Some screenshot of the simulator:
There is also a simulator for the controller using the arrow keys of the PC to control the simulator or the LED matrix
I will publish all the code soon after some code cleanup.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.