STM_8: Controlling Smart LED stripe

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 colour 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.

Sometimes such a chain of electronic elements is nicely called the Daisy Chain.

Prerequisites

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
Note, this library can also control other RGB LED stripes than WS2812B.

There are at least two ways (algorithms) to implement this task:

  • using the blocking (delay(…);) function calls in the void loop(); or,
  • using a timer (see advanced scenario).

Suggested Readings and Knowledge Resources

Hands-on Lab Scenario

Task to be implemented

Implement a rainbow of colours flowing through the LED Stripe.

Note, do not change colours too fast, as you won't be able to observe changes via the video stream. An update once per second is usually suitable.

Start

When booking a device, ensure the LED stripe is visible in the camera.

Due to the low camera dynamics, do not use the full brightness of the LEDs: off is equivalent to 0, and the full brightness of the colour is 255 (8-bit resolution, per colour). We suggest to use up to 60 or max 100.
Because of the camera and human eye characteristics, the same numerical brightness set for one colour can bring a much different brightness experience on another, so setting up 60 to channel Red will have a different overall experienced brightness than setting 60 to channel Blue or Green.

Steps

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.

Step 1

Include necessary library:

#include "Adafruit_NeoPixel.h"

Step 2

Declare configuration and a controller class:

#define NEOPIXEL_PIN D8  //Arduino numbering D8, STM numbering PC_12
#define NUMPIXELS 8      //How many LEDs are attached
 
Adafruit_NeoPixel strip(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);

The strip class definition contains the number of pixels, the pin for transmission, and the type of LEDs. In our laboratory LEDs use Green Red Blue format of data and 800kHz data transmission frequency.

Step 3

To switch a particular LED, use the function setPixelColor();. It accepts parameters of different types.

void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
void setPixelColor(uint16_t n, uint32_t c);

If you use the first version you give the LED number as the first parameter and then three colour values for red, green and blue colour intensity as the number in the 0-255 range.
If you use the second version you give the LED number as the first parameter and a 32-bit version of the colour information. To convert three RGB bytes to 32-bit value you can use the function Color();:

static uint32_t Color(uint8_t r, uint8_t g, uint8_t b);
Note that the LED number is 0-based, so in the case of our laboratory equipment, valid indexes are 0…7.

The setPixelColor(); sets the appropriate data in the internal buffer of the class object. Sending it to the LED stripe requires the usage of the show(); function afterwards.
The different versions of the setPixelColor(); function can look like in the following code:

strip.setPixelColor(0, strip.Color(10, 0, 0)); // Red
strip.setPixelColor(1, 0, 10, 0);              // Green
strip.setPixelColor(2, 0, 0, 10);              // Blue
strip.setPixelColor(3, 0x000F0F0F);            // White
strip.show();                           // Update strip 

Result validation

Observe the flow of the colours via the stripe.

FAQ

I cannot see the colour via the video camera - everything looks white…: Try to lower the LED's brightness.

Project information


This Intellectual Output was implemented under the Erasmus+ KA2.
Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, companies and labour force in the global IoT market.
Project number: 2022-1-PL01-KA220-HED-000085090.

Erasmus+ Disclaimer
This project has been funded with support from the European Commission.
This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein.

Copyright Notice
This content was created by the IOT-OPEN.EU Reloaded consortium, 2022,2024.
The content is Copyrighted and distributed under CC BY-NC Creative Commons Licence, free for Non-Commercial use.

en/iot-open/practical/hardware/sut/stm32/emb8_1.txt · Last modified: 2024/04/20 09:46 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0