Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Arduino – st7735 jak podłączyć

Wyświetlacz z procesorem ST7735 to chyba najbardziej popularny wyświetlacz do wykorzystania we własnych projektach. Informacji jest wiele ale niektóre się sprawdzają niektóre nie postanowiłem opublikować sposób podłączenia wyżej wymienionego wyświetlacza do Arduino UNO.

podlaczenie_bb

Wyświetlacz był zakupiony na stronie banggood.com  mają sporo części i akcesorium do arduino.

Pamiętajcie aby w programie który wgrywacie sprawdzić ustawienia i ustawić jak poniżej.

#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_SCLK 13
#define TFT_MOSI 11

Przykładowy program pokazujący napięcie


 

#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>


// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 10
#define TFT_RST 9 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 8

// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// Option 2: use any pins but a little slower!
#define TFT_SCLK 13 // set these to be whatever pins you like!
#define TFT_MOSI 11 // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;

void setup(void) {
 // Use this initializer if you're using a 1.8" TFT
 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab

 // Use this initializer (uncomment) if you're using a 1.44" TFT
 //tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab
 tft.fillScreen(ST7735_BLACK);
}

void loop() {
 int sensorValue = analogRead(A0);
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
 float voltage = sensorValue * (5.0 / 1023.0);
 float linia = sensorValue * (128 / 1023.0);
 // print out the value you read:
 Serial.println(voltage);
 tft.setCursor(0, 0);
 tft.setTextWrap(true);
 if (voltage < 2)
 {
 tft.setTextColor(ST7735_GREEN);
 }

 if (voltage > 2 and voltage <= 3.3)
 {
 tft.setTextColor(ST7735_YELLOW);
 }

 if (voltage > 3.3)
 {
 tft.setTextColor(ST7735_RED);
 }

 tft.setTextSize(2);
 tft.println("Napiecie:");
 tft.print(voltage);

 if (voltage < 2)
 {
 tft.fillRoundRect(0, 50, linia, 10, 0, ST7735_GREEN);
 }

 if (voltage > 2 and voltage <= 3.3)
 {
 tft.fillRoundRect(0, 50, linia, 10, 0, ST7735_YELLOW);
 }

 if (voltage > 3.3)
 {
 tft.fillRoundRect(0, 50, linia, 10, 0, ST7735_RED);
 }
 tft.print(" V");
 
 delay(500);
 tft.setCursor(0, 0);
 tft.setTextColor(ST7735_BLACK);
 tft.fillRoundRect(0, 50, linia, 10, 0, ST7735_BLACK);
 tft.println("Napiecie:");
 tft.print(voltage);
 tft.print(" V");
}