0

Well I am trying make language page with Nextion display and Arduino Mega. If user enter the language page Nextion display is sending page name with this commend to Arduino for which is current page.

enter image description here

While page preinitializing moment.

print "dil"

If user choice a language and then press the Next button, Nextion sending this comment to Arduino.

if(r0.val==1)
{
  va0.txt="en"
}else if(r1.val==1)
{
  va0.txt="tr"
}else
{
  va0.txt="de"
}
print va0.txt
page 2

Everyting is normal until here. If user press back button at page 2 in a short time. Serial print not only send "tr" or "de" or "en" but also sending "dil" comment all together. Because of that Serial2.readString(); commend return such as "trdil" or "endil" or "dedil". So that program not working properly. Just I want to receive language's 2 letter short code.

There is a comment which is useful if I send data Arduino to Nextion to understand last of the commend line.

  Serial2.write(0xff);
  Serial2.write(0xff);
  Serial2.write(0xff);

How can tell the Arduino there is a line break after sending "tr" or "en" or "de".

Assume that I am using simple Serial receiver commend.

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
}

void loop() {
  if (Serial2.available() > 0)
  {
    String Received  = Serial2.readString();
    Serial.println(Received);
  }  
}
4
  • check for the newline character ... if you receive it, then it is being sent
    – jsotola
    Sep 7 '20 at 23:17
  • Can you show me a tutorial
    – mehmet
    Sep 8 '20 at 5:21
  • You didn't show your Arduino code
    – chrisl
    Sep 8 '20 at 6:45
  • @chrisl I have added simple receiver code
    – mehmet
    Sep 8 '20 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.