In the previous article, we described how to make an addressable LED strip controller and write firmware based on the 2Smart Cloud SDK. This article will show you how to write a fully compatible firmware for the same controller but based on ESPHome.
Details on how to make a LED strip controller and write firmware for it are here. The first article describes how to create firmware using the SDK of the platform for IoT product development, a powerful tool that we recommend to most vendors.
However, in many cases, ESPHome is a fairly functional tool. Its main advantage is simplicity. Using ESPHome, it will be easier for you to modify the firmware and add new functionality — for example, connect additional sensors and create a smart multitool.
You can use the firmware configuration provided in this article as part of the code configuration for a more complex device. You can also use the LED strip controller to compare two firmware creation tools for the ESP32 microcontroller: SDK and ESPHome.
After selecting the appropriate lines of code, we added controller effects and included support for the Reset button and Wi-Fi signal sensor in the firmware.
Full code from our example:
light:
- platform: fastled_clockless
chipset: WS2812B
pin: 18
num_leds: 300
rgb_order: GRB
name: FastLED WS2812 Light
id: light_rgb
effects:
- random: null
- pulse:
name: "Fast Pulse"
transition_length: 0.5s
update_interval: 0.5s
- strobe: null
- addressable_scan:
move_interval: 50ms
scan_width: 4
- addressable_random_twinkle:
twinkle_probability: 20%
progress_interval: 100ms
- addressable_color_wipe: null
- addressable_rainbow: null
- addressable_fireworks:
name: Fireworks Effect With Custom Values
update_interval: 32ms
spark_probability: 10%
use_random_color: false
fade_out_rate: 120
binary_sensor:
- platform: gpio
id: led_switch
pin:
number: GPIO5
mode: INPUT_PULLUP
inverted: true
name: Led switch
on_click:
then:
- light.toggle: light_rgb
- platform: gpio
id: change_effect
pin:
number: GPIO4
mode: INPUT_PULLUP
inverted: true
name: Change effect
on_click:
then:
- lambda: !<!lambda> |-
uint32_t total = id(light_rgb)->get_effects().size();
uint32_t curr_idx = 0;
uint32_t i = 0;
std::string curr_effect = id(light_rgb)->get_effect_name();
auto call = id(light_rgb)->turn_on();
// set first effect in list
if (strcasecmp(curr_effect.c_str(), "none") == 0) {
call.set_effect(1);
call.perform();
return;
}
for (auto *effect : id(light_rgb)->get_effects()) {
i++;
if (strcasecmp(effect->get_name().c_str(), curr_effect.c_str()) == 0)
curr_idx = i;
}
if (curr_idx == total) {
call.set_effect(0);
} else {
call.set_effect(curr_idx + 1);
}
call.perform();
- platform: reset_sensor
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: true
name: Reset button
filters:
- delayed_on: 1s
sensor:
- platform: wifi_signal
name: WiFi1 Signal
update_interval: 30s
id: wifi_config
./2smart.sh erase_flash -d /dev/tty.SLAB_USBtoUART.
./2smart.sh write -d /dev/tty.SLAB_USBtoUART
We’re empower your business with our technology expertise
./2smart.sh erase_flash -d /dev/tty.SLAB_USBtoUART
./2smart.sh write -d /dev/tty.SLAB_USBtoUART
That’s it! We have created a LED strip controller without programming and using assembler programs. The firmware code for ESPHome was written according to the documentation for this base. In fact, we just took ready-made examples and used them on our device.
Simplicity is the main advantage of ESPHome. Therefore, even if you plan to use firmware based on our SDK on production devices, we recommend testing the product using simpler tools. This reduces the time to create an IoT device.
The development of this idea is an LED lighting smart IoT solution where the controller described above controls the LED matrix, which is the basis for a smart lamp with multiple effects.
Share with us your business idea and expectations about custom software development for the internet of things.