This section onwards will only be for the animations, graphics and images displayed on the screen, and we start off by filling the screen with a black background and writing some text with a white colour before a 1-second delay. To end off this section, we set a delay for 500 milliseconds before moving on. Since we already started the stopwatch which counts up, we can always reset the stopwatch back to zero by using subtracting the time function with the millis() . We then fill up the TFT screen with a black colour. After that, we count up the seconds from the startup with the millis() function and store it in an unsigned 16-bit integer, named time, for use later. From there, we print the text "Initialized" as our display is now correctly set up. If your display is flipped, remove tft.setRotation(2) . In regards to the display, we address that our display module is of 240x240 resolution and we set the rotation of our display in the next line.
The void setup section is now here where we first start by begining serial communication with a baud rate of 9600 bauds and printing a test message which is "Hello! ST7789 TFT Test!". We will be using this float variable later on for graphics and calculations needed. In the next line, we initialize the Adafruit ST7789 library for use with this display and we follow that by defining the value of pi as a float variable in that next line.
In the next three lines, the RST (Reset) and DC (Data/Command) pins are defined, which are connected to A8 (analog pin 8) and A9 (analog pin 9). In the first three lines, we declare libraries for running this display, the graphics used, and for the interface used, which is the SPI interface.
This code may seem slightly intimidating at first, due to its length and much newer functions, but once it is broken down, it isn't so hard anymore. For the RES (Reset) pin, connect it up to A8 (analog pin 8) as well as the DC (Data/Command) pin to A9 (analog pin 9). Now, for the i2c connections, hook up the SCL (Serial Clock) pin of the display to A13 (analog pin 13) on the Arduino and the SDA (Serial Data) pin to A11 (analog pin 11). +5v will have a possibility to damage the display. Firstly, take a jumper wire and connect the GND pin on the display to any of your Arduino's GND pins and follow that up by connecting the VCC pin from the display to the 3v3 pin of your Arduino to supply a +3.3 volt power supply to the module. This project is fairly straightforward to set up so make sure you start by unplugging any power source feeding into your Arduino to prevent any shorts while wiring. It is a trustworthy website for ordering electronic components with cheap price and excellent quality.
1 Arduino (the Seeeduino v4.2 is used in this example).
Finally, for this project, here are the components which you will need: For the wiring, a 6-pin wiring configuration is used with the SPI interface to the Arduino, which will be shown below. The code used below is a fairly complex code at first, which showcases this display's capabilities and what it can do, in terms of functionality. It is also very easy to program, as it runs on the STT789 display, which is helpful to know, as the Adafruit ST7789 library supports this display, and is what we will be using today. Since this is a 1.3" 240x240 IPS (In-Plane Switching) TFT display module, it does offer a high-resolution colour display with fine graphics, and that is one of the things which I really enjoy about this display. This project involves yet another Arduino-compatible display which can be used as an output to display any information in the form of graphics, text or animations.