As I often do, I bought a gadget and then tried to figure out what I could do with it. The latest gadget is a tiny TFT LCD Color Display module, with a 0.96 inch diagonal screen size.
This module is available from Amazon: ST7735S 0.96 Inch TFT LCD Display Module
Even though it has connections labeled SCL and SDA, I do not believe this is an IIC (I2C) device.
I played with the examples I found online, and then tried to create my own simple sketches, I struggled with understanding the coordinates of the pixels on the display. So I wrote a sketch to help me understand them better. I thought some other hobbyist programmers, like me, could benefit from this.
I got this library from a link in the text of this web page: PMDWay Tutorial
The download link to the library zip file is: Downloads Zip of Library
This library is based on the UTFT library by Henning Karlsen.
The PDF of the Manual for Universal TFT Display is at RinkyDink Tutorial UTFT Library Manual PDF
I wrote this sketch for a Nano.
It is a static display that shows lines every 10 pixels horizontally and vertically, a single red pixel near the upper left and lower right of the display with the pixel's coordinates, and an indication of the x and y axes orientation.
Arduino pins to LCD Display
GND ----- GND (GND)
3.3V ---- Vcc (I actually used 5 VDC to power the module)
D13 ----- SCL (SPI bus clock)
D11 ----- SDA (SPI bus data out from Arduino)
D10 ----- CS (SPI bus "Chip Select")
D9 ------ DC (Data instruction select pin)
D8 ------ RES (reset input)
Note: Even though the module has an SCL and SDA connection, it is not IIC (I2C).
This is my code:
/*
Display a static display of the screen coordinates for a 0.96 TFT display.
by Steve Ullom, casual Arduino programmer.
For ST7735S 0.96 Inch TFT LCD Display Module, Screen Size 80X160 pixels.
When module is in portrait orientation physically with the connections on top,
x=0, y=0 is the top left corner. 80X160 is 80 pixels in y direction, 160 pixels in the x direction
This sketch uses the ER-TFTM0.96-1 Library
*/
#include <UTFT.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define TFT_SDA 11
#define TFT_SCL 13
// //LCD: 4Line serial interface SDA SCL CS RST DC
UTFT myGLCD(ST7735S_4L_80160,TFT_SDA,TFT_SCL,TFT_CS,TFT_RST,TFT_DC);
int x1 = 10; // Line coordinates
int x2 =10;
int y1 = 20;
int y2 = 20;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
void setup() {
Serial.begin(9600);
Serial.println("Sketch: TFT__96in_Dispplay_Coordinates.ino");
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont); //Array defined above for text.
// Draw up-down lines
myGLCD.setColor(0,255,255); // Cyan
for (int i=0;i<80;i=i+10) {
myGLCD.drawLine(10,i,20,i);
}
// Draw left-right lines
myGLCD.setColor(255,255,0); // Yellow
for (int i=0;i<160;i=i+10) {
myGLCD.drawLine(i,35,i,45);
}
// drawPixel(x,y) To show where some coordinates display on the screen
myGLCD.setColor(255,0,0); // Red
myGLCD.drawPixel(30,10); // Draw a red pixel at (y=150 from left , x=70 from top)
myGLCD.drawPixel(150,70); // Draw a red pixel at (y=150 from left , x=70 from top)
// Label the two pixels with their coordinates
myGLCD.setColor(0,255,0); // Green
myGLCD.print ("(30,10)" , 35,2, 0); // Print label for the red pixel. Must be offwet for the length of the text
myGLCD.print ("(150,70)" , 80,60, 0); // Print label for the red pixel. Must be offwet for the length of the text
// Display the axis directions
myGLCD.setColor(255,255,0); // Yellow
myGLCD.drawLine(120,5,140,5); // Draw a horizontal arrow shaft using drawLine
myGLCD.drawLine(136,1,140,5); // Draw an arrow head using drawLine
myGLCD.drawLine(136,9,140,5); // Draw an arrow head using drawLine
myGLCD.print ("x",145,1, 0); // Print label for the red pixel. Must be offwet for the length of the text
myGLCD.setColor(0,255,255); // Cyan
myGLCD.drawLine(120,5,120,25); // Draw a vertical arrow shaft using drawLine
myGLCD.drawLine(116,21,120,25); // Draw an arrow head with drawLine
myGLCD.drawLine(124,21,120,25); // Draw an arrow head with drawLine
myGLCD.print ("y",125,20, 0); // Print label for the red pixel. Must be offwet for the length of the text
}
void loop() {
}
I have a picture of the module showing the display, but I don't know how to add pictures on the forum.