015 - MicroPython TechNotes: Neopixel 16
Introduction
In this article, we will learn about the addressable NeoPixel. Addressable Neopixel contains a WS2812B chip and an RGB LED in one package. With WS2812B, it is possible to make the a chain of RGB LED to be addressable. Meaning to say, it can be controlled individually.
Bill Of Materials
- ESP32 development board.
- ESP32 shield from Gorillacell ESP32 development kit (optional, you can still make it without this shield. It is just use to simplify the circuit connection).
- 3-pin female-female dupont jumper wires.
- Neopixel Ring (16 RGB)
Pinout
- GND – for the ground pin.
- VCC – for the supply voltage.
- DI – for the Data Input (DI) control signal pin.
Hardware Instruction
- First, attach the ESP32 dev board on top of the ESP32 shield making sure that pins are aligned and the USB ports are on the same side.
- Next, attach the dupont wires to the Neopixel ring according to the color coding which is black for the ground, red for the VCC, and yellow for the control signal pin.
- Next, attach the other side of the dupont to the ESP32 shield by matching the colors of the wires to the colors of the pin headers in the ESP32 shield, that is black to black, red to red, and yellow to yellow.
- Next, power the ESP32 shield by attaching an external power supply with a type-C USB connector. Make sure that the power switch is set to the ON state.
- Next, connect the ESP32 to the computer through the micro USB cable. The demo circuit should now be ready.
Software Instruction
MicroPython has a builtin module or driver library for the Neopixel. Just import it in the source code.
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, basic exploration of the neopixel:
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 = 16
8np = NeoPixel(Pin(23), NUM_OF_LED)
9
10
11# # The following lines of codes should be tested using the REPL
12# # Syntax:
13# # np[] = (, , )
14# # np.write()
15# # ------------------------------------------------------------
16# # 1. To set the 1st neopixel to red color:
17# np[0] = (255, 0, 0)
18# np.write()
19#
20# # 2. To set the 4th neopixel to green color:
21# np[3] = (0, 255, 0)
22# np.write()
23#
24# # 3. To set the 5th and 7th neopixel to blue color:
25# np[4] = (0, 0, 255)
26# np[6] = (0, 0, 255)
27# np.write()
28#
29# # 4. To set the 1st to red color,
30# # 3rd to green color, and
31# # 5th to blue color
32# np[0] = (255, 0, 0)
33# np[2] = (0, 255, 0)
34# np[4] = (0, 0, 255)
35# np.write()
36#
37# # 5. The value given to each neopixel LED
38# # represents its brightness
39# np[0] = (1, 0, 0)
40# np.write()
41#
42# # 6. To turn OFF all neopixel:
43# for npixel in range(16):
44# np[npixel] = (0, 0, 0)
45# np.write()
2. Example # 2, rotating LED light:
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
6from time import sleep_ms
7
8NUM_OF_LED = 16
9np = NeoPixel(Pin(23), NUM_OF_LED)
10
11while True:
12 for npixel in range(NUM_OF_LED):
13 np[npixel] = (0, 0, 255)
14 np.write()
15 sleep_ms(100)
16 np[npixel] = (0, 0, 0)
17 np.write()
3. Example # 3, same as Example # 2 but changes LED color each rotation:
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
6from time import sleep_ms
7
8NUM_OF_LED = 16 # Number of Neopixel LED
9LED_ON_VALUE = 255 # 255 is maximum value for the LED brightness
10LED_OFF_VALUE = 0 # while 0 to turned it OFF
11red_value = LED_ON_VALUE # Start with red
12grn_value = 0 # and all others
13blu_value = 0 # are turned OFF
14
15# Create the neopixel instantiation named np
16np = NeoPixel(Pin(23), NUM_OF_LED)
17
18while True:
19 for npixel in range(NUM_OF_LED):
20 np[npixel] = (red_value, grn_value, blu_value)
21 np.write()
22 sleep_ms(100)
23 np[npixel] = (0, 0, 0)
24 np.write()
25
26 # If its the last LED, change color
27 if npixel==NUM_OF_LED-1:
28 # If its now red, make it green
29 if red_value==LED_ON_VALUE:
30 red_value = LED_OFF_VALUE
31 grn_value = LED_ON_VALUE
32 # If its green, make it blue
33 elif grn_value==LED_ON_VALUE:
34 grn_value = LED_OFF_VALUE
35 blu_value = LED_ON_VALUE
36 # If its blue, make it red
37 elif blu_value==LED_ON_VALUE:
38 blu_value = LED_OFF_VALUE
39 red_value = LED_ON_VALUE
References And Credits
- Purchase the 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
- 016 - MicroPython TechNotes: RGB LED Matrix
- 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!