Example Code for Arduino-SPI Communication
Last revision 2026/01/18
The article explains how to establish SPI communication between an Arduino board and a TFT LCD display, using the DFRobot Beetle RP2040. It includes hardware setup, software preparation, wiring instructions, and sample code to display the text 'DFRobot' on the screen.
Hardware Preparation
- DFRobot Beetle RP2040, 1, Purchase Link
- USB Type-C Cable, 1
- Fermion: 1.8" 128x160 IPS TFT LCD Display (DFR0928), 1, Purchase Link
Software Preparation
- Arduino IDE: Download Link
- Raspberry Pi Pico/RP2040 SDK: Installed via Arduino Boards Manager (see Getting Started)
- DFRobot_GDL Library: Download Link
Wiring Diagram

- BeetleRP2040: GP0 (connect to) Display: MISO
- BeetleRP2040: GP2 (connect to) Display: SCLK
- BeetleRP2040: GP3 (connect to) Display: MOSI
- BeetleRP2040: GP4 (connect to) Display: DC
- BeetleRP2040: GP5 (connect to) Display: CS
- BeetleRP2040: GP28 (connect to) Display: RES
- BeetleRP2040: GND (connect to) Display: GND
- BeetleRP2040: 3V3 (connect to) Display: VCC
Other Preparation Work
- Open Arduino IDE.
- Select "DFRobot Beetle RP2040" as the development board.
- Connect the Beetle RP2040 to your computer.
- Wire the TFT display to SPI0 (GP0/MISO, GP1/CSn, GP2/SCK, GP3/MOSI) as per the diagram.
- Install the DFRobot_GDL library via Arduino Library Manager.
Sample Code
Function: make the LCD display connected to the SPI of the RP2040 display the text "DFRobot".
#include "DFRobot_GDL.h"
#define TFT_DC 4
#define TFT_CS 5
#define TFT_RST 28
DFRobot_ST7735_128x160_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
void setup() {
screen.begin();
screen.setTextSize(1);
screen.fillScreen(COLOR_RGB565_BLACK);
screen.setFont(&FreeMono12pt7b);
screen.setCursor(/*x=*/32,/*y=*/64);
screen.setTextColor(COLOR_RGB565_LGRAY);
screen.setTextWrap(true);
screen.print("DFRobot");
}
void loop() {
}
Result
The display shows the text "DFRobot" in the center of the screen.

Additional Information
- SPI0 uses pins GP0 (MISO), GP1 (CSn), GP2 (SCK), and GP3 (MOSI) for communication.
- The TFT display uses hardware SPI for fast data transfer.
Was this article helpful?
