BlackJack Machine
A singleplayer card game powered by a Raspberry Pi Pico 2 and Rust.
Author: Stavăr Laurențiu-Cristian
GitHub Project Link: https://github.com/UPB-PMRust-Students/proiect-StavarLaurentiu
Description
A fully interactive BlackJack game machine built on a Raspberry Pi Pico 2 - RP2350A, using the Rust programming language and Embassy async framework.
Features:
- Uses three buttons for game actions: HIT, STAND and START GAME.
- Displays dealer and player cards across 8 OLED 0.96" screens.
- Includes 1 OLED 0.96" display dedicated to real-time game state messages.
- Uses 2 RGB LEDs to indicate turns and round outcomes.
- Utilizes a TCA9548A I2C multiplexer to manage identical OLED addresses.
- Executes full BlackJack logic: card drawing, user input, dealer logic, and win conditions.
Motivation
This project combines microcontroller programming, real-time interaction, and game logic design. My goal was to build something fun and visually interactive, while pushing the limits of what I learned in embedded systems and Rust. The integration of I2C multiplexing, OLED control, and user inputs made this an ideal project to consolidate theory into a challenging and rewarding practical application.
Architecture
The Raspberry Pi Pico 2 - RP2350A acts as the central unit, managing peripherals and orchestrating the game flow.
- Buttons (GPIO): detect user input (HIT / STAND / START GAME).
- RGB LEDs (PWM): blink or hold to indicate whose turn or the round outcome.
- 9 OLED Display 0.96"s (I2C): show player/dealer cards and the game state.
- TCA9548A I2C MUX: used to route communication between the Pico and the OLEDs sharing the same I2C address.
Game Flow Summary:
- Startup: OLED instructs user to press START.
- Dealer draws 2 cards – LED blinks – game state updates.
- Player draws 2 cards – LED blinks – game state updates.
- Player phase: can HIT (get card) or STAND (end turn).
- If player busts: game ends.
- Else: dealer draws to at least 17.
- Compare scores: show result and reset after 5 seconds.
LED & OLED Usage
- Blinking LEDs indicate active turn.
- Solid yellow LED indicates winner or draw.
- OLEDs visually show each card and game progress.
Block Scheme
Log
Week 5 – 11 May
Finished the setup. Implemented buttons and LEDs functionalities. Also made the Game State OLED work properly.
Week 12 – 18 May
Implemented all the game logic(cards, deck, hands, state, etc). Started working with the I2C MUX and the 8 OLEDs for the cards display. The only thing left to do is showing the cards on the OLEDs(they are already working).
Week 19 – 25 May
Added 2D cards images display functionality. Finished the README. Updated the list of libraries that I used(I deleted some of them that I ended up not using). Also updated Cargo.toml file. Refactored the code. Deleted dead code and fixed some warnings.
Hardware
-
Raspberry Pi Pico 2 - RP2350A
- Main microcontroller; handles game logic, I2C communication, and peripheral control.
-
2 Push Buttons (HIT & STAND)
- User input; GPIO with pull-ups.
-
2 RGB LEDs
- Visual indicators for player/dealer turn and result status.
-
9 OLED 0.96" Displays (128x64)
- Display game content (cards and messages). All share the same I2C address.
-
TCA9548A I2C Multiplexer
- Routes signals to individual OLEDs as they can't share the bus directly.
Schematics
Photos and videos
https://drive.google.com/file/d/1Ra2BIl7wVw8DB3zTOpI6kNC0RgWqssET/view?usp=sharing
Bill of Materials
Device | Usage | Price |
---|---|---|
Raspberry Pi Pico 2 | Microcontroller | 40 RON x 2 |
TCA9548A I2C MUX | OLED Routing | 20 RON |
OLED 128x64 Displays × 9 | Visual display | 19 RON × 9 |
RGB LED × 2 | Player/Dealer Indicators | 2 RON × 2 |
Push Buttons × 3 | Game Inputs | 2 RON × 3 |
Breadboard | Connectivity | 10 RON |
Jumpers | Connectivity | 8 RON |
TOTAL: ~300 RON
Software
Library | Description | Usage |
---|---|---|
embassy-rp | RP2350 HAL for Raspberry Pi Pico 2 | GPIO control, I2C communication, async device management |
embassy-executor | Async/await executor for embedded systems | Task scheduling and async runtime |
embassy-time | Time management for Embassy | Delays, timers, and timeout handling |
embassy-futures | Future utilities for embedded systems | Select operations for button handling |
ssd1306 | SSD1306 OLED Display Driver | Control 9 OLED displays for cards and game state |
embedded-graphics | 2D Graphics Library | Text rendering and display formatting |
heapless | Collections without allocation | Fixed-capacity vectors and strings for no_std |
embedded-hal | Hardware Abstraction Layer | Standard traits for I2C and GPIO operations |
rand | Random number generation | Card deck shuffling with small_rng feature |
defmt + defmt-rtt | Efficient logging framework | Real-time debug output over RTT |
panic-probe | Panic handler for embedded | Debug-friendly panic messages with defmt |
cortex-m-rt | Cortex-M runtime | Boot sequence and interrupt vector setup |