A high-performance, DMA-based addressable RGB LED driver library for STM32 microcontrollers with 56 stunning visual effects.
- ๐ High Performance: DMA + PWM driven, minimal CPU overhead
- ๐จ 56 Visual Effects: From static colors to dynamic animations
- ๐ฏ Multi-Strip Support: Control multiple independent LED strips simultaneously
- ๐ Color Spaces: RGB and HSV color space support
- ๐ก Brightness Control: Global brightness adjustment (0-255)
- โก Gamma Correction: Optional gamma correction for better color reproduction
- ๐ช Flexible Configuration: Support for static or dynamic memory allocation
- ๐ฆ Easy Integration: Simple API, minimal dependencies
| LED Type | Color Order | Frequency | White Channel |
|---|---|---|---|
| WS2811S | RGB | 400kHz | โ |
| WS2811F | RGB | 800kHz | โ |
| WS2812/B | GRB | 800kHz | โ |
| SK6812 | RGBW | 800kHz | โ |
- STM32 microcontroller (tested on STM32F4 series)
- HAL Library
- Timer with PWM capability
- DMA channel
- GCC ARM toolchain or Keil MDK
Connect your LED strip data line to a PWM-capable timer pin (e.g., TIM1_CH1).
Copy the following files to your project:
ARGB.c
ARGB.h
ARGB_Effects.c (optional, for effects)
ARGB_Effects.h (optional, for effects)
#include "ARGB.h"
// Define buffers (for 30 LEDs, WS2812)
uint8_t rgb_buffer[ARGB_GET_RGB_BUF_SIZE(30, ARGB_WS2812)];
uint8_t pwm_buffer[ARGB_GET_PWM_BUF_SIZE(ARGB_DMA_BYTE, ARGB_WS2812)];
// Initialize ARGB handle
ARGB_HandleTypeDef hargb;
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM1_Init();
// Initialize ARGB driver
ARGB_Init(&hargb, &htim1, &hdma_tim1_ch1, TIM_CHANNEL_1,
30, // 30 LEDs
ARGB_WS2812, // LED type
ARGB_DMA_BYTE, // DMA size
1, // Enable gamma correction
rgb_buffer, // RGB buffer
pwm_buffer); // PWM buffer
// Set brightness
ARGB_SetBrightness(&hargb, 128);
// Set all LEDs to red
ARGB_FillRGB(&hargb, (ARGB_RGB){255, 0, 0});
// Update display
ARGB_Show(&hargb);
while (1) {
// Your code here
}
}#include "ARGB_Effects.h"
ARGB_FX_HandleTypeDef hfx;
int main(void) {
// ... initialization code ...
// Initialize effects
ARGB_FX_Init(&hfx, &hargb);
// Set effect mode
ARGB_FX_SetMode(&hfx, FX_MODE_RAINBOW_CYCLE);
// Set effect speed (lower = faster)
ARGB_FX_SetSpeed(&hfx, 10);
// Set effect color
ARGB_FX_SetColor(&hfx, COLOR_RED);
while (1) {
// Call service function periodically
ARGB_FX_Service(&hfx);
HAL_Delay(1);
}
}ARGB_STATE ARGB_Init(ARGB_HandleTypeDef *hargb,
TIM_HandleTypeDef *htim,
DMA_HandleTypeDef *hdma,
uint32_t tim_channel,
uint16_t num_pixels,
ARGB_LED_TYPE led_type,
ARGB_DMA_SIZE dma_size,
uint8_t use_gamma,
uint8_t *rgb_buf,
void *pwm_buf);void ARGB_SetRGB(ARGB_HandleTypeDef *hargb, uint16_t i, ARGB_RGB color);
void ARGB_SetHSV(ARGB_HandleTypeDef *hargb, uint16_t i, ARGB_HSV hsv);
void ARGB_FillRGB(ARGB_HandleTypeDef *hargb, ARGB_RGB color);
void ARGB_FillHSV(ARGB_HandleTypeDef *hargb, ARGB_HSV hsv);
void ARGB_Clear(ARGB_HandleTypeDef *hargb);ARGB_STATE ARGB_Show(ARGB_HandleTypeDef *hargb);
ARGB_STATE ARGB_Ready(ARGB_HandleTypeDef *hargb);
void ARGB_SetBrightness(ARGB_HandleTypeDef *hargb, uint8_t br);void ARGB_FX_Init(ARGB_FX_HandleTypeDef *hfx, ARGB_HandleTypeDef *hargb);
void ARGB_FX_SetMode(ARGB_FX_HandleTypeDef *hfx, ARGB_FX_MODE mode);
void ARGB_FX_SetColor(ARGB_FX_HandleTypeDef *hfx, ARGB_RGB color);
void ARGB_FX_SetSpeed(ARGB_FX_HandleTypeDef *hfx, uint16_t speed);
void ARGB_FX_Service(ARGB_FX_HandleTypeDef *hfx);- Static Color
- Blink
- Breath
- Fade
- Random Color
- Color Wipe
- Color Wipe Inverse
- Color Wipe Reverse
- Color Wipe Random
- Rainbow
- Rainbow Cycle
- Strobe Rainbow
- Blink Rainbow
- Theater Chase Rainbow
- Scan
- Dual Scan
- Theater Chase
- Chase White
- Chase Color
- Chase Random
- Chase Rainbow
- Chase Flash
- Chase Blackout
- Sparkle
- Flash Sparkle
- Hyper Sparkle
- Twinkle
- Twinkle Random
- Twinkle Fade
- TwinkleFOX
- Running Lights
- Running Color
- Running Red/Blue
- Running Random
- Larson Scanner (K.I.T.T.)
- Comet
- Fireworks
- Fire Flicker (3 variants)
- Strobe (Multi)
- Merry Christmas
- Halloween
- Circus Combustus
- Single Dynamic
- Multi Dynamic
- Bicolor Chase
- Tricolor Chase
- Color Sweep Random
The library includes 200+ predefined colors:
COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_BLACK,
COLOR_ORANGE, COLOR_PURPLE, COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA,
COLOR_PINK, COLOR_LIME, COLOR_TURQUOISE, COLOR_VIOLET, COLOR_GOLD,
// ... and many more!See ARGB_Effects.h for the complete color palette.
// In ARGB.h, keep commented:
// #define ARGB_USE_DYNAMIC_BUFFERS
uint8_t rgb_buf[ARGB_GET_RGB_BUF_SIZE(num_pixels, led_type)];
uint8_t pwm_buf[ARGB_GET_PWM_BUF_SIZE(dma_size, led_type)];// In ARGB.h, uncomment:
#define ARGB_USE_DYNAMIC_BUFFERS
// Pass malloc and free functions to ARGB_Init
ARGB_Init(&hargb, ..., malloc, free);Choose based on your timer bit width:
ARGB_DMA_BYTE- 8-bit timer (most common)ARGB_DMA_HWORD- 16-bit timerARGB_DMA_WORD- 32-bit timer
- Check power supply (5V for most LEDs)
- Verify timer frequency and PWM configuration
- Ensure DMA channel is properly configured
- Check data line connection
- Verify LED type (WS2812 vs WS2811 have different color orders)
- Check if
use_gammashould be enabled/disabled - Try different DMA transfer sizes
- Ensure stable power supply
- Check for electromagnetic interference
- Reduce PWM frequency if needed
- Add capacitor near LED strip
See the example/ folder for a complete STM32CubeIDE project demonstrating:
- Basic LED control
- Multiple effects
- Rotary encoder for mode selection
- UART debugging
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Dmitriy Semenov / Crazy_Geeks - ARGB Driver - Crazy Geeks
- LED Effects Library - Effects Implementation
- STMicroelectronics for HAL Library
- FastLED library for effect inspiration
- Community contributors
- ๐ Website: https://crazygeeks.ru
- ๐ง GitHub Issues: Report bugs or request features
If you find this project helpful, please consider giving it a star! โญ
Made with โค๏ธ for the STM32 community