How can I make box.clear work when I send new data from the serial port? Whatever I send, it clears from the panel.
The data I send should remain on the screen. When a new message arrives, I want to clear the screen and print the new message I sent. I couldn't do it.`#include <SPI.h>
#include <DMD2.h>
#include <fonts/BodoniMTBlack20.h>
SoftDMD dmd(3,1);
DMD_TextBox box(dmd, -1, 0, 96, 16);
void setup() {
dmd.setBrightness(250); // Set brightness 0 - 255
dmd.selectFont(BodoniMTBlack20); // Font used
dmd.begin(); // Start DMD
Serial.begin(1200);
Serial1.begin(1200);
}
void loop() {
if (Serial1.available() > 0) {
box.clear();
char inByte = Serial1.read();
box.print((char)inByte);
}
}
`
What have you got Line Ending set to in the Serial monitor ?
const char START_CHAR = '\x02';
const char END_CHAR = '\x0A';
ledsyn
March 16, 2025, 9:43pm
4
Try edit your post and format all code as code, right now it looks like this
ledsyn
March 16, 2025, 9:44pm
5
Isn't that a bit on the lowest range of speed?
When I send something to the P10 LED panel via the serial port at high speed, sometimes the characters are missing. It works very stable at this speed. The P10 LED panel writes beautifully.
I want it to clear the screen when sending data. But I couldn't do it. Whatever I send, it clears the screen. It doesn't wait for new data to arrive.
what do you think will happen when the sketch reads END_CHAR ?
A wild guess would be that it will clear the display then print the invisible Newline character
What is sending the serial data and how many characters are being sent ?
const char START_CHAR = '\x02';
const char END_CHAR = '\x0A';
const int BUF_SIZE = 32;
char message[BUF_SIZE];
void receive_message(HardwareSerial &serial)
{
int rx_index = 0;
char rx_char = '\0';
while (rx_char != START_CHAR)
{
while (!serial.available()) {}
rx_char = serial.read();
}
// skip STX
while (!serial.available()) {}
rx_char = serial.read();
// read until END_CHAR
while (rx_char != END_CHAR)
{
if (rx_char != END_CHAR)
{
if (rx_index < BUF_SIZE - 1)
{
message[rx_index] = rx_char;
rx_index++;
}
}
while (!serial.available()) {}
rx_char = serial.read();
}
message[rx_index] = '\0';
}
void send_message(HardwareSerial &tx_serial, size_t startPos = 0)
{
tx_serial.write (START_CHAR);
for (size_t index = startPos; index < strlen(message); index++)
{
tx_serial.write (message[index]);
}
tx_serial.write (END_CHAR);
}
void setup()
{
Serial.begin(1200); //slave-1 den gelen veriler.
Serial1.begin(1200);
Serial2.begin(1200);
Serial3.begin(1200);
}
void loop() {
receive_message(Serial);
switch (message[0]) {
case '3': send_message(Serial1, 2); break;
case '4': send_message(Serial2, 2); break; index 2
case '5': send_message(Serial3, 2); break; index 2
default: break; // do nothing oytherwise
}
}
It comes from here. Posted by arduino
If there is data greater than zero in the serial port, it will not work.
if (Serial1.available() > 0) {
What does the > in that line of code mean ?
#include <SPI.h>
#include <DMD2.h>
#include <fonts/BodoniMTBlack20.h>
SoftDMD dmd(3,1);
DMD_TextBox box(dmd, -1, 0, 96, 16);
void setup() {
dmd.setBrightness(250); // Set brightness 0 - 255
dmd.selectFont(BodoniMTBlack20); // Font used
dmd.begin(); // Start DMD
Serial.begin(1200);
Serial1.begin(1200);
}
void loop() {
if (Serial1.available() > 0) {
box.clear();
char inByte = Serial1.read();
box.print((char)inByte);
}
}
clear screen .read and write data.
then wait.
As each character is received Serial1.available() will be greater than zero, the clear() function will run, the character will be read and printed
while ((r = Serial.read()) != -1) {
…
}
if ((SerialRead_char > 0) { // do something}
}
Does the same thing
Do you want to send and print single characters or multiple characters ?
If the latter then I suggest that you look at Serial input basics - updated