Start a new topic

How to trigger a page from arduino to nextion ?

Hello friends,


I want to get an input signal from arduino to nextion, and it will trigger any page;


In arduino code i have created an input


#define BUTTON 2

and set it as an input

pinMode(BUTTON, INPUT);


and after setup i am using a code like this;


if(digitalRead(BUTTON)==HIGH){

    Serial.print("t1.txt=");

  Serial.write(0x22);

  Serial.print("READY");

  Serial.write(0x22); 

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);

}


I have a temp. sensor ds18b20 and i am using this code to get value to nextion;


 float temperature = getTemp();

  Serial.print("t0.txt=");

  Serial.write(0x22);

  Serial.print(temperature);

  Serial.write(0x22);

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);


I can see temp sensor (t0) and button input (t1) texts on nextion screen. I want to trigger a page when t1 text is "READY"


I have tried on my page 0's preinitialize and post initialize tab


if(t1.txt=="READY")

{

  page 1

}


and


if(t1.txt!="")

{

  page 1

}


i can see the text on the screen (t1) but it doesnt changes the page to page 1.


any suggestions to solve my problem ?


Regards



Without dealing with your actual code (sorry I don't do Arduino).


Using the same fashion you are sending t0.txt="READY",

try sending page 1 or pagenum variable containing desired page to go to


  Serial.print("page");

  Serial.write(0x20);

  Serial.print(pagenum);

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);


In the HMI design and in button Touch Press Event, assuming button is b1

if(b1.txt=="READY")

{

   page 1

}

The user pressing the button b1 on the screen will not change until .txt is "READY"


IF the HMI button is set as above, and the HMI current page is the page containing the button

  Serial.print("click b1,1");

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);


Serial.write(0xff) can be replaced with the character for 255 0xFF (in iso-8859-1 it is ÿ)

Therefore the above click command could be written as Serial.print("click b1,1ÿÿÿ");


Once the page has changed, do you also have a b1 for this button to effect?

or is your button like a home button - always changing to page 1


hi patrick,


thanks for your reply, my button is an external button, its not in hmi design.. Button is connected to arduino and while button is triggered, i want to call page 1 on HMI. Should i use this code directly to call page 1?


  Serial.print("page 1");

  Serial.write(0x20);

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);

or ?


  Serial.print("page");

  Serial.write(0x20);

  Serial.print("1");

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);

I am sorry, I will repeat - I don't do Arduino.  You will have to figure out your own programming code.


Please refer to the Nextion Instruction Set for page command.


In your first reply the sequence will fail as you are attaching a space after the page number before sending the three 0xFF byte terminators.   Removing the line Serial.write(0x20); which sends a space character would have made the sequence correctly.


In your last reply, the sequence is formatted correctly.


Again, you will have to figure out your own programming code.

try this


 nexSerial.print("page 1");
  nexSerial.write(0xFF);
  nexSerial.write(0xFF);
  nexSerial.write(0xFF);


it work but not perfect

or use this command

sendCommand("page 1");


all are same i think


if(digitalRead(BUTTON)==HIGH){

  Serial.print("page 1");

  Serial.write(0xff);

  Serial.write(0xff);

  Serial.write(0xff);

}



is working fine.. thanks to all.

Login or Signup to post a comment