Please send help with my school project. I cannot seem to get data from nextion to esp32(when I change page/press the button
Code
#include <Nextion.h>
#include <SPI.h>
#include <MFRC522.h>
#define RXD2 16
#define TXD2 17
String stringPage = "page page";
String stringPageS;
int Number;
int randomVals[10];
int currentdata;
int CurrentPage;
#define RST_PIN 22 // Configurable, see typical pin layout above
#define SS_PIN 5 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
NexPage page2 = NexPage(2, 0, "page2"); // Page added as a touch event
NexButton b1 = NexButton(2, 3, "b1"); // Button added
void DisplayPage(int pg) {
stringPageS = stringPage + pg;
Serial2.print(stringPageS);
Serial2.write(0xFF);
Serial2.write(0xFF);
Serial2.write(0xFF);
}
//RFID
int readRFID() {
int RFID = 0;
// Look for new cards
while ( ! mfrc522.PICC_IsNewCardPresent());
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
}
RFID = mfrc522.uid.uidByte[1]; //Read card value and store into the variable "RFID"
return RFID;
}
NexTouch *nex_listen_list[] =
{
&b1, // Button added
&page2, // Page added as a touch event
NULL // String terminated
};
void page2PushCallback(void *ptr) // If page 2 is loaded on the display, the following is going to execute:
{
CurrentPage = 2; // Set variable as 2 so from now on arduino knows page 2 is loaded on the display
} // End of press event
void b1PushCallback(void *ptr) // Press event for button b1
{
Serial.print("bye");
} // End of press event
void b1PopCallback(void *ptr) // Release event for button b1
{
Serial.print("hi");
} // End of release event
void setup() {
// put your setup code here, to run once:
nexInit();
Serial.begin(115200);
DisplayPage(0);
delay(2000);
DisplayPage(1);
page2.attachPush(page2PushCallback); // Page press event
b1.attachPush(b1PushCallback); // Button press
b1.attachPop(b1PopCallback); // Button release
}
void loop() {
nexLoop(nex_listen_list);
if (CurrentPage == 2) {
delay(3000);
Serial.println("hi");
}
}