Skip to main content
Version: ACS CC

BlackJack Machine

A singleplayer card game powered by a Raspberry Pi Pico 2 and Rust.

info

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:

  1. Startup: OLED instructs user to press START.
  2. Dealer draws 2 cards – LED blinks – game state updates.
  3. Player draws 2 cards – LED blinks – game state updates.
  4. Player phase: can HIT (get card) or STAND (end turn).
  5. If player busts: game ends.
  6. Else: dealer draws to at least 17.
  7. 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

diagram

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

  1. Raspberry Pi Pico 2 - RP2350A

    • Main microcontroller; handles game logic, I2C communication, and peripheral control.
  2. 2 Push Buttons (HIT & STAND)

    • User input; GPIO with pull-ups.
  3. 2 RGB LEDs

    • Visual indicators for player/dealer turn and result status.
  4. 9 OLED 0.96" Displays (128x64)

    • Display game content (cards and messages). All share the same I2C address.
  5. TCA9548A I2C Multiplexer

    • Routes signals to individual OLEDs as they can't share the bus directly.

Schematics

diagram

Photos and videos

diagram

diagram

diagram

https://drive.google.com/file/d/1Ra2BIl7wVw8DB3zTOpI6kNC0RgWqssET/view?usp=sharing

Bill of Materials

DeviceUsagePrice
Raspberry Pi Pico 2Microcontroller40 RON x 2
TCA9548A I2C MUXOLED Routing20 RON
OLED 128x64 Displays × 9Visual display19 RON × 9
RGB LED × 2Player/Dealer Indicators2 RON × 2
Push Buttons × 3Game Inputs2 RON × 3
BreadboardConnectivity10 RON
JumpersConnectivity8 RON

TOTAL: ~300 RON

Software

LibraryDescriptionUsage
embassy-rpRP2350 HAL for Raspberry Pi Pico 2GPIO control, I2C communication, async device management
embassy-executorAsync/await executor for embedded systemsTask scheduling and async runtime
embassy-timeTime management for EmbassyDelays, timers, and timeout handling
embassy-futuresFuture utilities for embedded systemsSelect operations for button handling
ssd1306SSD1306 OLED Display DriverControl 9 OLED displays for cards and game state
embedded-graphics2D Graphics LibraryText rendering and display formatting
heaplessCollections without allocationFixed-capacity vectors and strings for no_std
embedded-halHardware Abstraction LayerStandard traits for I2C and GPIO operations
randRandom number generationCard deck shuffling with small_rng feature
defmt + defmt-rttEfficient logging frameworkReal-time debug output over RTT
panic-probePanic handler for embeddedDebug-friendly panic messages with defmt
cortex-m-rtCortex-M runtimeBoot sequence and interrupt vector setup
  1. BlackJack rules
  2. Raspberry Pi Pico Tutorial - SSD1306 I2C OLED DISPLAY
  3. Playing cards images
  4. Using I2C MUX with OLEDs