Page 1 of 2 The ESP32 S3 has an onboard RGB NeoPixel LED and you can use it via a simple GPIO line - really easy. This is an extract from Harry Fairhead's latest book on programming the ESP32 using C and the IDF.
Programming The ESP32 In C Using The Espressif IDF
By Harry Fairhead
To be published in October 2024. Sign up to our newsletter or RSS feed to be notified.
Contents
Preface
- The ESP32 – Before We Begin
- Getting Started
- Getting Started With The GPIO
- Simple Output
Extract: The S3's RGB LED ***NEW!
- Some Electronics
- Simple Input
- Advanced Input – Interrupts
- Pulse Width Modulation
- Controlling Motors And Servos
- Getting Started With The SPI Bus
- Using Analog Sensors
- Using The I2C Bus
- One-Wire Protocols
- The Serial Port
- Using WiFi
- Direct To The Hardware
- Free RTOS
<ASIN:187196282X>
This is an advanced topic that pushes direct GPIO signal generation to the limit. In simple terms the requirements are such that the ESP32 is only just fast enough to cope. The task is to make use of the RGB LED that is standard on an ESP 32 S3. This is an addressable LED in the WS2812 family and you can run this program on an ESP32 by connecting a WS2312 “NeoPixel” device to a GPIO line. In the most general case you can daisy chain NeoPixels to produce linear strips of LEDs:
To set an LED to a color you have to send a 24 bit value on the Data line using a coding:
The data line rests low and a zero is sent with a high time of 350ns and a one is sent with a high time of 700ns and a total pulse width of 1.25μsAll timings are ±150ns. The RET code is just a minimum low time between groups of 24bit signals. If you have multiple LEDs daisy chained you can control each one individually by sending groups of 24bits at a time. Each LED consumes 24bits of the signal and passes the remaining bits on to the next LED in the chain. In this way each LED in the chain gets its own 24bits specifying the color. The LEDs process the stream of bits until the line is held low for at least 50μsi.e. the Ret code. At this point all of the LEDs transfer the data to a latch and display the specified color. The format used to set the color is:
As already mentioned you can connect a NeoPixel device to any GPIO line to act as the data line but the ESP32 S3 has a single NeoPixel connected to either GPIO38 or GPIO48 depending on the development board. Some boards also have a solder pad next to the LED that has to be connected before the LED can be used. You can connect them with a small blob of solder:
|