Games / Pocket Chance

Pocket Chance

A pocket casino John built for a Raspberry Pi Pico and a 1.3-inch screen. This is the real MicroPython code, running on a pretend Pico in your browser.

Starting the Pico…
The same 240 × 240 screen, blown up so you can see it
A B X Y

Raspberry Pi Pico, 51 × 21 mm, also actual size. It plugs into the back of the HAT.

Actual size: Waveshare Pico LCD 1.3" on a Raspberry Pi Pico (our drawing), 52.0 × 26.5 mm, with a 23.4 mm screen of 240 × 240 pixels, each 0.0975 mm.

Press the board's joystick and buttons, or use the keyboard: ←↑↓→ joystick, Enter joystick press, A B X Y buttons.

Serial output

        

What it is

Pocket Chance is a handheld casino: Blackjack, Ultimate Texas Hold'em, John's own Caribbean flop game and Baccarat, played on Waveshare's 1.3-inch LCD HAT (a 240 × 240 screen, a joystick and four buttons) plugged onto a Raspberry Pi Pico. It's written in MicroPython, runs offline on the board, and saves your chips to the Pico's flash.

Controls

Start this project

The full Pocket Chance runs every game from one menu on a 16 MB RP2040-Plus. To fit a regular Pico, each game here is its own small project: a short main.py that starts the screen and runs that one game, plus only the lib/ and games/ files it needs, unchanged from the Pocket Chance repo. These are the exact files running above.

What you need

  • A Raspberry Pi Pico or Pico W (RP2040). The RP2040-Plus works too.
  • The Waveshare Pico LCD 1.3" HAT.
  • A USB data cable, and Chrome or Edge on a computer for the Workbench.

Put it on your Pico

  1. Plug the HAT onto the Pico, with the Pico's USB end at the HAT's USB marking.
  2. Install MicroPython with the Workbench's Flash page.
  3. Pick a game above and press Open in the IDE. Its files open as tabs.
  4. Connect the Pico, press Save all (it creates the folders too), then Run. Because the file is main.py, the game also starts by itself whenever the Pico powers up.
  5. Screen stays dark? In main.py, set FAST_SPI = False, save, and run again.

How the emulator works

MicroPython 1.29, compiled to WebAssembly, runs the game's files in a background thread. Only the hardware is pretend: the bytes the game sends to the screen chip are decoded into the picture, the HAT's buttons are the keys and buttons on this page, and your chips are saved in this browser. Two things aren't modelled: the Pico's 264 KB of RAM and its speed. Test memory use on a real board.