Hello,
I am now struggling for quite a while with the Nextion display and Arduino Mega. I have a working project where sending the data from Arduino to Nextion is ok but from Nextion to Arduino I just can't get it.
I read tons of forums and pages but regardless of what I do I only always get number 0 or nothing from Nextion. I am using the default Nextion library.
I would really appreciate it if someone could share a working code so I can try to get the values from Nextion (7 inch intelligent) to Arduino Mega. Simple idea is button push -> read number value as int.
Thanks everyone who could help me
Please post your attempt and someone will be glad to help you.
I am sending the code. this version is returning 0 every time I push the button. I also tried reading the text as you will see but also nothing (0). I just can't get it working.
#include "Nextion.h"
NexButton b1_sonda = NexButton(7, 8, "b1_sonda"); //x15a
NexButton b_test = NexButton(7, 22, "b_test"); //x15a
NexNumber n_tempsonda1 = NexNumber(7, 20, "n_tempsonda1");
NexNumber n_tempsonda11 = NexNumber(2, 53, "n_tempsonda11");
NexText t1_Sonda1a = NexText(7, 21, "t1_Sonda1a"); //x15a
NexPage page0 = NexPage(0, 0, "page0"); // Page added as a touch event
NexPage page2 = NexPage(2, 0, "page2"); // Page added as a touch event
NexPage page7 = NexPage(7, 0, "page7"); // Page added as a touch event
char buffer[100] = {0}; //x15a
NexTouch *nex_listen_list[] =
{
&b1_sonda,
&n_tempsonda11,
&n_tempsonda1,
&t1_Sonda1a,
&b_test,
&page0,
&page2,
&page7,
NULL
};
void b_testPopCallback(void *ptr)
{
//float numbers1;
//memset(buffer, 0, sizeof(buffer));
//t1_Sonda1a.getText(buffer, sizeof(buffer));
//numbers1 = atof(buffer);
//Serial.print("SONDA_1a :");
//Serial.println(numbers1);
uint32_t number2 = 0; // Create variable to store value of slider
n_tempsonda1.getValue(&number2); // Read the value of the slider
//uint32_t numbers14 = 0;
//char sonda1[10] = {0};
//n_tempsonda1.getValue(&numbers14);
//utoa(numbers14, sonda1, 10);
if(number2==0){ // If I got a 0, then recheck:
n_tempsonda1.getValue(&number2); // Read the value of the slider
}
if(number2==0){ // If I got a 0, then recheck:
n_tempsonda1.getValue(&number2); // Read the value of the slider
}
Serial.print("SONDA_1 :");
Serial.println(number2);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void setup() {
nexInit();
Serial.begin(9600);
b_test.attachPop(b_testPopCallback);
}
void loop() {
nexLoop(nex_listen_list);
}