ESP32 board and TETRIS game

ESP32 06-03-25
36 0

Tutorial plan

1- Presentation of Tetris game

2- Description of ESP32 Tetris game

3- Required Components

4- Component Wiring

5- Tetris game program

 

 

Presentation of Tetris game

Tetris is a classic puzzle game where the player arranges falling blocks (Tetriminoes) to form complete rows. When a row is fully filled, it disappears, and the player earns points. The game gets progressively faster, increasing difficulty over time.

Basic Rules of Tetris

Tetriminoes Fall: Randomly generated blocks (Tetriminoes) fall from the top of the game area.

Player Control: The player can move left, move right, rotate, or soft drop the block.

Goal: Arrange blocks to form full horizontal lines.

Line Clearing: A completed row disappears, and the blocks above shift down.

Scoring System: Points increase with each cleared line.

Speed Increase: As the game progresses, the blocks fall faster.

Game Over: The game ends if a new block cannot spawn at the top.

 

Description of ESP32 Tetris game

The Tetris game follows a structured flow, where the ESP32 manages the game logic, the LCD I2C screen displays the game grid, the joystick controls the blocks, and the buzzer provides audio feedback

The game follows these main steps:

1- Initialization: The ESP32 sets up the display, joystick, and buzzer.

2- Block Spawning: A new Tetrimino (block) appears at the top of the grid.

3- Player Input: The joystick is used to move and rotate the block.

4- Block Movement: The block moves down automatically at a set interval.

5- Collision Detection: Checks if the block hits another block or the bottom.

6- Line Clearing: If a row is full, it is cleared, and the score increases.

7- Game Over Check: If new blocks cannot spawn, the game ends.

8- Repeat Steps 2-7 until the game is over.

 

Required Components

ESP32 Board

The ESP32 is the microcontroller that will run the Tetris logic, handle input from the joystick, update the display, and play sounds through the buzzer.

It provides multiple GPIO pins to interface with peripherals.

Supports I2C communication for the LCD screen.

Has enough processing power and memory to manage game logic efficiently.

LCD I2C Screen

Pinouts of 1602 LCD display with I2C

The LCD screen will serve as the display for the game, showing falling Tetriminoes and the game grid.

Typically, a 16x2 LCD (1602) or 20x4 LCD (2004) can be used.

It communicates via I2C protocol, reducing the number of GPIO pins required.

It uses libraries like i2c_lcd and lcd_api for display management.

Joystick (Controller)

The joystick is used to control the falling Tetriminoes.

It moves the blocks left or right by tilting left or right.

It moves the block down faster (soft drop) by tilting down.

It rotates the block when the joystick button is pressed.

It Connects to ESP32 via analog inputs (X & Y axes) and a digital button press.

Buzzer (Sound Effects)

The buzzer is used to play simple sound effects for: block movement, rotation, line clearing and game over.

Breadboard

Breadboard

Purpose: Used to assemble and connect components without soldering.

Jumper Wires

Jumper wires

Jumper wires will be used to make connections between the components.

 

Component Wiring

1- Joystick to ESP32 :

GND → GND

VCC → 3V3

X-axis (VRx pin ) → GPIO34

Y-axis (VRy pin) → GPIO35

Button (SW pin) → GPIO33

LCD Screen (I2C-based) to ESP32 :

SDA → GPIO21 (I2C Data).

SCL → GPIO22 (I2C Clock).

VCC → 5V

GND → GND

 

Tetris game program

Tle Micropython program is a simplified version due to the limitations of a character-based LCD, where Tetriminoes are represented using custom characters.

This script handles game logic, LCD updates, joystick input, and buzzer sounds.

1- Ensure MicroPython is installed on your ESP32

2- Flash your ESP32 with MicroPython using this file esp32-20210902-v1.17.bin

3- Import this two libraries : i2c_lcd and lcd_api for I2C LCD screen

 

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info