LED strip libraries not working with Arduino Nano ESP32

Hello!
I'm trying to use a WS2812B LED strip with an Arduino Nano ESP32 but it does not work at all.
After searching a little bit, here's what I found :

  • The pin used to send data to the LED strip doesn't output any signal (I scoped it with an oscilloscope, it stays at 0V).
  • I tried using both FastLED and Adafruit_NeoPixel libraries but the result was the same : no signal at all.
  • The same exact program works on an Arduino Uno R3 and on that one I can see a signal with the oscilloscope.
  • The pin and the Arduino seem to be working fine with simple circuits (analogWrite() and digitalWrite() work fine for example)

This leads me to think it's not a programming issue (since the program works on another Arduino) or a wiring issue (since the pin itself doesn't output any signal even with nothing wired to the Arduino and the Arduino plugged to my computer) but then I have no idea what the problem is :frowning_face:

Here is the program I used for FastLED for example :

#include <FastLED.h>

#define LED_PIN 2
#define NUM_LEDS 10
#define BRIGHTNESS 50

CRGB leds[NUM_LEDS];

void setup(){
  pinMode(LED_PIN, OUTPUT);
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop(){
  for(byte i = 0; i < NUM_LEDS; i++){
    leds[i] = CRGB(255, 0, 0);
  }
  FastLED.show();
}

I copied your sketch and tried to Verify it, but I got errors (a horrendously long error log).
[ Not meaning it's your fault. ]

I am taking a SWAG but try changing the name for the LED_PIN, change to LEDS_PIN2 and see what happens. I cannot compile it because I do not have the board information loaded. It is possible you have a bad port.

You have a great tool, write a small loop and keep turning your LED pin on and off and with your scope see if it matches. Do this with all to be sure the rest are OK, but one at a time.

I forgot to mention I'm also getting this warning :
"No hardware SPI pins defined. All SPI access will default to bitbanged output"
Is it the same? (I'm personally not getting any other error)
But I'm not sure if that's the issue, after googling it, according to the answers I found, it would seem that it's not really a problem.

Yes, I saw that in there, too.
(I'd post it, but it's 750K.)

I tried doing this and I indeed see a square signal on the oscilloscope.
Therefore I'm guessing LED_PIN isn't wrong either.
(Edit: I've just tried replacing LED_PIN 2 by LED_PIN LEDS_PIN2 as you said and it does an error : "Compilation error: 'LEDS_PIN2' was not declared in this scope")

1 Like

If they are going from ground to VCC you are correct (3.5V). You can stick a delay(2); and see if that changes the waveform.

I've just noticed something. When I do pinMode(LED_PIN, OUTPUT); in setup() (like in the code I put above), the oscilloscope shows me a constant line at 3.3V (not 0 like I initially said, sorry). But when I remove it, it's 0.

That is what you would get if the pin is on or you are connecting to VCC. I am assuming the ground of the scope is also the ground of the board. After you do pinmode digitalWrite() the pin to low. If it does not go low it is either a bad pin or the wrong one. Good luck.

Works as a simulation on a simulated Nano.

And on a simulated ESP32.

Yes, old horse, but we're doing with Nano ESP32.

I do not have a board but it looks to me like ESP32 GPIO 2 != D2. See the official pin out. Flashback to ESP8266 NodeMCU boards!

1 Like

to me too !
either start sniffing A1 or change it to D2

#define LED_PIN D2

Been having a similar problem. Busted out the scope and discovered that D5 is mapping to D2

Hello everyone, yes - the Nano ESP32 is part of the Arduino Nano board series, and shares the same pinout for compatibility with other architectures of the series. So, unlike similar ESP32 boards, on this one Dx is not GPIOx - see the above pinout for the full details.

This is also important for the libraries that require low-level I/O and do not use the core Arduino-ESP32 framework directly, such as the ones discussed here. We are offering to help lib developers adding this support. Stay tuned!

Thank you!!
Using pin 5 instead of 2 in the code to use the Arduino pin 2 worked :slight_smile:

1 Like

Actually that is the same as for other ESP based boards. 'Dx' should be referenced in the sketch as 'Dx', whereas 'GPIOx' can be referenced as 'x'

The FastLED library has the option to use a different a hw Output (i think it's IR) to create the WS2812b signal.
I think Neopixelbus does not support I2S on the ESP32-S3,.
From ESP32-I22.h

// ESP32C3/S3 I2S is not supported yet due to significant changes to interface
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)

bit-banged output should be avoided though if possible for reasons of CPU efficiency.

Sorry for my bad wording, but I meant exactly the opposite :slight_smile: : on this board, Dx is x, while the associated GPIO number is not used anywhere in the sketch. That is extremely common in Arduino on all platforms except the ESP32.

Let's for example consider the case of D0, which is GPIO44.

  • In most Arduino-ESP32 targets (boards not made by Arduino company but which are compatible with the Arduino ecosystem), the API expects a GPIO number, and the platform would have defined D0 to 44.
  • On the Arduino Nano ESP32 (made by Arduino), for sketch compatibility with other Arduino Nano boards, the API expects a D-number (either D0 or 0), and it will take care to convert this to GPIO44 internally.

Does that mean the FastLED sketch compiles by changing 2 to 5?

I was afraid of that, so instead of defining

#define D2 5

they did

#define D2 2

??
This doesn't make sense with the pinout, since now do not only D2 is not referenced properly, but it is also no longer similar to any of the other ESP32 boards core.

So what does that GPIO reference actually mean in the pinout that is given within this thread ?