/* Rui Santos & Sara Santos - Random Nerd Tutorials - https://RandomNerdTutorials.com/esp32-lvgl-ebook/ THIS EXAMPLE WAS TESTED WITH THE FOLLOWING HARDWARE: 1) ESP32-2432S028R 2.8 inch 240×320 also known as the Cheap Yellow Display (CYD): https://makeradvisor.com/tools/cyd-cheap-yellow-display-esp32-2432s028r/ SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/cyd-lvgl/ 2) REGULAR ESP32 Dev Board + 2.8 inch 240x320 TFT Display: https://makeradvisor.com/tools/2-8-inch-ili9341-tft-240x320/ and https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/ SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/esp32-tft-lvgl/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #define MAIN /* Install the "lvgl" library version 9.X by kisvegabor to interface with the TFT Display - https://lvgl.io/ *** IMPORTANT: lv_conf.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials *** *** YOU MUST USE THE lv_conf.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS *** FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/ */ #include /* Install the "TFT_eSPI" library by Bodmer to interface with the TFT Display - https://github.com/Bodmer/TFT_eSPI *** IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials *** *** YOU MUST USE THE User_Setup.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS *** FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/ */ #include #include "Weifi.h" #include "mqtt.h" #include "handlebme280.h" #include "grafik.h" #include "main.h" #define BMWREADTIME 10000 #define NTPREADTIME 1000 long bmeReadtimer = 0; long ntpReadtimer = 0; BME280Data bmedata; int currentSecond = -1; void showDateTime(struct tm tinfo); void setup() { // String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch(); delay (1000); String LVGL_Arduino = String("LVGL Library Version: ") + "9.0.0"; Serial.begin(115200); Serial.println(LVGL_Arduino); initBME280(); // Start LVGL setup_grafik(); Serial.println("LVGL started"); // Function to draw the GUI lv_create_main_gui(); Serial.println("Main GUI created"); setValuetoArc(arcTemp, 25.3); setValuetoArc(arcHum, 45.0); delay(1000); // Start WiFi connectToWifi(); // Start MQTT connectToMqtt(); Serial.println("MQTT started"); timeinfo = gettheTime(NTPREADTIME); showDateTime(timeinfo); bmeReadtimer = millis(); drawChart(); /* // Register print function for debugging lv_log_register_print_cb(log_print); Serial.println("Print function registered"); // Function to draw the GUI lv_create_main_gui(); Serial.println("Main GUI created"); delay(1000); mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast(connectToMqtt)); wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast(connectToWifi)); WiFi.onEvent(WiFiEvent); mqttClient.onConnect(onMqttConnect); mqttClient.onDisconnect(onMqttDisconnect); mqttClient.onSubscribe(onMqttSubscribe); mqttClient.onUnsubscribe(onMqttUnsubscribe); mqttClient.onMessage(onMqttMessage); mqttClient.setServer(MQTT_HOST, MQTT_PORT); mqttClient.setCredentials(BROKER_USER, BROKER_PASS); connectToWifi(); */ } void loop() { timeinfo = gettheTime(NTPREADTIME); if (timeinfo.tm_sec == 0) { // minute over showDateTime(timeinfo); printLocalTime(); } if (millis() - bmeReadtimer > BMWREADTIME) { bmeReadtimer = millis(); bmedata = readBME280(); setValuetoArc(arcTemp, bmedata.temp); setValuetoArc(arcHum, bmedata.hum); } lv_task_handler(); // let the GUI do its work lv_tick_inc(5); // tell LVGL how much time has passed delay(5); // let this time pass } void showDateTime(struct tm tinfo) { char time[6]; char date[50]; strftime(time, 6, "%H:%M", &tinfo); strftime(date, 50, "%A, %d %B %Y", &tinfo); lv_label_set_text(time_label, time); lv_label_set_text(date_label, date); }