Click here to read Part 1 of this article >

tft lcd

In Part 1, we were able to obtain and display values from KX022-1020 accelerometer on the TFT LCD panel. In Part 2, we’ll show how to control the TFT monitor while reading the contents of the program!

Today’s Electronic Recipe

Estimated time to complete: 60 minutes

Parts needed:

Rohm sensor evaluation kit can be purchased from the following site!

Chip One Stop

Mouser Electronics

 

Displaying on TFT LCD monitor with Arduino

As before, we’ll be using SainSmart ST7735R TFT monitor. It’s a compact LCD display that can be used both with Arduino and Raspberry Pi. The monitor has a built-in microSD card slot, so it’s possible to store and load images, in addition to reading and writing data. In this tutorial, we will only try to display values on the TFT monitor.

Let’s get started! First, connect TFT monitor to Arduino.

tft lcd

Figure 1. SainSmart ST7735R TFT monitor

tft lcd

Figure 2. Backside of TFT monitor

TFT Pins:

  • VCC – Correction Voltage
  • GND – Ground
  • SCL – Serial Clock Line
  • SDA – Serial Data Line
  • RS / DC – Command / Data Selection
  • RES – LCD Controller Reset
  • CS – Chipselect for TF Card

After connecting the Arduino to the TFT monitor, try running the sample program.

 

Apply TFT Monitor library for Arduino

As we mentioned in Part 1, we need to make a small change to the library file (ST7735R) to use this TFT monitor with Arduino.

SainSmart 1.8 ST7735R TFT LCD Module with MicroSD LED Backlight For Arduino

Raspberry Pi library (ST7735R V0.2)

There is a download link at the bottom of the page from the above URL. Click on the link labeled “Download Link” from the page to download a complete set of libraries, sample code, documentation, etc. After the download is complete, decompress the compressed file and rewrite the necessary files.

After opening “ST7735.h” with an editor that can edit text, change the part shown in the picture below. You can also use Arduino IDE.

tft lcd

Once you made the change, compile the unzipped “TFT 18” directory with zip again, add it as a library in Arduino (or Arduino Create) Add Library, or place it under the “libraries” directory in Arduino’s installed directory and load the library.

When it’s complete, try moving “TFT 18” – “graphictest” from the sketch sample.

When you look at the sample program, you can see that it’s displayed quite smoothly.

Sample program – graphictest

The following are the main functions of the TFT monitor:

tft.drawPixel(x,y,color); – Dots of the specified color (color) are displayed at the specified position (x, y).

tft.drawCircle(x, y, radius, color); – Draws a circle with the radius (radius) specified at the specified position (x, y).

tft.fillRect(x1,y1, x2, y2, color); – Fills a rectangle with the width and height from the specified position 1 (x1, y1) to position 2 (x2, y2).

tft.drawString(x, y, text, color); – Displays text with the specified color (color) at the specified position (x, y).

tft.fillScreen(0x0000); – Fill the entire monitor with the specified color.

Although there are some other functions, you can pretty much display anything using only the above functions.

 

Graphing the accelerometer values

Next, let’s display the accelerometer values on the TFT monitor! In the case of the Sensor Evaluation Kit, basically, it’s not necessary to change the wiring on the TFT monitor side. All that is needed is to insert KX022-1020 accelerometer to the Sensor Shield.

tft lcd

Figure 3. Accelerometer and TFT monitor

Program for displaying numerical values of accelerometer:

When you run the above program, a graph of the values of the accelerometer is displayed.

A summary of the program flow:

  1. Show “DEVICE PLUS !!” character in setup
  2. Acquire the value of the accelerometer and convert it to an integer
  3. Display graphs and text based on the values

We added 1 to the x-axis for each frame so that the graph is drawn from left to right.

When it goes to the edge of the 120px display, the graph is cleared with drawrect. The numbers on the upper part are updated with drawrect for each frame in the same way.

This concludes the tutorial on how to display and graph accelerometer values using TFT LCD monitor! There are quite a few side projects we can consider developing. For example, we can combine this TFT monitor and Arduino Pro Mini to make a wristwatch featuring small games, etc. It is also possible to make a data logger using, for instance, different sensors from the Sensor Evaluation Kit.

 

Click here to read Part 1 of this article >