Animated Random Patterns With RP2040-Matrix and MicroPython
by arduinocelentano in Circuits > Art
414 Views, 6 Favorites, 0 Comments
Animated Random Patterns With RP2040-Matrix and MicroPython
The RP2040-Matrix is a compact and charming development board that features a tiny 5x5 RGB LED matrix, along with the RP2040 microcontroller. It can be easily programmed using MicroPython. In this project, we will make it display random animated symmetric patterns. Possible use cases include electronic jewelry, trinkets, and holiday decorations.
Supplies
- RP2040-Matrix development board (alternatively, you may use any generic RP-2040 board with an external NeoPixel LED matrix)
- Thonny IDE to program it
Defining Pixel Groups
I defined six pixel groups. Each pixel in a group will have the same color.
In MicroPython, the groups are implemented using a 3D list.
Defining Palettes
Each palette consists of three colors. The black color corresponds to a turned-off LED. The sample palettes in the picture are not equivalent to what is defined in the code. The LEDs look different from the pixels on your screen.
In MicroPython, the definition will look like this:
Color Morphing
To create a smooth transition effect between patterns, a simple morphing technique is used. Each pixel does not switch to another color instantly, but passes through a few transitional colors.
The morph_colors() function handles this behavior.
Installing Thonny IDE
Now that we have discussed how it works, we are ready to run it.
Go to https://thonny.org/ and download Thonny. Follow the installation instructions for your operating system.
Installing MicroPython (Optionally)
If you have never used your board with MicroPython, you'll need to install it. To do this, hold the BOOT button on your RP2040-Matrix board before connecting it to your computer.
Once it is plugged in, release the BOOT button and open Thonny. Go to the 'Tools → Options' menu. In the 'Interpreter' tab, select the correct port and click the 'Install or update MicroPython' link.
Uploading the Code
Unplug your board and plug it in again. Create a new file and paste the attached MicroPython code. Press ▶️ 'Run' and enjoy the animation!
💡 If the onboard files are not shown in the 'Files' tab, try pressing 🛑 'Stop' button.
💡 If you want the code to start automatically, the filename should be main.py.