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

Software Preparation

Wiring Diagram

  1. I2C Communication Mode:
    DFR0997-I2C wiring diagram
    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
  2. UART Communication Mode:
    DFR0997-UART wiring diagram
    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

DFR0997- Background Color or Image Display

Was this article helpful?

TOP