Code Monkey home page Code Monkey logo

esp32ws2811's Introduction

esp32WS2811

Arduino Library for ESP32 to drive WS2811/WS2812 RGB leds using the RMT peripheral. The lib is lean and only drives the leds.

Hardware

As the ESP32 uses 3.3V levels and the WS2811 uses 5V, we need a level shifting device. I'm successfully using a TXS-0102 voltage-level translator. I've tested up to 50 leds and wire lengths to the first LED up to 2 meters.

Example circuit:

                                  3.3V                                  5V
                                    |                                    |
                                    |                                    |
      +--------------+              |         +---------------+          |
      |          Vin +--------------+---------+ Vcca     Vccb +----------+
      |              |                        |               |          |
      |      GPIO 23 +--------------------+-->+ OE       GND  +---+--||--+----- Vdd WS2811
      |     ESP32    |                    |   |     TXS0102   |   |  0.1µF
      |      GPIO 18 +----------------------->+ A1         B1 +---------------- DATA WS2811
      |              |                    |   |               |   |
      |     GND      |                    |   | A2         B2 |   +------------ GND WS2811
      +------+-------+                    |   +---------------+   |
             |                            |                       |
             |                            +--/\/\/\---+-------- --+
             |                                10k     |
             +----------------------------------------+
                                                      |
                                                     ---

The pulldown resistor on OE (output enable) prevents the output to float during startup. Unused pins are left unconnected as they have internal 10k pullups.

Firmware

Include the header file and define your LED string:

#include <esp32WS2811.h>

// first argument is the data pin, the second argument is the number of LEDs
WS2811 yourLedString(18, 50);

Start the LED string:

void setup() {
  // include your other code

  yourLedString.begin();
}

Change LED colours:

Colour colour = yourLedString.getPixel(size_t index);  // gives you the Colour of the led on index.
yourLedString.setPixel(size_t index, uint32_t red, uint32_t green, uint32_t blue);
yourLedString.show();  // this actually makes the LEDs light up

A number of helpers methods are available:

yourLedString.clearAll();  // turns off all LEDs
yourLedString.setAll(Colour colour);  // // gives all LEDs the specified colour
yourLedString.setAll(uint32_t red, uint32_t green, uint32_t blue);  // gives all LEDs the specified colour

Keep in mind that all these methods require to call show() afterwards.

Effects

Starting and stopping an effect is done by:

void startEffect(WS2811Effect* effect);
void stopEffect();

You don't have to stop a running effect before starting a new one. The effect stops immediately and does not wait for it's routine to complete.

Sample application

You can find a full working application in this repo: ledController

Credits

esp32ws2811's People

Contributors

bertmelis avatar guzlr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

esp32ws2811's Issues

Data appearing on multiple strips

Unable to use multiple strips, data appears on both lines.

Sample Code

#include <esp32WS2811.h>

WS2811 ws2811_Strip1(14, 50);
WS2811 ws2811_Strip2(15, 50);

void setup() {

  // start led strip
  ws2811_Strip1.begin();
  ws2811_Strip2.begin();
}

void loop() {

  ws2811_Strip1.setAll(255, 0, 0);
  ws2811_Strip2.setAll(0, 255, 0);

  ws2811_Strip1.show();
  ws2811_Strip2.show();
}

Add function

Hi,
nice lib.
Could You add a function to change only R or G or B.

somthing like .setR(n,255);

regards
Joerg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.