Start a new topic

Arduino physical button to change page

Greetings everyone!

 

Is there a way for me to use a physical button on my arduino, to change the page on the nextion display? Using it as a display in my car, but im want to use a button on my steering wheel and not touch the display.

 

Should be really simple yet i cant figure it out lol

 

Thanks!


 


Hi Nicholas,

I think this is quite possible.

Step one is to receive the button data inside the arduino, after that it can send the information to the Nextion screen.

Step two is to make sure the Nextion knows the information that the arduino is sending through serial communication. Unfortunately the Nextion doesn't has something like an interrupt to know when data is received from the arduino (As far as I know, I haven't played with it for a few months). So my solution is something like running a timer that is checking a variable that the arduino will change by sending the information. When the variable has changed you can use different of if statements to jump to a next page depending on the received information.

Hope this makes some sense.

Regards

Hi there,

 

Thank you very much for your reply! I ended up just sending new texts to every text box so long, so far its working great. I was worried about using to much processing time but so far for my application its working perfectly. Doesnt seem as slow as i thought it would be. Again thank you very much! I'll do some deeper research into your idea!

Regards

png

Hi,

There is a function in the Arduino library to change page.

It's in the examples CompPage.

It uses page3.show(); to change to page 3


Rod

do I need to install nexpage for this to work?


//*************** Sketch

/*********name:Flame Alarm*************************/

#include <SoftwareSerial.h>
#include <Nextion.h>

NexPage page6  = NexPage(6, 0, "page6");

//Nextion Code
SoftwareSerial nextion(10, 11);// Nextion TX to pin 10 and RX to pin 11 of Arduino
Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

const int analogInPin = 9;// D0
const int digitalInPin = A3; //A0
const int ledPin = 13; //pin13 built-in led
const int buzzerPin=25; //buzzer

void setup()
{
  //set the pins state
  pinMode(digitalInPin,INPUT);
  pinMode(ledPin,OUTPUT);
  pinMode(buzzerPin,OUTPUT);
  Serial.begin(9600);//initialize serial

}

void loop()
{
  int analogVal = analogRead(analogInPin); //read the value of A0
  Serial.print("A0: ");
  Serial.println(analogVal);//print to serial monitor
  boolean stat = digitalRead(digitalInPin);
  Serial.print("D0: ");
  Serial.println(stat); // print to serial monitor
  Serial.println(" ");
  if(stat == HIGH)
  {
  digitalWrite(ledPin,LOW);
  //noTone(25);//if you want to play different pitches on multiple pins, you need to  call noTone() on one pin before calling tone() on the next pin.
  }
  if(stat == LOW)
  {
  digitalWrite(ledPin,HIGH);
  tone(25,1000,200);
  myNextion.setComponentText("t10","TEST"); //Flame Sensor
  page6.show();
  }
  delay(500); // used to slow down readings while calibrating

}


// ***************This is the Error I get*************************

exit status 1
'NexPage' does not name a type

Login or Signup to post a comment