Example Code for Arduino-SPI Communication
Last revision 2026/01/31
This article offers detailed instructions on setting up and programming SPI communication between the FireBeetle 2 ESP32-E and an OLED display, including example code to drive the display and visualize text and numbers.
Hardware Preparation
- FireBeetle 2 ESP32-E (SKU: DFR0654) ×1
- Gravity: I2C OLED-128x64 Display(SKU: DFR0486)×1
- USB Data Cable ×1
- Dupont Wires
Software Preparation
- Download GDL library: https://github.com/DFRobot/DFRobot_GDL
Wiring Diagram

Pin Connections:
| FireBeetle 2 ESP32-E | Display |
|---|---|
| 3V3 | VCC |
| GND | GND |
| SCK | SCLK |
| MO | MOSI |
| MI | MISO |
| D6 | CS |
| D3 | RES |
| D2 | DC |
Sample Code
Drive the display via SPI to show text and numbers.
#include "DFRobot_GDL.h"
#define TFT_DC D2
#define TFT_CS D6
#define TFT_RST D3
#define TFT_BL D13
DFRobot_ST7789_240x320_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
void setup() {
Serial.begin(115200); //Init
screen.begin();
screen.setTextSize(2); //Text size is 4, range is 1-4
screen.fillScreen(COLOR_RGB565_BLACK); //Screen background color
screen.setFont(&FreeMono12pt7b); //Font format
screen.setCursor(/*x=*/10,/*y=*/120); //Starting point of text
screen.setTextColor(COLOR_RGB565_LGRAY); //Color of text
screen.print("DFRobot"); //Output text content
screen.setCursor(10,200);
screen.setTextColor(COLOR_RGB565_GREEN);
screen.setTextWrap(true);
screen.print("20220828");
}
void loop() {
}
Result
The screen displays the text "DFRobot" in white and the number "20220828" in green.
Was this article helpful?
