Hello @cattledog ,
I hope you are doing great, I am working with project which involve showing sensors values on nextion display which works fine but when I want to send values to arduino serial monitor from nextion display it showing me Error code 777777. I am sorry for not sharing full code because it is confidential of organization.
I used the following lines to recieving values from display.
int number = myNex.readNumber("t0.val");
delay(100);
Serial.println (number);
➜ Please do yourself a favor and read How to get the best out of this forum. Post accordingly, including code with code tags, necessary documentation for your request such as your exact circuit and power supply details, links to components, etc.
Please post your revised code. If you removed the Nextion.h library I'm not clear why you still see the get t0.val which is a command from that library. Error get t0.val���777777 .
For me to help further I will need to see the HMI file running on the Nextion. It still sounds like you are trying to read a text field as a number. Have you tried to read it as a text field. If you need to use it as a number you can convert it in your program.
What Nextion model are you using?
The Nextion file needs to be the file which is actually running with your posted code. If they are both simplified examples that is fine, as long as they both compile and run.
The forum does not allow the direct upload of an HMI file so you will need to make a compressed .zip file of the HMI code and then use the upload icon in the header of the reply box to get the .zip file attached to your post.
What ESP32 model are you using? There may be some differences in the hardware uarts between the different models. I have a original ESP32 Dev module, and not one of the later S2 or S3's and I don't use an ESP32 very much.
There are some things relating to how you handle the pages and the EasyNextion Library methods, but lets see where the Serial2 set up gets you.
I have confirmed that with the correct setup of Serial2, you can communicate with the Nextion.
There are several things I see wrong with this interface of your program with the Nextion. I'm actually surprised you have gotten as far along with only the problem of not read t3.
Wire.begin(9600);
// Nextion display setup
myNex.begin(9600);
delay(500);
myNex.writeStr("page 0");
delay(50);
myNex.lastCurrentPageId = 0; // Assuming you want to set the initial page as page 0
delay(50);
myNex.readStr("page 1");
// Update Nextion display with sensor data
myNex.writeNum("x0.val", a ); // Update "x0" with sensor 1 data
delay(100); // Small delay to ensure the value is sent correctly
myNex.writeNum("x1.val", b ); // Update "x1" with sensor 2 data
delay(100); // Small delay to ensure the value is sent correctly
// Print the pressure readings to the serial monitor
Serial.println("Sensor 1 data: ");
Serial.print("Pressure: ");
Serial.print(pressurePa1);
Serial.print(" Pa, ");
Serial.print(pressureMb1);
Serial.println(" mbar");
Serial.println("Sensor 2 data: ");
Serial.print("Pressure: ");
Serial.print(pressurePa2);
Serial.print(" Pa, ");
Serial.print(pressureMb2);
Serial.println(" mbar");
int number = myNex.readNumber("t0.txt");
delay(100);
Serial.println (number);
Serial.println("\nPressure difference = " + String(deltaP));
Serial.println("PWM value = " + String(Output));
Wire.end();
myNex.begin( ) belongs in setup()
The Wire.begin(9600) and Wire.end() which are bracketing this section are nonsense and should be deleted.
You are still trying to read a txt field as a number. Instead use myNex.readStr("t3.txt")
This line does not make sense to me and is not valid library syntax. myNex.readStr("page 1");
You have not pre initialized each page with the the library recommended syntax and I would not use currentPageID.
Navigate to the page you want to be on with
myNex.writeStr("page page0"); // Sending this command to change the page we are on Nextion using pageName
myNex.writeStr("page 1"); // Sending this command to change the page we are on Nextion using pageId
Given your use of local variables, it's necessary that when you write the numbers into the x float values, you need to be on their page, and when you read from the text boxes of the keypad you also need to be on that page.
Wire.begin(9600) creates a slave device with a a non valid address which is then set to 128 by default. Read the documentation o the Wire library. There is no master talking to that slave, and it is totally not related to the Nextion. I'm am very certain you can solve you communication issues without the Wire.begin(9600) and Wire.end() statements.
it directly show me page 1 and blinking i cannot write new value on t0 to show me on serial monitor.
The blinking is the result of this switching between pages
myNex.writeStr("page 0");
delay(50);
myNex.lastCurrentPageId = 0; // Assuming you want to set the initial page as page 0
delay(50);
myNex.writeStr("page 1");
You are getting down to issues of page management. Are you using the EasyNextionLibary page initialization method? If not, you should use the method, and you will find page management simplified for you.
It's not clear to me as to when you want to be using the t0 setting screen and when you want to see the values on the monitor. Can you explain more about how the user interface with the program works. Do you need to read the t0 values other then when you setting them? If it's just a matter of being on the t0 setting page with the keyboard and having the values read by the Arduino when you are on that page then its a fairly simple situation. Using the EasyNextion trigger functions might be useful as well.
I really need to understand more about how you want the user interface to work.
EDIT: You have not moved this line to setup(). Why? myNex.begin(9600);
Read the documentation on the function. You are only adding delays and clearing buffers. If you really need to do either of these things, there are more transparent ways to do either.
void EasyNex::begin(unsigned long baud){
_serial->begin(baud); // We pass the initialization data to the objects (baud rate) default: 9600
delay(100); // Wait for the Serial to initialize
_tmr1 = millis();
while(_serial->available() > 0){ // Read the Serial until it is empty. This is used to clear Serial buffer
if((millis() - _tmr1) > 400UL){ // Reading... Waiting... But not forever......
break;
}
_serial->read(); // Read and delete bytes
}
}