[Solved] Printing special characters from SD card to Thermal printer

Hi! I have a thermal printer like this one.

I have a already learnt how to read text from an SD card into Strings (yes, Strings, I know) and print them through the thermal printer.

I have figured out that if I wanted a special character from a code page, let's say char ▓ from CP852, I would have to first select CP852 and to print, I would use

printer.println("\xB2");

yet if I were to read it from the SD card with

myFile = SD.open("FILE");
  if (myFile) {
    if (myFile.available()) {
      String text = myFile.readStringUntil('\n');
      printer.println(text);
    }
    myFile.close();
  }

with the file "FILE" on the SD card containing

\xB2

it just prints out "\xB2" literally.

How could I make it print special characters read from a file into a String?

Thank you.

can you send the string without reading from the SD card ?

printer.println("\xB2");

or without the line feed
printer.print("\xB2");

do you have the correct library installed ?
have you run the examples that come with the library ?
are they working perfectly ?

also, when posting code, you need to post the entire code. The problem may be where you do not expect and the portion you posted may be perfect so snippets of code do not show the whole problem.

Do you have a link to the printer manual ?

The printer manual will tell you what format the printer requires.

'print codes' are sent in a specific format.
what the printer does with them is based on what you tell the printer.

An example is if I type a / and a : and a ) all separately and you get what I typed.
combined and you get the smiley face characters.

Yes, I have said that printer.println("\xB2"); or printer.print("\xB2"); prints the correct character when they are not read from SD.

Everything works perfectly with the printer. datasheet

I don't think I need to post the whole code because the entire problem is in the second snippet I sent, there are no other variables declared somewhere else used. It is "technically" doing what I tell it to do (it prints out \xB2, but literally, like \ next to x next to B next to 2), but it's not what I want (I want it to print the special character instead of the "description" of it).

Escape sequences are interpreted at compile time. As you observe, getting a string that happens to contain an escape sequence by any means at runtime will not apply the same transform.

You either need to put the literal character you need in your file or have some means of processing escape sequences in your data after you read it.

Thank you for your answer. I have observed that in most cases, if I placed the literal character in a file on the SD card, it would be read back as two different apparently random characters.

Do you have an example of handling escape sequences read from the SD card at runtime?

What do you see in the file you put the literal into if you use a hexdump utility? I'm wondering if it actually is 0XB2 as a byte or if your tools perhaps put some Unicode representation instead.

I seem to have solved my problem with probably the easiest method (this always happens).

My solution was to just write the escape sequences to the SD card using and Arduino (because they get transformed into the correct characters at compiling time), so the correct characters are written. Before, I was trying to use a PC to write them, but that was not successful.

So the way to solve this is just to write the files with the Arduino. I don't have time to check this now, but I suppose if you opened the Arduino-created file with the correct characters on a PC you would be able to just copy-paste where you want them.

Thank you.