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.
By Harry Fairhead
Available as a softback, hardback and kindle from Amazon
Contents
Preface
- The ESP32 – Before We Begin
- Getting Started
- Getting Started With The GPIO
- Simple Output
- 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
Extract: The S3's RGB LED
- The Serial Port
- Using WiFi
Extract:Socket Web Client ***NEW!
- Direct To The Hardware
- Free RTOS
<ASIN:1871962919>
<ASIN:187196282X>
A very simple one-wire protocol is used with the NeoPixel style of lighting strip. What follows is applicable to a general NeoPixel array, but it is specific to the RGB LED built-in to most ESP32 S3 development boards.
The task is to make use of the RGB LED that is standard on an ESP32 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 simple terms, the timing requirements are such that the ESP32 is only just fast enough to cope.
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 0 is sent with a high time of 350ns and a 1 is sent with a high time of 700ns and a total pulse width of 1.25μs, all timings are ±150ns. The RET code is just a minimum low time between groups of 24-bit signals. If you have multiple LEDs daisy chained you can control each one individually by sending groups of 24 bits at a time. Each LED consumes 24 bits 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 24 bits specifying the color. The LEDs process the stream of bits until the line is held low for at least 50μs, i.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:
|