Rust on an Arduino Uno
I have no idea what I’m doing.
I recently started working with a 8x32 LED matrix powered by an Arduino Uno. I got an example working without using any external libraries by using the onboard shift register to transfer data. The whole thing was coded using the Arduino language, something very close to C++.
Somewhere in my code I was allocating an array on the heap to store data to write to the device. I noted to myself that the performance could be improved by moving the allocation out of the hot loop, but turning lights on and off shouldn’t need that much CPU time anyway. Allocating in a hot loop is fine… as long as you remember to deallocate in the hot loop as well.
After a few seconds, the lights stopped, and I was confused why at first, until I suspiciously noticed no calls to free
in my code.
Moving to Rust
This along with the very annoying #ifdef
macros throwing locallity of behavior out the window made me want to move to rust if I wanted to do anything more complex.
I challenged myself to make some sort of tetris clone using this “screen” as a display.
A more detailed list of goals to accomplish in the project are
- matrix display control library / libraries
- turn on and off LEDS using bitshifting
- turn on and off LEDs using SPI
- only include specific parts of code depending on crate feature
- use a diffing algorithm to make updates more efficient
- handle arbitrary rotations
- add text display / scrolling
- tetris
- main game loop
- end score
- enclose in a hardware container
Devlog 0
I still have no idea what I’m doing.
-
started out by watching “the rusy bits embedded”
-
realized that the UNO prob has more support
-
look for resources for “rust on arduino uno”, only find outdated blogs + full books
-
remember ThePrimeagen did something like this in his Rustlang arc
- remember funny name “avrdude”
- embedded hal
find
- https://github.com/Rahix/avr-hal
- https://github.com/Rahix/avr-hal-template/tree/main?tab=readme-ov-file
tring to use ravedude
to run the program but cargo install ravedude
is failing for some reason
realize that I’m inside of a rust project using the wrong compiler and just cd
. that fixes it
- get blink working from the
avr-hal-template