The DIY Super Smart Chessboard Lets You Play Online Against an Opponent or a Raspberry Pi

See how Lewis from DIY Machines built this smart chessboard that allows for both remote and local play.

The Idea

Due to the pandemic, many people have been forced to stay indoors far more often, which means missing out on the usual social events, including sports and tournaments. Even playing a simple game of chess at the local makerspace against an opponent hasn't been doable- until now. Growing from his increasing boredom, Lewis over at DIY Machines designed and put together his own way to still play a physical game of chess, but remotely.

Some Amazing Features

The chessboard's surface is composed of a grid of translucent squares that alternate between white and gray with RGB LEDs underneath that can independently illuminate each position on the board. This is used primarily to see if the move a player is making is valid, along with checking the range of possible moves a piece can make, or for giving a hint about where to move next. The intelligence comes from the open-source chess engine Stockfish, which is what runs the game and computes moves. And that's ignoring the main draw: remote play. By connecting two of these devices over the internet, a pair of opponents can play against each other live, with the squares lighting up when the opponent makes a move.

Components Used

The parts used in the chessboard are surprisingly simple:

  • 86 WS2812B LEDs (aka NeoPixels)
  • 10 tactile momentary pushbuttons
  • An Arduino Nano for handling the I/O
  • A Raspberry Pi Zero or 3 A+ for more computing power
  • A logic level shifter
  • A 0.96in OLED screen for viewing moves and instructions
  • Miscellaneous hardware for the enclosure

Wiring

The WS2812B strip is split into 3 different sections. One is for illuminating the squares themselves, and it gets its data from one pin on the Nano, whereas the LEDs for the control panel and grid markers are chained together off of another pin. All of the momentary pushbuttons are connected in a matrix and attached to the Arduino Nano. Finally, the Nano is joined to the Pi via UART and the OLED is controlled over the Pi's I2C port. The whole thing is powered from a single Micro USB connection, making it extremely portable.

The Chess Engine

Stockfish is one of the world's leading chess engines, and combined with its open-source nature and readily-available apt package, it was an obvious choice for this project. Because it lives within a CLI process, the Python program Lewis wrote uses the subprocess.Popen class to run a new process and assign it to a variable called engine. With this, the program can call engine methods such as stdin.write and stdout.readline to move data to and from the process. The whole game is run by either sending player moves in and getting results back for multiplayer or also reading computer moves for single player.

How Online Play Works

To enable remote player between two of the smart chessboards, Lewis chose to use AdafruitIO as the broker. This lets both devices enroll in a pub/sub model, where each can publish their message (normally a move) to the service and then the other can receive it from its subscription.

The players' turns alternate automatically, and the data from the opponent is fed into stockfish on both sides to ensure the game is consistent between the two clients.

Playing Chess

To begin playing in multiplayer, the two devices are bonded by using the same AdafruitIO credentials. They negotiate which goes first based on the color chosen for each device. Moves are entered into a small keypad on the bottom left that correspond to a "from" position and a "to" position. The selected move will light up on the board in green if it's valid, or red if it's not.

Playing in single player mode is doesn't require internet access, which is a bonus for when it's being taken somewhere else. After selecting the "Against PC" option, the user can then choose the difficulty from 0 up to 8, along with the computer's move time. Helpful messages appear on the OLED to instruct the player, along with large letters on the chessboard's grid to symbolize the current configuration step.

Building Your Own

Nearly all of the pieces used within this project are 3D-printable, including the chess pieces themselves and the board. You can view the detailed instructions Lewis wrote here, along with the Github repository for the code and the 3D-printable parts over on Thingiverse.

Arduino “having11” Guy
19 year-old IoT and embedded systems enthusiast. Also produce content for Hackster.io and love working on projects and sharing knowledge.
Related articles
Sponsored articles
Related articles