Sending values from Nextion display to ESP32 Error code 777777

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);

On Serial monitor:
get t0.val���777777

Welcome to the forum

If the full code is confidential then write a small but complete sketch that illustrates the problem and post that here

1 Like

are you pinging @cattledog because of Arduino and Nextion dont communicate - #8 by cattledog ?

the issue is likely in the code or the circuit you did not share unfortunately...

The proverbial crystal ball is still in the dishwasher...

➜ 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.

1 Like

I see several issues with the code you posted.

#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
#include "Nextion.h"

Do not use both libraries. If using EasyNextion, remove Nextion.h and all use of its syntax in the code.

EasyNex myNex(Serial);

You can not have the monitor and the Nextion on the same serial channel. With an ESP32, find an other uart for communication with the Nextion.

int number = myNex.readNumber("t0.val");

The t0 sounds like a text field in the hmi code. How does it get a value? Why are you reading it as a number instead of text field?

1 Like

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.

1 Like

That is the correct way to go.

Serial2.begin(9600); // Start serial communication

This does not look correct in my experience with the ESP32.

To confirm Serial2 try this simple loop back test with pin 16 jumpered to pin 17. Enter data from the Serial monitor and it should echo back.

#define RXD2 16
#define TXD2 17
 void setup() {
   Serial.begin(115200);
   Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
   delay(1000);
   Serial.println("Loopback program started");
 }
 void loop() {
   if(Serial.available()){
     Serial.write("-");
     Serial2.write(Serial.read());  
   }
   if(Serial2.available()){
     Serial.write(".");
     Serial.write(Serial2.read());  
   }
 }

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.

Have you read the detailed documentation on the library and run some of the example programs?
https://github.com/Seithan/EasyNextionLibrary/tree/master

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.

This makes no sense.

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.

//----------------------------------
// Change Page Initialization
//----------------------------------

/* In order to update currentPageId variable with the current Id of the page,

  • you must write at the Preinitialize Event of every page: printh 23 02 50 XX , where XX the id of the page in HEX.
  •  For page0: `printh 23 02 50 00`
    
  •  For page9: `printh23 02 50 09`
    
  •  For page10: `printh 23 02 50 0A`
    

*/

Good information on page management and using conditionals depending on the page is here
https://github.com/Seithan/EasyNextionLibrary/tree/master/examples/ChangePagesAndSendFloatValues

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
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.