well, the point of the forum is to help and by doing so help others who could be stumbling upon the same roadblocks... so not so much about closed projects.
That's why I contribute here
May be you can recreate a minimal version of the code demonstrating what you are facing / trying to solve...
Sorry I understand the politics.
The problem is here somewhere.
void setup() {
Serial.begin(115200);
Serial.println("Serial monitor started");
Serial3.begin(38400, SERIAL_8N1); //Open serial port
}
void ReadNextionData() {
String RX_Buffer = "";
if (Serial3.available())
{
delay(100);
while (Serial3.available())
{
RX_Buffer += char(Serial3.read());
}
Serial.println(RX_Buffer);
AckLcdPage(RX_Buffer); //Para o arduino saber em que página o lcd está
DataTreatmentLCD(RX_Buffer); //Atualiza e trata os dados apenas da página onde está.
}
}
I think the problem it's not on the rest of the code, becaus the rest start after I received wich page is my Nextion lcd.
if you get more than 64 bytes back on Serial3, the delay(100); will make sure you lose some
you should not try to second guess the timing of an asynchronous protocol
what you could do - if you don' want to handle that properly with end markers etc - would be to use one of the Stream function dealing with getting data with a timeout
as you can get non ASCII characters, you might want to use one of the first two.
void ReadNextionData() {
char buffer[101];
if (Serial3.available()) {
size_t count = Serial3.readBytes((byte*) buffer, 100);
buffer[count] = '\0';
Serial.println(buffer);
String RX_Buffer = String(buffer); // ==> si realmente necesitas una String... :-(
AckLcdPage(RX_Buffer); //Para o arduino saber em que página o lcd está
DataTreatmentLCD(RX_Buffer); //Atualiza e trata os dados apenas da página onde está.
}
}
void setup() {
Serial.begin(115200);
Serial.println("Serial monitor started");
Serial3.begin(38400, SERIAL_8N1); //Open serial port}
Serial3.setTimeout(250); // https://www.arduino.cc/reference/en/language/functions/communication/stream/streamsettimeout/
}
may be something like this (not sure how the String class will handle non ASCII bytes from the buffer)
I do some changes, but now I receive the data that way:
void ReadNextionData() {
String RX_Buffer = "";
char buffer[101];
if (Serial3.available()) {
size_t count = Serial3.readBytes((byte*) buffer, 100);
buffer[count] = '\0';
Serial.println(buffer);
RX_Buffer = String(buffer); // ==> si realmente necesitas una String... :-(
AckLcdPage(RX_Buffer); //Para o arduino saber em que página o lcd está
DataTreatmentLCD(RX_Buffer); //Atualiza e trata os dados apenas da página onde está.
}
}
In the serial port I print one caracter at the time:
But I want all in the string like this in one string.
"$30d&"
But when I do on the code, doesn't increment the string
RX_Buffer = String(buffer); // ==> si realmente necesitas una String... :-(
Careful, the 100 there was the usable size of the buffer in my code
It should be 9 for you so that you keep space for the trailing null char since your buffer has 10 slots.
Did you use
Or did you change that value?
If you see the prints going byte by byte it means the data is coming in very slowly
Try printing the count
void ReadNextionData() {
String RX_Buffer = "";
char buffer[101];
if (Serial3.available()) {
size_t count = Serial3.readBytes((byte*) buffer, 100);
buffer[count] = '\0';
Serial.print(“got “); Serial.println(count); Serial.print(“ bytes => “);
Serial.println(buffer);
RX_Buffer = String(buffer); // ==> si realmente necesitas una String... :-(
AckLcdPage(RX_Buffer); //Para o arduino saber em que página o lcd está
DataTreatmentLCD(RX_Buffer); //Atualiza e trata os dados apenas da página onde está.
}
}
where does this come from? you understand that without seeing your code, you need to provide more info..
you still get the $30d&, but also tons of crap afterwards. May be there is a full buffer sent with the [] and three back question mark being field separators saying there is nothing there...
The only page this not ocure it's one page that I send information from arduino to LCD. The rest of them, that only I send information from LCD to arduino I recieve garbage.
The caracter $ is the start of the save data and & the end of save data to RX_Buffer.
I chante the title of the topic, makes more sense. Thanks on more time.