[go: up one dir, main page]

0% found this document useful (0 votes)
61 views7 pages

Playing Chess Against Arduino

This project simulates the board game of chess using an Arduino Pro Mini and an array of 256 RGB LEDs. The author had to overcome the limited memory of the Arduino by using a specialized LED library. This allowed them to display the chessboard and pieces on the LED matrix. Touch sensors are used to select moves. The software initializes the display, draws the chessboard and pieces, and handles cursor movement and move selection via the sensors. Playing a full game of chess is possible using only the LED display and touch inputs, demonstrating an entirely self-contained chess simulator built with an Arduino.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views7 pages

Playing Chess Against Arduino

This project simulates the board game of chess using an Arduino Pro Mini and an array of 256 RGB LEDs. The author had to overcome the limited memory of the Arduino by using a specialized LED library. This allowed them to display the chessboard and pieces on the LED matrix. Touch sensors are used to select moves. The software initializes the display, draws the chessboard and pieces, and handles cursor movement and move selection via the sensors. Playing a full game of chess is possible using only the LED display and touch inputs, demonstrating an entirely self-contained chess simulator built with an Arduino.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

instructables

Playing Chess Against Arduino

by andrei.erdei

This project has been developed with the “Games” OLED display, I have seen very few projects similar
contest in my mind, I hope you’ll like it and give your to mine that only use RGB LEDs assembly to
vote :) simulate games.

The idea of this project is quite simple. I want to For a first draft of this project, I thought of doing a
simulate as many board games as possible using a simulation of the game Ladders and Snakes, but in
simple electronic assembly. Of course, every game the end I told myself why not do the oldest strategy
with its own software, which must be loaded into the game of all time, played by millions of people, the
simulators microcontroller. Thus, I could simulate game of games, which is Chess. I could have made a
games like: Ludo, Ladders and Snakes, Morris, system that connects to the Internet and takes over
Checkers, a bunch of different dice based games... the moves from a powerful chess program (like for
Nowadays, unfortunately, children have lost interest example stockfish...). I could have used a hybrid
in board games, what attracts them are the computer system like a microcontroller (in the game simulator)
games with the most realistic graphics and audio connected to a Raspberry Pi, I could have entered
effects, that require a large storage space and and displayed the moves on an LCD keypad, as in
dynamic memory. Who knows, maybe working with the micro-Max variant on the Arduino Mega. But no. I
them in carrying out this project, we will be able to was stubborn enough to make a completely
distract them from the computer screens and point autonomous system to play chess on an... * drumroll
them to the basic games. Of course, I am aware that * Arduino PRO MINI and a display made with an
there are many other game projects on Arduino, but array of RGB leds .
most of them are based on the use of an LCD or

Playing Chess Against Arduino: Page 1


Step 1: Overview

However, by using an Arduino Mini Pro I had to for the chess program to work properly, I tried several
overcome a very large obstacle, the 2kb memory limit variants, I tried to maximize the available memory,
of the Atmega328p microcontroller! I found one chess but after the first 4-5 moves the system crashes. So I
engine, by H.G. Muller's micro-Max, ported to the had to use another library, another way to approach
Arduino UNO platform, you can find the complete the problem.
project on Hackaday. As you can see, in this project,
the chess game is displayed on the serial line The most used RGB led display libraries are Fastled
monitor. So you need a computer connected to and Neopixel, but I could not use them because of
Arduino to play. Through my project, the simulator memory problems. Looking for a solution, I came
consists of a display of 256 RGB LEDs, type across a small library that I had never heard of
WS2812 (4 arrays of 8x8 LEDs), where the before, but it seemed to solve the negative aspects of
chessboard and the game pieces appear, and by the mentioned libraries. It is called FAB_LED and you
using touch sensors, you can specify the moves. The can find it here on github. What does this library do?
system is completely independent, we only need a It can display colours in a specific palette, a palette
power source :) 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
In the first phase, I used the FastLed library to drive time). Using this method of palettes and 2-bit colour
the display, * cough cough * but let's do a little bit of coding (4 colours at a time - I only need 2 colours for
math: the colours for each RGB led are composed of the chessboard and 2 colours for the pieces), if we do
one led for each basic colour (red, green, blue) and a bit of math, we will find out that the 256 RGB LEDs
the values of the 3 colours are in the range 0-255 (so will take up 256*2 = 512 bit memory, which means 64
we can have for each led 255*255*255 = 16581375 bytes !!! So we have plenty of memory for the chess
colours). For each RGB led we need 8 bit information program to work.
per basic colour, 24 bits (3 bytes) for the colour
displayed by the RGB led. For 256 RGB LEDs, we In addition to the LED display, I also used 3 touch
need 3*256 = 768 bytes, which occupies 768 bytes of sensors (the project allows up to 8 touch sensors) to
the 2 kbytes memory we have available. It is very, move the "cursor" to the right and forward, and to
very much. We only have 1280 bytes left. I have also select the position. The development board I used is
the program itself that takes up memory with the a 5 Volt Arduino Pro Mini board with the ATMega
various global variables that I used in the program, at 328p microcontroller.
one point I had only 680 bytes available! It's too little

Step 2: Construction

Playing Chess Against Arduino: Page 2


Things needed for the project: - a piece of 165x165 white copier paper sheet;

for the enclosure - 3D printed 165x165mm 16x16 plastic grid;

- wooden photo frame (166x166mm interior- I ordered The enclosure is very similar to that from the VERBIS
mine online from a a frame maker company); - word clock I just didn't use screws for the assembly
but I glued everything with a hot glue gun. The parts
- 165x165mm 3mm grey smoked transparent and the assembly are depicted in the above photos.
plexiglass sheet;

for the electronics one after another they will light up like in the video
bellow, exactly how the connections are made.
- 65x65mm RGB 8x8 LedMatrix - 4 pieces;

- TTP223 capacitive touch sensor modules - at least


3 pieces;
https://www.youtube.com/embed/uy1haPVRbhM

- Arduino Pro Mini module 5v/16Mhz;

- Female DC Conector cable 5.5mmx2.1mm(2.5mm);


But I need to define my LED's in an 2D coordinate
system, I chose the origin to be in the down-left
- 5v/2A Power supply with 5.5mmx2.1mm(2.5mm)
corner, the x axis to be horizontal from left to right and
Male connector;
the y axis from down to up, in the video below you
can see what am I talking about (more at the next
- Some 2.54mm 1 row straight pin (male) header;
step).

- Colored wires;

The schematics are provided below (also between


the photos above), and in the pictures you can see https://www.youtube.com/embed/ebGnmvdKRH4
the assembly during the first testings with an Arduino
Uno.

Like I said I was using in the beginning the FastLed In the last main picture from this step you can see
library and a Led Matrix library for easy of definition of how the final electronic connections looks like.
the 16x16 led's matrix. The arrangement of the four
8x8 matrices must be made like in the image below.

In this way when I want to light up the 256 RGB leds

Playing Chess Against Arduino: Page 3


Playing Chess Against Arduino: Page 4
Playing Chess Against Arduino: Page 5
Step 3: Software

As I said before, to drive the LED display I used the LED_FAB library. I will try to explain what some of the
functions that I used do:

ClearBoard - at every step in the loop every led in the display is initialized to the (1,1,1) RGB color (dark grey), I
thought that the redraw of the chess square model of the board and the redraw of the pieces will be enough to
erase the previous colors but to my surprise not every "pixel" was erased, I don't know why...

DisplayBoard - with this function the square model of a chess table is drawn, using dark grey (1,1,1) and light
grey (8,8,8) colors (codified as 0 and 1 in the palette);

DisplayChessPieces - the name tells the purpose of this function. I thought it would be nice to display the chess
pieces on the board, you can play in this way, or you can use an old magnetic chess set that fits the square
dimensions (you can see how it looks in the main video - next step). The pieces are displayed as below:

Pawn Rook Knight Bishop Queen King

ShowCursor - it displays a flashing square of 4 pixels (it changes the four individual leds color of the square) on
the board and because it is called every 60 milliseconds, the flashing frequency is rather low

ShowMove - it displays 2 flashing squares, it is called every 20 milliseconds, so the flashing frequency is rather
high

buttonRIGHT, buttonUP - takes the touch sensors signal and updates the cursor position

buttonOK - it selects the start and the end position of the human moves but also continues the game after the
machine moves are shown

XY - transforms the x,y position into a led number on the display

The other functions are used by the chess engine..

I uploaded the code on github, you can download and program your own Arduino Pro Mini ChessMaster :)

Playing Chess Against Arduino: Page 6


Step 4: GamePlay

As you saw in the code, the serial monitor is not recommended the next moves depending on a certain
used, so you can rely only on the chessboard's visual position. Of course, micro max was going to be
feedback. But essentially, you need to move with the defeated this way but I thought that it handled the
RIGHT and UP touch sensors the slowly blinking task more than honorably (micro-Max is accounted
cursor under the chess piece that you want to move, with ELO of about 2000, which is not too bad).
select with the OK touch sensor the starting point, the
cursor will start blinking much faster, move the cursor What is still missing from the gameplay is the fact that
to the final move point in the same way again, and it does not show an illegal move more visibly (now,
select with the OK button. Make your move with the the actual program does not make the move and only
physical chess piece (if you are using a chess set) the cursor appears in the initial position) and also the
and touch the OK button. Your move will be made, fact that is does not signal the loss or gain of the
the machine will make its move, and you will see the game (the program simply stops).
move shown by two fast blinking squares. Move the
machine's physical chess piece (if you are using a However, in this state the game board is very well
chess set). Press OK and you can continue the suited for understanding chess and its rules by
game. That's it. It seems a little bit complicated but children.
after a little time you will get used to it. In the video I hope as many of you will try to build this project and
above, I filmed a short game. I am a very weak chess give it as much satisfaction as possible.
player so I admit that I cheated. I used a site that

https://youtu.be/b8A6UThnWm0

it's a good circuiting! i will try it.

Such an awesome projects, I will try to make this one day.

Thank you.

Playing Chess Against Arduino: Page 7

You might also like