Adafruit GFX Library Documentation

repository·master·Indexed 25 days ago

https://github.com/adafruit/adafruit-gfx-library

A core graphics library providing common primitives such as points, lines, and circles. It serves as a base layer that must be paired with hardware-specific driver libraries and the Adafruit BusIO library to control display devices. Includes guides for using custom bitmap fonts, converting images to bitmap arrays via Image2Code or XBM, and using the fontconvert tool to transform TrueType Fonts (.ttf) into compatible header files.

Tokens
1.1K
Snippets
3
Records
8
Agent score
34%

What's inside Adafruit GFX Library

  1. Build the fontconvert executable

    master

    To build the fontconvert tool, you need to modify the makefile located in the fontconvert directory to ensure it points to the correct MinGW and Freetype paths.

    1. Open the makefile in the fontconvert folder with a text editor.
    2. Update the all, CC, CFLAGS, and LIBS definitions to match this configuration:
    all: fontconvert
    
    CC     = gcc
    CFLAGS = -Wall -I c:/mingw/include/freetype2
    LIBS   = -lfreetype
    
    fontconvert: fontconvert.c
    	$(CC) $(CFLAGS) $< $(LIBS) -o $@
    
    clean:
    	rm -f fontconvert
    1. Open the MSYS command prompt.
    2. Navigate to the fontconvert directory:
    cd /c/adafruit_gfx_library\fontconvert
    1. Run the build command:
    make

    This will generate fontconvert.exe in the fontconvert directory.

    cd /c/adafruit_gfx_library\fontconvert
    make
  2. Install Freetype Library for font conversion

    master

    The fontconvert tool requires the Freetype library to process font files.

    1. Download the latest Freetype version (e.g., freetype-2.7.tar.gz) from freetype.org.
    2. Unzip the file to C:\ and rename the folder to ft27.
    3. Open the MSYS command prompt by running C:\MinGW\msys\1.0\msys.bat.
    4. Navigate to the directory and build the library using the following commands:
    cd /c
    cd ft27
    ./configure --prefix=/mingw
    make
    make install
    1. Verify the installation by checking for a freetype2 folder inside C:\MinGW\include.
  3. Install MinGW for font conversion on Windows

    master

    To use fontconvert.c to create custom fonts on Windows, you must first install MinGW (Minimalist GNU for Windows).

    1. Download and install MinGW from MinGW.org using the "Graphical User Interface Installer".
    2. Open the MinGW Installation Manager.
    3. In the left panel, select Basic Setup.
    4. In the right panel, mark the following packages for installation:
      • mingw32-base
      • mingw-gcc-g++
      • mingw-gcc-objc
      • msys-base
    5. Go to the Installation menu and select Apply changes.
  4. Use custom bitmap fonts

    master

    The library includes a Fonts folder containing bitmap fonts. To use a custom font in your Arduino sketch:

    1. #include the corresponding header file for the font.
    2. Use the setFont() method, passing the address of the GFXfont struct.
    3. To revert to the 'classic' fixed-space bitmap font, pass NULL to setFont().
  5. Install the Adafruit GFX Library

    master

    You can install the library using one of two methods:

    Search for "Adafruit GFX" in the Arduino IDE Library Manager and install it.

    Method 2: Manual Installation

    1. Download the ZIP from the repository.
    2. Uncompress the folder and rename it to Adafruit_GFX.
    3. Ensure the folder contains Adafruit_GFX.cpp and Adafruit_GFX.h.
    4. Place the Adafruit_GFX folder into your ArduinoSketchFolder/Libraries/ directory.
    5. Restart the Arduino IDE.

    Important: You must also install the latest Adafruit BusIO library for the GFX library to function. You can find this in the Library Manager or at https://github.com/adafruit/Adafruit_BusIO.

  6. Create custom font header files

    master

    Once fontconvert.exe is built, you can convert .ttf files into header files compatible with the Adafruit GFX library.

    Use the following command syntax: ./fontconvert <input_font.ttf> <font_size> > <output_header.h>

    Example: To convert yourfonts.ttf to a 9pt font and save it to yourfonts9pt7b.h:

    ./fontconvert yourfonts.ttf 9 > yourfonts9pt7b.h

    Place the resulting .h file in your project's Fonts folder.