Example Code for Arduino-Background Color or Image Display
Last revision 2026/01/29
This article offers a complete guide for setting up and displaying background colors or images on an Arduino using I2C and UART communication modes, alongside sample code and wiring instructions.
Hardware Preparation
- DFRduino UNO R3 (SKU: DFR0216) ×1
- Gravity: I2C&UART Color Display Module (SKU: DFR0997) ×1
- PH2.0-4P cable ×1
- USB cable ×1
Software Preparation
- Download Arduino IDE: Click here to download Arduino IDE
- Download Arduino library: Click here to download DFRobot_LcdDisplay library.
- For Arduino IDE V1.8.19 (or earlier), install the library manually: How to Add a Library?
Wiring Diagram
-
I2C Communication Mode:

Pin Connection Description- Display: + Pin --- (Connect to) --- Controller: 5V
- Display: - Pin --- (Connect to) --- Controller: GND
- Display: C Pin --- (Connect to) --- Controller: SCL
- Display: D Pin --- (Connect to) --- Controller: SDA
-
UART Communication Mode:

Pin Connection Description- Display: + Pin --- (Connect to) --- Controller: 5V
- Display: - Pin --- (Connect to) --- Controller: GND
- Display: R Pin --- (Connect to) --- Controller: 5/TX
- Display: T Pin --- (Connect to) --- Controller: 4/RX
Sample Code
Set the background of the display to your preferred color or a custom image.
#include "DFRobot_LcdDisplay.h"
DFRobot_Lcd_IIC lcd(&Wire, /*I2CAddr*/ 0x2c);
void setup(void){
lcd.begin(); // Display screen initialization
lcd.cleanScreen();
}
void loop(void)
{
lcd.setBackgroundColor(ORANGE); // Set background color
delay(1000);
lcd.setBackgroundColor(0xFF0000); // Set background color, color can also be represented in hexadecimal as 0xFF0000
delay(1000);
lcd.setBackgroundImg(0,"bgScience.png"); // 0 -> indicates the image source is the built-in storage of the display
delay(1000);
lcd.setBackgroundImg(1,"UDisk_Cat.png"); // 1 -> indicates the image source is the USB flash drive storage of the display
delay(1000);
}
Result

Was this article helpful?
