RPi Chessboard
This is a stand-alone chess computer project using magnetic sensors, LEDs, and a Raspberry Pi Zero 2W.
Hardware
This hardware is based on a magazine article "An Electronic Chessboard Using RGB Strips and Hall Effect Sensors", published in the January 2017 issue of "Nuts & Volts". The PCB was ordered from the ExpressPCB manufacturing service without any modifications.
Hardware changes made to the magazine article project:
The clear acrylic sheet was replaced by a 12"x12" transparent grey acrylic sheet.
The acrylic sheet was etched with a checkerboard pattern using an Epilog Helix 24 at the Ottawa Public Library's Imagine Space. See "RPiChessboard.svg" and "RPiChessboard.pdf" in the files section below.
The discontinued Teensy 3.1 was replaced with a Teensy LC. Unfortunately, the Teensy LC has also recently become unavailable. I hope to update this project to use a different microcontroller in the future.
A Raspberry Pi Zero 2 W without header was mounted to an available area of the PCB using nylon standoffs and screws.
Added 5 wires to connect:
RPi pin 4 (5V) to PBC +5V
RPi pin 6 (ground) to PCB ground
RPi pin 8 (UART Tx) to Teensy pin 9 (RX2)
RPi pin 10 (UART Rx) to Teensy pin 10 (TX2)
Teensy pin 1 (TX1) to Teensy pin 11 (the Nuts & Volts project uses pin 11 to drive the LEDs, but my project requires the WS2812Serial library, which needs pin 1 to drive the LEDs)
Software
Teensy LC
The magazine article includes Teensy software appropriate for a chess game played between two human opponents. The LEDs indicates legal moves to help novice players. But I wanted a chessboard that lets a human compete against a computer opponent. The Teensy did not have enough resources to play a competant game of chess, hence the need for a Raspberry Pi running PicoChess software.
PicoChess can connect to a variety of commercial chessboards. To allow PicoChess to work with this chessboard, I wrote a sketch that implements the protocol used by the DGT Revelation II.
Here are the steps to load the sketch on the Teensy:
Download "RPiChessboard.hex" from the "Files" section below.
Install Teensy Loader on your MacOS, Linux, or Windows computer.
Run Teensy Loader.
Select menu "File", "Open HEX File".
Select the "RPiChessboard.hex" file you downloaded earlier.
Connect the Teensy to your computer via USB.
Select menu "Operation", "Program".
If you wish to connect the Teensy to your computer via USB while the Teensy is connected to the PCB, you should first cut a trace to disable USB power. On the bottom of the Teensy, look for two equal-sized and closely-spaced rectangular pads near the "VUSB" label. Press down on a sharp blade to score the board between the two pads and cut the tiny trace between them. Now the Teensy will only be powered by the PCB only, not by USB.
If you wish to modify the sketch, download "RPiChessboard.ino" from the "Files" section below. Load the sketch into Teensyduino variant of the Arduino IDE. It is also necessary to install the WS2812Serial library to run this sketch.
Raspberry Pi Zero 2 W
Here are the steps to configure the RPi:
Download PicoV3.2DGTPiLite.img.7z and uncompress.
Write PicoV3.2DGTPiLite.img to a 32GB SD card using balenaEtcher or similar.
Plug the SD card into the RPi.
Connect a monitor to the RPi mini HDMI port.
Connect a keyboard to the RPi USB port.
Connect power to the RPi.
Login using the monitor and keyboard:
Raspbian GNU/Linus 11 picochess tty1
picochess login: pi
password: picochess
Configure Wi-Fi, enable SSH, and enable the serial port:
$ sudo raspi-config
Select "6 Advanced Options"
Select "AA Network Config"
Select "2 NetworkManager"
Select "1 System Options"
Select "S1 Wireless LAN"
Enter your Wi-Fi SSID
Enter your Wi-Fi password
Select "3 Interface Options"
Select "I2 SSH"
"Would you like the SSH server to be enabled?" - select "Yes"
Select "3 Interface Options"
Select "I6 Serial Port"
"Would you like a login shell to be accessible over serial?" - select "No"
"Would you like the serial port hardware to be enabled?" - select "Yes"
Select "Finish"
"Would you like to reboot now?" - select "Yes"
After the RPi reboots, login again.
Check whether the Wi-Fi is working, and get your IP address (highlighted below, yours will be different):
pi@picochess:~ $ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 11 bytes 1647 (1.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11 bytes 1647 (1.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.18 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a6af:e447:4ba3:9e4a prefixlen 64 scopeid 0x20<link>
ether d8:3a:dd:3f:0e:20 txqueuelen 1000 (Ethernet)
RX packets 179 bytes 41858 (40.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 105 bytes 15379 (15.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Check whether the Picochess web interface is working using a browser:
Check whether SSH is working using a Windows "cmd" or MacOS "terminal" window:
ssh pi@192.168.1.18
password: picochess
You can switch to using SSH for the remaining steps if you wish
Edit the Python code to allow a DGT Revelation II to connect via a USB serial port:
$ sudo nano /opt/picochess/dgt/board.py
At line 231, add these 2 lines:
if self.device.find('rfc') == -1:
text_l, text_m, text_s = 'USB e-Board', 'USBboard', 'ok usb'
self.channel = 'USB'
self.is_revelation = True
Rev2Info.set_revelation(self.is_revelation)
else:
Be sure to indent the new lines to match the lines above them. Save the change.
Edit the PicoChess configuration to enable the serial port and change the chess engine:
$ sudo nano /opt/picochess/picochess.ini
At line 52, change 1 line:
#dgt-port = /dev/ttyACM0
dgt-port = /dev/ttyS0
At line 62, delete 1 line:
dgtpi = True
At line 77, change 1 line:
engine = /opt/picochess/engines/armv7l/NNUE/StockfishNN
engine = /opt/picochess/engines/armv7l/ct800
While Stockfish works on a RPi 4 or 5 with 2+ GB RAM, ct800 is a better choice for the RPi Zero 2W with 512 MB RAM.
Save the changes and reboot:
$ sudo reboot
With luck, you should now be able to place the chess pieces in their initial position and make a move to start the game.