Start a new topic

How display double data from arduino on Nextion

Hello
I try send temperature from DHT to Nextion through arduino

I send for example from arduino 24.6 C - I change it for 246 (x10) and sending by command:

va5.setValue(dht);  
- this working - but if I change 246 and conversion to "float"

In preinitialize event section on page 0

va0.val=va5.val/10

va1.val=va5.val*10

va2.val=va0.val*100

va3.val=va1.val-va2.val

va4.val=va3.val/10

cov va0.val,t1.txt,0

cov va4.val,t2.txt,0

t0.txt=t1.txt+"."+t2.txt


I see only temperature data when I change page from other to main :(

Any help?

All variables I set to global - but it doesn't work because is run only one in the start ( refresh page)



Hi Everyone,


If anyone would like some shortcode for the terminating characters, here's a little trick that I use all the time.


At the top of your sketch declare a character array like so 

byte ter [3] = {0xff, 0xff, 0xff};

 Then each time you need the termination in your code, just call it like so. 

Serial.print("t0.txt=\"Hello World\"");
Serial.write(ter, 3);

 Neat and tidy, and saves a few bytes of SRAM as a bonus, each time you use it.



Hi Everyone,


If anyone would like some shortcode for the terminating characters, here's a little trick that I use all the time.


At the top of your sketch declare a character array like so 

byte ter [3] = {0xff, 0xff, 0xff};

 Then each time you need the termination in your code, just call it like so. 

Serial.print("t0.txt=\"Hello World\"");
Serial.write(ter, 3);

 Neat and tidy, and saves a few bytes of SRAM as a bonus, each time you use it.




1 person likes this

Hi Everyone,


If anyone would like some shortcode for the terminating characters, here's a little trick that I use all the time.


At the top of your sketch declare a character array like so 

byte ter [3] = {0xff, 0xff, 0xff};

 Then each time you need the termination in your code, just call it like so. 

Serial.print("t0.txt=\"Hello World\"");
Serial.write(ter, 3);

 Neat and tidy, and saves a few bytes of SRAM as a bonus, each time you use it.



Some Basics About Character Encoding


The binary representation for characters used in the (US-) English language are standardized in the ASCII Standard. For all other characters and symbols, there are several standards, one of the most common are Unicode, Windows CP1252 and UTF-8.


The gcc compiler that is used with Arduino supports UTF-8 encoding only.


UTF-8 and US-ASCII are identical for the lower 127 codes, so you don't have to worry about character encoding if you stay with these codes and characters like 'a' to 'z', numbers etc.


Although the gcc compiler used by Arduino only understands UTF-8, you can trick it by using hex codes for your special characters. In that way, you can use any one-byte character encoding you like, like Windows codepage 1252.


Example:


The German character 'ö' has character code 0xf6 in Windows-1252.

Therefore, you can write the German string "Hallöchen" as: char greeting[] = "Hall" "\xf6" "chen";

 

This all is no Arduiono limitation, but a "feature" of the used GCC compiler. There are plenty other compilers  out, which support natively the full 8bit ASCII code ...


Gerry

When you set your HMI settings in the Nextion Editor, you chose between ASCII and which iso-8859 character set Is appropriate for your project.  This choice is encoded into your TFT file.  Now, why would I choose and set iso-8859-1 and then expect UTF-8 to be compatible.

Well that would be true if you use an incompatible UTF-8.  If you use iso-8859 or i18n, it is a different story.  The fact that the Nextion firmware uses ASCII, GB2312, or the iso-8859 series and does not use UTF-8 means that you will have to deal with such issues as ÿ char 255 in iso-8859-1 resulting in a multi-byte and hence a conflict with the firmware and your program and results in 0xC3 0xBF.


However when one programs to be compatible with their device specs, then 0xFF, char(255) equals ÿ.

Just a clarification regarding the use of

Serial1.write("ÿÿÿ");


On Arduino it is not possible to replace

Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);

with

Serial1.write("ÿÿÿ");


This is because the Arduino file is encoded in UTF-8, where the character "ÿ" is encoded as 0xC3 0xBF.

That means that

Serial1.write("ÿÿÿ");

is the same as

Serial1.write(0xC3);
Serial1.write(0xBF);
Serial1.write(0xC3);
Serial1.write(0xBF);
Serial1.write(0xC3);
Serial1.write(0xBF);


See also more information about UTF-8 encoding in following thread:

http://support.iteadstudio.com/support/discussions/topics/11000007764


 

 Serial_Nextion.write("click m0,1");
                Serial1.write (0xFF);
                Serial1.write (0xFF);
                Serial1.write (0xFF);

 

Earlier you used ... the code has both Serial_Nextion and Serial1 used to issue the one command.

I am only attempting to save you some grief.


I agree, information is lacking.  Today marks one week since joining Itead, there is much to do.

It has much potential built in already, and we hope to be able to unlock even more.


Patrick I don't mx them ! I use Cortex and I have 3x I/O serial out, One I use to see result and debug
serial1 is for nextion
serial2 is for RS485
serial3 comunicate with other same device

I have no regrets, information on these displays are still poor, but this product has the potential, is becoming increasingly popular with a decent performance. Thanks to you I have the support and the possibility of solving even the seemingly simple problems


1 person likes this

They work because you are starting to listen to what you are being told and implementing what has been said.


The question of why you would mix Serial_Nextion and Serial1 is disturbing.

Although you may have defined one as an alias, mixing will cause errors in more complex examples.


On the lower levels, they become pointers that are incremented as each byte is written.

In a complex sketch, if communications become queued, you will have two pointers that are not synchronized and could create out of order issues.  You defined Serial_Nextion so that you could have an alias to describe your function of Serial1, but then you don't use it with consistency.  This will cause you grief later on.

Serial_Nextion.write("click m0,1"); Serial1.write (0xFF); Serial1.write (0xFF); Serial1.write (0xFF);




                Serial_Nextion.print("click m0,1"); // source is #define Serial_Nextion Serial1

                Serial_Nextion.write (0xFF);

                Serial_Nextion.write (0xFF);

                Serial_Nextion.write (0xFF); 


Both options work...

barth, the last code would again not be correct as the three instructions to write 0xFF have been commented out with //.


When // appear on a line, everything to the right of the // is ignored.  It has become a comment only not instruction.


Instead use

                Serial_Nextion.print("click m0,1"); // source is #define Serial_Nextion Serial1

                Serial_Nextion.write (0xFF);

                Serial_Nextion.write (0xFF);

                Serial_Nextion.write (0xFF);   


1 person likes this

                Serial_Nextion.print("click m0,1"); // source is #define Serial_Nextion Serial1

                //Serial_Nextion.write (0xFF);

                //Serial_Nextion.write (0xFF);

                //Serial_Nextion.write (0xFF);   


I check it and this options do not work :( - must be after coomand  0xFF x3 - and must be Serial_Nextion.write


Belive me

I don't see how this could possibly work

 

 Serial_Nextion.write("click m0,1");
                Serial1.write (0xFF);
                Serial1.write (0xFF);
                Serial1.write (0xFF);

The whole instruction should go to the same Serial port (to Nextion) and you would use .print when sending plain text between double quotations. Like so...  

                Serial1.print("click m0,1");
                Serial1.write (0xFF);
                Serial1.write (0xFF);
                Serial1.write (0xFF);

 


1 person likes this

Ahh, now you see - that is a Cortex M3, and is the reason why I like the STM32 (F1 series). The Edison was much less expensive two years ago ~1/2.  At the prices today, I might have perhaps passed it over.

Login or Signup to post a comment