ESP32 and WS2812B

Hi there,
I am using this WS2812B 16x16 matrix along with ESP32. It worked perfectly fine using Arduino UNO. Now, I know that ESP32 uses 3.3V logic level instead of 5V and that's what's causing the problems. But I read some articles and watched some videos that suggest that you can overcome this problem. I tried every possible method I could find. I tried using the logic level shifter from sparkfun as well as the SN74HCT245 which is suggested in this tutorial. I also tried this method from Hackaday. Nothing works. All of the LEDs are just randomly flashling. Can someone help? Thanks. :slight_smile:

It can be everything... like:

  • your power supply
  • your code
  • a bug in the library
  • your wiring
  • ...

Please give us some information about (see above)

Ok so:
I'm using the USB from the computer as my power supply. The electronics are not connected to the 5V pin but instead to the VIN pin so the matrix gets unregulated power.

I'm using the FastLED library. My code is attached.

GND is connected to the LED ground, VIN to the LED 5V input, and IO27 is connected to the LED data input. I'm using the ESP32 Dev kit board. Wirings used when using one of the methods mentioned in the previous post are in the links.

I was just wondering if someone actualy had and resolved this problem. Thanks.

WTF.ino (8.48 KB)

Jakub_Nagy:
I'm using the USB from the computer as my power supply.

Did you extract that from the ESP32 module?

An ESP32 board draws almost twice the current of an Uno, with peaks 8-10 times the current of an Uno.
A 500mA USB port can just handle those ~400mA peaks.

This LED module seemst to draw 5Amp on average, and it could draw up to 15A.
Do you think it's a good idea to connect that to a 500mA USB port.
Leo..

I did think that the ESP32 was supposed to be this super low-power board so this is a suprise to me.

I tried running sketches that light up only 10 LEDs or so to reduce the power draw. I also tried connecting an Arduino UNO to the second USB port and powering the ciruit from two USB ports at once. Also, I was using a power bank with output of 5V 2A.

Nothng works.

Jakub_Nagy:
I did think that the ESP32 was supposed to be this super low-power board so this is a surprise to me.

Whatever made you think that? it is a WiFi board, uses lots of power to transmit (where "lots" is about one Watt)! Apart from this it does not consume too much power when active.

A 74HCT245 will work (if correctly connected) but is phenomenal over-kill as a level converter; two gates in series on a 74HCT14 will do just as well.

But given that the level converter is correctly wired and you have your LEDs powered directly from a reliable 5 V supply, if it does not work, the problem is in the code.

OTOH some people seem to damage WS2812s easily. :astonished:

Ok, so is this the correct wiring of the 74HCT245? The LEDs still work withA Arduino UNO. I'll try again with different power supply and different code. Anyway, thanks.

Jakub_Nagy:
I tried running sketches that light up only 10 LEDs or so to reduce the power draw.

Unfortunately, I have found that even ws2812b leds that are not lit will draw ~1mA each, so even if no leds are lit, the matrix could be drawing ~250mA.

I was using a power bank with output of 5V 2A

With all leds lit at maximum brightness white, the matrix could draw 15A.

Even if you limit the leds lit to keep the current under 2A, you should not connect this much current via the esp32 board. The tiny copper tracks on the pcb are not designed for 2A, certainly not 15A! You need to power the matrix using separate cables, directly from the power source.

Ok so I switched to a 74HCT14 as Paul__B suggested. It still doesn't work. I'm using a lab bench power supply that can supply up to 5A output (the matrix only draws around 1.5A according to my measurments).

I'm including some photos of my setup and my code.

I'm really hopeless at this point. Any help would be appreciated.

WTF.ino (8.48 KB)

Jakub_Nagy:
I'm really hopeless at this point.

I agree. 15 posts, and you still have not read the forum guide. Please do that now, and then post your pictures and code correctly.

Jakub_Nagy:
Ok so I switched to a 74HCT14 as Paul__B suggested.

I will bet real money that you didn't:

Paul__B:
two gates in series on a 74HCT14 will do just as well.

Also, did you power the 74hc14 with 5V? Did you put a 0.1uF bypass cap next to it?

PaulRB:
I agree. 15 posts, and you still have not read the forum guide. Please do that now, and then post your pictures and code correctly.

I've read it. My code is to long to paste it here so I uploaded it as an attachment. I wanted to keep my pictures at the original size, and when I pasted the link as an image, it didn't show up. So I pasted it as a normal link. But sure, I've changed it to resized images.

PaulRB:
two gates in series on a 74HCT14 will do just as well.

Oooh, did you mean like how it's on the schematic I included in the attachment?

PaulRB:
Also, did you power the 74hc14 with 5V? Did you put a 0.1uF bypass cap next to it?

Yes, I use 5V. No I didn't. I'll try. Does it have to be 0.1uF? Thanks.


I see:

Only one gate of the 74hc14 used. The signal will be inverted and the led strip will not be able to use it.

No resistor between the gate output and the strip data input.

No large reservoir cap (e.g. 1000uF) across the power lines to the strip.

I can't open your sketch on my phone, so I can't help with that. But if the sketch is so large, no-one else will want to help you with that either. For the problem you are describing, only a small sketch is needed to demonstrate it. Post a small sketch, using code tags.

Jakub_Nagy:
Oooh, did you mean like how it's on the schematic I included in the attachment?

Does it have to be 0.1uF?

Yes, like that.

Yes, 0.1uF ceramic.

Yaaay, It works (partly)! Thank you very much. :slight_smile:

I connected the 74HC14 in series and added a large reservoir capacitor. Not sure if the capacitor works because it's old, though. Anyway I made a demo code that makes every second LED in the first row green, red in the second row and blue in the third row. This works, but there are some random LEDs turning ON and OFF and the image sometimes twists and shifts. Seems like there is still some little noise. I tried adding some resistors but it didn't help. Do you think the bypass capacitor will resolve this?


I have the 1000uF capacitor connected paralel to the power lines. Where do I connect the 0.1uF one?

My sketch here:

#include "FastLED.h"
#define NUM_LEDS 48
#define LED_PIN 27
CRGB leds[NUM_LEDS];

void setup() { 
  FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds,  NUM_LEDS);
}

void loop() {  
  leds[ 0 ] = CRGB(255, 0, 0);
  leds[ 1 ] = CRGB(0, 0, 0);
  leds[ 2 ] = CRGB(255, 0, 0);
  leds[ 3 ] = CRGB(0, 0, 0);
  leds[ 4 ] = CRGB(255, 0, 0);
  leds[ 5 ] = CRGB(0, 0, 0);
  leds[ 6 ] = CRGB(255, 0, 0);
  leds[ 7 ] = CRGB(0, 0, 0);
  leds[ 8 ] = CRGB(255, 0, 0);
  leds[ 9 ] = CRGB(0, 0, 0);
  leds[ 10 ] = CRGB(255, 0, 0);
  leds[ 11 ] = CRGB(0, 0, 0);
  leds[ 12 ] = CRGB(255, 0, 0);
  leds[ 13 ] = CRGB(0, 0, 0);
  leds[ 14 ] = CRGB(255, 0, 0);
  leds[ 15 ] = CRGB(0, 0, 0);
  leds[ 31 ] = CRGB(0, 255, 0);
  leds[ 30 ] = CRGB(0, 0, 0);
  leds[ 29 ] = CRGB(0, 255, 0);
  leds[ 28 ] = CRGB(0, 0, 0);
  leds[ 27 ] = CRGB(0, 255, 0);
  leds[ 26 ] = CRGB(0, 0, 0);
  leds[ 25 ] = CRGB(0, 255, 0);
  leds[ 24 ] = CRGB(0, 0, 0);
  leds[ 23 ] = CRGB(0, 255, 0);
  leds[ 22 ] = CRGB(0, 0, 0);
  leds[ 21 ] = CRGB(0, 255, 0);
  leds[ 20 ] = CRGB(0, 0, 0);
  leds[ 19 ] = CRGB(0, 255, 0);
  leds[ 18 ] = CRGB(0, 0, 0);
  leds[ 17 ] = CRGB(0, 255, 0);
  leds[ 16 ] = CRGB(0, 0, 0);
  leds[ 32 ] = CRGB(0, 0, 255);
  leds[ 33 ] = CRGB(0, 0, 0);
  leds[ 34 ] = CRGB(0, 0, 255);
  leds[ 35 ] = CRGB(0, 0, 0);
  leds[ 36 ] = CRGB(0, 0, 255);
  leds[ 37 ] = CRGB(0, 0, 0);
  leds[ 38 ] = CRGB(0, 0, 255);
  leds[ 39 ] = CRGB(0, 0, 0);
  leds[ 40 ] = CRGB(0, 0, 255);
  leds[ 41 ] = CRGB(0, 0, 0);
  leds[ 42 ] = CRGB(0, 0, 255);
  leds[ 43 ] = CRGB(0, 0, 0);
  leds[ 44 ] = CRGB(0, 0, 255);
  leds[ 45 ] = CRGB(0, 0, 0);
  leds[ 46 ] = CRGB(0, 0, 255);
  leds[ 47 ] = CRGB(0, 0, 0);
  FastLED.show();
}

The 0.1uF call also goes across the 5V & gnd lines, but as close to the 74hc14 chip as you can get it. Across the power strips on the breadboard, right next to the chip, would be ok. I don't know if it will fix anything, but there is no point investigating further until you have that cap in place.

So my new setup looks like this:

I added a new 1000uF capacitor across the power lines of the breadboard. I added the 0.1uF ceramic capacitor across the power lines right next to the 74HC14.

This works perfectly, until I try to controll more than exactly 20 LEDs at once. 20 LEDs work, 21 LEDs don't. I tried powering the circuit by a bench power supply, didn't help.

Any ideas?

20 working and 21 not working sounds like a software problem. Post your non-working 21-led sketch.

Here:

#include "FastLED.h"
#define NUM_LEDS 21
#define DATA_PIN 14
CRGB leds[NUM_LEDS];
int a, b;

void setup() { 
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
}
void loop() { 
  for(a = 0; a < 21; a++){
      leds[a] = CRGB(0, 0, 255);
  }
  leds[b] = CRGB(0, 0, 0);
  b++;
  FastLED.show();
  delay(1000);
  for(a = 0; a < 21; a++){
      leds[a] = CRGB(0, 255, 0);
  }
  FastLED.show();
  delay(1000);
}

The code switches all the LEDs from blue to red every one second and turns off a different LED every time. It works just fine when I change the 21s to 20s.

Hmm. I hoped I would see an error in your code, some small inconsistency. I can't.

It's just possible that the 20th or 21st led is faulty. Seems like a big coincidence, though. But I can't think of any other explanation at the moment.

Remind me, how are you powering the strip?

I hoped for that too.

The LED can't be faulty. I tried now and it still works with the Arduino UNO.

I'm mainly connecting the strip to the VIN and GND pins of the ESP32 which is powered from USB but I tried powering it from a bench power supply too.