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