Skip to content

Skosulor/ws8213b

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ws813b led strip driver

A ws813b led strip library written in C for the microcontroller esp32. This library is created to give a complex set of visual effects with minimal effort from the user.

The library have a range of predefined functions which operates/changes the color of the leds in different behaviours. Theese functions belong to different modes which are operated by an engine/server (freertos task). The engine reads a configuration file and cotrols the execution of a mode. Each mode can be enabled in combination with one and another for a unique visual effect.

This readme is a bit outdated so please refer to the examples in the examples directory. A short description for each example is available here.

To compile one of the examples copy it to the main folder and rename it to main.c

minimal.c

A minimal example of what is required to use the library.

example1.c

Example showcasing all the modes and their respective settings. However not all modes are activated.

example2.c

Example showcasing how the configuration can be accessed and altered during execution from another task/process.

fftExample.c

showcases the music mode. This requires a mic input on GPIO34. Its specifically tuned for a electret microphone - Amplifier - MAX4466.

Usage OUT OF DATE

Short manual

For a super quick introduction see Minimal Example.

The library works by enabling and configuring modes which are enabled in the config structure led_config. A mode is an visual effect applied to the led strip, e.g. the mode walk which rotates the leds one step at a configurable rate. Several modes can be enabled at the same time for a unique visual effect. Each mode have some common configurations such as rate. Rate will determine how often a function operates on the led strip. The modes are enables by setting the respective variable (in the config) to a non-zero value.

The colors of the led strip are divided into sections and the number of leds which belong to one section is automatically configured.

How to use in steps:

  1. Configure sdkconfig ( see sdkconfig ) or use the sdkconfig included
  2. Create an array of led_config
  3. Set desired modes ( see initRmt function and Config structures )
  4. Set desired colors ( see Set colors )
  5. Call ledEngine() with your led_config array as argument.
  6. Done!

The available modes can be found under Led Modes .

sdkconfig

CONFIG_FREERTOS_HZ Must be set to 1000 in sdkconfig for the rate and frequency variables to function as intended. If not set the the default is 100 and the update rate might not be as fast as desired for some modes. It is however possible to leave it as is.

CONFIG_MAIN_TASK_STACK_SIZE must be increased to accomodate the size of all the structures. It is probably possible to use freertos xCreateTask() to create a task in which the library is used. This is the end goal inteded way of using the library but it has not yet been tested.

initRmt function

Call initRmt() with a led_config array as argument to initRmtialize the library. The function is required to initialize the rmt library correctly by defining rmt_conf and calling rmt_config and rmt_driver_install functions. InitRmt() will also initialize and allocate memory for a led_struct array.

TODO Add argument for pin out

  • Library used: driver/rmt.h
  • Variables and structures:

Set colors

To be added:

  • Different ways to set the colors
    • Repeating sections
    • Mixed sections
    • etc..
  • Set new colors in runtime
  • setFadeColors function

Minimal Example

Minimal Example for 60 leds on a strip divided into 10 different colored sections. The colors will be smoothed out and rotate once every 15 mS. testColors is defined in colors.h.

#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "ws813b.h"
#include "colors.h"

void app_main(){
  volatile struct mode_config conf[2];
  initModeConfigs(conf, 1,   60 , 10);
  initRmt(conf);

  conf[0].smooth    = 30;
  conf[0].walk      = 1;
  conf[0].walkRate = 15;

  initColors(&conf, testColors);
  setSectionColors(conf[0], leds);

  while(1)
    ledEngine(conf);
}

Config structures OUT OF DATE

This section describes all the structures in the library. Under manually configured you’ll find the structures you need to configure, under automatically configured you’ll find structures the initiliazing function will take care of (you can ignore theese).

Manually Configured

Configuration structures which needs to be set manually.

struct mode_config

The mode configuration structure. Used to set modes and some basic configurations. To enable a mode set its respective variable named after the mode to a non-zero value. Each mode also have a set of configuration variables which needs to be set, you can find documentation for each mode under Led Modes.

There are some variables which need to be set to let the initRmt() function know how to initialize the library correctly.

  • Set length to number of leds you are gonna use on the led strip.
  • Set sectionLength to the number of section you are gonna use

Note: Set the the sectionLength so that length is evenly divisible by sectionLength. It might cause errors if this is not true. A feature is to be implemented which handles this.

variabletypeis requiredfunction
lengthuint8_tyesn of leds
sectionLengthuint8_tyesn of section
ledOffsetuint8_tnodont change
fadeRateuint8_tnorate of function fade
!stepuint8_tnoenable step
fadeuint8_tnoenable fade
fadeRateuint8_tnoRate of fade
fadeWalkuint8_tnoenable of fadeWalk
fadeWalkRateuint8_tnoRate of fadeWalk
!pulseuint8_tnoenable of pulse
pulseRateuint8_tnorat of pulse
walkuint8_tnoenable of walk
smoothuint8_tno“smooths” the colors

color_t

TODO make an struct section_colors

The structure color_t is meant to be used as an array. Each element corresponds to one sections color.

Variabletypefuctionality
reduint8_tvalue of red
blueuint8_tvalue of blue
greenuint8_tvalue of red

Automatically configured

A list of structures which do not need to be configured or altered when using this library. If you have no intrestest in tinkering or learning how the internals of this library works you can skip this section.

led_struct

An array of Led_struct is used to hold current colors of each led as well as an item used by the remote controller library to transmit the data to the led strip.

The led_struct structure holds an array of 24 rmt_item32_t structures, 7 integers of which three represents the current color setting for a led, three representing a target color for modes such as fade which requires a target color. The last integer is a direction teller, however no mode is currently using it.

  • The led_struct:
Variable nametypefunction
ruint8_tred value
guint8_tgreen value
buint8_tblue value
fadeRuint8_tred target value
fadeGuint8_tgreen target value
fadeBuint8_tblue target value
Diruint8_tdirection value

rmt_conf

Configuration file for the remote control driver library. Note: Output pin is set by gpio_num.

VariableValue
struct rmt_conf
rmt_modeRMT_MODE_TX
channelRMT_CHANNEL_0
gpio_num4
mem_block_num1
clk_div8
rmt_conf.tx_config
loop_en0
carrier_en0
idle_outpu_en1
idle_level0
carrier_duty_percent50
carrier_freq_hz10 000
carrier_level1

Led Modes OUT OF DATE

walk

Moves each led one step backwards on the strip each update. The first led will jump the the last place.

conf. variablesPurposeType
WalkRateUpdate rate (Hz)integer
WalkEnable/disablebool
  • Associated Function: stepForward

fade

smooth

fadeWalk

Music

Music mode 1

Music mode 2

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages