How to Play Tetris on ESP32 CYD With Nintendo 64 Controller

by Northstrix in Circuits > Microcontrollers

819 Views, 10 Favorites, 0 Comments

How to Play Tetris on ESP32 CYD With Nintendo 64 Controller

IMG_0511.jpg

Recently, I got my hands on the ESP32-2432S028R, also known as the ESP32 Cheap Yellow Display. While testing its capabilities, I came across Brian Lough's Tetris code written for the ESP32 that utilizes the Nintendo Wii Nunchuk as an input device. After playing the game with the Nunchuk for a while, I realized that I had a Nintendo 64 controller lying around, so without wasting any more time, I embarked on a journey of adapting this code to work with the Nintendo 64.

It took me roughly an hour of low-load programming mixed with debugging and gameplay to modify the code. Now, let me share the result of that endeavor with you.

Supplies

IMG_0540.jpg

ESP32-2432S028R x1

Arduino Nano x1

Nintendo 64 Controller x1

Prepare the Development Environment

gs.png

To flash the ESP32 CYD, you need to configure the Arduino IDE, install the necessary libraries, and put the “User_Setup.h” file where it should be. You can read how to do all of that at https://randomnerdtutorials.com/cheap-yellow-display-esp32-2432s028r/

Install the "arduino-n64-controller-library" Library

dl.png

This project only requires one additional library. You can download it at https://github.com/pothos/arduino-n64-controller-library

To install it, either unpack the content of the archive into the "…\Arduino\libraries" folder or open the Arduino IDE, click on "Sketch" -> "Include Library" -> "Add .ZIP Library…" and select the archive with the library.

Download Firmware

df.png

You can download the archive with firmware from one of these sources:

https://sourceforge.net/projects/esp32-tetris/

https://github.com/Northstrix/ESP32-Tetris-With-Nintendo-64-Controller/

If you only need the firmware, then download the archive from SourceForge. If you also want the project photos, then download the archive from GitHub.

Flash Arduino

flard.png

Upload the firmware from the "V1.1\Firmware_for_Arduino" folder into the Arduino.

Adjust the value of the "REPEAT_AFTER_HOLD" variable if needed.

Flash ESP32

flesp32.png

Upload the firmware from the "V1.1\Firmware_for_ESP32" folder into the ESP32 CYD.

Assemble the Circuit

Circuit Diagram.png

Assembling the circuit shouldn't be hard. Simply connect the Nintendo 64 controller to the Arduino, and then connect the Arduino to the ESP32 CYD.

Enjoy the Result

IMG_0605.jpg
IMG_0606.jpg
IMG_0607.jpg
IMG_0608.jpg
IMG_0609.jpg

Finally, you can play the game!

Here are the controls for the V1.1.

  • Press "Start" to begin/resume the game.
  • Press "B" to pause the game.
  • Use the D-pad and a stick to move the piece.
  • Use the "L" and "R" buttons to make a single move per click.
  • Press "A," "Z," or "C Up" to rotate the piece.

I think it's also worth mentioning that the source code of this project is distributed under the MIT license. That grants you the freedom to customize, adapt, and modify it according to your needs and preferences.

And though it's a short tutorial, I believe it's a useful one.

If you found this tutorial to be useful, please consider sharing it.

Thank you for reading this tutorial.

*All images demonstrated in this step were generated by Bing Image Creator.