Setup Guide - moh-abb/U8G2_for_Adafruit_GFX_extmem GitHub Wiki
This library is based on olikraus' U8g2_for_Adafruit_GFX library, but it relies on an external memory source (flash memory) in order to access the fonts, rather than the fonts being stored in the faster program memory.
Storing fonts on SPIFFS
SPIFFS (Serial Peripheral Interface Flash File System) is the flash storage used on boards using the ESP8266. In order to use SPIFFS, you need to initialise the interface with SPIFFS.begin()
with the "fs.h
" library. You can then open a file (using a binary format, not text) and pass the file to the library using setFontFile(fs::File file)
.
The binary file has the same structure as it would be stored in memory. This means that a simple program that prints out the byte values of each byte in the font (uint8_t*
) array to a binary (preferably .bin) file, could be used in order to convert the .c file given by bdfconv (see the u8g2 library for more information) into a binary format that the library can use.
For example, you can use a program that converts this type of document:
/*
Fontname: -Misc-Fixed-Medium-R-Normal--6-60-75-75-C-40-ISO10646-1
Copyright: Public domain font. Share and enjoy.
Glyphs: 18/919
BBX Build Mode: 0
*/
const uint8_t u8g2_font_4x6_tn[154] U8G2_FONT_SECTION("u8g2_font_4x6_tn") =
"\22\0\2\2\2\3\2\4\4\3\6\0\377\5\377\5\377\0\0\0\0\0} \4\300f*\7WdR"
"\265\32+\10W\344bZ\61\1,\6\312\343\24\0-\5Ge\6.\5ed\2/\7Wd\253\62"
"\2\60\10W\344\252\241*\0\61\7W\344\222\254\6\62\7W\344\232)\15\63\10Wdf\312`\1\64"
"\10Wd\222\32\261\0\65\10WdF\324`\1\66\7W\344\246j\1\67\10Wdf*#\0\70\7"
"W\344Vk\1\71\7W\344Zr\1:\6qdb\0\0\0\0\4\377\377\0";
to a binary file with the values:
00010010 00000000 00000010 00000010 00000010 00000011 00000010 00000100 00000100 00000011 00000110 ... ... 00000100 11111111 11111111 00000000
You could do this by copying and pasting the font file and modifying the name of the array from
const uint8_t u8g2_font_4x6_tn[154] U8G2_FONT_SECTION("u8g2_font_4x6_tn")
to const uint8_t font[154]
, which you could then pass to this program:
void main()
{
unsigned int FONT_SIZE = 154;
FILE* printfile;
printfile = fopen("output.bin", "wb");
for (unsigned int i = 0; i < FONT_SIZE; i++) {
fwrite(&(font[i]), 1, 1, printfile);
}
fclose(printfile);
}