Example Code for Arduino-Basic Graphics Display

Last revision 2026/01/29

This article guides you through setting up and coding an Arduino-based graphics display using DFRobot's Color Display Module, with comprehensive instructions and example code for creating various basic shapes.

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

The display has built-in instructions for basic graphics, which allows you to display points, lines, rectangles, circles, triangles, and other basic graphics on the display screen with simple commands, meeting various display requirements.

Except for drawing points, other basic graphics can be modified in terms of position, size, border color, fill color, etc.

#include "DFRobot_LcdDisplay.h"
DFRobot_Lcd_IIC lcd(&Wire, /*I2CAddr*/ 0x2c);

uint8_t lineId;
uint8_t rectsId;
uint8_t circlesId;
uint8_t trianglesId;
void setup(void){
    lcd.begin();
    lcd.cleanScreen();
    delay(500);
    lcd.setBackgroundColor(WHITE);
}

void loop(void){
//  // Draw a point
//  lcd.drawLPixe(120, 120, BLUE);
//  delay(1000);
//  lcd.cleanScreen();  
//  delay(200);
    
    // Draw a line
    lineId = lcd.drawLine(100, 20, 100, 100, 10, ORANGE);
    delay(1000);
    lcd.updateLine(lineId, 100, 20, 100, 300, 10, GREEN);
    delay(1000);
    lcd.deleteLine(lineId);
    delay(1000);

    // Draw a rectangle
    // Draw a rectangle with a size of 320x240 starting from the top left corner, border width of 1, random border color, no fill, fill color is blue, no rounded corners
    rectsId = lcd.drawRect(0, 0, 300, 200, 2, YELLOW, 1, BLACK, 0);
    delay(1000);
    lcd.updateRect(rectsId, 0, 0, 250, 120, 2, BLUE, 1, PURPLE, 1);
    delay(1000);
    lcd.deleteRect(rectsId);
    delay(1000);

    // Draw a circle
    // Draw a circle with a radius of 10 centered at (160,120), border width of 10, random border color, no fill
    circlesId = lcd.drawCircle(160, 120, 80, 10, RED, 0, WHITE);
    delay(1000);
    lcd.updateCircle(circlesId, 160, 120, 80, 2, RED, 1, BLUE);
    delay(1000);
    lcd.deleteCircle(circlesId);
    delay(1000);

    // Draw a triangle
    // Draw a triangle with the top center of the screen as the vertex and the bottom of the screen as the other two vertices
    trianglesId = lcd.drawTriangle(160, 0, 0, 239, 319, 239, 3, BLACK, 0, WHITE);
    delay(1000);
    lcd.updateTriangle(trianglesId, 160, 0, 0, 239, 319, 239, 3, BLACK, 1, YELLOW);
    delay(1000);
    lcd.deleteTriangle(trianglesId);
    delay(1000);
}

Result

DFR0997-Basic Graphics Display

Was this article helpful?

TOP