Nextion - element.setText problem [RESOLVED]


I have a development of a nextion screen.

At a certain point, I want to paint the date and time of my Clock module (RTC_DS3231) in some Text elements on my Nextion screen.

My method of painting the date and time on the screen is this:

void setClockDate(String theDay, String theMonth, String theYear) {  

void setClockTime(String theHours, String theMinutes, String theSeconds) {

The problem is that this execution: "XXXXXXX.setText()"


clock_date_day.setText (theDay)
clock_date_month.setText (theMonth)


It gives me this error:

sketch / screen.cpp: In function 'void setClockDate (String, String, String)': screen.cpp: 136: 34: error: no matching function for call to 'NexText :: setText (String &)' clock_date_day.setText (theDay); ^ In file included from /Users/javichuteck/Documents/Arduino/libraries/ITEADLIB_Arduino_Nextion/Nextion.h:33:0, from sketch / screen.cpp: 2: /Users/javichuteck/Documents/Arduino/libraries/ITEADLIB_Arduino_Nextion/NexText.h:53:10: note: candidate: bool NexText :: setText (const char *) bool setText (const char * buffer);

But, if I do this:

clock_date_day.setText ("16")


Why if I put direct text it works, but if I put text of a variable, it doesn't work?

Thank you

Hello again javichuteck,

On here the support for Nextion displays is basically me, with the occasional bit of help from a guy called Seithan. There's also Ray Livingston's Nextion libraries, which are improved versions of the ITEAD libraries. I've not seen Ray post here for some time though.

I can't help you with Nextion libraries; I don't use them. If you read my tutorial Using Nextion displays with Arduino you will see I use a simple clock to show how to use the displays. To use my methods you will have to understand how they work. If you get stuck with them I'll try to help. Please don't post questions about your project at the end of the tutorial.

To my knowledge there is no one here offering help for the Nextion libraries.

I see you are using Strings; don't use Strings. Use char arrays, sometimes also called C strings, for example

char someText[] =  {"Hello World"};

Strings make big holes in the limited memory in an Arduino and cause problems. Search this site, the subject comes up often.

The solution to my problem is the type conversion at the moment of marking the value of the String to the Nextion component.

In this case it is a component of type Text, and in calling the “setText” function with doing a type conversion, it works correctly.

Here is the example that worked for me:


.c_str() is the conversion to the “NexText” component.

Thanks again and I hope it helps more people.



Greetings! :)

Glad you solved it.

Can you edit the title of your first post and add something like [RESOLVED] at the end of the title? Yes, I know hardly anyone does but it helps if you do.