Pac-Man Game Setup Guide
Hardware Requirements
Components:
- Xiao Seeed RP2350 - Main microcontroller
- SSD1306 OLED Display - 128x64 pixels, I2C interface (0.96")
- Piezo Buzzer - For sound effects
- Red LED - Game over/death indicator
- Green LED - Dot collection indicator
- 4 Push Buttons - Directional controls (Up, Down, Left, Right)
- Resistors - 4x 10kΩ pull-up resistors for buttons (if not using internal pull-ups)
- 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
-
Download the latest MicroPython firmware for RP2350 from: https://micropython.org/download/
-
Hold the BOOT button on the Xiao RP2350 while connecting it to your computer via USB
-
The Xiao will appear as a mass storage device (RPI-RP2)
-
Drag and drop the
.uf2firmware file onto the drive -
The board will reboot automatically with MicroPython installed
Step 2: Install Thonny IDE
-
Download Thonny from: https://thonny.org/
-
Install and open Thonny
-
Go to Tools → Options → Interpreter
-
Select MicroPython (Raspberry Pi Pico)
-
Select the correct COM port for your Xiao RP2350
-
Click OK
Step 3: Install Required Libraries
The SSD1306 OLED library needs to be installed on the RP2350:
-
In Thonny, go to Tools → Manage packages
-
Search for
micropython-ssd1306and 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
-
Open
pacman_game.pyin Thonny -
Verify pin assignments match your wiring (lines 17-24)
-
Click File → Save as → Raspberry Pi Pico
-
Save the file as
main.py(so it runs automatically on boot) -
Or save as
pacman_game.pyand run it manually each time -
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_delayandghost_move_delayvalues - Simplify maze design for better performance
Import error for ssd1306:
- Make sure
ssd1306.pyis 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
- USB Power: Connect via USB-C cable (easiest for development)
- Battery Power: Connect 3.7V LiPo battery to BAT+ and BAT- pads on Xiao
- 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:
- Add a score display on screen
- Create multiple levels with increasing difficulty
- Add a high score system using flash memory
- Design a custom PCB to make it more compact
- 3D print an enclosure for a professional handheld look
- Add more maze designs and randomize them
- 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! 🎮