Skip to main content
Version: FILS English

Poker Game

A poker game against an AI using rust and the Raspberry Pi Pico 2

info

Author: Ciortan Rares-Sebastian
GitHub Project Link: https://github.com/UPB-PMRust-Students/project-troly69

Description

Pocket Poker is a single-player Texas Hold'em-style poker game that runs entirely on a Raspberry Pi Pico 2W, using a 1.8" SPI TFT LCD for the displays and push buttons for input. The game allows the player to go head-to-head against a simple AI dealer, simulating betting rounds, card dealing, and hand evaluation. All logic and graphics are written in Rust, demonstrating how embedded systems can be used for interactive, game-like applications without requiring internet or external screens.

Motivation

I wanted to create something more interactive and fun than traditional embedded projects. Poker is a great balance of logic, randomness, and user interface work. This project is a chance to explore Rust for embedded systems, work with SPI-based LCDs, and implement game logic on limited hardware.

Architecture

Architecture Diagram

Raspberry Pi Pico 2W: Acts as the main controller. Runs the game logic written in Rust. Communicates with the displays via SPI and handles button input through GPIO. -Connection: Communicates with the display via SPI and handles button input through GPIO.

Buttons: Used for player inputs (Check,Bet,Fold). -Connection: Each button is connected to a GPIO pin with pull-down resistors for clean signals. Displays: Used to show the table cards, your cards, balance of both players/game state. -Connection: Connected via SPI (MOSI and CLK), plus control pins (CS, DC, RST).

Log

Week 5-11 May

In this week I mostly made the documentation, containing the description, motivation, architecture showing how it would work more or less, the start of the hardware section, bill of materials, list of software i might use, and some links to websites.

Week 12-18 May

This week I finished building the hardware, bought a few more items I needed and updated the documentation with the kicad schematic, a photo of the hardware built and added the hardware i bought to the bill of materials. I tested to see if the displays were connected properly and they were fine.

Week 19-25 May

For the last week, i started creating the software. It went well for the most part, but had a few issues with making the lcd displays work. In the end, with a bit of help, i managed to make them work, while still encountering some problems that I solved in the meantime. I pushed the code when i remembered, usually after making a big change or adding something important. Making the software for the poker game wasn't necessarily complicated, but it just took a long time, i spent basically all of my weekend and a few hours each day trying to make the game work. What i managed to make is a display that shows one of my cards, one that shows the other card, and the last one that shows the flop, turn and river cards when i press the check button. at the end of the turns, the opponent(programmed him to recieve cards too) would have his hand revealed on the display, and in vscode I show the pairs we each had, who won and what ammount of money bet you recieved. I made three types of buttons with different functions: the CHECK button witch I already talked about, the BET button which allows me to bet a fixed amount of money and a fold button, which basically starts a new game. Also the money you have in the bank remains in between games, until you restart the software.

Hardware

The hardware consists of a raspberry pi pico 2W microcontroller as the core unit, around 3 displays used for displaying the cards, balance etc. , buttons for checking, folding, betting.

Schematics

Kicad Hardware1 Hardware2

Bill of materials

DeviceUsagePrice
Raspberry Pi Pico 2WThe microcontroller[40 RON]
Wireless Super Starter Kit with ESP8266 (Programmable with Arduino IDE)Kit[65 RON]
Modul LCD SPI de 1.8"(128x160)LCD Display[29 RON]
Ecran OLED 0.96" cu interfata IIC/I2COLED Display[19 RON]
LCD de 1.44'' pentru STC, STM32 și Arduino (5 V)LCD Display[35 RON]
[Breadboard]Connectivityin kit
[Buttons] X3Game Inputsin kit
[Jumpers]Connectivityin kit
[Resistors(10K)]Connectivityin kit
breadboard HQConnectivity[5 RON]
Raspberry Pi PicoDebugger[23 ron]
TOTAL: 225 RON.

Software

Library / ToolDescriptionUsage
randRandom number generationUsed to shuffle the deck with entropy from GPIO and time
embassy-rpHardware Abstraction Layer for the RP2040Access to SPI, GPIO, timers, clocks, etc.
embedded-halEmbedded hardware abstraction traitsInterface between display/button drivers and hardware
panic-probePanic handler that logs panics with defmtEnsures panics are displayed via defmt instead of crashing silently
embedded-graphics2D graphics library for embedded displaysDraws text, shapes, cards, etc. on screen
defmtLightweight logging framework for embedded systemsFor logging debug messages (e.g. hand results, chip updates) to the terminal via info!
defmt-rttReal-time target transport for defmt logs over RTTEnables defmt logs to be printed during runtime on the host
embassy-timeAsync timers for Embassy frameworkUsed for timing delays (e.g. waiting between game stages or animations)
embedded-timeTime units and delays for embeddedUsed for timing animations or button debounce
embassy-syncMutexes and sync primitives for shared peripheralsUsed to share the SPI bus safely between tasks
'embassy-embedded-hal'Adapters for using Embassy with embedded-halProvides shared bus support for SPI with SpiDevice
ssd1306Driver for SSD1306 OLED displays using I2CControls your OLED screen to display game state (cards, messages)
mipidsiDriver for MIPI-compliant displays like ST7735Controls the two ST7735 SPI LCD screens to show player cards
heaplessProvides Vec, String, etc., without dynamic memoryUsed for storing cards, formatting text, and tracking hand ranks without a heap
  1. [Texas Hold'em rules] (https://casinos.lotoquebec.com/dam/jcr:c49e36e5-1e3d-4123-ae10-e7250d837140/Regles_Ultimate-Texas-Holdem_e.pdf)
  2. [embedded-graphics] (https://github.com/embedded-graphics/examples)
  3. [Rust on Raspberry Pi Pico Guide] (https://github.com/knurling-rs/app-template)