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
- GND – for the ground pin.
- +5V – for the supply voltage.
- DIN – for the data input control signal pin.
Hardware Instruction
- First connect the ESP32 dev board on top of the ESP32 shield and make sure that both USB ports are on the same side.
- 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.
- 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.
- 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.
- 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
- Purchase Gorillacell ESP32 development kit at: gorillacell.kr
Posts in this series
- 049 - MicroPython TechNotes: MP3 Player
- 048 - MicroPython TechNotes: Analog Touch Sensor
- 047 - MicroPython TechNotes: E108 GPS
- 046 - MicroPython TechNotes: RF433 Transceivers
- 045 - MicroPython TechNotes: Infrared Transmitter
- 044 - MicroPython TechNotes: Infrared Receiver
- 043 - MicroPython TechNotes: ESP12E WiFi | External WiFi module
- 042 - MicroPython TechNotes: JDY-32 | Bluetooth Low Energy BLE
- 041 - MicroPython TechNotes: Bluetooth HC-06
- 040 - MicroPython TechNotes: Relay
- 039 - MicroPython TechNotes: Electromagnet
- 038 - MicroPython TechNotes: Buzzer
- 037 - MicroPython TechNotes: Servo Motor
- 036 - MicroPython TechNotes: Stepper Motor
- 035 - MicroPython TechNotes: Dual Motor Driver
- 034 - MicroPython TechNotes: DC Motors | Gear Motor and Fan Motor
- 033 - MicroPython TechNotes: TCS34725 RGB Color Sensor
- 032 - MicroPython TechNotes: BMP280 Sensor
- 031 - MicroPython TechNotes: TOF Distance Sensor
- 030 - MicroPython TechNotes: DS3231 RTC
- 029 - MicroPython TechNotes: HC-SR04 Ultrasonic Sensor
- 028 - MicroPython TechNotes: DHT11 Temperature and Humidity Sensor
- 027 - MicroPython TechNotes: Rotary Encoder
- 026 - MicroPython TechNotes: Light Dependent Resistor (LDR)
- 025 - MicroPython TechNotes: Joystick
- 024 - MicroPython TechNotes: Slider Switch
- 023 - MicroPython TechNotes: Continuous Rotation Potentiometer
- 022 - MicroPython TechNotes: Potentiometer | Reading an Analog Input
- 021 - MicroPython TechNotes: Color Touch Sensor
- 020 - MicroPython TechNotes: Touch Sensor
- 019 - MicroPython TechNotes: Switch Module
- 018 - MicroPython TechNotes: Button | Reading an Input
- 017 - MicroPython TechNotes: LASER Module
- 015 - MicroPython TechNotes: Neopixel 16
- 014 - MicroPython TechNotes: 8x8 Dot Matrix Display (I2C)
- 013 - MicroPython TechNotes: 8x16 Dot Matrix Display (SPI)
- 012 - MicroPython TechNotes: 8x8 Dot Matrix Display (SPI)
- 011 - MicroPython TechNotes: 1.3 OLED Display
- 010 - MicroPython TechNotes: 0.96 OLED Display
- 009 - MicroPython TechNotes: 7 Segment Display
- 008 - MicroPython TechNotes: 16x2 LCD
- 007 - MicroPython TechNotes: RGB LED
- 006 - MicroPython TechNotes: Traffic Light LED Module
- 005 - MicroPython TechNotes: Gorilla Cell LED | MicroPython Hello World
- 004 - MicroPython TechNotes: Gorilla Cell I/O Devices
- 003 - MicroPython TechNotes: Gorillacell ESP32 Shield
- 002 - MicroPython TechNotes: Introduction for Gorillacell ESP32 Dev Kit
- 001 - MicroPython TechNotes: Get Started with MicroPython
- 000 - MicroPython TechNotes: Unboxing Gorillacell ESP32 Development Kit
No comments yet!