Skip to content

Snake running on an ESP32 MCU written in Rust - requires OLED and Joystick

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

jamesmcm/snake_rust_esp32

Repository files navigation

Snake for ESP32 with Rust

This project implements the game Snake for an ESP32 microcontroller, written in Rust.

This was written as a basic starter project.

Hardware:

Photo:

Photo of breadboard

Video:

output.mp4

Wokwi project (note does not build there due to Rust dependencies): https://wokwi.com/projects/413450202628576257

Breadboard diagram

Embassy is used to run concurrent tasks (checking for input at a faster rate than the game update rate).

The joystick URX and URY axes inputs are handled with a built-in Analogue-Digital Converter (be careful about the choice of GPIO pins as the selection is limited). And the button click is handled with an interrupt.

Deployment

Install Rust and espup.

Then run:

$ source ~/export-esp.sh
$ cargo run --release

Simulation

Install Wokwi for VS Code. Open diagram.json and click Play button.

Notes

Note the input voltage to the joystick had to be lowered via a voltage divider to get a usable range, the voltage divider here used one 1k and one 2k Ohm resistors to the 5V input.

Note the SCL and SDA pins to the I2C display needed pull-up resistors, here I used 2k Ohm resistors to 5V.

Known Issues

  • The use of the buffered graphics mode means that the display becomes laggy for longer snake sizes. This could be reduced by using direct draws (to not redraw the whole screen) and increasing the baud rate of the I2C connection.

  • Food can spawn next to the snake which is confusing on the monochrome display (and can result in instant victory too).

  • The game is very easy on the current size / speed.

Resources

About

Snake running on an ESP32 MCU written in Rust - requires OLED and Joystick

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages