ArduinoGFX Color TFT Display Guide
This guide walks you from an empty Lopaka canvas to working Arduino_GFX_Library C++ code on ESP32, ESP32-S3, or Arduino color displays. Lopaka generates the gfx-> drawing function, RGB565/XBM assets, and font includes; you configure the data bus, display constructor, pins, and application loop.
What is Arduino_GFX_Library?
Arduino_GFX (Arduino_GFX_Library by Moon On Our Nation) is a fast graphics library for color TFT, IPS, and AMOLED panels. It supports SPI, 8-bit/16-bit parallel, QSPI, and ESP32-S3 RGB parallel buses, and configures both the bus and display panel directly in your sketch rather than in an external header file.
Check the upstream Arduino_GFX wiki for supported controllers (ST7789, ILI9341, ILI9488, GC9A01, ST7701, NV3041A, CO5300, and more).
Before you start
You need:
- An ESP32, ESP32-S3, RP2040, or Arduino-compatible board and a color display supported by
Arduino_GFX_Library. - Your display controller name, bus type (SPI, QSPI, or RGB parallel), resolution, and pinout.
- Arduino IDE or PlatformIO able to compile and upload a sketch to your board.
WARNING
Lopaka does not detect your panel or generate bus constructors. Prove your wiring with an official Arduino_GFX example first before adding Lopaka output.
Step 0: Install and test Arduino_GFX
- Arduino IDE: open Tools → Manage Libraries, search for GFX Library for Arduino (
Arduino_GFX_Library), and install it. - PlatformIO: add
moononournation/GFX Library for Arduinotolib_depsinplatformio.ini.
Open File → Examples → GFX Library for Arduino → HelloWorld, uncomment the matching Arduino_DataBus and Arduino_GFX lines for your panel, and upload it. Keep that working bus and gfx constructor as the base of your sketch.
Step 1: Create the Lopaka project
- Open lopaka.app and create a project.
- Select ArduinoGFX as the platform.
- Set Screen Size to your display's logical width and height (matching any rotation parameter passed to the
Arduino_GFXconstructor). - Choose your screen background color.
Coordinates start at (0, 0) in the top-left corner, matching Arduino_GFX.
Step 2: Design a screen
Add layers from the toolbar and rename them before export. Layer names become comments, bitmap identifiers, polygon helper names, animation header names, and optional variable names.
Lopaka's ArduinoGFX generator emits these calls on the gfx pointer:
| Lopaka layer | Arduino_GFX output |
|---|---|
| Line | gfx->drawLine() |
| Rectangle | gfx->drawRect() / gfx->fillRect() |
| Rounded rectangle | gfx->drawRoundRect() / gfx->fillRoundRect() |
| Circle | gfx->drawCircle() / gfx->fillCircle() |
| Ellipse | gfx->drawEllipse() / gfx->fillEllipse() |
| Triangle | gfx->drawTriangle() / gfx->fillTriangle() |
| Polygon | Generated helper calling closed gfx->drawLine() calls (outline only) |
| Text | setTextColor(), setTextSize(), setTextWrap(false), setFont(), setCursor(), println() |
| Monochrome image | gfx->drawBitmap() with 1-bit image_<Name>_bits array |
| RGB565 image | gfx->draw16bitRGBBitmap() or gfx->draw16bitRGBBitmapWithMask() (when transparent) |
| Animation | 1-bit frame arrays plus updateAnimations() and drawAnimations() helpers |
Use the Ellipse tool for circles and ovals in the toolbar; set equal radii for a circle.
Step 3: Configure Code Settings
Open Code Settings and pick your Syntax template:
- Arduino (C++) (default): places bitmap arrays in
PROGMEM, times animations withmillis(), and emits startersetup()/loop()when animation helpers are enabled. - ESP-IDF (C++): emits plain
static const uint8_t/static const uint16_tarrays withoutPROGMEM, times animations withesp_timer_get_time()(esp_timer.h), and leaves task scheduling to your ESP-IDF app.
| Setting | What it changes for ArduinoGFX |
|---|---|
| Wrapper function | Wraps the active screen in void draw{ScreenName}(void) |
| Include fonts | Emits #include "FontName.h" for every non-default GFX font |
| Declare images | Emits 1-bit or RGB565 arrays (and 1-bit masks when transparent) |
| Include image files | Emits #include "image_<Name>_*.h" instead of inline pixel arrays |
| Animation helpers | Includes downloaded animation headers and generates drawAnimations() helpers |
| Declare variables | Declares const char* and int variables for properties toggled as dynamic |
| Comments, layer titles | Adds // <layer name> comments before draw calls |
| Clear/Fill display | Starts the draw function with gfx->fillScreen(0x...) |
Step 4: Export RGB565 images and GFX fonts
RGB565 and monochrome bitmaps
ArduinoGFX projects support both 1-bit monochrome bitmaps and 16-bit RGB565 color images:
- Monochrome icons/paint: emit
image_<Name>_bits[]andgfx->drawBitmap(x, y, ..., color). - Opaque RGB images: emit
uint16_timage_<Name>_pixels[]in high-byte RGB565 order andgfx->draw16bitRGBBitmap(). - Transparent RGB images: with Transparency enabled in the Inspector, Lopaka also emits a 1-bit MSB-first
image_<Name>_mask[]and callsgfx->draw16bitRGBBitmapWithMask().
static const uint16_t PROGMEM image_sun_pixels[] = {0xFFE0, 0xF800};
static const unsigned char PROGMEM image_sun_mask[] = {0xC0};
gfx->draw16bitRGBBitmapWithMask(16, 20, image_sun_pixels, image_sun_mask, 2, 1);Enable Include image files to keep large pixel arrays out of your .ino file and download each .h from Code Settings → Images. To convert standalone images without an account, use the free Image Converter.
Byte order note
Lopaka packs ArduinoGFX RGB565 arrays in high-byte order (0xF800 for pure red) for draw16bitRGBBitmap(). Do not copy raw RGB565 arrays directly from a TFT_eSPI export without matching byte order.
GFX fonts
The default built-in 5×7 font calls gfx->setFont(); and needs no header. Every other GFX font emits a local include such as #include "FreeSans12pt7b.h". Download every listed .h file from Code Settings → Fonts and place it in your sketch directory.
You can upload .h GFX headers, .bdf files, or .ttf / .otf / .woff fonts through Lopaka's Font Wizard, or convert standalone fonts in the free Font Converter. Text supports foreground and background colors (gfx->setTextColor(fg, bg)) and integer scale multipliers (gfx->setTextSize()). As with Adafruit GFX, text background colors apply only to the built-in 5×7 font, not custom GFX fonts.
Step 5: Copy and integrate the code
Name your screen Main, click Copy, and paste the generated code into your working Arduino_GFX sketch:
#include <Arduino_GFX_Library.h>
// Hardware-specific: replace with the bus and panel for your board.
Arduino_DataBus *bus = new Arduino_ESP32SPI(2 /* DC */, 15 /* CS */, 18 /* SCK */, 23 /* MOSI */);
Arduino_GFX *gfx = new Arduino_ST7789(bus, 4 /* RST */, 0 /* rotation */, true /* IPS */);
// BEGIN LOPAKA GENERATED CODE
void drawMain(void) {
gfx->fillScreen(0x0000);
// Title
gfx->setTextColor(0xFFFF);
gfx->setTextSize(2);
gfx->setCursor(16, 20);
gfx->println("ArduinoGFX");
// Frame
gfx->drawRoundRect(8, 8, 224, 224, 8, 0x07E0);
}
// END LOPAKA GENERATED CODE
void setup(void) {
gfx->begin();
drawMain();
}
void loop(void) {
// Update variables and redraw only when values change.
}ArduinoGFX vs. TFT_eSPI vs. Adafruit GFX
| Feature | ArduinoGFX | TFT_eSPI | Adafruit GFX |
|---|---|---|---|
| Configuration style | C++ bus + panel constructors in sketch | Compile-time User_Setup.h / build flags | Separate hardware driver library |
| ESP32-S3 RGB / QSPI | First-class support | Limited (SPI-focused) | Board-specific drivers |
| Display object syntax | Pointer (gfx->...) | Object (tft....) | Object (tft.... or display....) |
| Arc primitive in Lopaka | No | Yes (drawSmoothArc / drawArc) | No |
| Font includes in Lopaka | Local #include "Font.h" (downloadable) | Built-in FreeFonts via LOAD_GFXFF | <Fonts/Font.h> for bundled FreeFonts |
See the TFT_eSPI guide or Adafruit GFX guide if your board uses those libraries instead.
Lopaka handles vs. you handle
| Lopaka handles | You handle |
|---|---|
| Layout, coordinates, and RGB565 color packing | Installing Arduino_GFX_Library and board core |
gfx-> drawing calls and polygon helpers | Arduino_DataBus and Arduino_GFX constructors & pins |
| 1-bit XBM and RGB565 (+ 1-bit mask) bitmaps | Placing downloaded .h font/image files in your sketch |
| Arduino (PROGMEM) and ESP-IDF (C++) templates | gfx->begin(), backlight PWM, and partial redraw logic |
| Variable declarations and animation helpers | Touch/buttons, sensor reads, and screen state management |
Troubleshooting
gfx was not declared in this scope
Lopaka expects a global pointer named Arduino_GFX *gfx. Rename your display pointer to gfx or pass Arduino_GFX *gfx as a parameter to drawMain().
Missing font header (FontName.h: No such file or directory)
Open Code Settings → Fonts in Lopaka, download every .h file listed, and place them in the same folder as your .ino or .cpp file.
Colors look inverted or red and blue are swapped
Adjust the ips boolean and bgr argument in your Arduino_GFX panel constructor (for example new Arduino_ST7789(bus, RST, rotation, true)), or check gfx->invertDisplay(true).
Custom font text leaves old characters behind
gfx->setTextColor(fg, bg) only paints a background box for the built-in 5×7 font. For custom GFX fonts, clear the previous text area with gfx->fillRect() before printing the updated value.
FAQ
Why does Lopaka emit gfx-> instead of tft. for ArduinoGFX?
Arduino_GFX_Library constructs bus and display drivers dynamically as pointers (Arduino_GFX *gfx = new ...). Lopaka emits gfx-> method calls so the generated function works directly with that standard Arduino_GFX pointer pattern.
How do I include custom fonts in ArduinoGFX?
Unlike Adafruit GFX or TFT_eSPI, ArduinoGFX projects emit #include "FontName.h" for every non-default GFX font. Download each .h header from Code Settings → Fonts and place it beside your sketch, or convert TTF/BDF fonts with the free Font Converter.
Does ArduinoGFX support transparent RGB565 images?
Yes. When an RGB image has transparent pixels and Transparency is enabled in the Inspector, Lopaka generates both the 16-bit image_<Name>_pixels array and a 1-bit image_<Name>_mask array, and calls gfx->draw16bitRGBBitmapWithMask().
When should I choose ArduinoGFX over TFT_eSPI or Adafruit GFX?
Choose ArduinoGFX for ESP32-S3 RGB parallel panels, QSPI displays (such as AMOLED or round smart-knob screens), and boards where runtime C++ bus/panel construction is easier than editing TFT_eSPI's compile-time User_Setup.h. Choose TFT_eSPI for smooth arcs and TFT_eSprite workflows, or Adafruit GFX for classic multi-MCU drivers.
Does ArduinoGFX support ESP-IDF export in Lopaka?
Yes. Switch Syntax in Code Settings to ESP-IDF (C++) to omit PROGMEM, replace millis() with esp_timer_get_time(), and remove starter Arduino setup()/loop() functions.