Sending serial data to Max7xxx Dot matrix display

Hi,
I a using an Arduino Uno R3 with a connected HC-05 bluetooth module and smartphone app to send a message to be displayed / scrolling on a 8 x 32 ICSTATION type dot matrix modue.

All physical component connections are o.k. and I can see that the data is received and the replies to the Serial Monitor / smartphone indicate all is well.
I have also tested the ICSTATION dot matrix module and it correctly scrolls text (see commented out line in the undernoted code).
What should be a relatively easy problem has me totally stumped - the fault must lie in the use of (cws.c_str() - but I confess I cannot understand why or how to correct it.
Any help would be greatly appreciated!

Chas

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

#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES 4
#define CS_PIN 10

// Create a new instance of the MD_Parola class with hardware SPI connection
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void setup() {
  Serial.begin(9600);
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.displayClear();
 }

void loop() {  
   if (Serial.available()) {                                // if there is data coming
    String cws = Serial.readStringUntil('\n');              // read string until meet newline character
    myDisplay.displayClear();                               // clear led matrix display
    myDisplay.displayScroll(cws.c_str(), PA_CENTER, PA_SCROLL_LEFT, 100);
    //myDisplay.displayScroll("Working fine!", PA_CENTER, PA_SCROLL_LEFT, 100);
    Serial.print("LED Matrix displayed: ");                 // reports action to smartphone app
    Serial.println(cws);
  }

  if (myDisplay.displayAnimate()) {
    myDisplay.displayReset();
  }
}


Using the serial port of an Uno for both debugging (serial monitor) and HC-05 at the same time is calling for trouble. It's not clear if you're doing that or not.

If you suspect c_str(), you can easily test that. Below is a modified version of your loop().

void loop() {  
    String cws = "Working fine!";
    myDisplay.displayClear();                               // clear led matrix display
    myDisplay.displayScroll(cws.c_str(), PA_CENTER, PA_SCROLL_LEFT, 100);
    Serial.print("LED Matrix displayed: ");                 // reports action to smartphone app
    Serial.println(cws);
  }

  if (myDisplay.displayAnimate()) {
    myDisplay.displayReset();
  }
}

How long are the messages that are received by the Arduino?

@chas1745
Your string will contain the '\r'.
Will that cause a problem with the display?

Hi, thanks for the very swift response!

I've tried your amendment and there is still no scrolling text - so the srting cws is not being sent to the dot matrix display. This must be something to do with c_str() - I'm lost!!

The messages from the smartphone are only a few characters long.

Chas

MD_Parola requires that the text string is in scope the entire time that the animation takes place as it does not copy the string to an internal buffer (to save RAM). I don't think that you are observing this rule with your construct.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.