Example Code for Arduino-Display Basic Shapes

Last revision 2026/01/24

This comprehensive guide explains how to display basic shapes on an Arduino using the 2.8 TFT Touch Shield, including hardware and software setup, wiring instructions, and example code implementation.

Hardware Preparation

Software Preparation

Other Preparation Work

  1. First download our DmTftLibrary from dmtftlibrary

  2. Extract the content to your Arduino library folder. In Windows this is usually located in Arduino IDE folder\libraries. Check Arduino's official guide if you want more information on how to install the Arduino Library. The official guide of Arduino

  3. Start Arduino IDE, open the sample code, click "File--> Examples-> DmTftLibraries", select the right board and COM port: DM-TFT28-105

  4. Open the Example and upload to your Arduino board.

Sample Code

Basic function could be found from the library file <libraries\DmTftLibrary\DmTftBase.h>

 #include <SPI.h>
 #include <DmTftIli9341.h>
 DmTftIli9341 tft = DmTftIli9341(10, 9);// Define the function body
 void setup ()
 {
  tft.init();
  tft.drawString(5, 10,"  Romantic cabin");//Displays a string
  int x=100,y=100;
  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 100, y-30, 20, RED );
  delay(1000);
 }
 void loop(){}

Result

DFR0347 2.8 TFT Touch Shield with 4MB Flash for Arduino and mbed Display Sample Code

Additional Information

Basic function could be found from the library file <libraries\DmTftLibrary\DmTftBase.h>

Was this article helpful?

TOP