ESP32 Onboard RGB LED. How many colors available?

I created a wrapping class in C++ for Adafruit Neopixel (I used it in my personal project). The question is... is it possible to represent more than 7 colors?. Is this a Neopixel limitation or hardware limitation (the on-board RGB led uses only 1 gpio). Sending differente brigthness level to R,G,B does not work.

That's my test code. It works like a charm. Even with 7 colors (+black) is enough for my project, but I'm curious about that:

#include <Arduino.h>
#include "rgbonbard.hpp"

RgbOnboard rgb;
void setup() {
    // BY DEFAULT THE GPIO IS RGB_BUILTIN, but you can change it with...
    // POR DEFECTO EL GPIO ES RGB_BUILTIN, pero puedes cambiarlo con...
    // rgb.setGpio(your_gio_number);
    rgb.setBrightness(0.15f);  // from 0.0 to 1.0 (0% - 100%)
}

void loop() {
    // Test all available colors
    // Testear todos los colores disponibles
    for (auto color : { 
            color::red, color::green, color::blue, color::cyan, color::purple, 
            color::yellow, color::white, color::black}) {
        rgb.setColor(color);
        delay(2000);
    }
}

Of course it is. Each LED can have one of 256 colours so the combined possible number of colours is 256 * 256 * 256, ie 16,777,216 different colours, not that the human eye can distinguish that many

2 Likes

Yes, I know how to create a RGB color, but this is no my question.

Using I.E dodger blue: neopixelWrite(gpio_num, 0X1E, 0x90, 0xFF) in the on-board RGB Led does not work. With neopixel the color only woks sending the same value of brightness:

neopixelWrite(8, 16, 0, 16);
neopixelWrite(8, 255, 255, 0);
neopixelWrite(8, 128, 0, 128);

And so on....

With this limitation, Is only possible create 7 seven color with different brightness level.

Where can the details of the rgbonbard.hpp file be seen ?

Doesnt matter, it's only a wrap class. Using directly neopixelWrite() same result. This is the sample code of arduino IDE. As you can see, it sets the same brightness level.

Official example of Arduino IDE. Examples/ESP32/GPIO/RGBBlink.

/*
  BlinkRGB

  Demonstrates usage of onboard RGB LED on some ESP dev boards.

  Calling digitalWrite(RGB_BUILTIN, HIGH) will use hidden RGB driver.
    
  RGBLedWrite demonstrates controll of each channel:
  void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)

  WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin
    with normal HIGH/LOW level
*/
//#define RGB_BRIGHTNESS 64 // Change white brightness (max 255)

// the setup function runs once when you press reset or power the board

void setup() {
  // No need to initialize the RGB LED
}

// the loop function runs over and over again forever
void loop() {
#ifdef RGB_BUILTIN
  digitalWrite(RGB_BUILTIN, HIGH);   // Turn the RGB LED white
  delay(1000);
  digitalWrite(RGB_BUILTIN, LOW);    // Turn the RGB LED off
  delay(1000);

  neopixelWrite(RGB_BUILTIN,RGB_BRIGHTNESS,0,0); // Red
  delay(1000);
  neopixelWrite(RGB_BUILTIN,0,RGB_BRIGHTNESS,0); // Green
  delay(1000);
  neopixelWrite(RGB_BUILTIN,0,0,RGB_BRIGHTNESS); // Blue
  delay(1000);
  neopixelWrite(RGB_BUILTIN,0,0,0); // Off / black
  delay(1000);
#endif
}
  void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)

This function prototype seems to indicate that the full range of colours is available. What happens if you use a value other than RGB_BRIGHTNESS in the function ?

// Colors from https://www.rapidtables.com/web/color/RGB_Color.html
  neopixelWrite(RGB_BUILTIN,75,0,130); // Indigo  ==> Display white
  delay(1000);
  neopixelWrite(RGB_BUILTIN,50,205,50); // Lime green ==> Display white
  delay(1000);
  neopixelWrite(RGB_BUILTIN,139,69,19); // Saddle brown ==> Display white
  delay(1000);

Oh dear !

I don't know what is going on, but it sounds naughty. I wish that I could try it for myself but I don't have a suitable ESP32 board.

1 Like

Actually it is not naughty at all

The LED on the Nano ESP32 is not a Neopixel but a straightforward RGB LED. Hence each LED can only be on or off

From the Nano ESP32 Cheat Sheet https://docs.arduino.cc/tutorials/nano-esp32/cheat-sheet/

RGB

The ESP32 features an RGB LED that can be controlled with the
LED_RED, LED_GREEN and LED_BLUE pin names. These pins are not accessible on the headers of the board, and can only be used for the RGB LED.

Some boards from the first limited production batch were assembled with a different RGB LED which has the green and blue pins inverted. Read our full Help Center article here

To control them, use

digitalWrite(LED_RED, STATE); //red2digitalWrite(LED_GREEN, STATE); //green3digitalWrite(LED_BLUE, STATE); //blue

These pins are so called active-low, what this means in practice is that to turn on one of the LEDs, you need to write it to LOW, like this:

1digitalWrite(LED_RED, LOW);
1 Like

As was pointed out, you don't have a neopixel (w/programmable driver) but an RGB led.

If your code does not block execution (no delays!) then one function in loop() can blink the 3 colors using soft-PWM. With the ESP clock rate, how many shades do you want?

And you do other things like watch a button?

Thanks for all replies. Actually green & red are enough for my project.

Perhaps the led may be defective. i'll try with another board as soon as possible.

What makes you say that the LED may be defective ?

Is the led a bulb with 4 leads/pins?

It is integrated on the board and uses only the GPIO number 8.

It sounds like a WS12xx node. Is there any docs on the ESP site?

That is not what https://docs.arduino.cc/tutorials/nano-esp32/cheat-sheet/ says

See post #8 for details

I would be interested to know the values of LED_RED, LED_GREEN and LED_BLUE when they are printed

1 Like

Out of interest the Nano ESP32 RGB is a 3 color common anode led with R = D14 G = D15 B = D16 ( GPIO46 GPIO0 GPIO45 micropython) and you can get different colors adjusting the duty values of PWM

P.S. as it says the pins are not available for use externally