Coder Social home page Coder Social logo

freenove_ws2812_lib_for_esp32's Introduction

Freenove WS2812 Lib for ESP32

Description

This is an Arduino library for controlling ws2812b led on esp32. Please note that our library supports ESP32 package versions up to 2.0.14. Beyond which an error will be reported. Do not use unstable esp32 package versions.

Examples:

Here are some simple examples.

Show Rainbow

This example make your strip show a flowing rainbow.

#include "Freenove_WS2812_Lib_for_ESP32.h"

#define LEDS_COUNT  8
#define LEDS_PIN	2
#define CHANNEL		0

Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL);

void setup() {
  strip.begin();
}

void loop() {
  for (int j = 0; j < 255; j += 2) {
    for (int i = 0; i < LEDS_COUNT; i++) {
      strip.setLedColorData(i, strip.Wheel((i * 256 / LEDS_COUNT + j) & 255));
    }
    strip.show();
    delay(2);
  }  
}

Usage

Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL, TYPE_GRB);
  • Construction. Create a strip object.
strip.begin()

Initialization data, ready for communication.

strip.setLedColorData(id, color);
strip.setLedColorData(id, r, g, b);
  • Send the color data of the specified LED to the controller.
  • Display color change after calling show function.
    • id: the index of led.
    • color: color value. egg, 0xFF0000 is RED color.
    • r,g,b: color value. 0-255.
strip.show();
  • Immediately display the color data that has been sent.
strip.setLedColor(id, color);
strip.setLedColor(id, r, g, b);
  • Send color data and display it immediately.
  • It is equivalent to "strip.setLedColorData(id, color); strip.show();"
    • id: the index of led.
    • color: color value. egg, 0xFF0000 is RED color.
    • r,g,b: color value. 0-255.
strip.Wheel(i)
  • A simple color picker.
    • i: 0-255.

freenove_ws2812_lib_for_esp32's People

Contributors

greggjaskiewicz avatar zhentao-lin 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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

freenove_ws2812_lib_for_esp32's Issues

Multiple setLedCount() function calls uses all RMT channels

Hello

I have noticed that calling the setLedCount() function multiple times will result in RMT channels all being used up.
Example of the problem captured from the Serial console using ESP32 -DCORE_DEBUG_LEVEL=5

[ 25220][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 1 - 1 RAM Blocks - pin 26
[ 26786][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 2 - 1 RAM Blocks - pin 26
[ 27666][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 3 - 1 RAM Blocks - pin 26
[ 28616][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 4 - 1 RAM Blocks - pin 26
[ 29527][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 5 - 1 RAM Blocks - pin 26
[ 30237][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 6 - 1 RAM Blocks - pin 26
[ 31037][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 7 - 1 RAM Blocks - pin 26
[ 31687][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels
[ 32687][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels
[ 33267][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels
[ 33967][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels

I found that adding following change to the library fixes it. PS I have no experience with RMT so I dont know if it is the best fix but it works!

void Freenove_ESP32_WS2812::setLedCount(u16 n)
{
	ledCounts = n;
	rmtDeinit(rmt_send); // Deinitialize the RMT channel before begin() initilizes RMT channel again.
	begin();
}

PS your library has alot of functions and I am very happy!!

LED index wrong?

I just installed this. I am able to light up LED's however its "Skipping" the first LED in the chain. Been looking at the code a bit and not sure how this can be fixed.

using RGB_BUILTIN for pin does not work, and will reset the S2 and S3 boards

I was experimenting with a couple of ESP boards and was playing with the rainbow example on the built-in RGB led on the boards. When switching between the boards I would at times forget to change the pin number. Then I found they had defined RGB_BUILTIN which looked promising, but, when I tried it, the LED did not work and on the S2 and S3 it would GURU Meditate, in the call to strip.begin().

#include "Freenove_WS2812_Lib_for_ESP32.h"

#define LEDS_COUNT 1
#define CHANNEL 0
Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, RGB_BUILTIN , CHANNEL, TYPE_GRB);

void setup() {
  strip.begin();
  strip.setBrightness(20);
}

void loop() {
  for (int j = 0; j < 255; j += 2) {
    for (int i = 0; i < LEDS_COUNT; i++) {
      strip.setLedColorData(i, strip.Wheel((i * 256 / LEDS_COUNT + j) & 255));
    }
    strip.show();
    delay(10);
  }
}

I posted on the ESP32 forum and a possible fix was suggested, which I first tried locally in the sketch, and then tried a variation of it in your library.

I put the change into the constructor, could have gone in the begin method.

Freenove_ESP32_WS2812::Freenove_ESP32_WS2812(u16 n /*= 8*/, u8 pin_gpio /*= 2*/, u8 chn /*= 0*/, LED_TYPE t /*= TYPE_GRB*/)
{
	ledCounts = n;
	pin = pin_gpio;
#ifdef RGB_BUILTIN
  	if((pin == RGB_BUILTIN) && (RGB_BUILTIN > SOC_GPIO_PIN_COUNT)){
    	pin -= SOC_GPIO_PIN_COUNT;
  }
#endif
	rmt_chn = chn;
	rmt_mem = RMT_MEM_64;
	br = 255;
	setLedType(t);
}

The new stuff was the stuff within the #ifdef
I added the check for RGB_BUILTIN > SOC_GPIO_PIN_COUNT on the off chance that someone actually defines the constant to be the actual pin.

worst example yet for ESP32-S3

you put one WS2812 on the board why you did not make a easy code to turn it on and off and change colors one at a time ,no you had to have something flashing and jumping and now it will not compile.All we want is a simple program to turn on one color and let us build on it as we see fit .Here is what my young teenager says' I told you that electronics stuff was no good Ha Ha Ha" all because some clown somewhere has forgotten how he /she got started (one step at a time) If this kit I purchased was designed to get young folk interested then you failed in a bad way. You need to sit down and rewrite this entire tutorial for this unit the ESP32-S development kit cause nothing works and if I had to show this to my boss for company use he would say HELL NO they cannot make a led blink. NOW FIX IT and REPUBLISH THE TUTORIAL.

Cannot set brightness dynamically?

I have a bunch of codes that looks like this to change the brightness:

} else if (strcmp(message.data().c_str(), "brightness30") == 0) {
strip.setBrightness(30);
delay(10);
strip.show();
} else if (strcmp(message.data().c_str(), "brightness50") == 0) {
strip.setBrightness(50);
delay(10);
strip.show();

however it doesn't seem to change the brightness at all.

Is the brightness setting only able to be set at start? Would it be possible to change brightness dynamically?

Variable cpu frequency

The library breaks when changing the cpu frequency using setCpuFrequencyMhz is there a way to change the clock source so that it works even when the cpu frequency is not the same as it was when initiated?

working again with last Arduino core ?

hi,

i'm testing the RGBW sketch and i have a strange flickers/random colors !
Rainbow test code seem strange too !

using pin 5 on my ESP32-WROOM-32UE board.
core 2.0.0, a lot of compilation complain and all leds are white !
core 1.0.6 a lot of flicker .

please anybody can confirm that it will work right on pin 5 ? with RMT feature ?

thanks, regards

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.