Code for Copyright Symbol

Good Evening.
I am attempting to print a copyright symbol on the tft screen using Adafruit HX8357D Display / Mega 2560

I am using the code ...

tft.print(" \xA9"" 2020");

OR

tft.print(char(169));
tft.print(" 2020");

All compile and run properly but A9 - hex for the copyright symbol - or (char(169)) give me the wrong characters - either ¬ or ?

What am I doing wrong? What is the correct code for the copyright symbol?
Thanks in advance - Kevin

169 is not one of the standard ASCII characters and how it is interpreted by the display depends on the specifics of your display.

...R

Hi Robin - many thanks for your speedy response.
I looked up the ASCII code table - the copyright symbol - Hex = A9; Decimal = 169; Octal = 251. I've tried all three! I am using the Adafruit GFX library for the tft and all I can guess is that the library doesn't include them --- but is there a work-around?
Regards Kevin

Does your TFT library include a custom character function?

That can't be ASCII - the highest valued ASCII character is decimal 127, hex 7F. ASCII is strictly a 7 bit code.

Think like a haxxor - write a sketch that prints all the characters above 0x80 to the LCD, along with their value in hex and/or decimal. Then you can see by inspection if it is there somewhere. Or, you could consult the Adafruit documentation, which is always pretty good.

Each filename starts with the face name (“FreeMono”, “FreeSerif”, etc.) followed by the style (“Bold”, “Oblique”, none, etc.), font size in points (currently 9, 12, 18 and 24 point sizes are provided) and “7b” to indicate that these contain 7-bit characters (ASCII codes “ ” through “~”); 8-bit fonts (supporting symbols and/or international characters) are not yet provided but may come later.

It looks like they are saying that characters above 127 are not supported. You can probably find (or write) a font that has the character you want.

Robin, Aarg, groundfungus and John.
Many thanks for your input from which I thought of a path the follow. Yes, normal ASCII only goes up to 127 as you say but there is extended ASCII up to 255 – hex FF which is used through the industry – type Control, Alt C on a computer and you get the copyright symbol. From this I thought that the font used by the Adafruit GFX library was only the 7 bit one. But in the GFX library there is an 8 bit font – Tom Thumb. So I put this code into my sketch….
tft.setFont(&TomThumb);
#define TOMTHUMB_USE_EXTENDED 0 ;
This compiled and uploaded okay and worked because all the other text on the tft screen changes
BUT I still cannot get the copyright symbol using …
tft.print(" 0\xA9");
OR
tft.print(char(A9))
Even although I now know that the symbol is in the font. So where to go now ????

Guessing, do you think that #define for extended should be a one instead?

tft.print(char(A9))when you write hexadecimal, use 0xA9... A9 refers to an analog input pin on your MEGA

there is extended ASCII up to 255 - hex FF which is used through the industry

Extended ASCII does not have a single defined code page - the most common is code page 437 a.k.a. the IBM PC character set.

"Using the term "extended ASCII" on its own is sometimes criticized,[1][2][3] because it can be mistakenly interpreted to mean that the ASCII standard has been updated to include more than 128 characters or that the term unambiguously identifies a single encoding, neither of which is the case".

What you are looking for is code page ISO/IEC 8859-1:

Looks like the TomThumb 3x5 font is the only official one that currently supports Extended ASCII.

What font did you want to use? It should not be hard to add the Copyright symbol to that one font.

Or, since it is a graphics display, draw the symbol where you want it.

Many thanks for responses
Yes - thought #define etc should be a 1 and not 0 but tried it and no go.
John - How would I add a copyright symbol to any font
Incidentally - have now proved
tft.print(" \xA9"" 2020"); is the correct way to display HEX characters as I replaced A9 with 41 (HEX for "A") and it worked perfectly. "A" is, of course in the non extended ASCII so it would appear that I have still to manage to enable the extended version of Tom Thumb.
Ain't this exciting!

kevin-pearce:
John - How would I add a copyright symbol to any font

Well, the easy way is to just define character 128 (0x80) and use that. Start by changing the font to have a new last character:

const GFXfont FreeSerif12pt7b PROGMEM = {(uint8_t *)FreeSerif12pt7bBitmaps,
                                         (GFXglyph *)FreeSerif12pt7bGlyphs,
                                         0x20, 0x7E, 29};

becomes

const GFXfont FreeSerif12pt7b PROGMEM = {(uint8_t *)FreeSerif12pt7bBitmaps,
                                         (GFXglyph *)FreeSerif12pt7bGlyphs,
                                         0x20, 0x80, 29};

Then, since 0x7F isn't defined you have to add two glyphs to the table of glyphs:

    {1803, 5, 21, 12, 2, -16},  // 0x7B '{'
    {1817, 1, 17, 5, 2, -16},   // 0x7C '|'
    {1820, 5, 21, 12, 5, -15},  // 0x7D '}'
    {1834, 12, 3, 12, 0, -6}};  // 0x7E '~'

becomes:

    {1803, 5, 21, 12, 2, -16},  // 0x7B '{'
    {1817, 1, 17, 5, 2, -16},   // 0x7C '|'
    {1820, 5, 21, 12, 5, -15},  // 0x7D '}'
    {1834, 12, 3, 12, 0, -6},  // 0x7E '~'
    {1845, 0, 0, 6, 0, 1}, // 0x7F ' ' (copied from 0x20 'blank')
    {1845, 15, 16, 17, 1, -15},  // 0x80 Copyright Sign (Copied from 'O')
};
    
Then add the 30 bytes of character image (15 columns of 16 rows) to the end of the bitmap array.  The 'O' starts at byte 921 :
[code]0x07, 0xC0, _____*****______
0x30, 0x60, __**_____**_____
0xC0, 0x63, **_______**___**
0x00, 0x66, _________**__**_
0x00, 0xD8, ________**_**___
0x00, 0xF0, ________****____
0x01, 0xE0, _______****_____
0x03, 0xC0, ______****______
0x07, 0x80, _____****_______
0x0F, 0x00, ____****________
0x1B, 0x00, ___**_**________
0x66, 0x00, _**__**_________
0xC6, 0x03, **___**_______**
0x06, 0x0C, _____**_____**__
0x03, 0xE0, ______*****_____

It looks like 16 rows of 15 pixels each. Each line is skewed by a pixel because the bytes hold 8 pixels each. Probably the best solution is to find a font editor.

Hi John. Many thanks for this and all your hard work in sorting it out.
In my personal summary I said that I was new to Arduino programming and I am afraid that all this is way above my pay scale!
I find it a little crazy that you need dozens of lines of code just to put a copyright symbol on the TFT.
What I know so far ....
tft.print(" \xA9"" 2020"); is the correct code to display a character described in HEX.
The normal Arduino font is 7bit and does not have the copyright symbol.
However, Tom Thumb extended does have it and I have proved that I have enabled Tom Thumb in my sketch (all the font change on the TFT).
What I have not managed to do is enable the extended Tom Thumb bit that contains the symbol I want.
#define TOMTHUMB_USE_EXTENDED 0 ; does not work -- neither does changing the 0 to a 1.
I firmly believe that making the extended font to work is the answer --- BUT HOW is the question.
Regards
Kevin

It looks to me that you will need to change that #define in the font file itself. It's defined and used there to enable the extended characters.

You might try defining it before you include any adafruit libraries, but I suspect that the entry in the font file will override it.

I think that youe problem with TomThumb is that the 'last character" in the font is still set to 0x7E even with the extended glyphs added.

const GFXfont TomThumb PROGMEM = {(uint8_t *)TomThumbBitmaps,
                                  (GFXglyph *)TomThumbGlyphs, 0x20, 0x7E, 6};

Try changing that to 0xFF to see if the extended characters start working.

Success. I have tried for over a week to display a copyright symbol on my tft screen and received lots of help on this forum so thought it best to show how I did it in case other people want to do the same. The symbol only appears in the 8bit fonts and most of the fonts in the GFX package are only 7bit – except the Tom Thumb one which has the symbol. I spent hours and hours trying to make the symbol show on the screen but whatever I tried only gave me a weird shape. After a lot of thinking I realized that my coding was correct and I was getting the symbol BUT the definition (number of pixels??) was too lacking to show the symbol correctly. I then tried the FontConvertor.exe package but here again the fonts supported were only 7bit. My final solution was to display an upper case “O” then reset the cursor and display a lower case “c”. Obviously both letters had the same starting position and base line so I played around with the last two entries in the bitmap for the “c” by trial and error and moved it along and up into the centre of the “O”. I had to use two different fonts so as not to move both letters. Here is the code I used

#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSansBoldOblique9pt7b.h>

tft.setFont(&FreeSans12pt7b);
tft.setTextColor(BLACK);
tft.setTextSize(1);
tft.setCursor(290,310);
tft.print("\x4F");
tft.setCursor(290,310);
tft.setFont(&FreeSans9pt7b);
tft.print("\x63");
tft.setCursor(290,310);
tft.setFont(&FreeSansBoldOblique9pt7b);
tft.setTextSize(1);
tft.print(" 2020");

Many thanks for all the help I got on this forum.
Kevin

Thanks for coming back with the info !

(even better would have been to use code tags for the code. :smiling_imp: :grin: !)