Receiving information from Nextion

Hi,

I am trying to capture serial data sent from Nextion to Arduino.

I have a text field setup keyed to an alpha-num pad limited to 4 digits, and I would like that 4-digit alpha-num upon pressing ok on the pad, to be transmitted to the Arduino, then decoded by the Arduino and saved as a string variable.

This 4-digit number constitutes a serial number the user needs to enter.

Stuffed if I can get off the launchpad with this one. Sending and receiving single commands is no problem, but receiving a whole string is kicking my butt.

Read my tutorial at the top of the display section of the forum. In part 4 you will find example code for a calculator, the code sends key presses to the Arduino, which is, I believe, what you are looking for.

Hi Perry, I don't think your tut covers my use case, or is there an alternative you could suggest?
See attached in order to understand what I would like to do.

Thanks for your time.



Upload your HMI file as it is, give me a day or 3 to think about it.

Sent to your DM. Thank you.

Yes, that's OK.

Negativ3_Keyboard.zip (15.4 KB)

@negativ3
Sample code and HMI file.

I have assumed that the text box will have 10 characters, you will have to modify the code for different numbers of characters.

I have never used or even attempted to use a keyboard, so had not taken them into account.
I have added another byte (numBytes) to the data from the Nextion, which indicates how many bytes follow.
I have added code to take this into account.
The text from the text box will be left in the char array printBuffer[20];
There is nothing significant about the sizes of the various arrays, other than they are more than big enough.
The code is untidy in places, and there is probably stuff in there that isn't needed and stuff that can be improved.

Have fun!

1 Like

@negativ3 There was a mistake in the sample Nextion configuration file I uploaded yesterday. I've removed the one with the error and replaced it with a corrected version.

Hi Perry,

I've been forward and back through the ino and hmi files but I cannot make it respond for page 6 with the contents of t2.

If you can explain some of the logic to help me understand what I'm doing wrong, much appreciated.
NEXTION_PERRY.zip (19.8 KB)

I've had a quick look and the thing that stands out as incorrect is for t2 on page 6 you need to set numBytes to the correct value for the number of bytes to follow, which I think will be 08, certainly not 0e. If not 08 then play around with different values to see what works. Remember the value is in hex, not decimal.

If that doesn't solve it for you I'll look a bit closer.