Happy New Year, with Embedded Rust!
Today is 1st January, 2022! Let’s display a “Happy New Year” scrolling message on an 8x8 LED matrix, just for fun!
The display module is controlled by a MAX7219.
The code is in Rust, and runs on a Raspberry Pi Pico. We use the SPI pins (SCK/GP14, Tx/GP15 and CS/GP13) of the Pico to communicate with the MAX7219.
Check out this link for setting up Rust to do development for the Pico. Don’t be surprised if you find this easier than setting up a C development environment!
Clone this git repo and do a cargo run to see the code in action!
How does it work?
The MAX7219 has 8 bytes of internal static RAM; we can think of this as 8 rows of 8 bit data, the rows being numbered 1 to 8.
The 8 bit value in each row can be modified by sending out a 16 bit SPI data frame; the lower 8 bits of this frame gets stored at the address represented by the upper 4 bits.
The MAX7219 constantly scans each row of this internal SRAM, putting on/off pixels in the corresponding row of the 8x8 LED matrix; note that pixels in only one row are enabled at any given point in time.
Special data frames can be constructed with the higher 4 bits having values other than 1 to 8; these frames can be used to do operations like control the intensity of the display etc.