Start a new topic

Sending ASCII charactor from Arduino to display on Nextion

Does anyone have an example of how to send and ASCII variable from the Arduino to the Nextion. I have an alpha variable ( Charactors A through Z). Any assitance would be appreciated.

 in general ...

    - create a variable in your HMI, e.g. MyVariable and define this variable as text

    - send out serially something like MyVariable.txt="my text" with trailing FF,FF,FF

and furthermore your Nextion variable is set ... for further purpose

Similar you can do with a simple text-object ...

What was wrong with using the CompText.ino example in the examples folder of Library?

Thanks for the response ComText.ino deals with number variable and not a character variable. I have a variable in Arduino called SurveyItems.Row which contains the a single character variable from "A" through "Z" and when I send this to the Nextion as a txt variable (t12 in this case) instead of the charactors A to Z the Nextion displays the ASCII code for the charactor. Following is the code, as you can see I have tried using buffer, without success and using the seril monitor dbSerialPrintln does print the correct charactor

// itoa(SurveyItems.Row, buffer, 10);


// strcpy(buffer_temperature, buffer);




I dint really understand the Nextion variable, I did try to set up Va0 as a Nextion variable (X) but could see how this ends up on the HMI display pages.


Nextion is text based instructions, with mostly two types of variables

- .val attribute : a signed 32 bit integer

       (receiving from Nextion in little endian order, sending to as text)

- .txt attribute : a string of ascii characters

       (receiving from Nextion in bytes, sending to as text)

t12.setText takes a char value as a parameter

    parses as t12.txt="A"ÿÿÿ

n1.setValue takes a uint32_t value as parameter

    parses as n1.val=65ÿÿÿ

If it helps you can view the code in NexHardware.cpp to see what these functions do

 - which is to parse the expression t12 + .txt=" +parameter+" and the three 0xFF data terminating bytes as per the Nextion Instruction Set.

Whether or not it is a number, temperature, month name it is sent as text

You may need to check your compiler manual on how to form your expression

or check your logic


does convert a number to char and puts it in buffer, then buffer is sent

   itoa(number, buffer, 10);


this is because number was declared as uint16_t number;

not compatible to the required char parameter of setText() function

But assuming the contents of buffer already contains what needs to be sent


If you are chosing Arduino C as your compiler of choice and language of choice

- you will need to become familiar with each.

The Nextion Variable?

 - if the HMI settings are numeric then


 - if the HMI settings are string then


The code is in the library NexVariable.cpp and NexVariable.h

exact same pattern from CompText for txt based variables

exact same pattern from CompNumber for val based variables

Hi Patrick,

So updating a .val of a number component requires you to send for example;

page0.n0.val=123(0xFF0xFF0xFF) to update the n0 value to show 123

or do you send it as;


This is a little confusing as I would expect that you could send it as ASCII, do we need to be sending numbers by Hex or is it ok to send in ASCII

An update to the above, what would happen if we went over the 255 do we then send little endien first?

I am working with a PIC rather than the arduino, I find it much easier to code.

I am making a project that requires multiple variables to be updated and transmitted an need the information to build my own library.

This forum Closed since Nov 15, 2017
New forum open

1 person likes this