Eps32 HUB 75 matrix panel library

Hi all,
I have connected 20P10 led modules of 32X16 each in 2 rows and 10 columns.
I want some part of the display to scroll text and some part should be standby text.
Am not getting the two functions at a time , other is getting cleared when one function runs.
am attaching the code please anyone help regarding this.

I think double buffer program helps me but not understanding it?

#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid = “dileepkumar”;
const char* password = “7842634205”;
char mqttServer = “broker.hivemq.com”;
int mqttPort = 1883;
int a=0;
const char
mqtt_client_name = “ESP/glowsignboard”;
//const char* mqtt_pub_topic = “/ys/testpub”; //The topic to which our client will publish
const char* mqtt_sub_topic = “cf/store1”; //The topic to which our client will subscribe

WiFiClient client;
PubSubClient mqttClient(client);

#define PANEL_RES_X 32 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 16 // Number of pixels tall of each INDIVIDUAL panel module.

#define NUM_ROWS 2 // Number of rows of chained INDIVIDUAL PANELS
#define NUM_COLS 8 // Number of INDIVIDUAL PANELS per ROW
#define PANEL_CHAIN NUM_ROWSNUM_COLS // total number of panels chained one to another
#define Matrix_width NUM_COLS
PANEL_RES_X

#define SERPENT true
#define TOPDOWN true

String str=“”;
String message= " ";
String str1=“Medplus offers”;

#include <ESP32-VirtualMatrixPanel-I2S-DMA.h>
#include <Fonts/FreeMonoBold9pt7b.h>

MatrixPanel_I2S_DMA *dma_display = nullptr;
VirtualMatrixPanel *virtualDisp = nullptr;

void callback(char* topic, byte* payload, unsigned int length)
{
a=1;
str=“”;
virtualDisp->clearScreen();
Serial.println("Message received from: ");
Serial.print(topic);
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
str += (char)payload[i];
}
//virtualDisp->setFont(&FreeMonoBold9pt7b);
message = str;
mqttClient.publish(“message/status”,“message”);
Serial.println("the string is ");
Serial.println(str);
//scroll_text(6,40,message,50,240,255);
}
void scroll_text(uint8_t ypos,unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB)
{
uint16_t text_length = text.length();
virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
virtualDisp->setFont(&FreeMonoBold9pt7b);
for (int xpos=(Matrix_width); xpos>-(Matrix_width+text_length*7); xpos–)
{
mqttClient.loop();
if(a)
{
break;
}
virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
virtualDisp->clearScreen();
virtualDisp->setCursor(xpos, virtualDisp->height()-ypos);
virtualDisp->setTextSize(1);
virtualDisp->print(text);
delay(scroll_delay);
yield();
delay(scroll_delay/5);
yield();
yield();
}
a=0;
}

void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(”.”);
}
randomSeed(micros());
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// esp_macaddress = WiFi.macAddress();
Serial.println("MAC address: ");
Serial.println(WiFi.macAddress());
}

void reconnect()
{

  while (!mqttClient.connected())
  {
     if(WiFi.status() != WL_CONNECTED)
       {
          setup_wifi();
       }
       Serial.print("Attempting MQTT connection...");
           // Create a random client ID
       String clientId = "ESP32Client-";
       clientId += String(random(0xffff), HEX);
      if(mqttClient.connect(clientId.c_str()))
     {
        Serial.println("MQTT Connected!");
        mqttClient.subscribe(mqtt_sub_topic);
        mqttClient.publish("glowsignboard/status","reConnected");
        mqttClient.setCallback(callback);
     }
     else
     {
      Serial.print("failed, rc=");
      Serial.print(mqttClient.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
      Serial.print(".");
     }
  }

}

void setupMQTT()
{
mqttClient.setServer(mqttServer, mqttPort);
// mqttClient.setCallback(callback);
}

void setup() //Setup!
{
Serial.println(“Starting Esp32:”);
Serial.begin(115200);
Serial.println(“In setup”);
setup_wifi();
setupMQTT();
reconnect();
HUB75_I2S_CFG mxconfig
(
PANEL_RES_X, // module width
PANEL_RES_Y, // module height
PANEL_CHAIN // chain length
);

if (NUM_ROWS <= 1)
{
Serial.println(F(“There is no reason to use the VirtualDisplay class for a single horizontal chain and row!”));
}
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->setBrightness8(192); // range is 0-255, 0 - 0%, 255 - 100%
if( not dma_display->begin() )
Serial.println(“****** I2S memory allocation failed ***********”);
virtualDisp = new VirtualMatrixPanel((*dma_display), NUM_ROWS, NUM_COLS, PANEL_RES_X, PANEL_RES_Y, SERPENT, TOPDOWN);
virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
delay(2000);

}

void loop()
{
if ((WiFi.status() != WL_CONNECTED))
{
setup_wifi();
}
if(!mqttClient.connected())
{
reconnect();
}
Serial.println(“in the main loop”);
mqttClient.loop();
delay(500);
// virtualDisp->setFont(&FreeMonoBold9pt7b);
// virtualDisp->setTextColor(virtualDisp->color565(255, 240, 0));
// virtualDisp->setCursor(20, virtualDisp->height()-20);
// virtualDisp->setTextSize(1);
// virtualDisp->print(str);
Serial.println(message);
scroll_text(6,40,message,50,240,255);
}

please insert the code using the code tags

sorry i didnt understand you

@Louis_Beaudoin_oauth @b707

When you insert code to the forum - enclose it in tags, using the </> icon at the top of the edit window. Correctly inserted code will be a much readable:

#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid = “dileepkumar”;
const char* password = “7842634205”;
char mqttServer = “broker.hivemq.com”;
int mqttPort = 1883;
int a=0;
const char mqtt_client_name = “ESP/glowsignboard”;
//const char* mqtt_pub_topic = “/ys/testpub”; //The topic to which our client will publish
const char* mqtt_sub_topic = “cf/store1”; //The topic to which our client will subscribe

WiFiClient client;
PubSubClient mqttClient(client);

#define PANEL_RES_X 32 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 16 // Number of pixels tall of each INDIVIDUAL panel module.

#define NUM_ROWS 2 // Number of rows of chained INDIVIDUAL PANELS
#define NUM_COLS 8 // Number of INDIVIDUAL PANELS per ROW
#define PANEL_CHAIN NUM_ROWSNUM_COLS // total number of panels chained one to another
#define Matrix_width NUM_COLSPANEL_RES_X

#define SERPENT true
#define TOPDOWN true

String str=“”;
String message= " ";
String str1=“Medplus offers”;

#include <ESP32-VirtualMatrixPanel-I2S-DMA.h>
#include <Fonts/FreeMonoBold9pt7b.h>

MatrixPanel_I2S_DMA *dma_display = nullptr;
VirtualMatrixPanel *virtualDisp = nullptr;

void callback(char* topic, byte* payload, unsigned int length)
{
a=1;
str=“”;
virtualDisp->clearScreen();
Serial.println("Message received from: ");
Serial.print(topic);
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
str += (char)payload[i];
}
//virtualDisp->setFont(&FreeMonoBold9pt7b);
message = str;
mqttClient.publish(“message/status”,“message”);
Serial.println("the string is ");
Serial.println(str);
//scroll_text(6,40,message,50,240,255);
}
void scroll_text(uint8_t ypos,unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB)
{
uint16_t text_length = text.length();
virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
virtualDisp->setFont(&FreeMonoBold9pt7b);
for (int xpos=(Matrix_width); xpos>-(Matrix_width+text_length*7); xpos–)
{
mqttClient.loop();
if(a)
{
break;
}
virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
virtualDisp->clearScreen();
virtualDisp->setCursor(xpos, virtualDisp->height()-ypos);
virtualDisp->setTextSize(1);
virtualDisp->print(text);
delay(scroll_delay);
yield();
delay(scroll_delay/5);
yield();
yield();
}
a=0;
}

void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(”.”);
}
randomSeed(micros());
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// esp_macaddress = WiFi.macAddress();
Serial.println("MAC address: ");
Serial.println(WiFi.macAddress());
}

void reconnect()
{

  while (!mqttClient.connected())
  {
     if(WiFi.status() != WL_CONNECTED)
       {
          setup_wifi();
       }
       Serial.print("Attempting MQTT connection...");
           // Create a random client ID
       String clientId = "ESP32Client-";
       clientId += String(random(0xffff), HEX);
      if(mqttClient.connect(clientId.c_str()))
     {
        Serial.println("MQTT Connected!");
        mqttClient.subscribe(mqtt_sub_topic);
        mqttClient.publish("glowsignboard/status","reConnected");
        mqttClient.setCallback(callback);
     }
     else
     {
      Serial.print("failed, rc=");
      Serial.print(mqttClient.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
      Serial.print(".");
     }
  }

}

void setupMQTT()
{
mqttClient.setServer(mqttServer, mqttPort);
// mqttClient.setCallback(callback);
}

void setup() //Setup!
{
Serial.println(“Starting Esp32:”);
Serial.begin(115200);
Serial.println(“In setup”);
setup_wifi();
setupMQTT();
reconnect();
HUB75_I2S_CFG mxconfig
(
PANEL_RES_X, // module width
PANEL_RES_Y, // module height
PANEL_CHAIN // chain length
);

if (NUM_ROWS <= 1)
{
Serial.println(F(“There is no reason to use the VirtualDisplay class for a single horizontal chain and row!”));
}
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->setBrightness8(192); // range is 0-255, 0 - 0%, 255 - 100%
if( not dma_display->begin() )
Serial.println(“****** I2S memory allocation failed ***********”);
virtualDisp = new VirtualMatrixPanel((*dma_display), NUM_ROWS, NUM_COLS, PANEL_RES_X, PANEL_RES_Y, SERPENT, TOPDOWN);
virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
delay(2000);

}

void loop()
{
if ((WiFi.status() != WL_CONNECTED))
{
setup_wifi();
}
if(!mqttClient.connected())
{
reconnect();
}
Serial.println(“in the main loop”);
mqttClient.loop();
delay(500);
// virtualDisp->setFont(&FreeMonoBold9pt7b);
// virtualDisp->setTextColor(virtualDisp->color565(255, 240, 0));
// virtualDisp->setCursor(20, virtualDisp->height()-20);
// virtualDisp->setTextSize(1);
// virtualDisp->print(str);
Serial.println(message);
scroll_text(6,40,message,50,240,255);
}

okay thankyou .

Any changes to be needed , please let me know .

You’re not using SmartMatrix Library, you’re using another library to drive the matrix, I think you’re posting on the wrong forum

Hi , can I use smart matrix for esp32 only , without using teensy boards.
I have only ESP32 , no teensy

If smart matrix library supports ESP32 alone , can you please send me the wiring and all code information here .

Thanks in advance

Take a look at the README and the ESP32 section in the Wiki