CJMCU-64 Neopixel Display Workout With Pi Pico and Micropython

by tonygo2 in Circuits > Microcontrollers

1473 Views, 7 Favorites, 0 Comments

CJMCU-64 Neopixel Display Workout With Pi Pico and Micropython

Npixels.jpg

The CJMCU-64 RGB LEDs board has 64 Neopixels arranged in 8 rows of 8. Each of the 64 LEDs can be set to any one of 16,777,216 colours by specifying each of the red, green and blue components with a number in the range 0 to 255. The board is very bright, colourful and easy to program. Most of the tutorials available assume that you will use an Arduino but I’m going to show you how to give the display a good workout using a Raspberry Pi Pico and MicroPython

Supplies

LED64.jpg
Pico.jpg

CJMCU-64 RGB LEDs board

Raspberry Pi Pico

3 connecting wires for 5V, GND and Data

Board Layout

Neopixels64.jpg

Connect is very simple. We need to connect only 3 wires: GND, 5V and DIN (data in). There are several GND pins on a Pi Pico and any can be used. The Official Raspberry Pi Pico Guide suggests that for Neopixels, 5V is connected to VBUS and I’m using GP16 for DIN but you could use any of the others. (These boards can be chained together. Power, with DOUT, are available on the opposite corner.) Page 133 of the guide gives the basic code for controlling a strip of Neopixels. In the picture the connections are the three blue blobs under the top left LED.

If we turn the board so that the input connections are positioned top left; then the Neopixels are numbered 0 – 7 on the top row moving left to right, 8 - 15 on the second row …. and 56 to 63 on the bottom row. If we use co-ordinates with the top left LED as the origin (0,0) the bottom right LED is at (7,7). From this it is easy to calculate the index, or position of any LED on the board with:

pos = x + y * 8 # Multiplication BEFORE addition!

so, the last Neopixel is numbered 7 + 7 * 8 = 63


I’ve written a function to help set specific pixels to the required colour:

def xy_set(x, y, color):

   pos = x + y*8

   # Avoid out of range errors

   if (pos > -1) and (pos < NUM_LEDS):

   pixels_set(pos, color)


x and y are the co-ordinates of the pixel and color is a tuple with the red, green and blue values. 


Tuples are used to store multiple items in a single variable.

Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set and Dictionary.

A tuple is a collection which is ordered and unchangeable.

Tuples are written with round brackets.”

                                                               

Red = (255,0,0)

Blue = (0,0,255)

Yellow = (255,255,0)

The brackets are essential. You can find help in finding the RGB values for "difficult" colours such as brown or pale pink here: htmlcolors.com

First Example

MVI 8810

This program gives a basic demonstration of the board with many colours, lines, squares and fills. The code is available below so you can try it yourself and see how the effects were produced.

You will probably notice that at times it appears to run more slowly. Updating 64 Neopixels is quite a slow process and doing it after every pixel colour change does take time. Where you place the

pixels_show()

instruction (inside or after the loop) makes a great deal of difference to run speed. Do not forget to put it in your script or you will not see pixels change colour.

Downloads

Displaying Numeric Values

362.JPG

We only have 64 pixels but I thought it would be fun to try and displays values on this very low resolution screen.

I designed a 3x5 pixel character set which works quite well and can easily be seen across a room. Only two digits fit on the screen so that gives a range of 0 to 99. We can just get 100 displayed by making it a special case.

Negative values can be indicated by a colour change or a bar over the number. These additions increase the range from -100 to +100.

Using 1, 2 or 3 blobs at the top of the screen to indicate hundreds allows a different range of 0 to 399 - enough for 360 degrees.

Numeric Values Demo

MVI 8805

Try out the demo and look at the code.

Downloads

Displaying Time

Hrs.JPG
Mins.JPG

I found it was possible to indicate hours and minutes by using the separating colon.

Binary and Hexadecimal

Bin.JPG
Hex AF.JPG

Binary is easy and hexadecimal values just needed an extension to the character set.

Conclusion

362.JPG
IMG_8824.JPG
Neg55.JPG

I hope you have found this workout useful and interesting and can see other uses for this inexpensive but useful board. I found mine on Amazon and it appears to be much cheaper than similar 64 Neopixel boards from other manufacturers.

Comments and feed back welcome.