2025-03-26 10:21 AM - last edited on 2025-03-29 12:56 PM by Amel NASRI
Hi everyone,
I'm having some strange issues with my ws2812b neopixels, and can't quite figure out what's causing them. Some color settings work perfectly, while others trigger this odd behaviour. Even weirder, certain fixes just seem to shift the issue to different color settings instead or resolving it entirely. And to make things more confusing - it doesn't happen every time.
When I send color data to my ws2812b, certain colors cause the first led to appear much brighter with an excessive amount of green. This happens only on the first led. No matter how many leds are in the chain, the rest display the correct colors. I've tested multiple ws2812b rings and strips, but the issue persists.
To rule out voltage level problems i added a level shifter to shift both, supply voltage and data line voltage to 5 volts. The problem remained, just brighter :) I can't quite put my finger on whats happening because it's just so bizarre.
I am using the nucleo stm32C071RB board. It works at 48MHz. I set the counter period to 60 (60-1) that leads to 1.25us for each bit (slight variations to the period have no effect). The T0H is 19 cycles high (0.395us) and the T1H is 38 cycles high (0.791us) - slight variations to the values have no effect. Changing reset time does not have any effects. Since I’m using DMA, I doubt it’s a timing issue.
Actual the issue appears when switching between red (r=102,g=b=0) and yellow (r=80,g=20,b=0) every 2 seconds. Red will be shown correctly but the yellow part shows the first led to bright with too much green. Therefore i got the issue by changing between red (r=100) and red (r=200) at r=200. Sometimes i even observe a strange cycle pattern:
1. All leds are red (right)
2. All yellow except the first which is too bright and green
3. All leds switch back to red, but too bright
4. All leds are yellow including the first one in the right color
This code transfers the data to dma. I've kept things simple for debugging purposes:
for (uint16_t index = 0; index < WS2812B_DMA_BUF_LEN; index++)
WS2812B_DMA_BUF[index] = 0;
uint16_t _bufIndex = 0;
for (uint16_t led = 0; led < START_LIGHTS; led++){
for (uint8_t greenIndex = 0; greenIndex < 8; greenIndex++){
if (WS2812B_DATA[led].g & (0x01 << (7-greenIndex)))
WS2812B_DMA_BUF[_bufIndex] = WS2812B_T1H;
else
WS2812B_DMA_BUF[_bufIndex] = WS2812B_T0H;
_bufIndex++;
}
for (uint8_t redIndex = 0; redIndex < 8; redIndex++){
if (WS2812B_DATA[led].r & (0x01 << (7-redIndex)))
WS2812B_DMA_BUF[_bufIndex] = WS2812B_T1H;
else
WS2812B_DMA_BUF[_bufIndex] = WS2812B_T0H;
_bufIndex++;
}
for (uint8_t blueIndex = 0; blueIndex < 8; blueIndex++){
if (WS2812B_DATA[led].b & (0x01 << (7-blueIndex)))
WS2812B_DMA_BUF[_bufIndex] = WS2812B_T1H;
else
WS2812B_DMA_BUF[_bufIndex] = WS2812B_T0H;
_bufIndex++;
}
}
HAL_StatusTypeDef halStatus = HAL_TIM_PWM_Start_DMA(htim, TIM_CHANNEL_1, (uint32_t *) WS2812B_DMA_BUF, WS2812B_DMA_BUF_LEN);
I’d really appreciate any insights, suggestions, or experiences you can share. Thanks so much for your help!
Solved! Go to Solution.
2025-10-15 11:54 AM
Hey Andrew,
thanks for the answers. Of course i only shifted the logic. I expressed myself incorrectly. I found out, that i have the issue only with hal and
HAL_TIM_PWM_Start_DMA
And it came out, it was a timing issue. The first interval was sometimes incorrect and the first led misinterpreted the 0 as 1. After I let the signal a few intervals 0 at the beginning, the issue disappears.
2025-10-15 2:55 AM
Hello,
See also: Controlling WS2812B LED Strip With STM32
WS2812 LED with STM32 || PWM using DMA
2025-10-15 3:01 AM - edited 2025-10-15 3:17 AM
@pmge wrote:This happens only on the first led. No matter how many leds are in the chain, the rest display the correct colors.help!
That sounds like a timing issue - since these LEDs regenerate the timing on their data output.
So get an oscilloscope or logic analyser, and look very carefully at your actual timing on the wire ...
As @mƎALLEm says, there have been many threads on this - try a forum search; eg,
PS:
@pmge wrote:To rule out voltage level problems i added a level shifter to shift both, supply voltage and data line voltage to 5 volts.!
Eh?
Voltage level shifters are only designed to shift signals - not power.
Again, look at the lines with an oscilloscope to be sure.
Please post the schematic.
Some good, clear photos of your setup would also help.
How to write your question to maximize your chances to find a solution
2025-10-15 3:58 AM
I made a ws2812 library some years back using dma+timer driven pwm. I don't know what is wrong with yours although I would agree with someone else who said it sounds like a timing issue. My library is here if you want to have a look and compare: https://github.com/lbthomsen/stm32-ws2812
2025-10-15 11:54 AM
Hey Andrew,
thanks for the answers. Of course i only shifted the logic. I expressed myself incorrectly. I found out, that i have the issue only with hal and
HAL_TIM_PWM_Start_DMA
And it came out, it was a timing issue. The first interval was sometimes incorrect and the first led misinterpreted the 0 as 1. After I let the signal a few intervals 0 at the beginning, the issue disappears.
2025-10-16 1:50 AM
Glad you fixed it - thanks for feeding back.
@pmge wrote:Of course i only shifted the logic. I expressed myself incorrectly
This is why showing a schematic is so much more effective than trying to describe circuits in words!