A snake game designed to run on Raspberry Pi with an addressable LED matrix display using CircuitPython and Pygame.
- Classic snake gameplay
- Addressable LED display support
- Joystick input support
- AI agent mode with BFS pathfinding
- Player mode with manual control
- Automatic restart and daemon support
- Raspberry Pi (tested on Pi Zero 2W and Pi 5)
- Addressable LEDs compatible with NeoPixel
- Joystick/controller (optional)
- SPI interface for LED control
- Python 3.7+
- pygame
- adafruit-circuitpython-neopixel-spi
- adafruit-blinka
# Create a virtual environment
python -m venv venv --system-site-packages
# Install build
pip install build
- Build and deploy to host:
HOST=raspberrypi.local chmod +x deploy.sh ./deploy.sh $HOST
- Start button: Switch to Player mode
- Back button: Switch to AI mode
- Joystick: Control snake direction
- Game automatically restarts when game over
The LED matrix mapping is defined in snake/led_map_v2.py
. Adjust the MAP array to match your specific LED matrix layout.
- Installation: Install Blinka library properly using this guide and not pip
- Disable audio on SPI: If you are using SPI, disable Audio
- Permission issues: Ensure SPI is enabled and user has proper permissions
- Display not working: Check LED matrix connections and SPI configuration
- Game not starting: Check journalctl using
journalctl --user-unit snake_dance
To modify the game:
- Edit
snake/main.py
for game logic - Edit
snake/led_map_v2.py
for LED mapping - Rebuild and redeploy using
./install.sh $HOSTNAME
- Install Pre-commit before making a PR
pip install pre-commit && pre-commit install