#include <WiFi.h>
#include <Wire.h>
#include <SPI.h>
#include <RTClib.h>
#include <GyverBME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#define TFT_CS 15
#define TFT_DC 10
#define TFT_RST 2
#define RAIN_DIGITAL_PIN 37
#define RAIN_ANALOG_PIN 36
SPIClass spi;
Adafruit_ST7789 tft = Adafruit_ST7789(&spi, TFT_CS, TFT_DC, TFT_RST);
RTC_DS3231 rtc;
GyverBME280 bme;
#define SADD 0x11
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Kolory
#define BLACK 0x0000
#define WHITE 0xFFFF
#define BLUE 0x001F
void setup() {
Serial.begin(115200);
Wire.begin(8, 9);
spi.begin(13, -1, 12, TFT_CS);
tft.init(240, 240);
tft.setRotation(2);
tft.fillScreen(BLACK);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(300);
Serial.print(".");
}
Serial.println("\nWiFi connected");
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
if (!bme.begin()) {
Serial.println("BME280 not found!");
while (1);
}
pinMode(RAIN_DIGITAL_PIN, INPUT);
pinMode(RAIN_ANALOG_PIN, INPUT);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(2);
// Stałe etykiety
tft.setCursor(10, 30); tft.print("Time: ");
tft.setCursor(10, 60); tft.print("Temp: ");
tft.setCursor(10, 90); tft.print("Hum: ");
tft.setCursor(10, 120); tft.print("Pres: ");
tft.setCursor(10, 150); tft.print("Rain: ");
tft.setCursor(10, 180); tft.print("IP: ");
}
void loop() {
DateTime now = rtc.now();
float temp = bme.readTemperature();
float hum = bme.readHumidity();
float pres = bme.readPressure() / 100.0; // hPa
int digitalValue = digitalRead(RAIN_DIGITAL_PIN);
int analogValueRaw = analogRead(RAIN_ANALOG_PIN);
float analogValueScaled = analogValueRaw / 4095.0 * 1023.0; // skalowanie do 0-1023
Wire.requestFrom(SADD, 1);
if (Wire.available()) {
// Read the data
byte data = Wire.read();
// Process the data (for example, print it)
Serial.print("Oxygen Saturation is: ");
Serial.print(data);
Serial.println("%");
}
// Ustaw kursor przy każdej wartości i nadpisz tekst
tft.setCursor(80, 30);
printTime(now);
tft.setCursor(80, 60);
tft.print(temp, 1);
tft.print(" C");
tft.setCursor(80, 90);
tft.print(hum, 1);
tft.print(" %");
tft.setCursor(80, 120);
tft.print(pres, 1);
tft.print(" hPa");
tft.setCursor(80, 150);
tft.print(analogValueScaled, 1);
tft.setCursor(10, 170);
tft.setTextColor(BLUE);
tft.setTextSize(2);
if (analogValueRaw > 700) {
Serial.println("Rain: Light");
} else if (analogValueRaw > 400) {
Serial.println("Rain: Moderate");
} else {
Serial.println("Rain: Heavy");
}
tft.setCursor(80, 150);
tft.print(analogValueRaw);
delay(500);
}
void printTime(DateTime now) {
if (now.hour() < 10)
tft.print("0");
tft.print(now.hour());
tft.print(":");
if (now.minute() < 10)
tft.print("0");
tft.print(now.minute());
tft.print(":");
if (now.second() < 10)
tft.print("0");
tft.print(now.second());
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1