Embedded Chess
Chess engine and game running on a fully embedded system.
Author: Oprea IonuΘ-Georgian
GitHub Project Link: https://github.com/UPB-PMRust-Students/project-mas-vi
Descriptionβ
This project implements a fully functional chess game designed to run on the resource-constrained Raspberry Pi Pico microcontroller. It integrates a custom-developed chess engine with a user interface (UI) displayed on an external LCD. User interaction is primarily handled through a connected keyboard, allowing players to navigate menus, select pieces, and input moves.
Features:β
- Game Mode Selection: Upon startup, the system presents a main menu on the connected LCD, allowing users to select between two distinct game modes: Player vs Player (PvP) for two human competitors, or Player vs AI (PvAI) where a single human challenges the integrated computer opponent. Users navigate this menu using designated keyboard inputs.
- Integrated Chess Engine: The core of the game is the custom-built chess engine, responsible for rigorous move validation according to standard chess rules (including special moves like castling and en passant) and, in PvAI mode, generating strategic moves for the computer opponent.
- Auditory Feedback (Buzzer): A piezoelectric buzzer provides distinct auditory cues for validating keyboard input.
- Turn Indication (LEDs): Two dedicated LEDs provide a clear visual indication of whose turn it is to move, the Blue LED indicating White's turn while the Red LED corresponds to Black's turn.
Motivationβ
I choose this project as I am passionate about chess and wanted to see the extent to which a chess engine could run on a mirco controller. I knew this involved a lot of optimization and wanted to take the challange.
Architectureβ
Architecture:β
Game Loop:β
Logβ
Week 6 - 12 Mayβ
- All the necessary components for the project, which had been ordered previously, were received.
- The various hardware components were assembled and connected together according to the project design.
- Initial testing was conducted on the core chess engine logic and the main game loop, which were developed prior to the arrival of all physical components.
- The game is currently in a functional state, allowing for gameplay, but requires the implementation of algorithms to enhance optimal piece selection logic.
- The project development log and related documentation were updated to reflect the recent progress and changes.
Week 7 - 19 Mayβ
- Ongoing development continued focused on refining the optimal piece selection algorithms.
- The project log and accompanying documentation specifically for the Hardware Milestone were updated and expanded upon to include more detailed information.
- The electronic scheme within the KiCad project files was updated to reflect the current hardware configuration.
- Completion of the physical hardware assembly and setup was achieved.
Week 20 - 26 Mayβ
- The move generation system is now fully implemented and thoroughly tested, accurately identifying all best moves.
- The project has been brought to its final, stable form after comprehensive bug fixes and refinements.
- Created the 3D encasing that makes the project look and behave like a game console.
- All project documentation and the repository's README have been updated to reflect the current state.
Hardwareβ
Picturesβ
Components Usageβ
For the project, the following were used:
- A Raspberry Pi Pico 2W serves as the central processing unit for the entire system. It is responsible for rendering the game state and interface graphics onto the LCD, polling input from the MPR121 Keyboard Module, controlling the Active Buzzer Module for auditory feedback, managing the game loop, and executing the complex logic of the integrated Chess Engine.
- The ILI9341 LCD 240x320 Display is used to display the game board, piece positions, menu options for game mode selection, and other relevant graphical user interface (GUI) elements to the user.
- The MPR121 Keyboard Module acts as the main input interface for the user. It processes signals from a connected capacitive touch keypad translating key presses into data that the Pico can interpret for navigating menus, selecting chess pieces, and specifying move destinations.
- The Active Buzzer Module the active buzzer module is integrated into the system specifically to provide immediate auditory feedback to the user. Its primary intended use is to emit a confirmation tone or signal upon successful detection of a key press.
- The Two Leds are utilized as simple but effective visual indicators. They are wired and controlled by the Pico to clearly show which player, either White or Black, currently has the turn to make a move.
Component Connectionsβ
-
ILI9341 LCD 240x320 Display
- Interface: SPI (SPI0)
- PIN Connections:
- GND: GND
- VCC: 3.3V
- CLK: PIN_2
- MOSI: PIN_3
- MISO: PIN_4
- RES: PIN_6
- DC: PIN_7
- CS: PIN_8
-
MPR121 Keyboard Module
- Interface: I2C (I2C1)
- PIN Connections:
- GND: GND
- VCC: 3.3V
- SCL: PIN_15
- SDA: PIN_16
-
Active Buzzer Module
- Interface: GPIO
- PIN Connections:
- GND: GND
- VCC: 3.3V
- S: PIN_16
-
Blue Led:
- Interface: GPIO
- PIN Connections:
- CATHODE: GND
- ANODE: PIN_11
-
RED Led:
- Interface: GPIO
- PIN Connections:
- CATHODE: GND
- ANODE: PIN_12
Schematicsβ
Bill of Materialsβ
Device | Usage | Price |
---|---|---|
Raspberry Pi Pico 2W | The microcontroller | 40 RON |
SPI LCD Module | The Display | 70 RON |
MPR121 Module with Keypad | Capacitive Touch Sensor | 30 RON |
Active Buzzer Module | Used to signal touch | 5 RON |
Blue Led | Blue Led | 0.29 RON |
Red Led | Red Led | 0.39 RON |
Male-Male Wires | Connection Wires | 5 RON |
Breadboard Power Supply | Power Supply | 5 RON |
Breadboard | Breadboards for Components connection | 2 x 12 RON |
220 Ξ© Resistor | Voltage Dividers | 2 x 0.10 RON |
Debug Probe | Software Debugging on the Pico | 67 RON |
Softwareβ
Library | Description | Usage |
---|---|---|
cortex_m_rt | A runtime crate for ARM Cortex-M microcontrollers | Provides the necessary entry point (#[entry]) and minimal runtime environment for the application to start and run on the Cortex-M0+ core of the Raspberry Pi Pico |
ili9341 | A hardware abstraction layer (HAL) driver crate for interfacing with the ILI9341 TFT LCD controller via SPI | Used to handle low-level communication with the physical ILI9341 display hardware |
embedded-graphics | A 2D graphics library providing traits and drawing primitives for embedded systems | Utilized for defining and creating graphical elements such as points, lines, rectangles, text, and colors (like Rgb565). These elements are then rendered to the display via the ili9341 driver |
embedded-alloc | The Rust standard library's allocation APIs and collection types, re-exported for use with a custom global allocator in no_std | Provides essential data structures that require dynamic memory allocation |
mpr121-hal | A Hardware Abstraction Layer (HAL) driver for the MPR121 capacitive touch sensor controller, typically using I2C | Employed to interface with the MPR121 module over the I2C bus, allowing the system to read the state of the capacitive touch electrodes and interpret them as keyboard input. |
embedded-canvas | A library that provides a canvas abstraction over embedded-graphics for more structured drawing operations | Used to create a drawing surface or context (Canvas) on top of the embedded-graphics framework |
defmt | A firmware debugging and logging framework optimized for embedded systems | Used (info!, panic!) for structured logging and debugging output, typically routed via defmt_rtt to a host computer, aiding in development and troubleshooting |
embassy_rp | A Hardware Abstraction Layer (HAL) for the Raspberry Pi RP2040 microcontroller, built for the Embassy framework | rovides high-level, asynchronous drivers and APIs for the RP2040's peripherals, including GPIO (gpio), I2C (peripherals::I2C1), and SPI (spi), used to interact with the connected hardware |
embassy_embedded_hal | Provides implementations of the embedded-hal traits built on top of Embassy's asynchronous drivers | Specifically, shared_bus::blocking::spi::SpiDevice is used here to create a concrete SPI device instance suitable for use with the ili9341 driver, potentially allowing the SPI bus to be shared |