serial communication & RGB matrix not working properly

Hello,

Recently I bought the following matrix:

I own an Arduino Uno for those who are interested.

I got the 32x32 variant and I am very happy with it. I managed to connect all the wires correctly and get the examples of the library working.

The problem I am facing right now is I can't get it to work properly for a personal project of mine. Somehow I am unable to use the serial functions and the matrix library functions in one project.

Currently my project looks like this:

Arduino is connected like this:

And my code looks like this:

#include <gamma.h>
#include <RGBmatrixPanel.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>

#define CLK 8
#define OE  9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);

String incomingCommand = "";

void setup()
{
  Serial.begin(9600);

  matrix.begin();

  matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 0, 0));
}

void loop()
{
  if (Serial.available() > 0)
  {
    int incomingByte = Serial.read();
    char receivedChar = (char) incomingByte;

    incomingCommand += receivedChar;
  }

  if (incomingCommand.indexOf('#') > - 1 && incomingCommand.indexOf('%') > - 1)
  {
    String rawCommand = incomingCommand.substring(incomingCommand.indexOf('#'), incomingCommand.indexOf('%') + 1);

    rawCommand = rawCommand.substring(1, rawCommand.length() - 1);

    Serial.print("Following command received: ");
    Serial.println(rawCommand);

    if (rawCommand == "turnledon")
    {
      matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
    }

    incomingCommand = "";
    rawCommand = "";
  }
}

The idea is that a command gets send from the serial monitor. Based on the command one led on the matrix will turn on. An example of a future command will looke similair to this: "#drawPixel_X1_Y2%", hence the part that checks on "#" and "&".

The problem that I am facing is that the functionality of the serial monitor isn't working with line 14 and 48 of the code. As soon as I remove those lines the serial monitor works perfectly and I can receive and write to the serial monitor. I have no idea what is causing this.

I was wondering if someone ever faced with a similair problem or just knows what I am doing wrong right now.

Thank you in advance!

The problem that I am facing is that the functionality of the serial monitor isn't working with line 14 and 48 of the code.

The code you posted has line 14 as a blank line and line 48 as an opening brace. This is silly, but not as silly at that diagram.

Currently my project looks like this:

An Arduino with wires attached to some pins going nowhere! That tells us nothing. We need to see a schematic, not a Fritzing physical layout diagram.

I edited the lines. I forgot to remove the space at the beginning making 14 into 15 and 48 into 49. Sorry for that.

For the pins layout, they go into this ribbon which I connect into the matrix:

For the pins layout, they go into this ribbon which I connect into the matrix:

Oh come on. Are you serious about wanting help. No schematic no help, not because we are mean but because it is impossible.

I am pretty sure it is not related to the hardware. All the examples of the library work properly. Except my own code.

Sure you can't help me out? I am pretty desperate at the moment.

I am pretty sure it is not related to the hardware.

Even if it is not, you can not understand software without knowing what hardware it is driving.
The only information you have provided is that when you include a library, that you have failed to provide any links to, the serial port stops working. I am not sure if you know how this game works but it does not work like this. Sorry

Sorry if I missed some information out. I thought the link I provided at the beginning at the post was enough sincs it covers everything.

I use two external libraries that didn't come with Arduino. I used the RGB Matrix Panel library, which can be found here: GitHub - adafruit/RGB-matrix-Panel: Arduino library and example code for the 16x32 RGB matrix panels in the shop . And I used the Adafruit GFX Library, which can be found here: GitHub - adafruit/Adafruit-GFX-Library: Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from .

Sorry if I didn't provide the full information.

You need to try out separately the business of receiving commands and the business of using the LED matrix.

Can you receive the commands correctly?

If you "hardwire" a command into the code for the LED matrix does that work correctly?

You are using Strings (capital S) which can corrupt the small memory of an Arduino. It is better to use strings (small s) which are char arrays terminated with a 0. Have a look at Serial Input Basics

...R

Can it really be because I use a String? The commands that I am sending are like this: "#drawPixel_X4_Y12%".

Robin2:
You need to try out separately the business of receiving commands and the business of using the LED matrix.

Can you receive the commands correctly?

If you "hardwire" a command into the code for the LED matrix does that work correctly?

You are using Strings (capital S) which can corrupt the small memory of an Arduino. It is better to use strings (small s) which are char arrays terminated with a 0. Have a look at Serial Input Basics

...R

Hardcoding a command doesn't work either.

I thought the link I provided at the beginning at the post was enough sincs it covers everything.

That is like going to the doctors and when he said "where does it hurt" you saying, "here is my wife's phone number she will tell you".

Now for the bad news. I have tried running your code an if you comment out matrix.begin and matrix.fillRect then serial communications( both ways ) still works. However once those are in the sketch then serial communications is screwed up.

This means that the RGB-matrix-Panel screws up serial operations. A quick look doesn't show why. It is probably the way it messes with the interrupts. Unfortunately there is nothing you can do about this.

The only thing I would recommend is if you post a question on the AdaFruit discussion forum.
Sorry.

I tried to remove all the string I used. I have it working now with the following code:

#include <gamma.h>
#include <RGBmatrixPanel.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>

#define CLK 8
#define OE  9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);

int incomingCommand[3];

int counter = 0;

void setup()
{
  matrix.begin();

  matrix.fillRect(0, 0, 32, 32, matrix.Color333(7, 0, 0));

  Serial.begin(9600);
}

void loop()
{
  if (Serial.available() > 0)
  {
    int incomingByte = Serial.read();
    char receivedChar = (char) incomingByte;

    incomingCommand[counter] = receivedChar;

    counter++;

    if (counter == 3)
    {
      Serial.println("test");

      matrix.drawPixel(incomingCommand[0], incomingCommand[1], matrix.Color333(7, 7, 7));

      counter = 0;
    }

  }
}

Could it be because there isn't sufficient memory?

Could it be because there isn't sufficient memory?

What you have done is moved the Serial.begin to after the matrix begin code. Looks like the matrix initialization code was stamping over the serial initialization code.

I change the order of things in the setup in your original code and when I did it did not screw things up. Looks like the matrix code is not too careful about setting bits in control registers.

Can you please provide me with the code you have at the moment? I am very curious.

Nobody else who knows what's going on?

All I did was to add the serial begin at the end of the setup function instead of at the beginning. I also added a serial print to show that serial communications are working, echoing each character as received.

You said:-

As soon as I remove those lines the serial monitor works perfectly and I can receive and write to the serial monitor.

So no serial communications work again I am assuming that the code works.

I have no idea what is causing this.

So now we know. It is a badly written library, what probably happens is that it writes to one of the control registers the number it wants, instead of doing what it should do which is set and clear the bits in that register to what it needs and leave other bits set by the serial software alone.

This is your original code with the modifications I made.

#include <gamma.h>
#include <RGBmatrixPanel.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>

#define CLK 8
#define OE  9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);

String incomingCommand = "";

void setup()
{
    matrix.begin();
    matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 0, 0));
  Serial.begin(9600); // move this to the start of the function and serial communications are screwed
  Serial.println("ready");
}

void loop()
{    // Serial.println("tick");
  if (Serial.available() > 0)
  {
    int incomingByte = Serial.read();
    Serial.write(incomingByte);  // echo back to serial monitor to show it is working
    char receivedChar = (char) incomingByte;

    incomingCommand += receivedChar;
  }

  if (incomingCommand.indexOf('#') > - 1 && incomingCommand.indexOf('%') > - 1)
  {
    String rawCommand = incomingCommand.substring(incomingCommand.indexOf('#'), incomingCommand.indexOf('%') + 1);

    rawCommand = rawCommand.substring(1, rawCommand.length() - 1);

    Serial.print("Following command received: ");
    Serial.println(rawCommand);

    if (rawCommand == "turnledon")
    {
      matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
    }

    incomingCommand = "";
    rawCommand = "";
  }
}