Start a new topic

Here is a Quick Way to Send Float to Nextion Text Control from Arduino

 

float num = 36.2523;

String numTXT= String(num,2);//Will show 2 decimal places
char buf[10] = {0};
numTXT.toCharArray(buf,10);
txtTemp.setText(buf);

 



How about keeping it simple and embedding a new function into the library?


In NexText.h copy and paste this...  

	 /**
     * Set float as text attribute of component.
     *
     * @param floatTxt - float variable. 
     * @param dp - number of decimal places (maximum 6). 	 
     * @return nothing 
     */
	void setFloatText(float floatTxt, uint8_t dp);	

  Then in NexText.cpp copy and paste this.... 

void NexText::setFloatText(float floatTxt, uint8_t dp)
{
	nexSerial.print(getObjName());
	nexSerial.print(".txt=\"");
	nexSerial.print(floatTxt, dp);	
	nexSerial.print("\x22\xff\xff\xff");
}

  To use, just call like the other functions, example....  

float myFloat = 34.712;

t0.setFloatTxt(myFloat, 3); 
 //Where the 3 is the number of decimal places to print (Max 6)

outputs... t0.txt="34.172"ÿÿÿ

  Converting to String class then to 'C' char array, then back to String class then back to 'C' string can hardly be fast. Serial.print() can handle floats, simples:-)  


Good Idea... I saw some other routines, but look cumbersome.


Maybe the Nextion folks should go ahead and update the library, then it's simple. A lot of folks were/are confused as adding float values to the Text objects should be easy!   ;-)


mmmmmmmmmmhhhhhhhhhhh

and to whom can I redirect all upcoming support questions coming up only users dont really read the instructions? :-)

    - I send my float to n0.val, but my Nextion dosn't display any ... BUUUUUG ....
    - Why can't I calculate with my floats on Nextion side ... BUUUUUG ...
    - when I convert the float to a number variable, I only get the integer part ... HELP ...

such implementations should stay in users responsibility ...

The Nextion is an Integer device ...

:-)


 

Neutron may be an integer device, but we are talking about the libraries which do the heavy lifting.


Correction - Nextion... darn spell corrector...

There are I think six user contributed libs on forum.

If none meet needs, then another user will again contribute

Login or Signup to post a comment