Recently I bought the following matrix: https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/overview

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:

My Arduino is connected like this:

enter image description here

And the code I wrote is:

#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 sent from the serial monitor. Based on the command one led on the matrix will turn on. An example of a future command will look similar to this: "#drawPixel_X1_Y2%", hence the part that checks on "#" and "&".

The problem 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 a similar problem or knows what I am doing wrong right now.

Thank you in advance!

  • 1
    Please format the code so that it is possible to read. If you need to reference a line please add line numbers or better add a comment in the code. Jan 14, 2016 at 10:58
  • 2
    Possibly you are running out of RAM. Your use of String is very inefficient. I suggest collecting the incoming data into a char array.
    – Nick Gammon
    Jan 14, 2016 at 23:20

1 Answer 1


According to Adafruit https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/overview these led matrixes require active scanning. It means that the RGBMatrixPanel will set up some scanning interrupt to refresh the screen periodically.

This can very much interfere with serial receive, as according to Adafruit, the panels require a serious data transmission all the time.

Try the followings:

  • have one byte serial commands, e.g. N for "on" and F for "off" (I know you will need more complex commands, but this is just to verify the theory)
  • remove all debug Serial.printlns (those also consume some time)

So try this:

void loop() {
  if (Serial.available() > 0) {
    char incomingByte = Serial.read();
    if (incomingByte=='N') {
       matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
    if (incomingByte=='F') {
       matrix.drawPixel(0, 0, matrix.Color333(0, 0, 0));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.