1.8" 128x160 SPI LCD example for Photon

Just for reference, here is a basic working example of the ‘el cheapo’ 1.8" SPI LCD that you can get for about $6.

NOTE: the display may be so cheap that it is mismarked. The correct labels are shown in the sketch below.

Using ‘Particle Dev’ create a folder that contains everything shown below except for the INO file which you will create later.
Rename the original example to BAK to avoid confusion.
Get the libraries from https://github.com/pkourany/Adafruit_ST7735_mfGFX

Create your test file with the following code:

// A starter sketch that gets the 1.8" 128x160 TFT going.
// If it includes an SD reader, this sketch does not use it.

#define cs   A2 // Chip select, may use any unused A or D pin (Use A2 to start)
#define dc   D0 // May be listed as 'A0' instead of 'dc' on the display (must use this pin)
#define rst  NO_RST_PIN // Connect to RST on Photon regardless
// Display LED to +3.3V
// Display SCK to A3 (must use this pin)
// Display MOSI may be shown as SDA, connect to A5 (must use this pin)
// Display GND to GND
// Display VCC to +3.3V

#include "Adafruit_mfGFX.h"    // Core graphics library
#include "Adafruit_ST7735.h"   // Hardware-specific library
#include <math.h>

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); // hardware spi

void setup() {
// Setup the TFT display
// If you hold the display so the connector is facing right and screen is up,
// the bottom left corner is 0,0
// X is the vertical axis
// Y is the horizontal axis
// Width is X (the narrow side)
// Height is Y (the wide side)
// (Everything is ass-backwards by default)

// Draw the basic meter arc
    int x1 = 15; // leave space from the bottom
    int y1 = tft.height()/2; // center across the long edge
    int x2 = 0; // initialize
    int y2 = 0; // initialize
    int needleLength = 70; // length of needle (hypotenuse of triangle)
    tft.drawCircle(x1, y1, needleLength + 5, ST7735_YELLOW); // draw a big circle to start an arc
    tft.fillRect(0, 0, x1+30, tft.height(), ST7735_BLACK); // erase bottom part of circle
    tft.fillRect(0, 0, x1+tft.width(), 30, ST7735_BLACK); // erase left part of circle
    tft.fillRect(0, tft.height()-30, tft.width(), tft.height(), ST7735_BLACK); // erase right part of circle

// Add some labels
    tft.setCursor(80, 25);
    tft.print ("0");

    tft.setCursor(80, 128);
    tft.print ("100");

// Draw the needle
// This is just a test that draws a moving needle.
    for (y2 = - needleLength + 30; y2 < needleLength +1 -30; y2++){
    x2 = sqrt (pow(needleLength,2) - pow(y2,2)); // calculate the X position of the needle tip
    tft.fillTriangle (x1-3,y1-3,x2+x1,y2+y1, x1+3, y1+3, ST7735_RED);
    delay (200);
    tft.fillTriangle (x1-3,y1-3,x2+x1,y2+y1, x1+3, y1+3, ST7735_BLACK);
    tft.fillCircle (x1,y1,6, ST7735_RED);

void loop() {

The test file makes a moving needle gauge.

1 Like