Display TFT SPI ST7735
Display TFT SPI ST7735
Display TFT SPI ST7735
This is an example on how to use the 1.8" TFT 128x160 SPI ST7735 display using the
Adafruit library.
SPI pin names can be confusing. These are the alternative names for the SPI pins:
MOSI = DIN = R/W = SDO = DI = SI = MTSR = SDA = D1 = SDI
CS = CE = RS = SS
DC = A0 = DO = DOUT = SO = MRST
RESET = RST
SCLK = CLK = E = SCK = SCL = D0
Libraries needed:
https://github.com/adafruit/Adafruit-ST7735-Library
https://github.com/adafruit/Adafruit-GFX-Library
Common colors:
* BLACK 0x0000
* BLUE 0x001F
* RED 0xF800
* GREEN 0x07E0
* CYAN 0x07FF
* MAGENTA 0xF81F
* YELLOW 0xFFE0
* WHITE 0xFFFF
// Create display:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// Display setup:
// We are going to print on the display everything that is static on the setup,
to leave the loop free for dynamic elements:
// Draw triangle:
tft.drawTriangle(60,120, 70,94, 80,120, ST7735_YELLOW); // Draw triangle
(x0,y0,x1,y1,x2,y2,color)
// Draw line:
tft.drawLine(0, 125, 127, 125, ST7735_CYAN); // Draw line (x0,y0,x1,y1,color)
// Draw circle:
tft.drawCircle(15, 144, 14, ST7735_GREEN); // Draw circle (x,y,radius,color)
} // End of setup
// We are going to print on the display everything that is dynamic on the loop,
to refresh continuously:
// There is a problem when we go, for example, from 100 to 99 because it doesn't
automatically write a background on
// the last digit we are not longer refreshing. We need to check how many digits
are and fill the space remaining.
if(Variable1 < 10) // If Variable1 is less than 10...
{
// Fill the other digit with background color:
tft.fillRect(23, 67, 12, 18, ST7735_BLACK); // Draw filled rectangle
(x,y,width,height,color)
}
if(Variable1 < 100) // If Variable1 is less than 100...
{
// Fill the other digit with background color:
tft.fillRect(36, 67, 12, 18, ST7735_BLACK); // Draw filled rectangle
(x,y,width,height,color)
}
} // End of loop