#include <Wire.h> // include Wire library (required for I2C devices)
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_ST7735.h> // include Adafruit ST7735 TFT library
// ST7735 TFT module connections
#define TFT_RST -1 // TFT RST pin is connected to NodeMCU reset pin
#define TFT_CS D8 // TFT CS pin is connected to NodeMCU pin D8 (GPIO15)
#define TFT_DC D4 // TFT DC pin is connected to NodeMCU pin D4 (GPIO2)
// initialize ST7735 TFT library with hardware SPI module
// SCK (CLK) ---> NodeMCU pin D5 (GPIO14)
// MOSI(DIN) ---> NodeMCU pin D7 (GPIO13)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
/* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial
/* Blynk credentials */
char auth[] = "********************";
/* WiFi credentials */
char ssid[] = "*******************";
char pass[] = "******************";
/* TIMER */
//#include <SimpleTimer.h>
SimpleTimer timer;
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5 // DS18B20 подключаем на D1 на плате
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp_1;
float temp_2;
char temp1_s[7];
char temp2_s[7];
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer.setInterval(2000L, getSendData);
DS18B20.begin();
DS18B20.setResolution(12);
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK); // fill screen with black color
tft.drawFastHLine(0, 10, tft.width(), ST7735_WHITE); // draw horizontal white line at position (0, 15)
tft.setTextColor(ST7735_WHITE, ST7735_BLACK); // set text color to white and black background
tft.setTextSize(1); // text size = 1
tft.setCursor(44, 0); // move cursor to position (40, 0) pixel
tft.print("KOLONNA");
tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set text color to green and black background
tft.setCursor(8, 20); // move cursor to position (8, 20) pixel
tft.print("TEMPERATURA =");
tft.fillTriangle(4, 60, 10, 41, 16, 60, ST77XX_RED); // print Triangle up symbol
tft.fillTriangle(4, 71, 10, 90, 16, 71, ST77XX_BLUE); // print Triangle down symbol
tft.drawCircle(120, 42, 2, ST7735_CYAN); // print degree symbol ( ° )
tft.drawCircle(120, 72, 2, ST7735_CYAN); // print degree symbol ( ° )
}
void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
DS18B20.requestTemperatures();
delay(2000); // wait a 2 second
//Serial.println(DS18B20.getResolution());
temp_1 = DS18B20.getTempCByIndex(0); // Sensor 0 показания для датчика 1 в цельсиях
temp_2 = DS18B20.getTempCByIndex(1); // Sensor 1 показания для датчика 2 в цельсиях
dtostrf(temp_1 , 0, 1, temp1_s);
//Serial.println(temp1_s);
dtostrf(temp_2 , 0, 1, temp2_s);
//Serial.println(temp2_s);
tft.setTextSize(3);
tft.setCursor(35, 40);
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // set text color to yellow and black background
tft.printf(temp1_s);
tft.setCursor(35, 70);
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // set text color to yellow and black background
tft.printf(temp2_s);
}
/***************************************************
Send Sensor data to Blynk
**************************************************/
void getSendData()
{
Blynk.virtualWrite(10, temp1_s); //вывод данных на виртуальный пин V10
Blynk.virtualWrite(11, temp2_s); //вывод данных на виртуальный пин V11
}