Example Code for Arduino-Bitmap Display

Last revision 2026/01/18

This article offers a detailed tutorial on setting up and coding an Arduino bitmap display, covering hardware preparation, software installation, wiring diagrams, and providing sample code for effective implementation.

Hardware Preparation

  • FireBeetle ESP32-E (or similar) x 1
  • 1.8Inch 128×160 TFT LCD Display with MicroSD Card Slot x1
  • Wires

Software Preparation

Wiring Diagram

The following figure shows two ways of connection: SPI and GDI.

Connection

Other Preparation Work

  1. For using GDI, please make sure your controller has GDI interface.
  2. It is recommended to use Arduino version 1.8.10 and above.
  3. If the SD card slot is not well connected, the initialization may fail, and it will succeed after unplugging and plugging again.
  4. Arduino UNO is not recommended for memory reasons.
  5. All the Demos of this product are stored in the file of DFRobot_GDL->ST7735_128x160-.
  6. Before burning the Demo, please open the corresponding substantiation function (DFRobot_ST7789_128x160_HW_SPI)

Note

Sample Code

#include "DFRobot_GDL.h"
#include "Bitmap.h"
#include "XBitmap.h"
#include "RGBBitmap.h"

/*M0*/
#if defined ARDUINO_SAM_ZERO
#define TFT_DC  7
#define TFT_CS  5
#define TFT_RST 6
/*ESP32 ESP8266*/
#elif defined(ESP32)
#define TFT_DC  D2
#define TFT_CS  D6
#define TFT_RST D3
/*ESP8266*/
#elif defined(ESP8266)
#define TFT_DC  D4
#define TFT_CS  D6
#define TFT_RST D5
/* AVR series mainboard */
#else
#define TFT_DC  2
#define TFT_CS  3
#define TFT_RST 4
#endif


DFRobot_ST7735_128x160_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
/* M0 mainboard DMA transfer */
//DFRobot_ST7735_128x160_DMA_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);


void setup() {
  Serial.begin(115200);
  screen.begin();
}

void loop() {
  screen.fillScreen(COLOR_RGB565_WHITE );
  screen.drawXBitmap(/*x=*/(screen.width()-146)/2,/*y=*/(screen.height()-128)/2,/*bitmap gImage_Bitmap=*/gImage_XBitmap,/*w=*/146,/*h=*/128,/*color=*/0x0000);
  screen.fillScreen(COLOR_RGB565_WHITE);
  screen.drawRGBBitmap(/*x=*/(screen.width()-146)/2,/*y=*/(screen.height()-128)/2,/*bitmap gImage_Bitmap=*/(const unsigned uint16_t*)gImage_RGBBitmap,/*w=*/146,/*h=*/128);
  screen.fillScreen(COLOR_RGB565_BLACK);
  for (int16_t i = 0x00ff; ; i+=0x3300) {
    screen.drawBitmap(/*x=*/(screen.width()-146)/2,/*y=*/(screen.height()-128)/2,/*bitmap gImage_Bitmap=*/gImage_Bitmap,/*w=*/146,/*h=*/128,/*color=*/i);
  }

}

Result

0928-2

Was this article helpful?

TOP