Skip to content

shuki25/smart-chessboard-upython

Repository files navigation

Smart Chessboard - Micropython

Introduction

This is a micropython project for the ESP32. It is a chessboard with a sensors that sense the position of the pieces. It is an embedded system project.

It uses API endpoints to communicate with the server, sending the position of the pieces and receiving the moves to be made. The moves are generated by stockfish, a chess engine.

Hardware

Software

  • Micropython
  • Stockfish
  • API endpoints

Miscellanous

Python dependencies

Install the following python dependencies necessary to upload the code to the ESP32:

pip install -r requirements.txt

Installing Micropython on ESP32

  • Download the latest version of nightly builds Micropython firmware (fixes a particular bug that the chess program depends on) from here. The controller board is an ESP32-ROVER-E with SPIRAM for additional memory to run the chess program. So the firmware to download would be a file that resembles the following filename from the nightly builds download repository: esp32spiram-YYYYMMDD-unstable-v1.19.1-xxx-xxxxxxxxx.bin.
  • Download the latest version of esptool from here. This tool will flash the MicroPython firmware to the ESP32 chip. esptool.py is part of requirements.txt and should already been installed if you followed the instructions above.

Program your board using the esptool.py program, found here.

If you are putting MicroPython on ESP32 for the first time then you would first erase the entire flash using:

esptool.py --chip esp32 --port /dev/cu.usbserial-0001 erase_flash

From then on program the firmware starting at address 0x1000:

esptool.py --chip esp32 --port /dev/cu.usbserial-0001 --baud 460800 write_flash -z 0x1000 <es>.bin

Bytecode compilation

Due to large size of the chess program, it is necessary to compile them into bytecode and stored in the bytecode-complied folder. The repository includes bytecode compiled scripts to be uploaded to micropython. If you are modifying some of the scripts, you would need to re-compile the scripts by running a script in the src folder. The script will compile all the scripts in the src folder and store them in the bytecode-complied folder. The script is compile-project. To run the script, run the following command (MacOS or Linux) in the top level directory of the repository:

cd src
./compile-project

or run the following command on Windows:

cd src
./compile-project.ps1

Running unit tests

The repository includes unit tests for the chess program to ensure the validity of the game rules and logic. The unit tests are written using the pytest module. To run the unit tests, run the following command in the top level directory of the repository:

python -m pytest -v

Installing this project

  • Clone this repository to your computer
  • Install Thonny IDE
  • Copy the files in the bytecode-compiled folder to the ESP32 board
  • Connect your ESP32 to WiFi to be able to install the dependencies
  • Install dependencies using mip after dropping into the micropython interactive shell (REPL)
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('your-ssid', 'your-password')
sta_if.isconnected()
import mip
mip.install("ssd1306")

After installing the dependencies, you can upload the files in the bytecode-compiled folder to the ESP32 board via Thonny IDE or other tools. The files in the bytecode-compiled folder are the compiled scripts that are ready to be uploaded to the ESP32 board. However, the scripts boot.py and main.py are not compiled. They are the scripts that are executed when the ESP32 board is powered on. The boot.py script is executed first and the main.py script is executed after the boot.py script is executed. The boot.py script is responsible for the ESP32 startup and the main.py script is responsible for loading and running the chess program.

Installing the Nextion display firmware

Two ways to install the Nextion display firmware

  1. Using the Nextion Editor
  • Download the latest version of the Nextion Editor
  • Upload the smart-chessboard.tft file to the Nextion display using the Nextion Editor software
  1. Using the Nextion Uploader

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages