Snake and Pong games on an ESP32

Introduction

Hi, our team is formed with three members Roope Rajahalme, Rasmus Rautakallio and Phong Phan. Before this course our background in programming and electronics was quite basic. We had some experience with Java programming projects but had never worked with displays or games before. We all had deep love for games, so we were curious if it was possible to create a game console on this course.

Ideas

At the start, we brainstormed several project ideas, IoT Plant device, humidity tester, and a retro-style game. We finally decided on Snake game on ESP32 with a TFT screen and joystick controller. We went with these components because course criteria, was to use ESP32 and teacher suggested to use joystick instead of buttons. We decided on retro games because this offered room for creative effects like flashing colours or modifying snake animation also this was challenging enough to keep the project interesting. Creating one small minigame would be too easy and boring, so we decided to add a couple more games to our application. On top of having the snake game, we also made pong game, which is a basic ping pong game where you bounce the ball against walls and it returns it, and lastly we made a memory game, where the game shows inputs in different directions and the player is supposed to replicate the inputs from memory.

What did we need to learn

The initial scope was to build a working Snake game where the player moves a snake with a joystick and eats food while avoiding collisions. We learned many things from this course.

  • Learning how to program graphics with the Adafruit GFX library and the ST7735 TFT display.
  • Wiring the joystick and calibrating it to work smoothly.
  • Wiring ESP32 and TFT LCD screen.
  • Programming game logic like snake movement, collision detection and scorekeeping.

The building phase

Building the game was frustrating and requested a lot of testing and debugging. At first, we tested that every component worked as expected, then we started to add some logic step by step until the game, joystick and LCD Screen worked smoothly. Then we added some graphics like white borders, making snake look more, flashy and food colour change gradually. Lastly, we added two more games “Pong” and “Memory game”. We discovered some issues along the way.

For example:

  • Joystick had to be calibrated many times in order to work smoothly.
  • Border was disappearing when snake moved along it.
  • Snake left a piece of itself on the screen every time it ate.
  • Screen redrawing every time snake move.
  • The border was pulsing every frame, which made the background distracting.
  • Snake and Pong game was moving too fast
  • Trying to apply three games at the same time was difficult.

The outcome

What we learned from this project was,

  • How to program and make a structure for the games.
  • How to create effects and make the game run smoother.
  • How to wire difference components alone and together with each other.
  • How to calibrate joystick controller.
  • How to connect ESP32 to internet.
  • How to create multiple minigames and combine them into a single working application.
  • How to send data from our program to a database.

This course definitely made us more interested in tinkering. Now we know more how IoT-devices are built from the scratch, but also now we can see microcontrollers like sensors not only as tools, but these could be implied into game consoles.

In the future we would like to add some sound effects or expanding into a better display and limit test more games to see how far we can go with these components.

This is the program’s start menu:

 

 

This is the snake game:

 

This is the pingpong game:

 

 

This is the memory game:

 

This is the game over screen:

 

This is the game menu screen:

 

This is how the data is displayed in a database:

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.