Skip to content

Build a Snake Game with Raspberry Pi Pico W & LED Matrix

License

Notifications You must be signed in to change notification settings

potier97/snake-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPA Logo

Snake Game on Raspberry Pi Pico W

Table of Contents

  1. Introduction
  2. Objective
  3. Components
  4. Connection
  5. Installation
  6. Usage
  7. Screenshots
  8. Authors
  9. License
  10. Contributing

Introduction

Welcome to the Snake Game project! This is a classic Snake game recreated using the Raspberry Pi Pico W with MicroPython. The game features an 8x8 LED Matrix controlled by a MAX7219 driver, an OLED SSD1306 display for additional information, a joystick for controlling the snake, and an LED strip to indicate the current game level.

This project showcases a blend of embedded programming, hardware integration, and interactive design, making it a perfect addition to any IoT or electronics portfolio.


Objective

The main goal of this project is to create an interactive and visually appealing version of the Snake game using accessible hardware components. Specifically, this project aims to:

  • Implement game logic in MicroPython.
  • Integrate multiple display devices (OLED and LED Matrix).
  • Utilize a joystick for intuitive user control.
  • Visualize game levels using an LED strip.
  • Provide clear and professional documentation for easy replication.

Components

Here’s a list of all the components used in this project:

  • Raspberry Pi Pico W
  • OLED SSD1306
  • 8x8 LED Matrix with MAX7219
  • Joystick
  • LED Strip
  • Breadboard
  • Resistors

Connection

Pin Connections:

NPA Logo

Note: RPI ZERO W pinout is used for reference.

OLED SSD1306:

  • SCL to GPIO9
  • SDA to GPIO8
  • VCC to 3.3V
  • GND to GND

8x8 LED Matrix with MAX7219:

  • DIN to GPIO3 (MOSI)
  • CLK to GPIO2 (SCK)
  • CS to GPIO5
  • VCC to 5V
  • GND to GND

Joystick:

  • VCC to 3.3V
  • GND to GND
  • VRx to GPIO26 (ADC X)
  • VRy to GPIO27 (ADC Y)
  • SW to GPIO6

LED Strip:

  • Connect to GPIO15-22 through appropriate resistors.

Installation

Follow these steps to set up the project on your Raspberry Pi Pico W:

  1. Clone the Repository First, clone the project repository to your local machine:
git clone https://github.com/your-username/snake-game-pico.git
cd snake-game-pico
  1. Set Up MicroPython on Raspberry Pi Pico W

  2. Install Required Libraries The project uses custom libraries for the OLED and LED Matrix. Make sure the following files are present in the project directory:

  • ssd1306.py
  • max7219.py

These libraries are included in the repository, so no additional installation is required.

  1. Upload Files to Pico W Use an IDE like Thonny to upload the project files to your Raspberry Pi Pico W:

    1. Open Thonny and select the Raspberry Pi Pico W as the interpreter.
    2. Drag and drop the following files to the Pico:
    • main.py
    • ssd1306.py
    • max7219.py
  2. Verify Connections Double-check all hardware connections as per the connection diagram to ensure everything is connected correctly.

Usage

Once everything is set up, follow these steps to run the game:

  1. Power Up: Connect your Raspberry Pi Pico W to a power source.
  2. Start the Game: The game should start automatically. If it doesn't, press the reset button on the Pico W.
  3. Control the Snake: Use the joystick to move the snake in the desired direction.
  4. Gameplay: Guide the snake to eat the food (indicated on the LED matrix) to grow and increase your score. Avoid collisions with the walls or the snake's own body.
  5. Level Indicators: The LED strip will light up to show your current game level based on your score.

Screenshots

NPA Logo

NPA Logo

NPA Logo

Demonstration Video

Watch the video

Autor

Licencia

This project is licensed under the MIT License. You are free to use, modify, and distribute this project as per the terms of the license

Contributing

Contributions are welcome! Follow these steps to contribute to the project:

  1. Fork the Repository: Click the "Fork" button at the top right of this page.
  2. Create a New Branch:
    git checkout -b feature-new-feature
  3. Make Changes: Commit your changes with clear and descriptive messages.
  4. Push to Branch:
    git push origin feature-new-feature
  5. Create a Pull Request: Go to the repository on GitHub and click "Compare & pull request."