Skip to content

Pac-Man Game Setup Guide

Hardware Requirements

Components:

  1. Xiao Seeed RP2350 - Main microcontroller
  2. SSD1306 OLED Display - 128x64 pixels, I2C interface (0.96")
  3. Piezo Buzzer - For sound effects
  4. Red LED - Game over/death indicator
  5. Green LED - Dot collection indicator
  6. 4 Push Buttons - Directional controls (Up, Down, Left, Right)
  7. Resistors - 4x 10kΩ pull-up resistors for buttons (if not using internal pull-ups)
  8. Breadboard and jumper wires

Wiring Diagram

Pin Connections:

I2C OLED Display (SSD1306):

OLED VCC  →  Xiao 3.3V
OLED GND  →  Xiao GND
OLED SDA  →  Xiao GPIO 6 (I2C1 SDA)
OLED SCL  →  Xiao GPIO 7 (I2C1 SCL)

Piezo Buzzer:

Buzzer (+) →  Xiao GPIO 26
Buzzer (-) →  Xiao GND

LEDs:

Red LED (+)   →  Xiao GPIO 27 (with 220Ω resistor)
Red LED (-)   →  Xiao GND

Green LED (+) →  Xiao GPIO 28 (with 220Ω resistor)
Green LED (-) →  Xiao GND

Control Buttons:

Button UP     →  Xiao GPIO 2 (one side) and GND (other side)
Button DOWN   →  Xiao GPIO 3 (one side) and GND (other side)
Button LEFT   →  Xiao GPIO 4 (one side) and GND (other side)
Button RIGHT  →  Xiao GPIO 5 (one side) and GND (other side)

Note: Buttons use internal pull-up resistors, so they connect directly between GPIO and GND.


Pin Configuration Summary

Component GPIO Pin Notes
I2C SDA GPIO 6 OLED Data
I2C SCL GPIO 7 OLED Clock
Buzzer GPIO 26 PWM capable
Red LED GPIO 27 With 220Ω resistor
Green LED GPIO 28 With 220Ω resistor
Button UP GPIO 2 Internal pull-up
Button DOWN GPIO 3 Internal pull-up
Button LEFT GPIO 4 Internal pull-up
Button RIGHT GPIO 5 Internal pull-up

Software Setup

Step 1: Install MicroPython on RP2350

  1. Download the latest MicroPython firmware for RP2350 from: https://micropython.org/download/

  2. Hold the BOOT button on the Xiao RP2350 while connecting it to your computer via USB

  3. The Xiao will appear as a mass storage device (RPI-RP2)

  4. Drag and drop the .uf2 firmware file onto the drive

  5. The board will reboot automatically with MicroPython installed

Step 2: Install Thonny IDE

  1. Download Thonny from: https://thonny.org/

  2. Install and open Thonny

  3. Go to ToolsOptionsInterpreter

  4. Select MicroPython (Raspberry Pi Pico)

  5. Select the correct COM port for your Xiao RP2350

  6. Click OK

Step 3: Install Required Libraries

The SSD1306 OLED library needs to be installed on the RP2350:

  1. In Thonny, go to ToolsManage packages

  2. Search for micropython-ssd1306 and install it

OR manually download and upload ssd1306.py:

# Save this as ssd1306.py on the RP2350
# You can find the official library at:
# https://github.com/micropython/micropython-lib/blob/master/micropython/drivers/display/ssd1306/ssd1306.py

Step 4: Upload the Game Code

  1. Open pacman_game.py in Thonny

  2. Verify pin assignments match your wiring (lines 17-24)

  3. Click FileSave asRaspberry Pi Pico

  4. Save the file as main.py (so it runs automatically on boot)

  5. Or save as pacman_game.py and run it manually each time

  6. Click the Run button (green play icon) to start the game


Game Controls

  • UP Button: Move Pac-Man up
  • DOWN Button: Move Pac-Man down
  • LEFT Button: Move Pac-Man left
  • RIGHT Button: Move Pac-Man right

Game Features

Gameplay:

  • Navigate Pac-Man through the maze
  • Collect all dots (small pixels) to win
  • Avoid ghosts or you'll lose a life
  • Collect power pellets (blinking squares) to eat ghosts temporarily
  • You have 3 lives

Visual Feedback:

  • Green LED: Flashes when you eat a dot
  • Red LED: Lights up when you lose a life or game over
  • OLED Display: Shows the maze, Pac-Man, ghosts, and score

Audio Feedback:

  • Eating dots: Short beep
  • Eating ghost: Rising tone sequence
  • Power pellet: High pitch tones
  • Death: Descending tone sequence
  • Win: Victory melody

Troubleshooting

Display doesn't work:

  • Check I2C connections (SDA to GPIO 6, SCL to GPIO 7)
  • Verify display is 3.3V compatible
  • Check I2C address (default is 0x3C, may be 0x3D on some displays)
  • Modify line in code if needed: SSD1306_I2C(SCREEN_WIDTH, SCREEN_HEIGHT, self.i2c, 0x3D)

Buttons not responding:

  • Verify buttons are connected between GPIO and GND
  • Test continuity when button is pressed
  • Check that Pin numbers in code match your wiring

No sound from buzzer:

  • Check buzzer polarity (+ to GPIO 26, - to GND)
  • Verify buzzer is a passive (not active) piezo buzzer
  • Try a different GPIO pin if GPIO 26 doesn't support PWM

Game runs slowly:

  • Reduce move_delay and ghost_move_delay values
  • Simplify maze design for better performance

Import error for ssd1306:

  • Make sure ssd1306.py is uploaded to the RP2350
  • Check spelling and capitalization

Customization Ideas

Modify Game Difficulty:

# In __init__ method, change:
self.move_delay = 100  # Faster player movement
self.ghost_move_delay = 150  # Faster ghosts

Change Maze Layout:

Edit the init_maze() method to create your own maze design

Adjust Sound:

Modify the frequency and duration values in sound effect functions

Add More Ghosts:

In init_maze(), add more ghost dictionaries to the self.ghosts list


Power Options

  1. USB Power: Connect via USB-C cable (easiest for development)
  2. Battery Power: Connect 3.7V LiPo battery to BAT+ and BAT- pads on Xiao
  3. 5V Power: Connect regulated 5V to 5V and GND pins

Note: For a truly portable handheld system, use a small LiPo battery (500-1000mAh).


Next Steps

Once you have the basic game working, consider these enhancements:

  1. Add a score display on screen
  2. Create multiple levels with increasing difficulty
  3. Add a high score system using flash memory
  4. Design a custom PCB to make it more compact
  5. 3D print an enclosure for a professional handheld look
  6. Add more maze designs and randomize them
  7. Implement fruit bonuses for extra points

License and Credits

This is an educational project inspired by the classic Pac-Man game. Feel free to modify and share!

Happy Gaming! 🎮