Skip to content

Latest commit

ย 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

STM32 ARGB LED Library

A high-performance, DMA-based addressable RGB LED driver library for STM32 microcontrollers with 56 stunning visual effects.

License: MIT STM32

ไธญๆ–‡ๆ–‡ๆกฃ | English

โœจ Features

  • ๐Ÿš€ 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

๐Ÿ”Œ Supported LED Types

LED Type Color Order Frequency White Channel
WS2811S RGB 400kHz โŒ
WS2811F RGB 800kHz โŒ
WS2812/B GRB 800kHz โŒ
SK6812 RGBW 800kHz โœ…

๐Ÿ“‹ Requirements

  • STM32 microcontroller (tested on STM32F4 series)
  • HAL Library
  • Timer with PWM capability
  • DMA channel
  • GCC ARM toolchain or Keil MDK

๐Ÿš€ Quick Start

1. Hardware Setup

Connect your LED strip data line to a PWM-capable timer pin (e.g., TIM1_CH1).

2. Add Files to Your Project

Copy the following files to your project:

ARGB.c
ARGB.h
ARGB_Effects.c  (optional, for effects)
ARGB_Effects.h  (optional, for effects)

3. Basic Usage Example

#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
    }
}

4. Using Effects Library

#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);
    }
}

๐Ÿ“š API Reference

Core Functions

Initialization

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);

Color Control

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);

Display Control

ARGB_STATE ARGB_Show(ARGB_HandleTypeDef *hargb);
ARGB_STATE ARGB_Ready(ARGB_HandleTypeDef *hargb);
void ARGB_SetBrightness(ARGB_HandleTypeDef *hargb, uint8_t br);

Effects Functions

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);

๐ŸŽจ Available Effects (56 Total)

Static & Basic

  • Static Color
  • Blink
  • Breath
  • Fade
  • Random Color

Wipe Effects

  • Color Wipe
  • Color Wipe Inverse
  • Color Wipe Reverse
  • Color Wipe Random

Rainbow Effects

  • Rainbow
  • Rainbow Cycle
  • Strobe Rainbow
  • Blink Rainbow
  • Theater Chase Rainbow

Scan & Chase

  • Scan
  • Dual Scan
  • Theater Chase
  • Chase White
  • Chase Color
  • Chase Random
  • Chase Rainbow
  • Chase Flash
  • Chase Blackout

Sparkle & Twinkle

  • Sparkle
  • Flash Sparkle
  • Hyper Sparkle
  • Twinkle
  • Twinkle Random
  • Twinkle Fade
  • TwinkleFOX

Running Effects

  • Running Lights
  • Running Color
  • Running Red/Blue
  • Running Random

Special Effects

  • Larson Scanner (K.I.T.T.)
  • Comet
  • Fireworks
  • Fire Flicker (3 variants)
  • Strobe (Multi)

Seasonal & Themed

  • Merry Christmas
  • Halloween
  • Circus Combustus

Advanced

  • Single Dynamic
  • Multi Dynamic
  • Bicolor Chase
  • Tricolor Chase
  • Color Sweep Random

๐ŸŽจ Predefined Colors

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.

โš™๏ธ Configuration Options

Memory Management

Static Allocation (Default)

// 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)];

Dynamic Allocation

// In ARGB.h, uncomment:
#define ARGB_USE_DYNAMIC_BUFFERS

// Pass malloc and free functions to ARGB_Init
ARGB_Init(&hargb, ..., malloc, free);

DMA Transfer Size

Choose based on your timer bit width:

  • ARGB_DMA_BYTE - 8-bit timer (most common)
  • ARGB_DMA_HWORD - 16-bit timer
  • ARGB_DMA_WORD - 32-bit timer

๐Ÿ”ง Troubleshooting

LEDs don't light up

  • Check power supply (5V for most LEDs)
  • Verify timer frequency and PWM configuration
  • Ensure DMA channel is properly configured
  • Check data line connection

Colors are wrong

  • Verify LED type (WS2812 vs WS2811 have different color orders)
  • Check if use_gamma should be enabled/disabled
  • Try different DMA transfer sizes

Flickering or unstable

  • Ensure stable power supply
  • Check for electromagnetic interference
  • Reduce PWM frequency if needed
  • Add capacitor near LED strip

๐Ÿ“ Examples

See the example/ folder for a complete STM32CubeIDE project demonstrating:

  • Basic LED control
  • Multiple effects
  • Rotary encoder for mode selection
  • UART debugging

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Authors

  • Dmitriy Semenov / Crazy_Geeks - ARGB Driver - Crazy Geeks
  • LED Effects Library - Effects Implementation

๐Ÿ™ Acknowledgments

  • STMicroelectronics for HAL Library
  • FastLED library for effect inspiration
  • Community contributors

๐Ÿ“ฎ Contact & Support

โญ Star History

If you find this project helpful, please consider giving it a star! โญ


Made with โค๏ธ for the STM32 community

About

STM32 Library for Addressable LEDs: WS2812(b), WS2811, SK6812, etc. Supports RGB & RGBW LEDs.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages