Adafruit mfGFX discussion

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Adafruit mfGFX discussion

Post by tomek »

HI! I'm hoping to make this thread about the mfGFX offshoot of adafruit GFX. It started with some members at Spark.io, and I derailed their thread a little bit to about about using it with the Teensy 3.1 (their forums are for the spark core.) One user there had already succeeded at that.

(original thread: https://community.spark.io/t/new-adafru ... brary/4156)

The mfGFX is the GFX library, but with slight modification for easier handling for custom fonts.

I'm not sure if I should post this here. It was suggested I use the teensy forum, but I'd like to see this more as a general MCU thread, and I imagine people would like to get this working on more controllers and boards than the teensy.

Is this ok? or is this forum more about direct product support? I'm not totally familiar. I have no problem moving this to the teensy forum, as well.

Next posts will include more info, copied from the thread.

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Hey, I was going to right away post the info on the mfGFX library, but I realize I should give it a few hours till I make sure everything is working for me, too.

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Ok! So let's look at the important information. Note! the following has been tested on the teensy 3.1 microcontroller but we'll need more people to see if things worked on their other controllers.

First, you need to grab the mfGFX library from the spark core github. https://github.com/pkourany/Adafruit_mfGFX_Library

I recommend pulling it from there, even though in a moment we'll be replacing the main files, because it will include the example file and the readme file for loading fonts.

Now, that you have the main file we're going to replace the fonts.cpp, fonts.h, and the main mfGFX.cpp and mfGFX.h with copies originally supplied by "RWB" on the spark.io forums.

What are the differences between those files and the main git files? I'm not sure! and haven't had the chance to carefully examine them to see if there are even significant differences. What I do know is that I struggled to get the mfGFX code to compile, until RWB supplied his/her files. Attacchhinnggg, the files! 3 will be attached here, and another 1 on the next post. I just recreated them so hopefully I didn't mess up any copy-paste.
Attachments
fonts.cpp
(45.17 KiB) Downloaded 618 times
Adafruit_mfGFX.h
(2.95 KiB) Downloaded 554 times
Adafruit_mfGFX.cpp
(14.36 KiB) Downloaded 643 times

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Anndd, fonts.h [forum limited me to only 3 attachments]
Attachments
fonts.h
(1.07 KiB) Downloaded 569 times

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

OK! So how do we load this for a general adafruit screen and library? Well one thing we should establish is that the GFX library is used as a 'core' for the individual screen controllers. So you also need to get the controller-specific library to point to the right GFX library (the mfGFX library.)

That's really easy! You just need to change one line.

In "controller.h", change "#include <Adafruit_GFX.h>" to "#include <Adafruit_mfGFX.h>"

For me, that was "Adafruit_RA8875.h" where I made the include change.

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Next, the process for adding fonts follows closely the description in the core files we downloaded from github. There are a few quirks that I don't think the readme.pdf quite addresses, though.

To clarify: Right now I'm suggesting anyone interested in using this thread uses the README.pdf directions for generating new fonts and loading them into the library. In this ultra-mini tutorial I'm just going to offer a few tips that were short roadblocks for me but should simplify following the directions.

(1) Be mindful that you can't add fonts larger than 120pt size. I found that to be the case, but I don't know exactly why. They won't display correctly. They also take up a ton of flash space, so most controllers wouldn't be happy with it anyway.

(2) "TheDotFactory" [see readme.pdf] produces files which name the datatype to be "uint_8." That's fine and dandy, except arduino wants to see the datatype "uint8_t." So you must rename everything to uint8_t. The readme.pdf does not seem to mention this. You will get an easy to read compiler error if you do not remember to do that.

(3) The readme.pdf indicates an "extra row" to define the characters you included in your font. For example, when I made the giant 120pt font, it was only for digits 0-9. So I looked at a table here, http://www.bluesock.org/~willg/dev/ascii.html, to find that I needed to use the 0x30, 0x39, as opposed to the 0x20, 0x7F, shown in the example.

(4) For me, TheDotFactory also generated an array called "FONT_INFO". You do not need this array, and it can be deleted. But it is different than "FONT_CHAR_INFO" which you do want to keep!

(5) In the readme, it suggests removing all comments from "FONT_CHAR_INFO". In reality, you only need to remove the forward slash "\" if you were generating a full set of characters including the forward slash key. The forwardslash, despite being in the comments, triggers some sort of compiler error. The other comments are not an issue.

(6) theDotFactory will generate three lines for the header file, of which you can again remove the one simply called "FONT_INFO."


So, really, besides these six notes, and the modification to your controller library (for me, RA8875) I think the readme.PDF will be a suitable document to explain how to get mfGFX running for other screens and controllers.

Maybe the way I've presented these things is not sufficient, but for now I'll see if it's useful at all for anyone before bothering with more details.

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

One more note!!

(7) You will notice TheDotFactory does not initiate the files as PROGMEM. For 99% of the situations, you want to add your fonts as PROGMEM so they dont immediately take up flash space until you load them.

So where-ever you have an array in the .c file, for example,
"const FONT_CHAR_INFO microsoftSansSerif_11ptDescriptors[] = "
you just need to change it to
"const FONT_CHAR_INFO microsoftSansSerif_11ptDescriptors[] PROGMEM ="

nothing more complicated than that.

There are two arrays that you need to modify. I don't think README.Pdf covers this point. I'm also not certain if PROGMEM isn't already implicit in the "const" declaration, but by adding the PROGMEM command you make it more certain (in my eyes anyway...I am sure someone more knowledgeable will know if it's necessary or not.)

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

*ram space is what I meant.
I wish adafruit forums had edit functionality :(

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Ok, there's no way for me to edit pages that I know of (serious, this seems like a major forum flaw..Or if there is a way to edit, it's not immediately apparent to me.)

But here's a new link to the general library files, I haven't tested them yet (https://github.com/pkourany/Adafruit_mfGFX_IDE) but it should be the same as the files I hosted above.

Below I've also included some example snaps of what can be done with this library.

The first line is in ARIAL pt.8, scaled x6.
The second is in CALIBRI_48, scaled to x1 [noscaling]

Next is VERDANA_88pt, and VERDANA_120pt. It's worth noting although 120pt seems to be the limit of the dotfactory+mfGFX procedure, you can still scale the 88pt and 120pt fonts. So there may be an avenue to understanding the root problem by exploring that interesting fact. Or it might be something trivial that allows it [I dont know how the scaling executes.]

For the record, this example image would not fit on an UNO, though I think it should fit on a MEGA.
adafruit mfGFX.jpg
adafruit mfGFX.jpg (953.08 KiB) Viewed 3547 times

User avatar
tigers
 
Posts: 16
Joined: Fri Oct 31, 2014 6:11 pm

Re: Adafruit mfGFX discussion

Post by tigers »

Hi, I finally managed to compile the mfGFX on Arduino 1.0.5 using your guide. Unfortunately all I got is garbage when I try to display text.
Let me see if I got this straight: I downloaded the original library (that won't compile because of some #include not good for arduino and some other syntax error I am not good enough to track down also). Then I substituted the files with the ones form your message (that are NOT the ones on the pkourany Github as you state in one of the latest messages).
After that I modified the "controller.h" file in the LCD library (mine was ILI9341.h) to include the mfGFX library instead of the standard one (and the main sketch include to include the mfGFX, of course).
At this point everything compiles, but when I try to display text I got garbage.
Am I missing some steps?

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Hi! Cool! Glad to hear someone is giving it a shot. Bear in mind if you're to look at a matrix of the MCUs vs. the specific Screen Controller, there are a ton of combinations, and as far as I know few have been tried so far. But the underlying idea of the GFX library should be that it should work for all the screens.

(1) Can you be specific of what #include is "not good for the arduino"? I just checked the files and found:
"#include "fonts.h"
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <SPI.h>
#include "Adafruit_RA8875.h"
#include "Adafruit_mfGFX.h"
#include "Arduino.h"
#include "Print.h"
#include "WProgram.h"
#include <Adafruit_mfGFX.h>"

None of those should be a problem with Arduino. Bear in mind when I am loading this on the teensy 3.1 I am actually using the arduino IDE, so for the most part these things are compatible devices.

(2)
Then I substituted the files with the ones form your message (that are NOT the ones on the pkourany Github as you state in one of the latest messages).
blah, I will try to look into the differences. I was under the impression they should be very similar, with Pkourany's maybe being better/more generalized. Thank you for the info.

(3) Quick question: Is the ILi9341 driver you're using definitively using the GFX library as its core? EDIT: I just checked, you're good on that front.

(4) What MCU are you using? Have you tried the library exclusively with the default font (Arial_8pt, I believe, but basically the same as never calling setFont)? If not, do that first [basic steps first.] Then, try another font but not much bigger, maybe a 16pt font. I want to avoid running out of memory because although you do store the fonts in PROGMEM it is my understanding that the processor needs to at some point be able to store all of the font into its memory when it sends messages, although it should be deallocated for the rest of the sketch.

(5) when you say your font displays garbage, what is specifically the message you try to setup for testing, and what is the font you're set to (if anything?)

(6) Please confirm you've successfully run the screen with the default libraries (GFX, etc.)



___________

Sorry you've had trouble getting this running! I'm not too experienced either, but I'd like to help out getting this running. I don't immediately notice mistakes on your part, but I do need the details to the questions I asked and I think that might help troubleshooting.

Also, it might be worth it for you to attach a zip with your main sketch, driver files, and mfGFX (if there is a lot of private stuff in your sketch then don't include that.) But when testing functionality you should only use a striped down minimal version of your project. I should bold the last sentience but it looked a bit preachy that way, yet, it's really important.

User avatar
marteke
 
Posts: 10
Joined: Wed Jul 09, 2014 10:00 am

Re: Adafruit mfGFX discussion

Post by marteke »

Tomek wrote:OK! So how do we load this for a general adafruit screen and library? Well one thing we should establish is that the GFX library is used as a 'core' for the individual screen controllers. So you also need to get the controller-specific library to point to the right GFX library (the mfGFX library.)

That's really easy! You just need to change one line.

In "controller.h", change "#include <Adafruit_GFX.h>" to "#include <Adafruit_mfGFX.h>"

For me, that was "Adafruit_RA8875.h" where I made the include change.
hello
could you show me a code ex.? use RA8875.

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

Heya, sure, I can post all the code for the ra8875 demo on the teensy 3.1. Can't get to it until tmrw noonish

If you want to replicate it you'll need to define the pins correctly, of course.

User avatar
tigers
 
Posts: 16
Joined: Fri Oct 31, 2014 6:11 pm

Re: Adafruit mfGFX discussion

Post by tigers »

Tomek wrote:Hi! Cool! Glad to hear someone is giving it a shot. Bear in mind if you're to look at a matrix of the MCUs vs. the specific Screen Controller, there are a ton of combinations, and as far as I know few have been tried so far. But the underlying idea of the GFX library should be that it should work for all the screens.
I totally agree, and since this is the only topic I found so far that got me anywhere let's try and see what we can do.
Tomek wrote: (1) Can you be specific of what #include is "not good for the arduino"? I just checked the files and found:
[...]
None of those should be a problem with Arduino. Bear in mind when I am loading this on the teensy 3.1 I am actually using the arduino IDE, so for the most part these things are compatible devices.
I've not been clear, sorry: the #include in your library are OK, the one in the original library aren't (there's an "application.h" just to name one. But that's fine since it's a non-Arduino library.

Tomek wrote: (2)
Then I substituted the files with the ones form your message (that are NOT the ones on the pkourany Github as you state in one of the latest messages).
blah, I will try to look into the differences. I was under the impression they should be very similar, with Pkourany's maybe being better/more generalized. Thank you for the info.
I took a further look into it and noticed there's another folder inside of the pkourany that is labelled SharMemDisplay that contains the library that's Arduino compatible and it's potentially a little better that yours in the fact that it has the original gLCD font from the Adafruit library AND it is the default one, so that it is fully compatible with sketches from the original library.
Tomek wrote: (4) What MCU are you using? Have you tried the library exclusively with the default font (Arial_8pt, I believe, but basically the same as never calling setFont)? If not, do that first [basic steps first.] Then, try another font but not much bigger, maybe a 16pt font. I want to avoid running out of memory because although you do store the fonts in PROGMEM it is my understanding that the processor needs to at some point be able to store all of the font into its memory when it sends messages, although it should be deallocated for the rest of the sketch.
I'm using a Arduino UNO R3 clone and of course I started off easy by just adapting the libraries and trying to see if the default font works, just not calling setFont. Then I tried calling setFont with Arial and Times. The only result is that the garbage displayed changes a little (this could be a good thing in a way: it means the command is recognized and points to different things).
No problem with them memory: I use the Arduino Enhanced IDE that tells me at compile time the PROGMEM used and the extimated RAM usage. Both of them are fine and far from the limits. I'll try with a MEGA just to be sure.
Tomek wrote: (5) when you say your font displays garbage, what is specifically the message you try to setup for testing, and what is the font you're set to (if anything?)
I'm using a (of course modified to use your library) version of the Adafruit test sketch, with the "Hello World!" and GROOMP or something like that.
Tomek wrote: (6) Please confirm you've successfully run the screen with the default libraries (GFX, etc.)
Of course I did, the screen works great with both the UTFT and the Adafruit_ILI9341 libraries with the GFX standard lib. Also with the mfGFX the other primitives are OK, just the text is displayed badly.


Tomek wrote: Sorry you've had trouble getting this running! I'm not too experienced either, but I'd like to help out getting this running. I don't immediately notice mistakes on your part, but I do need the details to the questions I asked and I think that might help troubleshooting.
That's part of the Arduino experience; Also I like to actually learn things instead of always relying on other people work, at least as much as I can (I don't have the experience nor the ability to write a library on my own).
Tomek wrote: Also, it might be worth it for you to attach a zip with your main sketch, driver files, and mfGFX (if there is a lot of private stuff in your sketch then don't include that.) But when testing functionality you should only use a striped down minimal version of your project. I should bold the last sentience but it looked a bit preachy that way, yet, it's really important.
[/quote]

Well, you are absolutely right, and that's usually how I proceed: I start with the simply examples, make sure everything works and that start with the most difficult part.

As for the code I could post it but really it's just your library downloaded from here, the Adafruit_ILI9341 library modified to include mfGFX instead of the standard GFX and the Adafruit example modified to use the mfGFX and the modified ILI9341.

I took a photo of the garbage I see on the screen.
Attachments
IMG_3216.JPG
IMG_3216.JPG (147.27 KiB) Viewed 3485 times

User avatar
tomek
 
Posts: 73
Joined: Wed Jun 13, 2012 1:37 pm

Re: Adafruit mfGFX discussion

Post by tomek »

marteke wrote:hello
could you show me a code ex.? use RA8875.
ok! I have added a .zip with a cut version of my code for the RA8875 and a 800x480 TFT (must change values if your screen is the other common value, e.g, 272x480)

I have not tested it on my hardware yet...I will test it tomorrow morning, and I will update if I had any issues. The libraries need to be put in library files, as usual, but I put them in the .zip so I can easily attach.
_____________________________________________________________

Hi Tigers! Sorry for the slow response. The unfortunate thing is it sounds like you're working thoroughly and carefully, so I'm not yet sure what's going on. All of the common mistakes I mentioned you seem to be addressing. I hope I didn't make any mistakes in my descriptions. I have uploaded the working RA8875 code on this message [stripped down version of code currently working in my larger project], in case that is useful.

Now onto some bits of your message.
"The only result is that the garbage displayed changes a little (this could be a good thing in a way: it means the command is recognized and points to different things)."
:/ I'm not certain what to say here. Nothing comes to mind yet.
No problem with them memory: I use the Arduino Enhanced IDE that tells me at compile time the PROGMEM used and the extimated RAM usage. Both of them are fine and far from the limits. I'll try with a MEGA just to be sure.
Have you had any luck with the mega to be sure? I am not sure how they determine the estimated RAM usage, but from what I understand that is not as easy to determine as (of course) the sketch size.


Being slightly uncertain what suggests to make, I'm going to look at the touschreen you're using itself. The ILI9341 I guess it is. A 240x320 screen, so big enough that the work examples we're suggesting should totally fit. I guess I checked out the basic drawPixel function in the ILI9341 library, since the char driving depends on that. It doesn't look strange or anything controller-specific.


Right now I'm wondering what might be missing. I can glance at your code if you include it in a .zip like I've attached, or if you look at what I've attached it might be useful. Could be I made a mistake in my instructions but my instructions were followed three times by myself to add new fonts and make new code, so I believe they work- maybe I need to be clearer in one section or another though.
Attachments
mfGFX_RA8875_test_code.zip
stripped down version. compiles but untested as of sunday, will check with hardware on monday
(238.19 KiB) Downloaded 211 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”