2 ws2812b LED Matrix + arduino uno + HT-05

Hi guys, complete noob here regarding arduino, I've been getting into this world since last monday, and trying to learn by doing small things. Please excuse my errors and lack of knowledge.

So I have 2 WS2812b LED Matrix connected to an arduino UNO R3 and a HC-05 BT module used to send data to the arduino

My first attempt was to have two independent scrolling texts, one on each matrix, which I was able to do it defining each used pin for each matrix and naming the second one matrix2:

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif

#define PIN 5
#define SECPIN 6

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
                            NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
                            NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                            NEO_GRB + NEO_KHZ800);

Adafruit_NeoMatrix matrix2 = Adafruit_NeoMatrix(32, 8, SECPIN,
                             NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
                             NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                             NEO_GRB + NEO_KHZ800);

const uint16_t colors[] = {
  matrix.Color(0, 0, 255), matrix.Color(0, 0, 255), matrix.Color(0, 0, 255)
 
};

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(6);
  matrix.setTextColor(colors[0]);

  matrix2.begin();
  matrix2.setTextWrap(false);
  matrix2.setBrightness(6);
  matrix2.setTextColor(colors[0]);
}


int x    = matrix.width();
int z    = matrix.width(); 
int pass = 0;


void loop() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F("TEXT MATRIX 1"));
  if (--x < -64) {
    x = matrix.width();
    if (++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(50);

  matrix2.fillScreen(0);
  matrix2.setCursor(z, 0);
  matrix2.print(F("TEXT MATRIX 2"));
  if (--z < -64) {
    z = matrix2.width();
    if (++pass >= 2) pass = 0;
    matrix2.setTextColor(colors[pass]);
  }
  matrix2.show();
  delay(25);
}

So now I wanted to change the text via bluetooth, wasn't really getting nowhere, because every tutorial seems to be using MAX72XX instead of WS2812b panels for this. Nevertheless, finally made it work. And now is where I'm stuck, I need to have again both matrix, one with the fixed scrolling text, and the second matrix I want to be able to change it via bluetooth.
So in the same way I mix the codes for having text sent to each matrix through each pin, I'm trying to make it work now with this code:


#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif

#define PIN 5                 
#define SECPIN 6
#define NUMPIXELS      256   

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, 5,  // Matrix with editable text via BT
                            NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
                            NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                            NEO_GRB + NEO_KHZ800);

Adafruit_NeoMatrix matrix2 = Adafruit_NeoMatrix(32, 8, 6,  // Matrix with non editable text via BT
                             NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
                             NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                             NEO_GRB + NEO_KHZ800);

String text = "EDIT MESSAGE VIA BT";                 //Default text to be printed on the LED matrix when it's powered on

int brightness = 10;                   

const uint16_t colors[] = {
  matrix.Color(0, 0, 255), matrix.Color(0, 0, 255), matrix.Color(0, 0, 255)
};


int string_length = 0;
static byte byteRead = 0;
bool print_text = true;
bool print_off = false;


void setup() {

  Serial.begin(38400);         

  matrix.begin();               //This line should start Matrix 1
  matrix.setTextWrap(false);
  matrix.setBrightness(20);
  matrix.setTextColor(colors[0]);

  matrix2.begin();                //This line should start Matrix 2
  matrix2.setTextWrap(false);
  matrix2.setBrightness(6);
  matrix2.setTextColor(colors[0]);

}

int x    = matrix.width();
int z    = matrix.width();
int pass = 0;

void loop()

{
  if (Serial.available() > 0)
  {
    byteRead = Serial.read();     //Read data from the BT module
    if (byteRead == 'T')          //If we receive a "T", then we gen into text scroll mode
    {
      text = Serial.readString(); //Store the bluetooth received text
      print_text = true;

    }

    if (byteRead == 'B')            //If we receive a "B", then we change brightness to the received value
    {
      String Received = Serial.readString();
      int brightness = (int(Received[0]) - 48) * 10;
      if (brightness == 0)
      {
        brightness = 100;
      }
      brightness = constrain(brightness, 0, 100);
      matrix.setBrightness(brightness);
      matrix2.setBrightness(brightness);
      Serial.println(brightness);
    }

  }//end of serial read

  if (print_text && !print_off)
  {
    string_length = text.length();
    matrix.fillScreen(0);
    matrix.setCursor(x, 0);
    matrix.print(text);
    if (--x < -(string_length * 6)) {
      x = matrix.width();
      if (++pass >= 3) pass = 0;
      matrix.setTextColor(colors[pass]);
    }
    matrix.show();
    delay(60);

  matrix2.fillScreen(0);
  matrix2.setCursor(z, 0);
  matrix2.print(F("NON EDITABLE TEXT"));
  if (--z< -(string_length * 6)) {
    z = matrix2.width();
    if (++pass >= 2) pass = 0;
    matrix2.setTextColor(colors[pass]);
  }
  matrix2.show();
  delay(60);
  
  }//End of print text

}//end of void loop

With this I can change using and app and bluetooth, the text on the matrix I need to, but cannot make the matrix2 show the "non editable text". I have one matrix with text and matrix2 completely off

I've been really trying to search online, but haven't found much help about this. I'm sure I'm doing something wrong but I can't figure it out, maybe one of you guys can slap me in the back of the head and point me to the right direction.

Excellent starting post! Good info.

You will be asked, so I'll do it up front. How are you powering the panels? Because 512 LEDs is a huge load for an Uno power supply...

512 LEDs will need to allocate 1536 bytes of ram for buffers at runtime. Your code only has 1485 bytes available.

Thanks, tried to explain the best I could what I wanted to do :slight_smile:

Well, since this is for a simple costume, and the idea is to run just for a few mins at a time, without the HT-05 I was powering everything with a Powerbank and it was doing fine. Should I use a different power source for the leds? I intend to use it only in blue and quite low brightness.

While making the tests I was just powering everything from my pc, nothing else... and I've been running it for hours while looking for a solution

Got me there man, I don't know what that really means, but how can I solve it? Or how could I search for a solution for that?

What @david_2018 Is saying is that, once your sketch starts running, the Neopixel library will try to allocate 3 bytes of ram memory per led in your matrices, to hold the colour information of each led. That's 1.5K of the 2K ram memory available on Uno. It appears that @david_2018 compiled the code you posted and saw that it requires some ram for the sketch to use while running, leaving less than 1.5K left. When the sketch starts to run, there won't be enough to allocate the 1.5K needed, and all manner of strange things will happen, which could easily explain what you have seen.

I have a suggestion. Get an Arduino Pro Micro (not Pro Mini). This will be smaller and more convenient than Uno for a costume, has 2.5K ram, and an extra serial port you can use to connect to the BT module, while simultaneously using the USB port to help you debug your code using the serial monitor.

Thanks @PaulRB and @david_2018, so what you are saying my limitation at the moment is the hardware but the code should work? Or should I review also the code?

Do some simple math. The power bank can supply either 1A or 2.5A depending on the USB power design. You have 512 LEDs so the maximum drain per LED could be 1A/512 = 0.2mA or 2.5A/512 = 0.5mA.

As you lean towards the low RGB numbers in their 0-255 range, the steps become more obvious and even low values still draw significant current. It's not too unexpected since a typical bare LED may run on 5-20mA.

Your power goes through the Arduino, and although it can supply significant current via the 5V pin, it is better to supply the strip directly from 5V, bypassing the Arduino. If, for example, you tried this circuit with a Nano, an onboard diode would likely overheat and cause a failure.

Thanks @aarg , regarding power in the final version, I was thinking of using one of this with a step down to 5v.
711557ze1SL.AC_SX425
I think I could power the LED strips without pasing through the arduino. As I've mention before, it's not intended for long periods of use, less than 20 or 30 mins at a time

If you overload the Arduino, the bad stuff happens in the first few milliseconds or seconds. If you can make it work for 30 minutes, you should be able to make it work for a year.

1 Like

You may be able to use a single buffer for both matrixes, that would probably work on your current hardware. Have not tried that with Adafruit's library, but I notice there is a .setPin() function to reassign the output pin for the LEDs.

What @david_2018 Is saying is that, once your sketch starts running, the Neopixel library will try to allocate 3 bytes of ram memory per led in your matrices, to hold the colour information of each led. That's 1.5K of the 2K ram memory available on Uno. It appears that @david_2018 compiled the code you posted and saw that it requires some ram for the sketch to use while running, leaving less than 1.5K left. When the sketch starts to run, there won't be enough to allocate the 1.5K needed, and all manner of strange things will happen, which could easily explain what you have seen.

Was thinking about this again, shouldn't the problem be also when I run the first code? without the bluetooth? Because with the first code I can have both matrices running without any problem

The first code uses less ram.

1 Like

Good, you must not pass all that current though any Arduino board. The PCB tracks on Arduino boards are not designed for such high currents.

On the subject of current, your 2 matrices will probably draw up to 0.5A in total even with every led off. The chips inside each led need around 0.5~1mA each. If you light 1 in 4 LEDs in blue at half maximum brightness, I guess that would be around 1.8A.

1 Like

Thanks for the answer but... sorry, I don't understand, care to explain a bit more?