Nextion - Perry Bebbington method - degree symbol

Quick question - can the nextion deal with ascii characters such as the degree symbol? I've tried lots of methods using the debug editor and no luck.

t1.txt="21 C" --> 21 C
t1.txt=" " -- > 21ºC ??

I don't know, I've never tried. I am on holiday at the moment so can't try it, but the degree symbol is not part of the ASCII character set, so I suspect not.

I suggest you open character map in Windows, find the degree symbol, copy it, paste into a text box in the Nextion IDE, compile it and check in the debug tool to see if it is correctly displayed.

Please report on what you find.

I wasn't thinking earlier, you will have uploaded at least one font in order to display text. Does the font you used include a degree symbol? I think the font I used in the tutorial probably doesn't, but I can't check.

You need a font that includes the degree symbol.

Thanks for the quick response.

I'm using Arial Bold 16 which includes the degree symbol.

If I copy the symbol from character map, or use the shortcut Alt-0176 in the Nextion debug screen, it works.

When I send 24°C via serial it almost works - I get 24Ā°C instead of 24°C

I don't really understand serial very well so I can't guess where the extra character is coming from.

Serial1.print(F("tIn.txt=\"24°C\""));
Serial1.print("\xFF\xFF\xFF");

Read this UTF-8
The degree symbol is encoded as 0xc2 b0 in UTF-8. The Nextion is seeing 0xc2 and 0xb0 as separate characters. When you type code into the Arduino IDE it is encoding the degree symbol as 2 bytes, but the Nextion is reading them as separate characters. You will have to find a way to send only 0xb0.

I did two programming units in around 1975 with Basic on I think a PDP8. I was hopeless at it so I stuck to hardware. I took up programming again in 2000 using Bascom for a few simple projects. And then Arduino in 2013 and I'm finally starting to grasp the basics.

So thanks to Perry's help I've got this working for displaying temperatures with the correct alignment:

 Serial1.print(F("tIn.txt=\""));
 Serial1.print(insideTemp / 10);  // lhs of dp
 Serial1.print(F("."));
 Serial1.print(insideTemp - (int(insideTemp / 10)) * 10);  // rhs of dp
 Serial1.print(" "); // space
 Serial1.write(0xB0); // degree symbol in hex
 Serial1.print("C\""); // C for Celcius
 Serial1.print("\xFF\xFF\xFF");

Very good! I don't understand why you need such a complicated means of printing the temperature though.

I have a whole column of different values, some with decimals, some without and it was the only way I could get them all to align correctly through their entire range. I tried padding with spaces but I found this way easier. If you can suggest an even easier way I'd be very grateful.

Do you really need to print the identifiers such as 'Inside', 'Outside' etc? I suggest you give them their own text boxes with the text included in the Nextion configuration (if it doesn't change) or printed separately from the various (if they do change). That way you can deal with justifying the text separately from the associated values.

Also look at how I use sprintf in my example code in the tutorial.

I have something that works, The text box on the Nextion is left aligned, and all numbers line up as expected.

  char string[20];
  sprintf(string, "%s%2d.%1d %s%c%c%s", "tIn.txt=\"", insideTemp / 10, insideTemp % 10, "\xB0", 'C','"',"\xFF\xFF\xFF");
  Serial1.print(string);

Result:

25.4 °C