ESP32 VGA Snake

by Rob Cai in Circuits > Arduino

5651 Views, 8 Favorites, 0 Comments

ESP32 VGA Snake

ESP32 VGA Snake
IMG_5490.JPG

In this instructable I will show how to reproduce a classical arcade game - Snake - with an ESP32, with the output for a VGA monitor.

The resolution is 640x350 pixels, in 8 colors.

I have previously done a version with an Arduino Uno (see here), but the resolution was only 120 x 60 pixels, 4 colors.

This project is made possible by the awesome ESP32 VGA library written by Fabrizio Di Vittorio. See here for more details.

Step 1: ESP32 Boards, Arduino IDE Installation and VGA Library Configuration.

This step is identical to Step 1 of my previous project done with an ESP32, thus just follow this link, start reading from Step 1 until the Sub-step 3 excluded.

You have than to install the FabGL VGA library, but for Snake you need the latest version: just in case it will change in the future, I put at the bottom of this step a working version in the file src.new.rar. You can download, uncompress and rename the folder as "src" in your

"...\arduino-1.8.9\libraries" folder.

Downloads

Step 2: Uploading "Snake" to the ESP32

Download Snake.ino at the bottom of this step.
Open it with the Arduino IDE and upload it to your raw ESP32. If you have no error messages, the code should already be running.

Downloads

Step 3: Connecting the VGA Port

DSUB15connector.png

You need the following parts:

  • a DSUB15 Connector, i.e. a VGA female connector or a VGA cable to be cut.
  • three 270 Ohm resistors.

Connect the ESP32 GPIO pin 2, 15 and 21 to VGA Red, Green and Blue respectively, through the 270 Ohm resistors.

Connect the VGA Hsync and Vsync to ESP32 GPIO pins 17 and 4 respectively.

Connect the DSUB15 connectors pins 5, 6, 7, 8 and 10 to ESP32 GND.

For the VGA DSUB15 connector pin definition, see the picture in this step. NB, this is the soldering side of the female connector.

Step 4: Connect the Four Buttons

Button.png
IMG_5485.JPG
IMG_5484.JPG

The schematic in this step shows how to connect a single button (Normally Open) from +5V to the ESP32 given pin. Note that you also need to connect the ESP given pin to GND trough a 1 to 2 kOhm resistor. In this way when the button is released (open) the ESP pin is at exactly zero Volts.

More specifically, you need to connect four buttons with the following order:

  • Pin 12 to Right button
  • Pin 25 to Up button
  • Pin 14 to Left button
  • Pin 35 to Down button

Step 5: Conclusion and Acknowledgment

If everything works properly, just connect the VGA monitor and you should be able to enjoy Snake.

I wish to express my tanks to Fabrizio Di Vittorio for his awesome ESP32 VGA library. For more details, examples, and... Space Invaders, visit his site.

If you like this project, please write a comment or share a picture of the device you build... and, over all, vote for it in the GAMES Contest!