Has anyone got the Adafruit 3.5" display (HS9357D display to work with fonts?

I've tried every library on the planet and NONE seem to work with this display. UTFT, etc don't even have a define for and HX8357

The UTFT_DLB will not even compile--i get an error which I have no idea how to fix

C:\Program Files (x86)\Arduino\libraries\UTFT_DLB\DejaVuSans18.c:26:9: error: variable 'DejaVuSans18' must be const in order to be put into read-only section by means of 'attribute((progmem))'

I can use the Adafruit library (#include "Adafruit_HX8357.h") , but custom fonts don't work

Non helpful replies would be
"just write your own fonts" or "just patch the QR56 library" or some other cryptic C terminology

Helpful replies would be
"get these libraries and use this sketch" or "correct, that display will not support custom fonts"

Thanks in advance,

PS as you can see i'm very frustrated with this %#@ display--spent some 20 hours trying get custom fonts to work....

PS here's the sketch that will not even compile

//***************************************************************
// UTFT_DLB Demo
//***************************************************************

#include <UTFT.h>
#include <UTFT_DLB.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
extern uint8_t DejaVuSans18[];
extern uint8_t DejaVuSans24[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT_DLB myGLCD(ITDB32S,19,18,17,16); // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT_DLB myGLCD(ITDB32S,38,39,40,41); // Remember to change the model parameter to suit your display module!

//*************************************************************************************************
// Setup
//*************************************************************************************************

void setup()
{
randomSeed(analogRead(0));

myGLCD.InitLCD(LANDSCAPE);
}

//******************************************************************************************************************
// Main loop
//******************************************************************************************************************
void loop()
{
while (1)
{
// Clear the screen and draw the frame
myGLCD.clrScr();

//myGLCD.setFont(BigFont);
myGLCD.setFont(DejaVuSans18);

myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);

myGLCD.setFont(BigFont);
myGLCD.print("Fixed-Width Font", 20, 20, 0);

myGLCD.setColor(255, 120, 0);
myGLCD.setBackColor(50, 50, 50);

myGLCD.setFont(DejaVuSans18);
myGLCD.print("DejaVuSans 18", 20, 90, 0);
myGLCD.setColor(255, 120, 120);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("DejaVuSans 18", 130, 150, -10); // rotated text

myGLCD.setFont(DejaVuSans24);
myGLCD.setColor(255, 120, 255);
myGLCD.setBackColor(50, 250, 50);
myGLCD.print("DejaVuSans 24", 20, 180, 0);
myGLCD.setColor(0, 120, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("DejaVuSans 24", 150, 50, 20); // rotated text

delay(5000);
}
}

Hi Kris,

You really should post code using code tags!! '</>'

The example sketch you posted compiles fine for both Mega and Due under IDE V1.6.5. Which version of IDE are you using?

Edit: I have had UTFT_DLB for so long now, I cannot remember if I already made the edits that will fix your errors or not, but to fix that particular error, ensure line 26 of DejaVuSans18.c is const uint8_t DejaVuSans18[] PROGMEM =
Regards,

Graham

Hi Kris,

I have added extra fonts to Adafruit libraries, as you found this is not easy.

Unfortunately I do not have a HX8357D based display to try, but if you are willing to experiment and report back then by working together we would have a good chance of getting an updated library working.

Bear in mind though that it would be challenging to add new fonts to those I have created because of the way they are encoded (Run Length Encoding to reduce FLASH footprint and speed rendering). AS the fonts set was designed to fit in an UNO the larger fonts I added (over 26 pixels high) only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : - .

If those constraints are OK then let me know. It would take about 2 hours of my time to update the library so only say yes if your are seriously interested.

Hi Kris,

I had some spare time so I had a look at potential libraries for the HX8357D.

Were you aware that Adafruit have added fonts to their GFX library here.

The GFX library is the generic support library and, for the HX8357D, can be used with their library here.

I have not used the Adafruit GFX library since fonts were added so cannot advise how to use those fonts. Since you have a genuine Adafruit product I expect they will provide support.

Curiosity got the better of me so I have loaded the new Adafruit GFX library to try it.

Sadly there don't appear to be any example sketches that use the new fonts but with the help of the tutorial here I got it going on a Leonardo with a ILI9341 based display.

There is a lot of font files but only a few different sizes that are all quite small.

Limitations of note are:

  1. Font are rendered without background, the cludge solution is to use the provided function getTextBounds() and blank the old text with a filled rectangle, but there is a bug and the x position and width bounds returned need to be tweaked to erase the old text fully.
  2. The cludge above causes a lot of "flicker" when values are updated
  3. Because text rendering uses generic methods like drawPixel() printing text to the screen is very very slow even for the small fonts

If you have fairly static displays or are using a DUE you may find the Adafruit implementation OK for your needs.

Attached are two examples, one for an SPI interface and one for a 8 bit interface. I can't test these myself but they compile OK and work with another Adafruit display driver.

Char_Times_HX8357.ino (1.99 KB)

Char_Times_HX8357_8_bit.ino (3.15 KB)

Thanks to all, i'll take a look at this.

my ide is 1.6.6

I know to use code tags, but I forgot to include the first post. Since I have very restrictive posting capabilities on this overly protective forum, I could not edit my original post only reply, and oddly the code tags were not available in the reply, so my options were

  1. post w/o code tags
  2. post w/o code a
  3. wait until i can edit my original post

I chose #1

thanks rowboteer, i'm looking at the sketches now

ghlawrence2000
I used your suggestion and I get a ton of compile errors...
is there something to be added after the = ?

++++++++

Arduino: 1.6.6 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

UTFT_DLB_Demo:12: error: expected primary-expression before ';' token

const uint8_t DejaVuSans18[] PROGMEM = ;

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_858aa09963a2def53aeea96a2b8622ce\UTFT_DLB_Demo.ino: In function 'void loop()':

UTFT_DLB_Demo:43: error: invalid conversion from '' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

myGLCD.setFont(DejaVuSans18);

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_858aa09963a2def53aeea96a2b8622ce\UTFT_DLB_Demo.ino:5:0:

C:\Program Files (x86)\Arduino\libraries\UTFT/UTFT.h:219:8: error: initializing argument 1 of 'void UTFT::setFont(uint8_t*)' [-fpermissive]

void setFont(uint8_t* font);

^

UTFT_DLB_Demo:54: error: invalid conversion from '' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

myGLCD.setFont(DejaVuSans18);

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_858aa09963a2def53aeea96a2b8622ce\UTFT_DLB_Demo.ino:5:0:

C:\Program Files (x86)\Arduino\libraries\UTFT/UTFT.h:219:8: error: initializing argument 1 of 'void UTFT::setFont(uint8_t*)' [-fpermissive]

void setFont(uint8_t* font);

^

exit status 1
expected primary-expression before ';' token

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Should not have a ';' after PROGMEM = !

Graham

without the ; was the first thing i tried, got several compile errors.

did you actually get that sketch to compile or taking a stab at what to do?

all right... I got it working

I used a combination of rowboteer's code and mine, but i can now use the free adafruit fonts.

This saga is worthy of a YouTube video, stay tuned...

Man that was painful, but thanks to all.

KrisKasprzak:
did you actually get that sketch to compile or taking a stab at what to do?

ghlawrence2000:
The example sketch you posted compiles fine for both Mega and Due under IDE V1.6.5. Which version of IDE are you using?

Edit: I have had UTFT_DLB for so long now, I cannot remember if I already made the edits that will fix your errors or not, but to fix that particular error, ensure line 26 of DejaVuSans18.c is

const uint8_t DejaVuSans18[] PROGMEM =

Code lifted directly from my WORKING DejaVuSans18 file!

I don't appreciate sideways insinuations!! I compiled the damn thing, no guesswork required!!

G

PS. I don't see why I should justify myself, but in case I have to....

Compiled for DUE :-

C:\Users\Graham\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-objcopy -O binary C:\Users\Graham\AppData\Local\Temp\build2207531675003081359.tmp/UTFT_DLB_Demo.cpp.elf C:\Users\Graham\AppData\Local\Temp\build2207531675003081359.tmp/UTFT_DLB_Demo.cpp.bin

Sketch uses 34,280 bytes (6%) of program storage space. Maximum is 524,288 bytes.

Compiled for Mega :-

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy -O ihex -R .eeprom C:\Users\Graham\AppData\Local\Temp\build2207531675003081359.tmp/UTFT_DLB_Demo.cpp.elf C:\Users\Graham\AppData\Local\Temp\build2207531675003081359.tmp/UTFT_DLB_Demo.cpp.hex

Sketch uses 18,166 bytes (7%) of program storage space. Maximum is 253,952 bytes.
Global variables use 278 bytes (3%) of dynamic memory, leaving 7,914 bytes for local variables. Maximum is 8,192 bytes.

G,

I wasn't insinuating anything--sorry if my post read that way. My original post asked for a working sketch as I figured that would save us all some time. Your reply "can't remember" with a single line of code, made me wonder.

What I meant was, I had UTFT_DLB for a long time now, I knew it worked, but the changes I made were a long time ago.....

Before I made my original post, I compiled it for Mega and Due, and then updated the post to give you the necessary correction. There was NO guesswork involved.

UTFT_DLB is an old unmaintained library, and the changes brought about by IDE V1.5.7 is when the 'const' issue became a problem, I have had many libraries requiring the same fix..... I just didn't appreciate the feeling you thought I was giving poor advice.

Regards,

Graham

I would guess that your Adafruit display will use Adafruit drivers and Libraries. Hence expect Adafruit-style class methods()

The original Adafruit TFT drivers would use the Adafruit_GFX.h library for graphics and just scale a single 7x5 "system" font.

Subsequently, a "Adafruit_GFX_AS.h" library has appeared in various hacked versions. This can use multiple Fonts, accessed by number.

Rowboteer has posted a link to a new "Adafruit_GFX.h" library that handles Fonts, Buttons, ... on GitHub
This uses Glyphs for the description. It comes with a program to generate Fonts from TrueType. The Fonts that come with the ZIP render very nicely.

Since there are a lot of TFT libraries that follow the Adafruit style, using the Fonts is very straightforward:

#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>   // Hardware-specific library
MCUFRIEND_kbv tft;

#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeMono18pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#if !defined(__AVR_ATmega328P__)
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSans24pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <Fonts/FreeSerif18pt7b.h>
#include <Fonts/FreeSerifItalic9pt7b.h>
#include <Fonts/FreeSerifItalic18pt7b.h>
#include <Fonts/FreeSerifBold12pt7b.h>
#include <Fonts/FreeSerifBold24pt7b.h>
#endif

#define BLACK   0x0000
#define GREEN   0x07E0

void setup(void) 
{
    uint16_t ID = tft.readID();
    if (ID == 0xD3) ID = 0x9481;
    tft.begin(ID);
    tft.setRotation(1);
}

void showfont(const GFXfont *f1, const GFXfont *f2, char *name, char *name2)
{
    int wid;
    tft.fillScreen(BLACK);
    tft.setTextColor(GREEN, BLACK);
    tft.setFont(NULL);
    tft.setTextSize(1);
    tft.setCursor(0, 0);
    tft.print(name);
    tft.setFont(f1);
    tft.setTextSize(1);
    tft.setCursor(0, 50);
    tft.print(name);
    tft.setTextSize(2);
    tft.setCursor(0, 120);
    tft.print(String(name) + " x2");
    tft.setFont(f2);
    tft.setTextSize(1);
    tft.setCursor(0, 239);
    tft.print(name2);
    delay(2000);
}

#define SHOWFONT(x, y) showfont(&x, &y, #x, #y)
void loop() 
{
    SHOWFONT(FreeMono9pt7b, FreeMono18pt7b);
    SHOWFONT(FreeMonoBold9pt7b, FreeMonoBold18pt7b);
    SHOWFONT(FreeSans9pt7b, FreeSans18pt7b);
#if !defined(__AVR_ATmega328P__)
    SHOWFONT(FreeSans12pt7b, FreeSans24pt7b);
    SHOWFONT(FreeSerifItalic9pt7b, FreeSerifItalic18pt7b);
    SHOWFONT(FreeSerifBold12pt7b, FreeSerifBold24pt7b);
#endif
    delay(4001);
}

This sketch compares the appearance of scaling a font x2 with the correct size font.
You can save memory by scaling but they do not look as good.

There are several strategies for describing and rendering Fonts.
If the Font is going to be stored in the Uno's Flash memory, you worry more about size and less about speed.
Fonts on a Due or Mega are less critical. Fonts on SD card or SPI Flash chip have no size worries. You can just go for speed.

I would guess that you can simply replace with the "Adafruit_HX8357D.h" library or any Adafruit-style hardware specific library.

David.