• Post category:Nano
  • Commentaires de la publication :0 commentaire
  • Dernière modification de la publication :mars 13, 2022
  • Temps de lecture :3 min de lecture

Affichage température humidité sur TFT TZT GMT130 ST7789 *

 

 

    Prérequis :

Matériel :

  • 1 x Carte Arduino Nano
  • 1 x TFT TZT GMT130 ST7789 
  • 1 x DHT11
  • Fils de connexion
  • 1 x Breadboard

Version IDE :

Bibliothèque :

  • DHT.h
  • Adafruit_GFX.h
  • Adafruit_ST7789.h

 

 

Vidéo de démonstration :

 

Schéma de câblage :

 

Code :

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h> // Arduino SPI library

// ST7789 TFT module connections
#define TFT_CS 10
#define TFT_DC 8
#define TFT_RST 9

// Initialize Adafruit ST7789 TFT library
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup(void) {
Serial.begin(9600);
dht.begin();
tft.init(240, 240, SPI_MODE2);
tft.setRotation(2);
tft.setTextWrap(false);
tft.fillScreen(ST77XX_WHITE);
}

void loop() {
tftPrintTempHum();
}

void tftPrintTempHum() {
int h = dht.readHumidity();
float t = dht.readTemperature();
tft.setCursor(40, 80);
tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE);
tft.setTextSize(4);
tft.print(t);
tft.drawCircle(171, 85, 4, ST77XX_BLACK);
tft.drawCircle(171, 85, 5, ST77XX_BLACK);
tft.setCursor(180, 80);
tft.print("C");

tft.setCursor(100, 130);
tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE);
tft.setTextSize(3);
tft.print(h);
tft.print("%");
}

 


 

Laisser un commentaire