🎁📬❄️📦Adafruit Holiday Shipping Deadlines 2019: Please place all UPS 2 Day orders by 11am Monday, December 16 📦❄️📬🎁
0

Arduino, RA8875, and Fonts
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino, RA8875, and Fonts

by georgeioak on Wed Nov 20, 2019 3:12 pm

I'm running some initial tests with the RA8875 and 5" 800x480 screen. Everything works well except for when I try to load and use a different font. I've read through the forum and the internet and I've seen others with the same issue but I haven't seen a solution.

From reading and looking at the source code I know that you cannot run in TextMode when you want to use a loaded font. TextMode works, as expected, when using the internal font. I'm not sure if perhaps the RA8875 needs the font in a different format or if the print calls are not working properly. I do know that the drawChar function works so that leads me to believe that issue lies in how the print calls are being used but I'm not a good enough programmer to try and debug this further. Here's a section of my code with comments:

Code: Select all | TOGGLE FULL SIZE
 // Put some text on the screen
  tft.textMode(); //Comment this to try drawChar
  tft.textSetCursor(10, 10);
  tft.setFont(&FreeSans12pt7b); //This isn't working
  tft.setTextSize(1);
  tft.textColor(RA8875_RED, RA8875_BLACK);
  tft.print("Villara Tester Running"); //This does get displayed
 
  tft.graphicsMode();
  tft.setFont(&FreeMonoBoldOblique24pt7b);
  //tft.setXY(10, 100);
  tft.setCursor(10, 100);
  tft.println("2nd Line of Text"); //this doesn't display anything
  tft.drawChar(400, 240, 'T', RA8875_WHITE, RA8875_BLUE, 2); //this works
  tft.drawChar(450, 240, 'e', RA8875_WHITE, RA8875_BLUE, 2); //just guessing
  tft.drawChar(500, 240, 's', RA8875_WHITE, RA8875_BLUE, 2); //on spacing
  tft.drawChar(550, 240, 't', RA8875_WHITE, RA8875_BLUE, 2); //for now
  tft.textMode();


If someone could help me debug this I'd be more than happy to put the time in testing things and getting this to work as I don't believe it's just a problem on my side. I should mention that I am running this on a ST Micro Nucleo-F401RE board (STM32F401RE) so that too could be another cause of the problem but so far everything else seems to be working as expected and it's just the font loading that doesn't work.

georgeioak
 
Posts: 34
Joined: Fri Jun 15, 2012 10:36 pm

Re: Arduino, RA8875, and Fonts

by adafruit_support_mike on Thu Nov 21, 2019 3:02 am

Try sending the text as an array of char values instead of a String object (automatically created by the Arduino environment whenever it sees a quoted string).

The RA8875 class inherits from the GFX class, which in turn inherits from the Print class. The Print class accepts a bunch of different kinds of arguments, and shuffles the data around to call a function named write() with a C string. The connections aren't obvious though, and change in unexpected ways with the way the text is encoded.

You might want to skip the whole thing and call .write() directly.

adafruit_support_mike
 
Posts: 59708
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino, RA8875, and Fonts

by georgeioak on Thu Nov 21, 2019 9:48 am

OK, first I tried:

Code: Select all | TOGGLE FULL SIZE
tft.write("2nd Line of Text");

and I received this error:

Code: Select all | TOGGLE FULL SIZE
invalid conversion from 'const char*' to 'uint8_t' {aka 'unsigned char'} [-fpermissive]


so then I tried:

Code: Select all | TOGGLE FULL SIZE
char message[6] = "hello";
  //tft.print(message[0]); //This didn't display anything
  tft.write(message[0]); //This didn't either


Is this what you wanted me to try or did I do something wrong?

georgeioak
 
Posts: 34
Joined: Fri Jun 15, 2012 10:36 pm

Re: Arduino, RA8875, and Fonts

by adafruit_support_mike on Fri Nov 22, 2019 1:23 am

The second version is closer, but the code above is just sending the first character.

Try this:

Code: Select all | TOGGLE FULL SIZE
char message[6] = "hello";
  tft.write( message );

adafruit_support_mike
 
Posts: 59708
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino, RA8875, and Fonts

by georgeioak on Fri Nov 22, 2019 1:30 pm

I forgot to say that doing that also throws an error:

Code: Select all | TOGGLE FULL SIZE
invalid conversion from 'char*' to 'uint8_t' {aka 'unsigned char'} [-fpermissive]


One other thing to note, when I use the successful drawChar command:

Code: Select all | TOGGLE FULL SIZE
tft.drawChar(400, 240, 'T', RA8875_WHITE, RA8875_BLUE, 2); //this works


only text sizes of 2 and 3 are successful in drawing the character on the screen. Sizes 0 and 1 don't display anything but I think 0 or 1 did display a pixel or 2

georgeioak
 
Posts: 34
Joined: Fri Jun 15, 2012 10:36 pm

Re: Arduino, RA8875, and Fonts

by adafruit_support_mike on Mon Nov 25, 2019 3:01 am

Ah.. the version that takes a buffer also wants the number of characters:

Code: Select all | TOGGLE FULL SIZE
  /**************************************************************************/
  /*!
       Alias of textWrite to Play nice with Arduino's Print class
   
       @param buffer The buffer to write
       @param size The size of the buffer
       @return The number of bytes written
   */
  /**************************************************************************/
  virtual size_t write(const uint8_t *buffer, size_t size) {
    textWrite((const char *)buffer, size);
    return size;
  }
So for a buffer that contains "hello, world.", the call would be:

Code: Select all | TOGGLE FULL SIZE
    char buffer[] = "hello, world.";
    ra8875.write( buffer, 13 );

adafruit_support_mike
 
Posts: 59708
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino, RA8875, and Fonts

by georgeioak on Mon Nov 25, 2019 12:04 pm

Thanks for hanging in there with me, sorry I missed how to use the write function but using your example I still get an error calling the write function:

Code: Select all | TOGGLE FULL SIZE
invalid conversion from 'char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]


using this code:

Code: Select all | TOGGLE FULL SIZE
  tft.graphicsMode();
  tft.setFont(&FreeMonoBoldOblique24pt7b);
  tft.setCursor(10, 100);
  char message[] = "hello";
  tft.write( message, 5 ); //throw's an error

georgeioak
 
Posts: 34
Joined: Fri Jun 15, 2012 10:36 pm

Re: Arduino, RA8875, and Fonts

by adafruit_support_mike on Tue Nov 26, 2019 1:29 am

Redeclare the string buffer as the type specified in the error message:

Code: Select all | TOGGLE FULL SIZE
    const unsigned char message[] = "hello";
The Arduino IDE has gotten more strict about type interpolation, to the point where it's more of a nuisance than help.

adafruit_support_mike
 
Posts: 59708
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino, RA8875, and Fonts

by georgeioak on Tue Nov 26, 2019 3:10 am

Well that fixed the compile error but the end result is still nothing drawn/written to the screen. I had also tried to redefine the message type and didn't get it to work but your declaration was a combination I hadn't tried.

Code: Select all | TOGGLE FULL SIZE
tft.setCursor(10, 100);
  const unsigned char message[] = "hello";
  tft.write( message, 5 ); //doesn't display

georgeioak
 
Posts: 34
Joined: Fri Jun 15, 2012 10:36 pm

Re: Arduino, RA8875, and Fonts

by adafruit_support_mike on Wed Nov 27, 2019 3:05 am

Hmm.. let me pass this to the people who handle the GFX library.

adafruit_support_mike
 
Posts: 59708
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino, RA8875, and Fonts

by georgeioak on Wed Nov 27, 2019 9:22 am

Thanks, I'm sure that if someone familiar with the GFX library has the time to debug we can get this solved and hopefully easily.

georgeioak
 
Posts: 34
Joined: Fri Jun 15, 2012 10:36 pm

Please be positive and constructive with your questions and comments.