Digole UART/I2C/SPI Display Library

It looks like it will be pretty easy to add direct output of u8g binary fonts. Let me know if there is interest and I will add it otherwise I can just use the stand-alone utilty.

1 Like

billprozac, that would be cool, especially if it’s easy to add. :smile:

@peekay123 Done!

Ok, quick tutorial on custom glyph fonts.

  1. Using gimp or whatever tool you want, create an image of the glyph size you want (16x16, 32x32, 16x32, whatever).
  2. Set the color mode to indexed. If doing a B&W image, set the index to 1-bit. If doing color separation, set just the colors you NEED.
  3. Draw the image you want.
  4. Keep in mind the color you are using for background. For B&W, this is either one. For color, you can use any color that is not part of the image. This color will be “transparent” in the final font.
  5. Save the image(s) into a folder. If you prefer a specific order in the font, name that so they are in alphabetical order the way you want. (01-warning.jpg, 02-notification.jpg, 03-coolassicon.jpg, etc)
  6. Use the newest version of the tool, Fontalizer.py, from the gitrepo.
    The sytax is:
    fontalizer.py -H <height> -W <width> -n <basename for fonts> [-o outputBDF file if you want it] -u [u8blib font file if you want it] -c <RGB background color eg. ffffff> -i <starting char number> <all of your image files to convert>

An example is:
fontalizer.py -H 16 -W 16 -o -u -n myfont -c ffffff -s 65 testfiles/*.gif
This will create two files, myfont.bdf and myfont.u8g

There are some more "experimental’ options in the script for doing things related to alpha channels. If you stay away from using alpha channels then you should have no issues. Also, unlike before, now I am properly computing the BBOX, which means that thin images (those that are fewer bytes wide that the fonts default width) will use less memory. So a vertical pipe ‘|’, in a 16x16 font will only take 8 bits per row, not 16.

I have verified that a BDF generated checks out with Fony and the converted bytestream from the converter tool matches what I am outputting, so give it a try and let me know.

One important thing to know is how to calculate the expected font size. multiply the number of bytes wide (not bits!) by the height and add 6 bytes per glyph. Then add a 17 bytes header. As you can see, the 2K per font goes pretty quick if you have large fonts. I think for 16x16, you get 53 glyphs in 2048B. Also keep inb mind that the space is based on the byte boundary, not bit boundary, so a 14x14 font would take the same space as a 16x16. no advantage is gained until you get down to 16x8 or 8x8.

Enjoy!

2 Likes

@peekay123 @billprozac @bko @BDub

Hey guys I came across a update to the Adafruit GFX library that allows you to add and use fonts other than the stock Adafruit GFX library font. Using other fonts Adafruits GFX lib still is not supported by the official Adafruit GFX Library.

I ended up getting the Sharp 2.7 Inch Memory Displays working on the Teensy 3.1 which has 96Kb or SRAM + 256Kb of program memory which is more than enough to run the larger screen and hold tons of sprite animations. Now I need to figure out how to add the new fonts to the Adafruit GFX library via the update and I came here to see if you guys could take a look at this update and tell me what you think since you understand this all better than I do.

Here is the Github link to the updated Adafruit GFX library code that allows the use of new fonts. https://github.com/adafruit/Adafruit-GFX-Library/pull/32

And here is a free app that allows you to create new fonts quickly and easily from the fonts you have installed on your computer. We just need to set the font pixel dimensions and export it to be used with the GFX library: http://www.mikroe.com/glcd-font-creator/

Who ever helps me understand how to use this will receive a free Spark Core with Chip Antenna. I have a few coming from Sparks next batch of Cores that are about to ship out and I have a total of 5 Spark Cores so giving one away is not a problem :smiley:

Man that Sharp display is a beauty! Very, well, sharp! Can I ask where you are getting the Sharp displays? Do they have backlights or just reflective?

The changes to the Adafruit library are not that bad–it looks like the fonts (there are two) have a slightly different structure and are now variable width, which is nice. So instead of just a 5x7 font, you could have a 16x20 or similar. There are some comments about kerning (pushing certain letter combinations closer together so it looks better) but there does not seem to be per character kerning, just one common number per font.

The font creator software is a PC thing and I will have a hard time helping out with that part unless I do it at work–which is a no-no! Maybe one of the other guys can help you out.

Hey @Bko the displays have a very high resolution. This 2.7 inch screen is 400 x 240 pixels.

I get the screens from Mouser but they are all sold out right now. The 1.26 inch screens are instock though, same as used in the Pebble watch and a few others actually. The key is that they only consume micro amps while holding a static image.

I get the backpacks here: https://www.tindie.com/products/kuzyatech/sharp-memory-lcd-breakout-a2/

About the 2 fonts, yes it looks like it makes it easy to use any new sized font. I’m just wanting others to check it out before I dig in a screw something up and waste a few days in the process.

I was wondering what the Kerning was all about. Thanks for the info.

RWB, after some fiddling I was able to get the new GFX library to compile. I was recently testing a 320x240 ILI9341 LCD recently with the standard GFX library so it was a perfect testing platform.

I imported a times new roman font into glcd-font-creator and did an export of the “C” code with an 11x14 font size. I then cleaned up the resulting code, added the necessary metric bytes at the start of the font arrary, put into the library and added a new font descriptor for the font, compiled and sent it to display and BOOM… no go. The fonts come out garbled. I will be doing more testing, including testing TheDotFactory to see if I can get a working font. :smile:

@peekay123 Thanks for taking a look and testing it out real quick. I’m dying to get this working since it should allow us to use just about any font we could ever desire with the screens.

Were you able to get the 2 Alternative fonts that are built into the code to work?

Are you testing this on the Arduino Platform also?

I tried to get help from the guy who wrote this updated code but no response yet. Here is that forum post, I can’t seem to directly PM people with Adafruits new forum. https://forums.adafruit.com/viewtopic.php?f=25&t=52643&p=269899#p269899

Also when you reply use the @RWB so I get an email notification of your reply please.

@RWB, I have it going but I am having a snot of a time understanding why I can’t import a new font created by TheDotFactory. I am testing everything on a Spark of course! There are only two fonts that come with his modified library. I have only tried one (the default) but the second one is the same font with less characters so I don’t see the point! I can’t seem to get TheDotFactory to put out the data in the right format. A different font would be the real test.

Have you seen this:

http://www.georgegardner.info/arduino/easy-font-creation-for-led-matrix-from-truetype-system-fonts.html

I was looking at this project for ideas and I noticed he has a good explaination of the font format.

1 Like

@Bko Good find. There are some great tips in that article on Exporting fonts in GLCD format. Hopefully it helps @peekay123 out some

Sweet bko! I will absolutely look at that. Thanks!

@peekay123 I can also try the updated library on Arduino’s I just need to know where to put the code needed to switch over to the newly added fonts.

I assume that you define the font you want to use at the top of the program code but I’m not 100% sure. Once I know how I’m supposed to pick which font I want to use I’ll start testing it out on my side and see if I am getting the same results.

Really exited to see this working since it would allow me to make the screen look any way I could imagine it. I know how to make bitmap images and animations so the only thing left to figure out is how to use any font I have available on my computer. I’m ready to put these Sharp Memory Displays to good use :smiley:

@RWB, using an arduino does not change anything. There are a few things to change to get things going:

  1. You need a demo program (application.cpp) so you can test your font
  2. You need to generate a font in "C" array format using font creator software. Then, you need to copy the resulting array into glcdfont.c. Look at the way the existing font array is setup in the file and use the same convention:
    const unsigned char yourfont[] PROGMEM = { arrary... };
  3. In font.h, you need to add a new font index and declaration

#define GFXFONT_GLCD 0
#define GFXFONT_GLCD_ASCII 1
#define GFXFONT_FONTNAME 2 - ADD AN INDEX FOR EACH NEW FONT

extern const unsigned char glcdFont;
extern const unsigned char glcdFont_ascii;
extern const unsigned char fontname; - ADD DECLARATION FOR EACH NEW FONT

Finally, in Adafruit_GFX.cpp, you need to add a bit of code:

Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h):
  WIDTH(w), HEIGHT(h)
{
  _width    = WIDTH;
  _height   = HEIGHT;
  rotation  = 0;
  cursor_y  = cursor_x    = 0;
  textsize  = 1;
  textcolor = textbgcolor = 0xFFFF;
  wrap      = true;
  //setFont(GFXFONT_GLCD_ASCII);  // THESE LINES SELECT THE DEFAULT FONT
  //setFont(GFXFONT_GLCD);
  setFont(GFXFONT_YOUFONT);
}

void Adafruit_GFX::setFont(uint8_t f) {
  font = f;
  switch(font) {
    case GFXFONT_GLCD:
      fontData = glcdFont;
      fontKern = 1;
      break;
    case GFXFONT_GLCD_ASCII:
      fontData = glcdFont_ascii;
      fontKern = 1;
      break;
    case GFXFONT_YOURFONT:    // ADD A CASE STATEMENT FOR EACH NEW FONT
      fontData = yourfont;
      fontKern = 1;
      break;
    default:
      font = GFXFONT_GLCD;
      fontData = glcdFont;
      fontKern = 1;
      break;
  }

And that should do it! If I can get a darn font working, I'll post everything on my github.

1 Like

@peekay123 Thank you very much! I’ll give it a shot and report back.

@peekay123

I spent alittle bit today trying to get it up and working but I don’t have a good understanding of how I should rig up the code to get it all work together. I’m short on time also with other work I have to going on but I really want to get this working.

I was trying to generate a GLCD font library by using http://www.mikroe.com/glcd-font-creator/

I was specifically trying to create a library out of the Agency FB Font in 11 Size. I’m just getting confused on where to put the font width and height numbers so the new code knows how to correctly display the new larger font.

If you can get it working I’ll give ya $200 and you pick out what you want and I’ll have it mailed to you. I which I had more time to try to figure it out but I don’t right now.

I also emailed the guy who wrote that Font Article that @BKO posted to see if he might be able to help out.

@BDub @BDub1 You still around? Can you make any sense of this?

RWB, if I get this working you can donate the $200 to a charity. :wink:

1 Like

@RWB, so I got things working after realizing the code has major flaws! I even loaded your font but there are problems. Because the code assume fixed font sizes, the spacing on the fonts looks way to large. Normally, you would have per-character spacing data to do spacing properly but no such luck.

I found another (older) library for the Sharp Memory display that DOES uses font metrics. I may be able to adapt the code to the Adafruit_GFX library though it may take some time. Or I could simply port that library and use it instead. Your thoughts?

So very busy! Sorry buddy :smile: 12:30am time to sleep before I feel like crap again tomorrow for staying up til 1am last night.

@peekay123 Yea man you get this problem solved for me and I'll send the $200 where ever you want it to go :smiley:

So it works except for the font spacing? Or it has more issues than that?

Yea I'm all for what ever works. Would we be able to use multiple fonts with this other option? I have plenty of memory to work with so thats not a problem.