RGBMatrixPanel text problem with P10 2727

'''
Hi i am really tired of serching so i have problem with 16x32 P10-2727-Matrix a pack of 4 horizontaly so a simple sys to print text on lcd and matrix with button.now i used the rgbmatrixpanel.h from adafruit but for some reason nothing appears on the Matrix (the wirdest thing is the test codes inluded in the liberary work just perfect !!!) so i serch for solution and i found a modefied version of this liberary and acctuly it worked but have problem the text not appear correctly it looks like the font size small so it like dots maybe but i try everything i know and no hope so i need some help if anyone can :wink:
'''

<

#include <RGBmatrixPanel.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>

// Define HUB75E matrix pins (for 16x32 matrix)
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2

// Define button pins
#define BUTTON_1_PIN 3
#define BUTTON_2_PIN 4
#define BUTTON_3_PIN 5
#define BUTTON_4_PIN 6
#define BUTTON_5_PIN 7

// Button press settings
#define LONG_PRESS_TIME 3000 // 3 seconds for shutdown
#define DEBOUNCE_DELAY 50 // Debounce delay for stable button reading

// Initialize display (16x32 matrix setup)
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false, 1);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Command texts and colors
const char* commands[] = {"<<<<<<", "Follow me", "Slow down", "STOP", ">>>>>>"};
uint16_t colors[] = {matrix.Color333(0, 7, 7), matrix.Color333(0, 7, 0),
matrix.Color333(7, 7, 0), matrix.Color333(0, 0, 7),
matrix.Color333(0, 7, 7)};

bool systemOn = true;
unsigned long buttonPressTime[5] = {0, 0, 0, 0, 0};
unsigned long lastDebounceTime[5] = {0, 0, 0, 0, 0};
bool buttonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};
bool lastButtonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};

// Font configuration
int textSize = 1; // Default text size (1 = normal)
bool isBold = false; // Default to non-bold text

void setup() {
// Set up pins and initialize displays
pinMode(BUTTON_1_PIN, INPUT_PULLUP);
pinMode(BUTTON_2_PIN, INPUT_PULLUP);
pinMode(BUTTON_3_PIN, INPUT_PULLUP);
pinMode(BUTTON_4_PIN, INPUT_PULLUP);
pinMode(BUTTON_5_PIN, INPUT_PULLUP);

lcd.init();
lcd.backlight();
matrix.begin();

displayStartupMessage();
}

void loop() {
if (systemOn) {
checkButtons();
} else {
checkForStartup();
}
}

// Function to display a welcome message on startup
void displayStartupMessage() {
lcd.setCursor(0, 0);
lcd.print("WELCOME TO EGYPT");

matrix.fillScreen(0);
matrix.setTextColor(matrix.Color333(3, 3, 3)); // Red
matrix.setCursor(2, 2);
matrix.print("WELCOME TO EGYPT");

matrix.swapBuffers(true);
delay(5000);
}

// Function to handle button presses and shutdown trigger
void checkButtons() {
int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};

for (int i = 0; i < 5; i++) {
int reading = digitalRead(buttonPins[i]);

if (reading != lastButtonState[i]) {
  lastDebounceTime[i] = millis();
}

if ((millis() - lastDebounceTime[i]) > DEBOUNCE_DELAY) {
  if (reading != buttonState[i]) {
    buttonState[i] = reading;
    
    if (buttonState[i] == LOW) {
      buttonPressTime[i] = millis();
    } else {
      if (millis() - buttonPressTime[i] < LONG_PRESS_TIME) {
        updateDisplay(i);
      }
      buttonPressTime[i] = 0;
    }
  }

  // Check if button is held for shutdown
  if (buttonState[i] == LOW && millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
    shutdownSystem();
    systemOn = false;
  }
}
lastButtonState[i] = reading;

}
}

// Function to update the display based on the command
void updateDisplay(int commandIndex) {
// Update LCD to show command
lcd.clear();
lcd.setCursor(4, 1);
lcd.print(commands[commandIndex]);

// Display command on matrix with sliding animation
matrix.fillScreen(0);
matrix.setTextColor(colors[commandIndex]);

// Set font size (scale text size)
matrix.setTextSize(textSize);

// If bold, simulate boldness by printing text multiple times with offset
if (isBold) {
for (int i = 0; i < 2; i++) {
matrix.fillScreen(0);
matrix.setCursor((128 - strlen(commands[commandIndex]) * 6) / 2 + i, 0); // Slight offset for bold effect
matrix.print(commands[commandIndex]);
matrix.swapBuffers(true);
delay(50);
}
} else {
matrix.setCursor((128 - strlen(commands[commandIndex]) * 6) / 2, 0);
matrix.print(commands[commandIndex]);
matrix.swapBuffers(true);
delay(50);
}
}

// Function to shut down the system and display GOOD BYE message
void shutdownSystem() {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("GOOD BYE");

matrix.fillScreen(0);
matrix.setTextColor(matrix.Color333(7, 0, 0)); // Red
matrix.setCursor(40, 5);
matrix.print("GOOD BYE");
matrix.swapBuffers(true);

delay(2000); // Show GOOD BYE for 2 seconds

lcd.clear();
lcd.noBacklight();
matrix.fillScreen(0);
}

// Function to check for system startup after shutdown
void checkForStartup() {
int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};

for (int i = 0; i < 5; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
if (millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
lcd.backlight();
displayStartupMessage();

    systemOn = true;
    updateDisplay(0);  // Default to first command
    break;
  }
} else {
  buttonPressTime[i] = 0;
}

}
}

Blockquote

Unplug matrix panels until it works again. Then swap a good panel for an unknown panel. Once you know all panels are good, re-connect all panels.

Also, do any of the hard coded (magic) numbers indicate the number of panels you are using?

When you post code, please click the <CODE> button in the message box and paste your formatted code between the sets of triple-ticks ( ``` here ``` ) with an easy to read result that can be used in an IDE...

#include <RGBmatrixPanel.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>

// Define HUB75E matrix pins (for 16x32 matrix)
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2

// Define button pins
#define BUTTON_1_PIN 3
#define BUTTON_2_PIN 4
#define BUTTON_3_PIN 5
#define BUTTON_4_PIN 6
#define BUTTON_5_PIN 7

// Button press settings
#define LONG_PRESS_TIME 3000 // 3 seconds for shutdown
#define DEBOUNCE_DELAY 50 // Debounce delay for stable button reading

// Initialize display (16x32 matrix setup)
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false, 1);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Command texts and colors
const char* commands[] = {"<<<<<<", "Follow me", "Slow down", "STOP", ">>>>>>"};
uint16_t colors[] = {matrix.Color333(0, 7, 7), matrix.Color333(0, 7, 0),
                     matrix.Color333(7, 7, 0), matrix.Color333(0, 0, 7),
                     matrix.Color333(0, 7, 7)
                    };
bool systemOn = true;
unsigned long buttonPressTime[5] = {0, 0, 0, 0, 0};
unsigned long lastDebounceTime[5] = {0, 0, 0, 0, 0};
bool buttonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};
bool lastButtonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};

// Font configuration
int textSize = 1; // Default text size (1 = normal)
bool isBold = false; // Default to non-bold text

void setup() {
  // Set up pins and initialize displays
  pinMode(BUTTON_1_PIN, INPUT_PULLUP);
  pinMode(BUTTON_2_PIN, INPUT_PULLUP);
  pinMode(BUTTON_3_PIN, INPUT_PULLUP);
  pinMode(BUTTON_4_PIN, INPUT_PULLUP);
  pinMode(BUTTON_5_PIN, INPUT_PULLUP);
  lcd.init();
  lcd.backlight();
  matrix.begin();
  displayStartupMessage();
}

void loop() {
  if (systemOn) {
    checkButtons();
  } else {
    checkForStartup();
  }
}

// Function to display a welcome message on startup
void displayStartupMessage() {
  lcd.setCursor(0, 0);
  lcd.print("WELCOME TO EGYPT");
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color333(3, 3, 3)); // Red
  matrix.setCursor(2, 2);
  matrix.print("WELCOME TO EGYPT");
  matrix.swapBuffers(true);
  delay(5000);
}

// Function to handle button presses and shutdown trigger
void checkButtons() {
  int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};
  for (int i = 0; i < 5; i++) {
    int reading = digitalRead(buttonPins[i]);
    if (reading != lastButtonState[i]) {
      lastDebounceTime[i] = millis();
    }
    if ((millis() - lastDebounceTime[i]) > DEBOUNCE_DELAY) {
      if (reading != buttonState[i]) {
        buttonState[i] = reading;
        if (buttonState[i] == LOW) {
          buttonPressTime[i] = millis();
        } else {
          if (millis() - buttonPressTime[i] < LONG_PRESS_TIME) {
            updateDisplay(i);
          }
          buttonPressTime[i] = 0;
        }
      }
      // Check if button is held for shutdown
      if (buttonState[i] == LOW && millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
        shutdownSystem();
        systemOn = false;
      }
    }
    lastButtonState[i] = reading;
  }
}

// Function to update the display based on the command
void updateDisplay(int commandIndex) {
  // Update LCD to show command
  lcd.clear();
  lcd.setCursor(4, 1);
  lcd.print(commands[commandIndex]);
  // Display command on matrix with sliding animation
  matrix.fillScreen(0);
  matrix.setTextColor(colors[commandIndex]);
  // Set font size (scale text size)
  matrix.setTextSize(textSize);
  // If bold, simulate boldness by printing text multiple times with offset
  if (isBold) {
    for (int i = 0; i < 2; i++) {
      matrix.fillScreen(0);
      matrix.setCursor((128 - strlen(commands[commandIndex]) * 6) / 2 + i, 0); // Slight offset for bold effect
      matrix.print(commands[commandIndex]);
      matrix.swapBuffers(true);
      delay(50);
    }
  } else {
    matrix.setCursor((128 - strlen(commands[commandIndex]) * 6) / 2, 0);
    matrix.print(commands[commandIndex]);
    matrix.swapBuffers(true);
    delay(50);
  }
}

// Function to shut down the system and display GOOD BYE message
void shutdownSystem() {
  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print("GOOD BYE");
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color333(7, 0, 0)); // Red
  matrix.setCursor(40, 5);
  matrix.print("GOOD BYE");
  matrix.swapBuffers(true);
  delay(2000); // Show GOOD BYE for 2 seconds
  lcd.clear();
  lcd.noBacklight();
  matrix.fillScreen(0);
}

// Function to check for system startup after shutdown
void checkForStartup() {
  int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};
  for (int i = 0; i < 5; i++) {
    if (digitalRead(buttonPins[i]) == LOW) {
      if (millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
        lcd.backlight();
        displayStartupMessage();
        systemOn = true;
        updateDisplay(0);  // Default to first command
        break;
      }
    } else {
      buttonPressTime[i] = 0;
    }
  }
}

thank for reply.
the code works after some text position editing , but now another problem my project have 4 (32x16) connected horizontaly to make a (128x16) panel but the text printed 4 times on each panel alone as the photos i attach.so, the code still see them as seperate panels insted of showing the text once in the center of the 4 panels, is there any solution for this?
Thanks,

#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define HUB75E matrix pins (for 16x32 matrix)
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2

// Define button pins
#define BUTTON_1_PIN 3
#define BUTTON_2_PIN 4
#define BUTTON_3_PIN 5
#define BUTTON_4_PIN 6
#define BUTTON_5_PIN 7

// Button press settings
#define LONG_PRESS_TIME 3000  // 3 seconds for shutdown
#define DEBOUNCE_DELAY 50     // Debounce delay for stable button reading

// Initialize display (16x32 matrix setup)
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Command texts and colors
const char* commands[] = {"<<<<<<", "Follow me", "Slow down", "STOP", ">>>>>>"};
uint16_t colors[] = {matrix.Color333(0, 7, 7), matrix.Color333(0, 7, 0),
                     matrix.Color333(7, 7, 0), matrix.Color333(0, 0, 7),
                     matrix.Color333(0, 7, 7)};

bool systemOn = true;
unsigned long buttonPressTime[5] = {0, 0, 0, 0, 0};
unsigned long lastDebounceTime[5] = {0, 0, 0, 0, 0};
bool buttonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};
bool lastButtonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};

// Font configuration
int textSize = 1;  // Default text size (1 = normal)
bool isBold = false;  // Default to non-bold text

void setup() {
  // Set up pins and initialize displays
  pinMode(BUTTON_1_PIN, INPUT_PULLUP);
  pinMode(BUTTON_2_PIN, INPUT_PULLUP);
  pinMode(BUTTON_3_PIN, INPUT_PULLUP);
  pinMode(BUTTON_4_PIN, INPUT_PULLUP);
  pinMode(BUTTON_5_PIN, INPUT_PULLUP);

  lcd.init();
  lcd.backlight();
  matrix.begin();

  displayStartupMessage();
}

void loop() {
  if (systemOn) {
    checkButtons();
  } else {
    checkForStartup();
  }
  
}

// Function to display a welcome message on startup
void displayStartupMessage() {
  // LCD Message
  lcd.clear();
  lcd.setCursor(2, 0);  // Centered on 16-char LCD
  lcd.print("WELCOME TO EGYPT");

  // Clear the matrix display and set up the static message
  matrix.fillScreen(0); // Clear entire screen

  // Draw "WELCOME TO EGYPT" centered on the first panel
  const char* message = "C.A.C";
  uint16_t color = matrix.Color333(7, 7, 0);  // White color

  // Draw the text on the 16x32 area of the first panel (starting X=0, Y=5)
  int x = 2;  // Near center of 16x32 panel horizontally
  int y = 3;  // Centered vertically in 16 pixels
  
  // Print message with individual characters (static)
  for (int i = 0; i < strlen(message); i++) {
    matrix.drawChar(x + (i * 6), y, message[i], color, 0, 1); 
  }

  // Display message statically for 3 seconds
  delay(10000);

  // Clear the display after delay
  lcd.clear();
  matrix.fillScreen(0);
}

// Function to handle button presses and shutdown trigger
void checkButtons() {
  int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};
  
  for (int i = 0; i < 5; i++) {
    int reading = digitalRead(buttonPins[i]);

    if (reading != lastButtonState[i]) {
      lastDebounceTime[i] = millis();
    }
    
    if ((millis() - lastDebounceTime[i]) > DEBOUNCE_DELAY) {
      if (reading != buttonState[i]) {
        buttonState[i] = reading;
        
        if (buttonState[i] == LOW) {
          buttonPressTime[i] = millis();
        } else {
          if (millis() - buttonPressTime[i] < LONG_PRESS_TIME) {
            updateDisplay(i);
          }
          buttonPressTime[i] = 0;
        }
      }

      // Check if button is held for shutdown
      if (buttonState[i] == LOW && millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
        shutdownSystem();
        systemOn = false;
      }
    }
    lastButtonState[i] = reading;
  }
}

// Function to update the display based on the command
// Function to update the display based on the command
void updateDisplay(int commandIndex) {
  // Update LCD to show command
  lcd.clear();
  lcd.setCursor(4, 1);  // Centered on 16-char LCD
  lcd.print(commands[commandIndex]);

  // Display command on the 128x16 combined matrix (centered on the first panel only)
  matrix.fillScreen(0);  // Clear the matrix
  matrix.setTextColor(colors[commandIndex]);

  // Set font size
  matrix.setTextSize(textSize);

  // Calculate the center position for the text on the 128x16 screen
  int textX = (128 - strlen(commands[commandIndex]) * 6) / 2;  // Center horizontally within 128 pixels
  int textY = 0;  // Start at the top of the matrix

  // Print the command text centered on the 128x16 screen
  matrix.setCursor(textX, textY);
  matrix.print(commands[commandIndex]);
  matrix.swapBuffers(true);  // Immediately update the display buffer
}


// Function to shut down the system and display GOOD BYE message
void shutdownSystem() {
  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print("GOOD BYE");
  
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color333(7, 0, 0)); // Red
  matrix.setCursor(0, 0);
  matrix.print("GOOD BYE");
  matrix.swapBuffers(true);
  
  delay(5000);  // Show GOOD BYE for 2 seconds

  lcd.clear();
  lcd.noBacklight();
  matrix.fillScreen(0);
}

// Function to check for system startup after shutdown
void checkForStartup() {
  int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};
  
  for (int i = 0; i < 5; i++) {
    if (digitalRead(buttonPins[i]) == LOW) {
      if (millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
        lcd.backlight();
        displayStartupMessage();
        
        systemOn = true;
        updateDisplay(0);  // Default to first command
        break;
      }
    } else {
      buttonPressTime[i] = 0;
    }
  }
}


This looks like your code has created an object with "one panel" and using the one panel many times.

Try only two panels... it seems the constructor of the library only can use two...

Parameters
    a	Address/row-select A pin number.
    b	Address/row-select B pin number.
    c	Address/row-select C pin number.
    d	Address/row-select D pin number.
    clk	RGB clock pin number.
    lat	RGB latch pin number.
    oe	Output enable pin number.
    dbuf	If true, display is double-buffered, allowing for smoother animation (requires 2X RAM).
    width	Specify 32 or 64 for the two supported matrix widths (default is 32). 

Here is a web site from Adafruit using Python, showing how to program multiple panels using the chain_across parameter.

1 Like