Skip to content

Library that provides the simple function ws2812Write(pin, color) to set the color of a single WS2812 LED without prior initialization and without any special peripherial hardware requirements by using bitbang output. Currently ESP MCUs are supported.

License

Notifications You must be signed in to change notification settings

hackffm/Single_WS2812_Bitbang_Write

Repository files navigation

WS2812 Bitbang Write — Single LED driver for WS2812(B) based RGB-LEDs (also known as NeoPixels)

Library that provides the simple function ws2812Write(pin, color) to set the color of a single WS2812 LED without prior initialization and without any special peripherial hardware requirements (no Timer, RMT, IRQ, DMA...) by using bitbang output. Currently ESP MCUs are supported.

Features

  • No initalization of library or ws2812 LED required
  • Simple api: ws2812Write(uint8_t pin, uint32_t color_rgb) Color 0xRRGGBB
  • Extended api: ws2812Write(uint8_t pin, uint32_t color, uint8_t led_count, ws2812_write_led_type_t led_type) if you want to set color of more than one LED or need other color orders
  • Minimal Footprint but time sensitive, works only for certain MCUs (tested on ESP8266, ESP32 and ESP32S3) and clock frequencies

Hints

  • Ideally to control the single RGB-LED often found on ESP32 boards
  • You can also cut-off a single WS2812B LED from a LED strip and connect it directly to a GPIO. Connect VCC to +3.3V instead of +5V - by that you will not need any additional components like level-shifters or resistor and small amounts of WS2812-LEDs are running just fine even on 3.3V.
  • Use the well-known Adafruit_Neopixel or FastLED libraries if you need to control LED stripes or if you need more control - you can still combine those with this library to e.g. indicate the status on the on-board single LED for your multi-LED stripe-controller...
  • With this library you can control single WS2812 LEDs on nearly all available GPIOs without running out of RMT or whatever MCU special peripherials.
  • Newer LED stripes uses WS2812B instead of the older WS2812. They are compatible, but the newer WS2812B do not require a level-shifter when they are powered with 5V but attached to a 3.3V GPIO.

Info

  • Blocks interrupts while pushing out data to LED (around 30us per LED)
  • Data latching pause is not generated by this library, so wait at least 50us between ws2812Write calls to same port (usually no need to do something here as you don't update the LED that often and the start of the function takes quite some time to calculate timing and resort color values). In extreme case add delayMicroseconds(50); manually to allow latching of data into LEDs.
  • With the third argument more than one LED can be set if you are using LED stripes, but all will be set to the same color.

API

#include <WS2812Write.h>
void ws2812Write(uint8_t pin, uint32_t color_rgb, uint8_t led_count = 1, ws2812_write_led_type_t led_type = WS2812WRITE_GRB);

Installation

Arduino

Install via library manager, pick an ESP32 or EPS8266 board and run examples.

Platformio

Install via Platformio registry or by adding tutgit/Single_WS2812_Bitbang_Write@^1.0.0 to your lib_deps line. You can also download this repository and run the examples directly - select the example you want to run in platformio.ini.

About

Library that provides the simple function ws2812Write(pin, color) to set the color of a single WS2812 LED without prior initialization and without any special peripherial hardware requirements by using bitbang output. Currently ESP MCUs are supported.

Resources

License

Stars

Watchers

Forks

Packages

No packages published