Hello guys, I have a problem with my arduino and Nextion comunication.
I have created diferent pages to receive and send comands to arduino.
But in some pages I receive the next information:
Before I enter the page its all normal, but when I enter the page apears the code in arduino "$240d&" and next apears the information I have shown in the previous image.
And the code I run initializing the page is:
I see the code many times, but I am new with this lcd.
The problem it's not on wiring, because in other pages I receive the correct information from lcd.
The baundrate is 38400, and I set the baudrate on first page.
I have RX_Buffer, and when I receive data from lcd, I print them.
while (Serial3.available())
{
RX_Buffer += char(Serial3.read());
Serial.println(RX_Buffer);
}
Normally I receive data like this ($70d&):
One more example what happen wrong:
All instructions over seria are terminated with three bytes of 0xFF 0xFF 0xFF ➜ so that could be your three question marks and there is a trailing null char.
is RX_Buffer a String instance ?
your prints are accumulating input...
try something like this
while (Serial3.available()) {
int x = Serial3.read();
Serial.print(F("0x");
if (x < 0xF) Serial.write('0');
Serial.print(x, HEX);
Serial.write(',');
}
I don't know why it would need to be a String but with
while (Serial3.available())
{
RX_Buffer += char(Serial3.read());
Serial.println(RX_Buffer);
}
you print the buffer as it grows and you are not even sure you got everything that was sent since the while loop will likely run faster than the 38400 bauds you have on the other end
you still have the issue that the buffer might not be complete as you can read faster than the data is coming in. if you know the end marker of the communication, you should wait for this end marker before you print your RX_Buffer (otherwise the next time you read you'll have the leftover from the previous communication coming in)
this is trying to second guess the timing of an asynchronous process...
the incoming buffer has only 64 slots, at 38400 you might have received 384 bytes in that time and lost a lot of them...
I would suggest to study Serial Input Basics to understand how the Serial port should be handled
this is not going to do what you want
if(C != "⸮")
the ⸮ you see is generated by the Serial monitor, it does not mean this is the character you got (and this is not a standard ASCII one char anyway, more an UTF8 thingy, so you have zero chance of getting it whilst reading only 1 byte)
When I refer the end marker is the "⸮⸮⸮" simbols!
But only ocurs on some pages, not all of them. And some times when I change between some pages the symbols stop apearing on the arduino serial port.