Communication between Nextion Editor and Arduino UNO

46 Views Asked by At

I am just starting to use Nextion Editor, and I have the following issue. In the Nextion Editor, I have an ON/OFF button. It is green when it is ON and red when it is OFF. I want that when a person presses this button on the screen (which is initially off), before changing its state (and therefore its color), it sends this state to the Arduino UNO. Arduino should recognize that it is turned on and send an 'OK' to the screen as a way of saying 'I confirm that the connection between both has been made, and I send an OK for you to change the button's state.' Once the 'OK' is received on the screen (which does not modify any text object, it's just a signal sent by Arduino and should not be displayed on the screen), only then should the color and state of the button change.

My Arduino code is very simple, and I don't know how to modify it to achieve the above.

char val;

void setup() {
  Serial.begin(115200);
}

void loop() {
  if(Serial.available()>0){
    val = Serial.read(); 
    Serial.print(val);
  }
}

I also don't know what code or command to use in Nextion Editor to receive the 'OK' from Arduino. Please help!

I receive recommendations of where to learn more about this topic. Thanks!

0

There are 0 best solutions below