ESP32 & 410 LEDs: Experiments 1 – Matrix

How many LEDs is too many? We are about to find out in this part!

I have made this awesome 410 RGB LEDs matrix. It’s fun and serves the educational purposes for now. Soon enough, the ESP32 & 410 LEDs matrix will be transformed into something even more fun. I thought I will take you on this journey with me while I’m trying to figure out how everything works. If you are new to LEDs, this read if for you. I hope you will learn as much as me!

ESP32 & 410 LEDs

First of all, I’d like to thank Banggood.com for sponsoring this. They were kind enough to let me play with some LEDs. Here are the items I use in my matrix

Support NotEnoughTech

410 LEDs is quite a alot!  This thing will need a good power supply. I will test things out first and see how I can wire things up. I used the existing adhesive to glue the strips to the piece of wood. This should be good enough for the testing. I will see how comfortable I am with writing a code for this, then decide what would be my final project.

Signal

To build this matrix I cut the strips to 41 LEDs per line.  The 41 isn’t a magical number, it’s the upper limit of the longest wooden board I could find in my garage. I have the total of 10 lines. Each new line has an opposite direction. To drive the WS2812B correctly, you have to check what direction the strip should be facing. Basically, I have created one very long snake. To learn how to drive WS2812B read this.

5V power supply

To power it all up I needed a power supply. I picked a 5V 30A switching power supply. My napkin math tells me this is more than plenty to get each individual LED powered up. This thing looks beefy!

Initially, I connected the power supply at the beginning of the strip to figure out how many LEDs I could power before the voltage collapses. The answer is 40 (depending on brightness). Increasing the voltage could work, but remember, these are individually addressable LEDs, therefore, you are risking a damage to it, if you drive bigger than 5V voltage, but turn on only a few LEDs.

As you can see, up to about 50 LEDs we have no issues at all. Past that, you can notice small flickering. Turning on more LEDs reveals an even bigger problem. The entire matrix turns yellow, then orange and then almost all red.

Time to change the way I connect the power supply. I followed this schematic to make sure that voltage is evenly distributed.

I used 2 channels of my power supply connecting it from both ends. I also interlinked each line to reduce the voltage drop even further. I have more than enough current to drive all the junctions. Remember that each time a junction is created, the current splits in half.

Lastly, I changed the brightness to 253 (max) to see if I have enough juice to power the entire matrix. I’m pleased to say, it’s bright as hell. I’m still half blind while I type these words.

Calibration

The FastLED library comes with a calibration script. My strips had to be calibrated before I could write colours using names.  Upload the script and follow the instructions. You will be asked to change the order (if needed) of RGB values. This change is declared in the void setup().

ARDUINO IDE: Calibration
#include "FastLED.h"


////////////////////////////////////////////////////////////////////////////////////////////////////
//
// RGB Calibration code
//
// Use this sketch to determine what the RGB ordering for your chipset should be.  Steps for setting up to use:

// * Uncomment the line in setup that corresponds to the LED chipset that you are using.  (Note that they
//   all explicitly specify the RGB order as RGB)
// * Define DATA_PIN to the pin that data is connected to.
// * (Optional) if using software SPI for chipsets that are SPI based, define CLOCK_PIN to the clock pin
// * Compile/upload/run the sketch 

// You should see six leds on.  If the RGB ordering is correct, you should see 1 red led, 2 green 
// leds, and 3 blue leds.  If you see different colors, the count of each color tells you what the 
// position for that color in the rgb orering should be.  So, for example, if you see 1 Blue, and 2
// Red, and 3 Green leds then the rgb ordering should be BRG (Blue, Red, Green).  

// You can then test this ordering by setting the RGB ordering in the addLeds line below to the new ordering
// and it should come out correctly, 1 red, 2 green, and 3 blue.
//
//////////////////////////////////////////////////

#define NUM_LEDS 6

// Data pin that led data will be written out over
#define DATA_PIN 6
// Clock pin only needed for SPI based chipsets when not using hardware SPI
//#define CLOCK_PIN 8

CRGB leds[NUM_LEDS];

void setup() {
	// sanity check delay - allows reprogramming if accidently blowing power w/leds
   	delay(2000);

      // Uncomment one of the following lines for your leds arrangement.
      // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
      // FastLED.setBrightness(CRGB(255,255,255));
      // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);

      // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, 9, 10, RGB>(leds, NUM_LEDS);

      // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {
   leds[0] = CRGB(255,0,0); 
   leds[1] = CRGB(0,255,0);
   leds[2] = CRGB(0,255,0);
   leds[3] = CRGB(0,0,255);
   leds[4] = CRGB(0,0,255);
   leds[5] = CRGB(0,0,255);
   FastLED.show();
   delay(1000);
}

Coding ESP32 & 410 LEDs using Arduino IDE

I wrote a very simple code in Arduino IDE to map the pot’s input to the LEDs. The ADC (Analog to Digital Converter) has 12-bit value. I have to take this into consideration when translating the analogue voltage from pin 2 to a digital output (PWM) sent via pin 5.

As the voltage on the power rail can drop due to power draw, connect the potentiometer to the 5V pin of the ESP32 so the mapping script would read the values without any interference.

Here is the code:

ARDUINO IDE: LED Test
#include 
#define NUM_LEDS 410
#define DATA_PIN 5
#define BRIGHTNESS 50

CRGB leds[NUM_LEDS];
int potPin = 2;
int val = 0;

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); // GRB is the correct value for me
  FastLED.setBrightness(  BRIGHTNESS );
}

void loop() {
        int val = analogRead(2);
        int numLedsToLight = map(val, 0, 4095, 0, NUM_LEDS);
        FastLED.clear();
        for(int led = 0; led < numLedsToLight; led++) { 
            leds[led] = CRGB::White; //change colour here
        }
        FastLED.show();
    }

Conclusion

As you can see, ESP32 & 410 LEDs matrix works great. The next step is to decide how to drive the LEDs. There is more than one option. We can use LED channels for each line, or try to leave it as it is. This is something I will explore in part 2.

Support NotEnoughTech
A lot of time and effort goes into keeping NotEnoughTech alive! If my work helped you out, consider buying me a coffee or check out exclusive rewards available to Patreon supporters.
SHARE