Animated Random Patterns With RP2040-Matrix and MicroPython

by arduinocelentano in Circuits > Art

408 Views, 6 Favorites, 0 Comments

Animated Random Patterns With RP2040-Matrix and MicroPython

cover.jpg
Animated Random Patterns on RP2040-Matrix

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

001.JPG
  1. RP2040-Matrix development board (alternatively, you may use any generic RP-2040 board with an external NeoPixel LED matrix)
  2. Thonny IDE to program it

Defining Pixel Groups

pixels.png

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.

pixel_groups=[[[0,0],[4,0],[0,4],[4,4]],\
[[1,1],[3,1],[1,3],[3,3]],\
[[2,2]],\
[[2,0],[0,2],[4,2],[2,4]],\
[[2,1],[1,2],[3,2],[2,3]],\
[[0,1],[0,3],[1,0],[1,4],[3,0],[3,4],[4,1],[4,3]]]

Defining Palettes

palettes.png

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:

palettes = [[[0,0,0],[32,22,0],[0,22,16]],\
[[0,0,0],[5,10,32],[4,32,2]],\
[[0,0,0],[12,44,0],[48,6,2]],\
[[0,0,0],[32,24,0],[32,0,0]]]

Color Morphing

transition.gif

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

thonny.png

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)

mp-install.png

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

upload.png
photo.jpg
output.gif

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.

Downloads