June 16, 2022

Try the LED blink example for the ESP32-C3 DevKitC-02

The ESP32-C3 has a 3 color LED. The schematic shows it driven by 3 gpio. I want to see if we can make it do something.

The IDF has a blink example. I am accustomed to boards with a single LED on a single GPIO, so it will be interesting to see if they have an example that can do something with the multicolor LED.

cd /u1/Projects/RISCV/esp32c3
cp -r esp-idf/examples/get-started/blink .
cd blink
I edit the file main/blink_example_main.c and change one line to enable s_led_state.
Note! I already set up an alias "get_esp" to load the environment settings needed to run idf.py.
get_esp
idf.py set-target esp32c3
idf.py menuconfig
idf.py build
It tells me it runs "ninja all" and blasts away with 800 build steps. When the build finishes, I do:
idf.py flash monitor
The blink demo is clearly running (based on console messages), but nothing at all is happening with the LED. (The demo claims to be turning it on and off).

What does the schematic tell us about the LED?

First of all, there is no plain old power LED. All of the LED are under software control via some GPIO. This was becoming clear even before looking at the schematic as the bright LED blinks several times when software is being flashed.
GPIO19 - LED4 - super bright white LED next to RGB led
GPIO18 - LED5 - yellow LED away from RGB led
GPIO3 - R
GPIO4 - G
GPIO5 - B
There is no silkscreen to tell me which is LED4 versus LED5. I find out by experimenting (see below)

It is becoming clear to me that the board I have is significantly different than the bona-fide Espressif board. The Espressif has a WS2812 (which only requires one GPIO). My "NodeMCU" boards apparently have a similar looking device which really have three LED inside (independently driven, requiring three GPIO, as per the schematic.)

It is comical, but the schematic for the Espressif board is crap and does not even show which GPIO drives the LED! Some searching suggests that it is driven by GPIO8 and the LED is a WS2812. And indeed, some more searching finds in "build/config/sdkconfig.h"

#define CONFIG_BLINK_GPIO 8

So I run "idf.py menuconfig" and can change the LED via the examples submenu. I tell it that it is a plain old GPIO driven LED on GPIO 19. This ends up blinking the super white LED right next to the RGB led.

I discover that I can just edit "main/blink_example_main.c" and avoid menuconfig. After than the "idf.py build" step goes very quickly (only rebuilding 4 or 5 things rather than 800). I verify my table above by trial and error.

Strangely enough, when I blink the yellow LED, I see the white and yellow blink in alternation. I explicitly initialized the bright LED and turned it off, fixing that nonsense.

Notes on the WS2812 aka "neopixel"

I don't have one of these (so why am I writing all of this). You however may have one if you have a bona fide Espressif board, and if you do, it will be connected to GPIO8.

Apparently "neopixel" is the Adafruit marketing name for WS2812 devices. They have a detailed guide on how to use the things, which a person ought to read before fooling with them.

I'll note that if you peek throug the window at one, you will see a tiny chip bonded to LED segments. The device I have on my NodeMCU board is in the same package, but there is no "smart" chip inside.

The WS2812 is in a 6 pin package. 2 for ground, 2 for power, then Di and Do for data in and out (you can chain these in a long string if you want to). If you only have one of them, you just control Di (as an Espressif board does using GPIO8).

Here is how the protocol works. You send 24 bits (3*8) for each LED in a strip. The first LED removes its 24 bits and then goes transparent (sends the rest of what it receives down the line). A reset starts the game over.


Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]