unable to use RGB matrix and the serial monitor at once


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()


  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: ");

    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!

Nobody encountered this issue?

The funny thing I just found out if I remove D from this line: RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);

I get it working but the matrix will only light up half of the pixels.

HI, I’m facing exactly the same problem, were you able to find the fix?

Many thanks in advance for any help.

These panels are normally run by very fast processors or FPGAs, not a 16 MHz Arduino. To achieve reasonable performance in this limited environment, the library is optimized by tying specific signals to specific Arduino pins and on a Uno they use PORT manipulation on full port and as you can see in the extract of the library on a UNO this is PORTD which encompasses PINs 0 to 7 so RX and TX

// A full PORT register is required for the data lines, though only the
// top 6 output bits are used.  For performance reasons, the port # cannot
// be changed via library calls, only by changing constants in the library.
// For similar reasons, the clock pin is only semi-configurable...it can
// be specified as any pin within a specific PORT register stated below.

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
 // Arduino Mega is now tested and confirmed, with the following caveats:
 // Because digital pins 2-7 don't map to a contiguous port register,
 // the Mega requires connecting the matrix data lines to different pins.
 // Digital pins 24-29 are used for the data interface, and 22 & 23 are
 // unavailable for other outputs because the software needs to write to
 // the full PORTA register for speed.  Clock may be any pin on PORTB --
 // on the Mega, this CAN'T be pins 8 or 9 (these are on PORTH), thus the
 // wiring will need to be slightly different than the tutorial's
 // explanation on the Uno, etc.  Pins 10-13 are all fair game for the
 // clock, as are pins 50-53.
 #define DATADIR  DDRA
#elif defined(__AVR_ATmega32U4__)
 // Arduino Leonardo: this is vestigial code an unlikely to ever be
 // finished -- DO NOT USE!!!  Unlike the Uno, digital pins 2-7 do NOT
 // map to a contiguous port register, dashing our hopes for compatible
 // wiring.  Making this work would require significant changes both to
 // the bit-shifting code in the library, and how this board is wired to
 // the LED matrix.  Bummer.
 #define DATADIR  DDRD
 // Ports for "standard" boards (Arduino Uno, Duemilanove, etc.)
 #define DATADIR  DDRD

A few control lines can be reconfigured, but others are very specific.

So long story short if you want to keep a serial line, then get à MEGA.

Note that there are time sensitive operations so serial interrupts or blocking calls can mess up your display.