Introduction to Lighting Solutions

[中文]

Note

This document is automatically translated using AI. Please excuse any detailed errors. The official English version is still in progress.

Overview and Advantages of Light Solutions

Espressif’s lighting solutions are renowned for their richness and maturity. Our solutions support a variety of common lamp-related peripherals, including LEDC, SPI, I2C, MCPWM, etc., offering a wide range of choices for your lighting needs. Combined with Espressif’s mature wireless protocols such as Wi-Fi and BLE, as well as cloud adaptation technology, you can easily implement remote control functions and manage your lighting system anytime, anywhere.

Moreover, Espressif has implemented AI voice recognition technology, allowing you to control lights through voice. Our audio algorithm makes music rhythm lights possible, while color recognition and image rhythm algorithms provide you with a variety of cutting-edge innovative solutions. These innovative technologies will bring more possibilities to your lighting system, making it smarter, richer, and more attractive. Here are the advantages of Espressif’s lighting solutions:

  • Zero-code lighting solution: ESP ZeroCode Solution No need to worry about complex steps such as firmware, mobile APP, cloud connection, certification, and production, directly build smart home devices compatible with Matter, including lighting devices

  • Rich software references: Provide comprehensive lamp-related software development materials, including detailed guidance documents and examples

Common Application Scenarios of Light

Espressif’s lighting solutions are widely used in various fields, and the types of lamps used in different fields also vary, summarized as follows:

ESP32

ESP32-S3

ESP32-C2

ESP32-C3

ESP32-C6

General Lighting

Bulb/Desk Lamp

LEDC/I2C

LEDC/I2C

LEDC/I2C

LEDC/I2C

LEDC/I2C

Adjustable Color Temperature Strip

SPI

SPI/RMT

SPI

SPI/RMT

SPI/RMT

Spotlight/Downlight/Candlelight/Ceiling Light

LEDC

LEDC

LEDC

LEDC

LEDC

Ambient Lighting

Colorful Strip/String Lights

SPI

SPI/RMT

SPI

SPI/RMT

SPI/RMT

Copper Wire Lights

SPI

SPI

SPI

SPI

SPI

Aroma Lamp/Splicing Lamp

SPI

SPI/RMT

SPI

SPI

SPI/RMT

Other Accessories

Silicon Controlled Dimmer

MCPWM

MCPWM

x

x

MCPWM/ETM+Analog Comparator

Other Functions

Music Rhythm

ESP-NOW Local Control

CSI Human Detection Function

Infrared Remote Control

x

x

Light Reference Materials

In addition, we currently have some public light github repositories, videos, and module materials, as follows:

Light Dimming Solutions Summary

PWM Dimming Solution

PWM dimming is a technique to control LED brightness by adjusting pulse width, the core of which is to adjust by changing the duty cycle of the current pulse (i.e., the proportion of high-level time in the entire cycle time). When the duty cycle is high, the LED gets a long current time and high brightness; conversely, when the duty cycle is low, the LED gets a short current time and low brightness. All ESP chips support using hardware LEDC Driver / MCPWM to output PWM, with the LEDC driver recommended for implementation first, as it supports hardware gradient, configurable frequency duty cycle, and a maximum resolution of 20 bit.

Note

  1. Does it support outputting complementary waveforms to adjust color temperature and brightness?

    • Yes, the hpoint function of LEDC can be used for phase shifting.

I2C Dimming Solution

I2C Dimming sends control commands to the dimming chip through the I2C bus, adjusting the LED brightness by changing the output current of the dimming chip. The I2C bus consists of two lines: the data line (SDA) and the clock line (SCL). All ESP chips support using hardware I2C dimming chips, and currently, perfect driving has been completed on common dimming chips such as SM2135EH, SM2235EGH, SM2335EGH, BP5758, BP5758D, BP5768, BP1658CJ, KP18058.

Note

  1. How much should the pull-up resistor for the I2C driver be selected?

    • Usually choose between 2.2 k-4.7 k, the signal quality can be determined by actual measurement.

Single-line Dimming Solution

The single-wire dimming solution is a method of controlling LED brightness through a single communication line, the core of which is to adjust the brightness of the LED by sending control signals through a specific communication protocol. There are currently 2 categories:

  • WS2812 and SK6812 types use a separate data bus to transmit color data through specific timing control.

  • Similar to power line carrier, multiplexing VCC and modulating communication data on it, only 2 wires are needed for the bead.

This type of solution can be implemented on the ESP chip using RMT peripherals or SPI peripherals. It is recommended to use SPI for bead communication control, and RMT is mostly used for receiving infrared remote control data.

Note

  1. What is the principle of SPI implementation?

    • Taking WS2812 as an example, it has RGB three-channel data, each channel is 1 byte, the default configuration SPI clock is 2.4 MHz, single bit transmission, then sending a bit is a clock about 400 ns, usually use 3 bits to represent 0 code and 1 code, that is, 0 code is composed of 2 bit high + 1 bit low, 1 code is composed of 1 bit high + 2 bit low, so each bit of 1 byte original data needs to be expanded to 3 bits to represent 0 and 1, so 1 byte original data needs to be expanded to 3 bytes SPI data. If we send orange, then the conversion is as follows:

    255 (0b11111111)        ->      11011011 01101101 10110110      ->      0xDB 0x6D 0xB6
    127 (0b01111111)        ->      10011011 01101101 10110110      ->      0x9B 0x6D 0xB6
    0   (0b00000000)        ->      10010010 01001001 00100100      ->      0x92 0x49 0x24
    

    The actual data sent by SPI is {0xDB 0x6D 0xB6},{0x9B 0x6D 0xB6},{0x92 0x49 0x24 }, the RGB data sequence of different light strips may be different, and need to be adjusted according to the actual situation.

  2. Does SPI support connecting multiple light strips?

    • Yes, changing the SPI transmission mode to 4 bit can support 4 light strips. It should be noted that the original data conversion to SPI data also needs to be changed. At this time, 4 bits of data will be sent in 1 clock.

  3. Can you provide the design idea of SPI driving light strip driver?

    • If the SPI clock is 2.4 MHz, each clock is 0.4167 us, if it is sent in 8 bit mode, 1 byte is sent in 1 clock, 10 KB is also 10000 clocks, and it is sent in 4160 us. Use the STC mode of SPI, and group 10 1 KB brush light data in one spi_multi_transaction_t. The SPI queue length is set to 1, malloc 2 10 KB buf, each time the data is grouped, use spi_device_queue_multi_trans to send, then another buf fills the data, after filling, use spi_device_get_multi_trans_result to get the previous result of the light strip, after returning successfully, group the data again, and 2 buf cycle fill the data.

Silicon Controlled Dimming Solution

Triac dimming is a dimming technology that controls the brightness of a lamp by adjusting the phase of the current. It is widely used in incandescent lamps, halogen lamps, and some LED lamps compatible with triac dimming. The core is to adjust the phase angle of the triac conduction, changing the conduction time of the current in each AC cycle, to achieve the regulation of the lamp’s power output and brightness. There are mainly two types of phase-cutting methods for triac dimming:

  • Leading edge cutting: Cutting is performed in the first half of the AC waveform, and the Triac starts to conduct at the leading edge of each AC cycle. Suitable for incandescent lamps and some compatible LED lamps.

  • Trailing edge cutting: Cutting is performed in the second half of the AC waveform, and the Triac starts to conduct at the trailing edge of each AC cycle. Suitable for some compatible LED lamps and electronic transformers.

The software design follows the following 3 steps:

  1. Phase detection: Detect the zero-crossing point of the AC power to determine the timing of the dimming signal. Zero-crossing detection can be achieved through optocouplers and detection circuits.

  2. Phase control: Calculate the corresponding conduction delay time according to the brightness set by the user, and control the Triac to conduct at the appropriate time.

  3. Trigger control: After detecting the zero-crossing point, trigger the Triac to conduct according to the set delay time, generally using a 50 us pulse to trigger conduction.

In ESP chips, the above functions are usually implemented using MCPWM peripherals or ETM + Analog comparator peripherals. It is recommended to use MCPWM peripherals for implementation. The implementation principle is: Enable 2 comparators A and B on the same timer, and operate the same IO. Comparators A and B output low levels when the timer counter is 0. Set a comparison value x, x is the delayed conduction time, and set comparator A to output a high level when the timer is x, and comparator B to output a low level when the timer is x + 50. Use the synchronization function of MCPWM to capture the zero-crossing point. The timer will be automatically reset when synchronized, thus completing a phase-cutting control. The accuracy of the zero-crossing point capture can be controlled to less than 1 us.

Note

  1. Can it be implemented on chips such as ESP32C2 that do not have MCPWM peripherals?

    • It can be implemented using a gptimer + IO simulation scheme. All control functions need to be placed in ram. However, due to chip and software design factors, the accuracy of zero-crossing point capture will still be affected by system interrupts. Especially after enabling Wi-Fi and Bluetooth, it usually fluctuates between 4.7 us ~ 20 us, which is very unstable. This will cause poor compatibility of the dimmer, and some LED lamps compatible with the dimmer will have intermittent flickering. If the evaluation is acceptable, the above scheme can be used.

Light Additional Feature Components

Music Rhythm

Music rhythm is a lighting control technology that analyzes music signals in real time to synchronize the lights with the rhythm, melody, and sound effects of the music. All ESP32 platform chips support local music rhythm, obtain audio data through ADC, and then get waterfall, jump, gradient and other lighting effect data after FFT or loudness calculation, refresh to the bulb through the driver, and display.

ESP-NOW Local Control Function

ESP-NOW is a connectionless Wi-Fi communication protocol defined by Espressif. In ESP-NOW, application data is encapsulated in the action frames of various vendors, and then transmitted from one Wi-Fi device to another Wi-Fi device without connection. In the field of smart lighting, this technology is often used as a random sticker switch for lamps.

CSI Human Detection Function

Channel State Information (CSI) is an important parameter describing the characteristics of wireless channels, including signal amplitude, phase, signal delay, and other indicators. In Wi-Fi communication, CSI is used to measure the state of wireless network channels. CSI is very sensitive to environmental changes. It can not only perceive large-scale movements such as walking and running of people or animals, but also perceive subtle movements such as breathing and chewing in a static environment. In the field of smart light bulbs, CSI can be used as a human perception sensor to realize the function of turning on the light when someone comes and turning off the light when someone leaves.

Infrared Remote Control

Infrared remote control is a technology that uses infrared light signals to transmit control instructions, which is widely used in the remote control operation of household appliances such as televisions, air conditioners, audio equipment, and lighting fixtures. The infrared remote control system usually consists of an infrared transmitter (remote control) and an infrared receiver (controlled device). The infrared transmitter modulates the infrared light signal and sends out the control instruction in the form of pulse coding. After the infrared receiver receives the signal, it demodulates and decodes the control instruction, and then performs the corresponding operation. In the lighting field, this technology is used as a local infrared remote control for light strips, downlights, spotlights, and ambient lights.

Light Bulb Driver Component

The Light Bulb Component encapsulates several common dimming schemes in light bulbs, and adds effects, calibration, state memory, power limit and many other common functions, making it easy for developers to integrate into their own applications. All ESP32 series chips are currently supported.

Supported dimming schemes are as follows

  • PWM scheme

    • RGB + C/W

    • RGB + CCT/Brightness

  • I2C dimming chip scheme

    • SM2135EH

    • SM2X35EGH (SM2235EGH/SM2335EGH)

    • BP57x8D (BP5758/BP5758D/BP5768)

    • BP1658CJ

    • KP18058

  • Single bus

    • WS2812

Supported lamp board layouts are as follows

  • Single channel: Cold or warm color temperature beads, can complete brightness control under single color temperature.

  • Dual channel: Cold and warm beads, can complete color temperature and brightness control.

  • Three channels: Red, green, and blue beads, can complete any color control.

  • Four channels: Red, green, blue, cold or warm beads, can complete color and single color temperature brightness control, if a color mixing table is configured: it supports using these beads to mix different color temperatures, to achieve color temperature control.

  • Five channels: Red, green, blue, cold, warm beads, can complete color and color temperature brightness control.

Gradient Principle

The gradient in the light bulb component is implemented by software. Each channel records the current value, final value, step size, number of steps, number of cycles, minimum value, the last two parameters are used for effects. When using the API to set the color, it will sequentially change the final value, step size, and number of steps, and enable the gradient timer. The timer triggers a callback every 12 ms. The callback function will check the number of steps of each channel. As long as there are steps that have not been executed, it will add or subtract the current value according to the step size and update it to the underlying driver. When the number of steps of all channels is 0, it means that the gradient is completed, and the timer will be stopped at this time.

Low Power Implementation

If the bulb is to pass power consumption certifications such as T20, after optimizing the lamp board power supply, some low-power configurations need to be made on the software side. In addition to the configurations mentioned in the Low Power Mode Usage Guide, some logic also needs to be done in the driver part. The bulb component has added related content in both the PWM and I2C dimming driver schemes. The specific logic is that when the switch is turned on, the I2C scheme calls the low-power command of the dimming chip itself to exit or enter low power. In the PWM scheme, the ESP32 needs to manage the power lock due to the use of the APB clock source, otherwise the light will flicker. When the light is on, take the power lock and disable dynamic frequency adjustment. When the light is off, release it. Other chips use the XTAL clock source and do not need to take any measures.

Maintain Color After Abnormal Restart

The implementation in the bulb driver component is as follows: The PWM scheme can use the XTAL clock source, and the software restart does not affect the LEDC driver output; The I2C scheme needs to do software logic. After each successful operation of the lamp, the color needs to be recorded in the flash. After an abnormal restart, the color saved in the flash is used directly to light the lamp.

Power-on Lighting Speed

When using the bulb driver component to light up, the time from the lamp board power supply to the lamp lighting is usually between 150 ~ 300 ms. The main time consumption is in the log printing and various verifications related to chip security (Flash encryption, secure boot, etc.) in the ROM and bootloader stages. If encryption is not enabled and all logs at the startup stage are turned off, the lighting time will be less than 100 ms.