MD parola: problem in scrolling updated text

Hello all,
I have made IOT based notice board using Esp32 and max7219 where any message received via mqtt app will be displayed on led.
I have used MD_parola lib along with others.
I can scroll the default text but having difficulty in scrolling the text received via app.

The below code works only for the word 'on' as mentioned. I would like that that any word received(I have used the word message for any random word received) should scroll

Extracting a line from code to explain better:
this works:

P.displayText("On" , PA_RIGHT, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);

This doesnt:

P.displayText(message , PA_RIGHT, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);

Error says message not declared in scope. relevant code is posted below.

partial workaround I got by using

P.Print(message)

which displays the updated message but doesnt scroll.

void MQTTcallback(char* topic, byte* payload, unsigned int length) {
 Serial.print("Message arrived in topic: ");
 Serial.println(topic);
 Serial.print("Message:");
 String message;
 for (int i = 0; i < length; i++) {
 message = message + (char)payload[i]; //Conver *byte to String
 }
 Serial.print(message);

 if(message == "on") {
 digitalWrite(LED,HIGH); //LED on
 P.displayText("On" , PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); 

 } else {
 P.print(message);
 P.displayAnimate();
 }
 Serial.println();
 Serial.println("-----------------------");
 
}
void loop() {
 client.loop();
}

(Being honest, I don't know how to use the commands that properly as this is my 1st such project).

Kindly help
Thank you.

void MQTTcallback(char* topic, byte* payload, unsigned int length) {
 Serial.print("Message arrived in topic: ");
 Serial.println(topic);
 Serial.print("Message:");
 String message;
 for (int i = 0; i < length; i++) {
 message = message + (char)payload[i]; //Conver *byte to String
 }
 message = message + '\0'; // EOL
 Serial.print(message);

 if(message == "on") {
 digitalWrite(LED,HIGH); //LED on
 P.displayText("On" , PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); 

 } else {
 P.print(message);
 P.displayAnimate();
 }
 Serial.println();
 Serial.println("-----------------------");
 
}
void loop() {
 client.loop();
}
1 Like

Thanks for quick reply. It still gives an error.
note: no known conversion for argument 1 from 'String' to 'const char*'

exit status 1

Compilation error: no matching function for call to 'MD_Parola::displayText(String&, textPosition_t, int, int, textEffect_t, textEffect_t)'

Here I am posting full code. Hope it helps. I have commented the line which shows error

Also, if possible, can u help me loop the message once it has scrolled?


#include <WiFi.h>
#include <PubSubClient.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 

#define CLK_PIN   D18 //green
#define DATA_PIN  D23 //orange
#define CS_PIN    5 //yellow

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); 

#define LED 2
 
//Enter your wifi credentials
const char* ssid = "POCO";
const char* password = "taral15988";

//Enter your mqtt server configurations
const char* mqttServer = "broker.hivemq.com";    //Enter Your mqttServer address
const int mqttPort = 1883;       //Port number
 
WiFiClient espClient;
PubSubClient client(espClient);
 
void setup() {
  delay(1000);
  pinMode(LED,OUTPUT);
  Serial.begin(115200);
 P.begin();
 P.displayText("Welcome to the project", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
    P.displayAnimate();
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.print("Connected to WiFi :");
  Serial.println(WiFi.SSID());
 
  client.setServer(mqttServer, mqttPort);
  client.setCallback(MQTTcallback);
 
  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");

    if (client.connect("ESP32" )) {
 
      Serial.println("connected to MQTT");  

    } else {
 
      Serial.print("failed with state ");
      Serial.println(client.state());  //If you get state 5: mismatch in configuration
      delay(2000);
 
    }
  }
 
  client.publish("esp/test", "Hello from ESP32");
  client.subscribe("esp/test");
  
}
 
void MQTTcallback(char* topic, byte* payload, unsigned int length) {
 
  Serial.print("Message arrived in topic: ");
  Serial.println(topic);
 
  Serial.print("Message:");

  String message;
  for (int i = 0; i < length; i++) {
    message = message + (char)payload[i];  //Conver *byte to String
  }
  message = message + '\0'; // EOL
   Serial.print(message);
  
  if(message == "on") {
    digitalWrite(LED,HIGH);  //LED on
   P.displayText("On" , PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); //initialise all text output to be in the middle
    P.displayAnimate();
  }
  if(message == "off") {
    digitalWrite(LED,LOW);
    P.displayText("Off" , PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); //initialise all text output to be in the middle
    P.displayAnimate();
  }  else {
    P.displayText(message , PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); //this line gives error
    P.displayAnimate();
    //P.print(message);// this is a workaround for above line but it doesnt scroll
    //P.displayAnimate();
  }
 
  Serial.println();
  Serial.println("-----------------------");
  
}
 
void loop() {
  client.loop();

}


Try in this way

  char message[length + 1];
  message[length] = '\0'; // end of string
  for (int i = 0; i < length; i++) {
    message[i] = (char)payload[i];
  }
  Serial.print(message);

instead of

  String message;
  for (int i = 0; i < length; i++) {
    message = message + (char)payload[i];  //Conver *byte to String
  }
  message = message + '\0'; // EOL
  Serial.print(message);
1 Like

Hi, I have updated the code.
I am having following problems:
1-When new message comes, it scrolls but only once. I want it to scroll continuously.

2-If i dont use displayclear, display freezes:

  }  else {
    P.displayClear(); //display freezes on getting new message if i dont use this line here
    P.displayText(message , PA_CENTER, 10, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
    P.displayAnimate();
    P.displayReset();
  }

3-it shows maximum 6-7 alphabets. is there a way to display entire text?

I would really appreciate the help. Thank you

Here is the entire code for reference:


#include <WiFi.h>
#include <PubSubClient.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 //If you're only using a single 32x8 display then please set this to 4.

#define CLK_PIN   D18 //green
#define DATA_PIN  D23 //orange
#define CS_PIN    5 //yellow

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); 

#define LED 2
 
//Enter your wifi credentials
const char* ssid = "monika";
const char* password = "12345678";

//Enter your mqtt server configurations
const char* mqttServer = "broker.hivemq.com";    //Enter Your mqttServer address
const int mqttPort = 1883;       //Port number
//const char* mqttUser = "seVU93RhYk"; //User
//const char* mqttPassword = "c5xFF6zhxT"; //Password
 
WiFiClient espClient;
PubSubClient client(espClient);
 
void setup() {
  delay(1000);
  pinMode(LED,OUTPUT);
  Serial.begin(115200);
 P.begin();
 P.setIntensity(0);
  P.displayClear();
 //P.displayScroll("HELLO MONIKA", PA_CENTER, PA_SCROLL_LEFT,30); //initialise all text output to be in the middle
    //P.displayAnimate();
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.print("Connected to WiFi :");
  Serial.println(WiFi.SSID());
 
  client.setServer(mqttServer, mqttPort);
  client.setCallback(MQTTcallback);
 
  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");

    if (client.connect("ESP32" )) {
 
      Serial.println("connected to MQTT");  
      P.displayText("MQTT ON" , PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
      P.displayAnimate();

    } else {
 
      Serial.print("failed with state ");
      Serial.println(client.state());  //If you get state 5: mismatch in configuration
      delay(2000);
 
    }
  }
 
  client.publish("esp/test2", "Hello from ESP32");
  client.subscribe("esp/test2");
  
}
 
void MQTTcallback(char* topic, byte* payload, unsigned int length) {
 
  Serial.print("Message arrived in topic: ");
  Serial.println(topic);
 
  Serial.print("Message:");

char message[length + 1];
  message[length] = '\0'; // end of string
  for (int i = 0; i < length; i++) {
    message[i] = (char)payload[i];
  }
  Serial.print(message);
  //String message;
  //for (int i = 0; i < length; i++) {
    //message = message + (char)payload[i];  //Conver *byte to String
  //}
  //message = message + '\0'; // EOL
   //Serial.print(message);
   //P.displayText(message)
    //P.displayAnimate();
    //delay(10000);
  
  if(message == "on") {
    digitalWrite(LED,HIGH);  //LED on
    P.displayClear();
   P.displayText("LED on" ,  PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
    P.displayAnimate();
  }
  if(message == "off") {
    digitalWrite(LED,LOW);
    P.displayClear();
    P.displayText("Off" ,  PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
    P.displayAnimate();
  }  else {
    P.displayClear();
    P.displayText(message , PA_CENTER, 10, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
    P.displayAnimate();
  }
  Serial.println();
  Serial.println("-----------------------");
}
 
void loop() {
  client.loop();
  if (P.displayAnimate()) {
    P.displayReset();
    
  }
}
  1. You need to pass the library a C string not a String.
  2. displayAnimate() must be in your loop(). Animation will only progress when this method i called multiple times (one step, if the right step time has elapsed, for each invocation). Please look at the examples and documentation provided with the library for how to use this. The closest example for what you are trying to do is the Scrolling example, where a new message is received from the serial port.
1 Like

Hi, thank you for the reply.
I am Sorry I did not understand what you are sayin.
Can you please tell me in an easier way? (I had to make entire project in just 2 days for some reasons and I have never used arduino IDE before this)

  1. String is a type of structure that contains the characters for the text you are storing and also additional information. a C-string is an array of characters terminated in a nul ('\0') character. Please google this if you do not know, as it is an important piece of understanding if you program. There are methods in the String to convert this to a C-string - here is the reference to the String object (https://cplusplus.com/reference/string/string/)

  2. You really need to look at the examples. I am not sure how to explain this any better than what the example can show you, especially as they are so similar. If you have specific questions about the example then please ask.

1 Like

Hi, sorry to bother you. Actually I am a doctor but doing this programming for some reasons. I have to finish this today itself so not much scope to learn about it at present.

It would be a great help if u can just look at the code and tell me which lines or words to replace with what things..

Once again, sorry to bother.. Would be a great help if u can do it.. Thank you

This compiles but I cannot test it as I don't have your hardware.

#include <WiFi.h>
#include <PubSubClient.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 //If you're only using a single 32x8 display then please set this to 4.

#define CLK_PIN   D18 //green
#define DATA_PIN  D23 //orange
#define CS_PIN    5 //yellow

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

#define LED 2

//Enter your wifi credentials
const char* ssid = "monika";
const char* password = "12345678";

//Enter your mqtt server configurations
const char* mqttServer = "broker.hivemq.com";    //Enter Your mqttServer address
const int mqttPort = 1883;       //Port number
//const char* mqttUser = "seVU93RhYk"; //User
//const char* mqttPassword = "c5xFF6zhxT"; //Password

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
  delay(1000);
  pinMode(LED, OUTPUT);
  Serial.begin(115200);
  P.begin();
  P.setIntensity(0);
  P.displayClear();
  //P.print("HELLO MONIKA");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.print("Connected to WiFi :");
  Serial.println(WiFi.SSID());

  client.setServer(mqttServer, mqttPort);
  client.setCallback(MQTTcallback);

  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");

    if (client.connect("ESP32")) {

      Serial.println("connected to MQTT");
      P.displayText("MQTT ON", PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
    }
    else {
      Serial.print("failed with state ");
      Serial.println(client.state());  //If you get state 5: mismatch in configuration
      delay(2000);
    }
  }

  client.publish("esp/test2", "Hello from ESP32");
  client.subscribe("esp/test2");

}

void MQTTcallback(char* topic, byte* payload, unsigned int length)
{
  char message[length + 1];
  
  Serial.print("Message arrived in topic: ");
  Serial.println(topic);

  Serial.print("Message:");

  memcpy(message, payload, length);
  message[length] = '\0'; // end of string

  Serial.print(message);

  if (strcmp(message, "on") == 0) 
  {
    digitalWrite(LED, HIGH);  //LED on
    P.displayText("LED on", PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
  }
  else if (strcmp(message, "off") == 0)
  {
    digitalWrite(LED, LOW);
    P.displayText("LED off", PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
  }
  else 
  {
    P.displayText(message, PA_CENTER, 10, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
  }
  
  // reset the display for new message to be shown
  P.displayClear();
  P.displayReset();
  
  Serial.println();
  Serial.println("-----------------------");
}

void loop() {
  client.loop();
  if (P.displayAnimate())
     P.displayReset();
 }
1 Like

Thank you for taking such effort, I tried this code but display turns off when it receives new message

Update: I was able to get scroll work by using P.displayScroll instead of P.displayText but it displays some weird characters and not the word i sent. (If i send "on" or "off", i can see words correctly, but other words r converted to weird characters)

Well, you are just going to have to debug what is going on then.

You already have some print statements in the code, add a few more in to show you when it gets to key points so that you can follow the flow in the serial monitor and get an idea where to look closely (for example, is message being shown correctly on the serial monitor?).

1 Like

Yes it shows correctly in serial monitor. But on display it shows random characters

Paste them here.

1 Like

In that case make the variable ‘message’ a global variable with fixed size something bigger than you will ever need, say 100, instead of length.

1 Like

I wrote "hi" which is displayed by symbol lik 0 or theta
I wrote "HELLO" and it was converted to the image shown below


Sorry, I dont know how to do that. Please tell me which line to change to what.. Thank you

Your LED wiring is not correct.

To map your LED wiring, start with lighting one LED. Then, logically move that one LED. Find the LEDs that are wired backwards, shorted and open.

1 Like

words mentioned in the code works correctly. For eg: word "MQTT" "LED ON" AND "LED OFF" can be read properly as I have mentioned in code that when the message is "on", led should display "LED ON". Same for other 2 words mentioned.
But words which are not mentioned, displays such characters

Would you show these?

1 Like