I want to send messages from my PC with the Serial Monitor to my Arduino Uno connected to MAX7219 displays.
My code (see hereunder) works correctly if I send the message "Scrolling text" (see the comment line in the code with mDisplay.displayText("Scrolling ...).
However, when I try with the code line mdisplay.displayText(curMessage, ... I see unreadable characters on the MAX7219 displays.
1/ where is the mistake?
2/ The code mdisplay.displayText is in the void setup part. So if I want to send a new message, I have to restart the application. What must I change to use the code mdisplay.displayText in the void loop part. This should allow me to send different messages.
Thanks in advance for helping me.
// Test based on MAX7219-BenneDeBakker2.ino + instructions to use the Serial Monitor;
#include "MD_Parola.h"
#include "MD_MAX72xx.h"
#include "SPI.h"
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 3
// 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() {
myDisplay.begin(); // Intialize the object
myDisplay.setIntensity(0); // Set the display intensity (brightness) (0-15)
myDisplay.displayClear(); // Clear the display:
Serial.begin(9600); // for Serial monitor
while (Serial.available() == 0) {} // wait for data available
String frompc = Serial.readString(); // read until timeout
frompc.trim(); // remove any \r \n whitespace at the end of the String
Serial.println(frompc); // send message to Serial monitor
int ArrayLength = frompc.length()+1;
char curMessage[ArrayLength];
frompc.toCharArray(curMessage, ArrayLength);
Serial.println(curMessage);
//myDisplay.displayText("Scrolling text", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
myDisplay.displayText(curMessage, PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}
You are probably displaying the CR and LF at the end of the serial string.
Also, as noted, you don't have a loop() function with the Parola animation loop. You will never see anythig being displayed with the code you have here (and it won't compile properly either).
Thank you, Marco_c, for your quick response.
1/ I don't see what I can do regarding the CR and LF characters. In my code I wrote:
frompc.trim(); // remove any \r \n whitespace at the end of the String
And I also tried to shorten the ArrayLength of the char variable curMessage. But then I see via Serial.println(curMessage), that I lose the last character of my message.
2/ I now understand that I can't use Parola in the Loop() part of my code. Is there another way to display messages on MAX7219?
Kind regards.
Hard to say unless you show a picture of what is unreadable characters.
The Parola_Scrolling example demonstrates the use of the scrolling function to display text received from the serial interface. This seems what you want you are trying to do.
Hello All,
as I got no valid answer, I made a new program including my own scrolling process. Here below the code (less than 40 lines). This code is waiting on a message from the Serial Monitor and displays the message on MAX7219 with character scrolling.
// <<<<<<< From Serial Monitor to MAX7219 by JACK: JACK-MAX7219-CharScrolling.ino >>>>>>>
#include "MD_Parola.h"
#include "MD_MAX72xx.h"
#include "SPI.h"
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 3
// 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() {
myDisplay.begin(); // Intialize the object
myDisplay.setIntensity(0); // Set the display intensity (brightness) (0-15)
myDisplay.displayClear(); // Clear the display:
Serial.begin(9600); // for Serial monitor
}
void loop() {
// Serial monitor
Serial.println("Enter a message, please:");
while (Serial.available() == 0) {} // wait for data available
String frompc = Serial.readString(); // read until timeout
frompc.trim(); // remove any \r \n whitespace at the end of the String
Serial.print("Received from Serial Monitor: "); Serial.println(frompc);
myDisplay.setTextAlignment(PA_LEFT); // Display serial monitor answer
myDisplay.print(frompc);
delay(2000);
String curMessage = frompc; //Initialize the while
while (curMessage.length() > 6){
curMessage = curMessage.substring(1); //supress the first character
myDisplay.print(curMessage);
delay(1000);
}
}