This is an old revision of the document!
A Smart LED stripe is a chain of connected digital LEDs (also referenced as NEOPIXEL) which can be individually controlled. The stripe in our lab equipment consists of eight RGB LEDs. There exist also other configurations such as RGBWW (Red+Green+Blue+Warm White+Cold White) or WWA (Warm White+Cold White+Amber). They are controlled with just one pin/GPIO. GPIO sends the digital signal to the first LED in a chain and the LED passes data to the next one, and so on.
The most common type of LED stripes is WS2812B (RGB). Initially LED Stripes were powered with 5V, but that limits the length of the chain up to some 1-2m (because of the voltage drop), so nowadays LED stripes powered with 12V and even 24V are getting more and more popular.
In this scenario, you will learn how to control a small LED RGB Stripe, composed of 8 Smart (Digital) LEDs with STM32 SoC.
Familiarise yourself with a hardware reference on the LED Stripe. It is controlled with a single GPIO (D8 in Arduino style naming, or PC_12 in Nucleo style naming), as presented in the “Table 1: STM32WB55 Node Hardware Details” on the hardware reference page. To control a WS2812B LED stipe, we will use a library:
adafruit/Adafruit NeoPixel@^1.12.0
There are at least two ways (algorithms) to implement this task:
delay(…);
) function calls in the void loop();
or,Implement a rainbow of colours flowing through the LED Stripe.
When booking a device, ensure the LED stripe is visible in the camera.
Below, we provide a sample colour configuration that does not reflect the desired effect that should result from the exercise. It is just for instructional purposes. You need to invent how to implement a rainbow effect yourself.
Include necessary library:
#include "Freenove_WS2812_Lib_for_ESP32.h"
Declare configuration and a controller class:
#define WLEDS_COUNT 8 #define WLEDS_PIN 34 #define WLEDS_CHANNEL 0 static Freenove_ESP32_WS2812 stripe = Freenove_ESP32_WS2812(WLEDS_COUNT, WLEDS_PIN, WLEDS_CHANNEL, TYPE_GRB);
To switch a particular LED, use the following function:
stripe.setLedColorData(1,60,0,0); //light Red of the 2nd LED stripe.show(); //Writes colours to the LED stripe
Parameters are: setLedColorData(int index, u8 r, u8 g, u8 b);
.
If you want to set all LEDs in the stripe to the same colour, there is a handy function: setAllLedsColorData(u8 r, u8 g, u8 b);
.
Remember to use the show();
function afterwards.
Observe the flow of the colours via the stripe.
I cannot see the colour via the video camera - everything looks white…: Try to lower the LED's brightness.