This project has been developed with the “Games” contest in my mind, I hope you’ll like it and give your vote 🙂
The idea of this project is quite simple. I want to simulate as many board games as possible using a simple electronic assembly. Of course, every game with its own software, which must be loaded into the simulators microcontroller. Thus, I could simulate games like: Ludo, Ladders and Snakes, Morris, Checkers, a bunch of different dice based games… Nowadays, unfortunately, children have lost interest in board games, what attracts them are the computer games with the most realistic graphics and audio effects, that require a large storage space and dynamic memory. Who knows, maybe working with them in carrying out this project, we will be able to distract them from the computer screens and point them to the basic games. Of course, I am aware that there are many other game projects on Arduino, but most of them are based on the use of an LCD or OLED display, I have seen very few projects similar to mine that only use RGB LEDs assembly to simulate games.
For a first draft of this project, I thought of doing a simulation of the game Ladders and Snakes, but in the end I told myself why not do the oldest strategy game of all time, played by millions of people, the game of games, which is Chess. I could have made a system that connects to the Internet and takes over the moves from a powerful chess program (like for example stockfish…). I could have used a hybrid system like a microcontroller (in the game simulator) connected to a Raspberry Pi, I could have entered and displayed the moves on an LCD keypad, as in the micro-Max variant on the Arduino Mega. But no. I was stubborn enough to make a completely autonomous system to play chess on an… * drumroll * Arduino PRO MINI and a display made with an array of RGB leds .
Step 1: Overview
However, by using an Arduino Mini Pro I had to overcome a very large obstacle, the 2kb memory limit of the Atmega328p microcontroller! I found one chess engine, by H.G. Muller’s micro-Max, ported to the Arduino UNO platform, you can find the complete project on Hackaday. As you can see, in this project, the chess game is displayed on the serial line monitor. So you need a computer connected to Arduino to play. Through my project, the simulator consists of a display of 256 RGB LEDs, type WS2812 (4 arrays of 8×8 LEDs), where the chessboard and the game pieces appear, and by using touch sensors, you can specify the moves. The system is completely independent, we only need a power source 🙂
In the first phase, I used the FastLed library to drive the display, * cough cough * but let’s do a little bit of math: the colours for each RGB led are composed of one led for each basic colour (red, green, blue) and the values of the 3 colours are in the range 0-255 (so we can have for each led 255*255*255 = 16581375 colours). For each RGB led we need 8 bit information per basic colour, 24 bits (3 bytes) for the colour displayed by the RGB led. For 256 RGB LEDs, we need 3*256 = 768 bytes, which occupies 768 bytes of the 2 kbytes memory we have available. It is very, very much. We only have 1280 bytes left. I have also the program itself that takes up memory with the various global variables that I used in the program, at one point I had only 680 bytes available! It’s too little for the chess program to work properly, I tried several variants, I tried to maximize the available memory, but after the first 4-5 moves the system crashes. So I had to use another library, another way to approach the problem.
The most used RGB led display libraries are Fastled and Neopixel, but I could not use them because of memory problems. Looking for a solution, I came across a small library that I had never heard of before, but it seemed to solve the negative aspects of the mentioned libraries. It is called FAB_LED and you can find it here on github. What does this library do? It can display colours in a specific palette, a palette that can be encoded in 8 bits (256 colours at a time), 4 bits (16 colours at a time) and 2 bits (4 colours at a time). Using this method of palettes and 2-bit colour coding (4 colours at a time – I only need 2 colours for the chessboard and 2 colours for the pieces), if we do a bit of math, we will find out that the 256 RGB LEDs will take up 256*2 = 512 bit memory, which means 64 bytes !!! So we have plenty of memory for the chess program to work.
In addition to the LED display, I also used 3 touch sensors (the project allows up to 8 touch sensors) to move the “cursor” to the right and forward, and to select the position. The development board I used is a 5 Volt Arduino Pro Mini board with the ATMega 328p microcontroller.
Step 2: Construction
Things needed for the project:
for the enclosure
– wooden photo frame (166x166mm interior- I ordered mine online from a a frame maker company);
– 165x165mm 3mm grey smoked transparent plexiglass sheet;
– a piece of 165×165 white copier paper sheet;
– 3D printed 165x165mm 16×16 plastic grid;
The enclosure is very similar to that from the VERBIS – word clock I just didn’t use screws for the assembly but I glued everything with a hot glue gun. The parts and the assembly are depicted in the above photos.
for the electronics
– 65x65mm RGB 8×8 LedMatrix – 4 pieces;
– TTP223 capacitive touch sensor modules – at least 3 pieces;
– Arduino Pro Mini module 5v/16Mhz;
– Female DC Conector cable 5.5mmx2.1mm(2.5mm);
– 5v/2A Power supply with 5.5mmx2.1mm(2.5mm) Male connector;
– Some 2.54mm 1 row straight pin (male) header;
– Colored wires;
The schematics are provided below (also between the photos above), and in the pictures you can see the assembly during the first testings with an Arduino Uno.
Read more: Playing Chess Against Arduino