Example Code for Arduino-SPI Communication
Last revision 2026/01/08
This article explores Arduino-SPI communication, detailing hardware and software setups with DFRobot components. It includes a sample code that demonstrates the integration of a TFT display, providing a practical guide for enthusiasts to effectively utilize SPI interfaces in their projects.
Hardware Preparation
Software Preparation
- Click to download DFRobot_GDL library file
Wiring Diagram

| Mainboard | Pin name | screen | Pin name |
|---|---|---|---|
| Beetle RP2350 | GND | TFT display | GND |
| Beetle RP2350 | 3V3 | TFT display | VCC |
| Beetle RP2350 | 4 | TFT display | DC |
| Beetle RP2350 | 5 | TFT display | CS |
| Beetle RP2350 | 8 | TFT display | RST |
| Beetle RP2350 | 16 | TFT display | MISO |
| Beetle RP2350 | 18 | TFT display | SCK |
| Beetle RP2350 | 19 | TFT display | MOSI |
Sample Code
#define PIN_SPI0_MISO (16u)
#define PIN_SPI0_MOSI (19u)
#define PIN_SPI0_SCK (18u)
Code:
#include "DFRobot_GDL.h"
#define TFT_DC 4
#define TFT_CS 5
#define TFT_RST 8
DFRobot_ST7789_240x320_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 screen displays the character "DFRobot".
Additional Information
The SPI interface, full name Serial Peripheral Interface, is a simple, two-way serial interface developed by Motorola. It can enable the microcontroller to communicate with various peripheral devices in a serial manner to exchange information. Peripheral devices include Flash, RAM, LCD displays, A/D converters, and MCUs, etc.
The SPI communication interface pin distribution of Beetle RP2350 is as follows:
| Pin Number | SPI Function |
|---|---|
| 16 | SPI0/MISO |
| 18 | SPI0/SCK |
| 19 | SPI0/MOSI |
Was this article helpful?
