016 - MicroPython TechNotes: RGB LED Matrix

Instruction

In this article, we will on how to use an RGB LED matrix or 8×8 Neopixel display with MicroPython language.

Pinout

  1. GND – for the ground pin.
  2. +5V – for the supply voltage.
  3. DIN – for the data input control signal pin.

Hardware Instruction

  1. First connect the ESP32 dev board on top of the ESP32 shield and make sure that both USB ports are on the same side.
  2. Next, attach the dupont wire to the RGB LED matrix according to the color coding that is black for the ground, red for the +5V, and yellow for the DIN control signal pin.
  3. Next, attach the other side of the dupont wire to the ESP32 shield by matching the colors of the dupont wires to the colors of the pin headers in the ESP32 shield. That is black to black, red to red, and yellow to yellow. For this experiment, I used GPIO 23 pin as a control signal pin for the RGB LED matrix.
  4. Next, power the ESP32 shield by attaching an external power supply with a type-C USB connector and make sure that the power switch is set to ON state.
  5. Lastly, connect the ESP32 to the computer through a micro-USB connector. The demo circuit is now ready.

Software Instruction

MicroPython have a builtin library to drive the RGB LED matrix by importing the neopixel library.

Video Demonstration

Call To Action

For any concern, write your message in the comment section.

You might also like to support my journey on Youtube by Subscribing. Click this to Subscribe to TechToTinker.

Thank you and have a good days ahead.

See you,

– George Bantique | tech.to.tinker@gmail.com

Source Code

1. Example # 1, exploring the basics:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin
 5from neopixel import NeoPixel
 6
 7NUM_OF_LED = 64
 8np = NeoPixel(Pin(23), NUM_OF_LED)
 9
10# # The following lines of codes should be tested using the REPL
11# # Syntax:
12# #    np[] = (, , )
13# #    np.write()
14# # ------------------------------------------------------------
15# # 1. To set the 1st neopixel to red color:
16# np[0] = (0, 10, 0)
17# np.write()
18# 
19# # 2. To set the 1st to red color,
20# #               9th to green color, and
21# #               17th to blue color
22# #    which are basically 3 LEDs in the first column
23# np[0] = (255, 0, 0)
24# np[8] = (0, 255, 0)
25# np[16] = (0, 0, 255)
26# np.write()
27#
28# # 3. To turn OFF all neopixel:
29# for npixel in range(64):
30#     np[npixel] = (0, 0, 0)
31#     np.write()

2. Example # 2, turning each LED one-by-one:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin, reset
 5from neopixel import NeoPixel
 6from time import sleep_ms
 7
 8NUM_OF_LED = 64
 9LED_INTENSITY = 10
10np = NeoPixel(Pin(23), NUM_OF_LED)
11
12while True:
13    try:
14        for npixel in range(NUM_OF_LED):
15            np[npixel] = (LED_INTENSITY, 0, 0)
16            np.write()
17            sleep_ms(100)
18            np[npixel] = (0, 0, 0)
19            np.write()
20    except KeyboardInterrupt:
21        print('Keyboard Interrupt')
22    finally:
23        print('Exiting....')
24        reset()

3. Example # 3, class to handle addressing of matrix by coordinates:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin, reset
 5from neopixel import NeoPixel
 6from time import sleep_ms
 7
 8class RGB_Matrix:
 9    
10    def __init__(self, gpio, width, height):
11        self.width = width
12        self.height = height
13        self.neopixel = NeoPixel(Pin(gpio), width*height)
14        
15    def pixel_set(self, row, col, r=0, g=0, b=0, color=''):
16        if color == '': 
17            self.neopixel[col + (row*self.width)] = (r, g, b)
18            self.neopixel.write()
19        else:
20            self.neopixel[col + (row*self.width)] = self.color
21            self.neopixel.write()
22            
23    def pixel_clr(self, row, col):
24        self.neopixel[col + (row*self.width)] = (0, 0, 0)
25        self.neopixel.write()
26        
27    def clear_all(self):
28        self.neopixel.fill((0,0,0))
29        self.neopixel.write()
30
31
32np = RGB_Matrix(23, 8, 8)

References And Credits

  1. Purchase Gorillacell ESP32 development kit at: gorillacell.kr


Posts in this series



No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.