Example Code for Arduino-Display Basic Graphics
This guide offers step-by-step instructions to create basic graphics using an Arduino-compatible board and a 3.5 TFT Resistive Touch Shield, covering hardware and software setup, wiring, and sample code for visual displays.
Hardware Preparation
- 3.5 TFT Resistive Touch Shield (SKU:DFR0348) × 1
- Arduino Compatible Board × 1
Software Preparation
- Arduino IDE (Latest Version), Download Link: https://www.arduino.cc/en/software
- DmTftLibrary, Download Link: https://bitbucket.org/displaymodule/dmtftlibrary/get/master.zip
- Arduino Library Installation Guide: https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries
Wiring Diagram
The 3.5 TFT Resistive Touch Shield connects directly on top of an Arduino pin compatible device (no additional wiring required).
Sample Code
Basic function could be found from the library file <libraries\DmTftLibrary\DmTftBase.h>
#include <SPI.h>
#include <DmTftSsd2119.h>
DmTftSsd2119 tft = DmTftSsd2119(10, 9);// Define the function body
void setup ()
{
tft.init();//Initialization screen
}
void loop()
{
tft.drawString(5, 10," Romantic cabin");//Displays a string
int x=160,y=50;
tft.drawLine (x, y, x-80, y+30, YELLOW );//Draw line
delay(1000);
tft.drawLine (x, y, x+80, y+30, YELLOW );
delay(1000);
tft.drawLine (x-60, y+25, x-60, y+160, BLUE );
delay(1000);
tft.drawLine (x+60, y+25, x+60, y+160, BLUE );
delay(1000);
tft.drawLine (x-60, y+160, x+60, y+160,0x07e0 );
delay(1000);
tft.drawRectangle(x-40, y+50,x-20, y+70, 0x8418); //Draw rectangle
delay(1000);
tft.drawRectangle(x+40, y+50,x+20, y+70, 0x07ff);
delay(1000);
tft.fillRectangle(x-20, y+100, x+20, y+160, BRIGHT_RED);//Draw fill rectangle
delay(1000);
tft.drawLine (x, y+100, x, y+160, WHITE );
delay(1000);
tft.fillCircle(x+120, y-20, 20, RED );//Draw fill Circle
delay(1000);
}
Result
The house design pattern will be displayed on the screen, as shown in the image below.
Was this article helpful?
