Storing ASCII characters properly

Hi, I have the following char* array in my code:

char* lines[] = {
  " WAYPT         0   D5/B1 ",
  "                         ",
  "±1      SP    INIT POSIT¡",
  "                    UNK  ",
  "EL:23      ******** DTOT¡",
  " NO CR                   ",
  "¡N34°35.367           ?1©",
  "             WND ***/*** ",
  "¡E036°00.680         L/L®",
  "[¶              ]   P1/2 "
};

The special characters map to custom glyphs in my font. However, the encoding seems to get mangled when compiled and flashed to the Arduino. If i open the .ino file in Sublime Text, it opens as UTF-8. If i reopen it with an ASCII encoding, all the special characters take up double the space (2 width) which messes up the rendering on the Arduino.

How can i make sure these are encoded as their proper ASCII value? For example, ± should be 0xB1.

I have tried "\0xB11 SP INIT POSIT " and "\0X"" 1 SP INIT POSIT " but that doesn't do anything. "\xB11 SP INIT POSIT " messes up the display instead.

What is the ASCII value of the special characters ?

ASCII is only 7 bits long, so ASCII is 0x00 thru 0x7f.

± is 0xB1 or 177 DEC for example

If i do "\xB11 SP INIT POSIT " it messes up the display, but "\xB1" alone works. How can i mix both hex and normal strings in the same variable?

Sorry, i didn't mean ASCII then, whatever you would call 0x00 - 0xFF. The values come in over serial like this, and i need to be able to print 0xB1 and so on locally while debugging, so i need a way to write it in the strings.

I call that a byte

Yes, but in the text-encoding world. Whatever we decide to call it, i need to mix raw bytes with strings, how can i do that? Like so "\0xB1 SP INIT POSIT "

Okay, this works:

"\xB1 1 SP INIT POSIT ",

And this doesn't:

"\xB11 SP INIT POSIT ",

Notice the lack of space between \xB1 and the second 1. How can i tell the compiler that i am "finished" with hex other than using a space which i dont want there?

You are dealing with a program that only displays ASCII characters. If you have other plans, find a terminal emulator that will display what you want.

No, I have glyphs for 0x20-0xBB and am getting such bytes over serial, that works. However, for debugging purposes i need to be able to store such strings in the sketch.

Use "\xB1" "1 SP INIT POSIT ".

Directly adjacent string literals are concatenated automatically.

Thanks. I swear to god i already tried it and it didn't work. Now it works... facepalm thanks again.

I think that feature is very useful to break down long literals onto different lines.

Try raw string literal (6) String literal - cppreference.com

Useful for even longer constants that are to include the CRs.

It SHOULD have worked. You should be able to work around it by using the fact that adjacent string literals are concatenated.

Try: "\xB1" "1 SP INIT POSIT "

Yes, for some reason "\xB11… didnt work but "\xB1""1… worked.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.