Start a new topic

Nextion String Keypad, receiving string in Arduino

Hey! I hope i dont 'break' the rules again Mr. Patrick! :)


I'm using Nextion Display Basic 3.5"

Arduino Mega 2560

no aditional libraries except for the Nextion.h


I see there is some people in here having trouble to get values from nextion and receive in arduino. I was in there too, cause i'm not an expert in C code. Then i come with a simple solution you can adapt to whatever, i think.


First you need to read the documentation about the data return of nextion displays. For the example i'm using a text component to send ASCII characters through serial.

for this the nextion returns:

0x70 -> indicate the data type is ASCII characters in HEX

0xXX -> bytes for the ASCII chars

0xFF |

0xFF |_> Transmission END

0xFF |


Well, now its simple, you use a button(or any touch event) on nextion that executes the command:

get t0.txt

and it will send through serial the bytes for the text in t0.txt


so, in arduino, you read the string on the serial, and by testing the index 0 of the string, you determinate what kind of data the nextion sent.

after, you need to know where the data ends ( 3 x 0xFF)

in this case, i used a String function that returns the index of the first 0xFF.

string.indexOf(0xff);

and use this index as reference, because the lenght of this data will depend on the numbers of characters.

and just concatenate the bytes between index 0 and the index of first 0xFF.

simple as that!


The commented .ino code and HMI file is attached. I hope I can help someone with this and contribute to the community.


ino
HMI
1 Comment

sorry, but breaking "rules" is nothing I even can smile about ... :-)


anyway, thanks for your contribution ... we need more of such ...

Login or Signup to post a comment