hello, im using the ESP32-S3-Touch-LCD-4.3 and wan to run this code:
#include "lv_conf.h"
#include "lvgl.h"
#include <SPI.h>
#include <MFRC522.h>
#include <TFT_eSPI.h>
#include <DHT.h>
#include "HX711.h"
lv_obj_t *label_temp;
lv_obj_t *label_hum;
lv_obj_t *label_weight;
lv_obj_t *label_color;
lv_obj_t *label_type;
// RFID Setup
#define SS_PIN 5
#define RST_PIN 22
MFRC522 mfrc522(SS_PIN, RST_PIN);
String color = "Unknown";
String type = "Unknown";
// DHT Sensor Setup
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// HX711 Setup
#define LOADCELL_DOUT_PIN 5
#define LOADCELL_SCK_PIN 6
HX711 scale;
// LCD Display Setup
TFT_eSPI tft = TFT_eSPI();
#define LV_HOR_RES 800
#define LV_VER_RES 480
// Dynamically allocated buffer
lv_color_t* buf1;
lv_color_t* buf2;
lv_display_t *disp;
// --- DISPLAY FLUSH FUNCTION ---
void my_disp_flush(lv_display_t * disp, const lv_area_t * area, unsigned char * color_p) {
uint16_t w = area->x2 - area->x1 + 1;
uint16_t h = area->y2 - area->y1 + 1;
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
// Access color directly as uint16_t
for (int i = 0; i < w * h; i++) {
uint16_t color_val = lv_color_to_u16(((lv_color_t*)color_p)[i]); // Convert lv_color_t to uint16_t
tft.pushColor(color_val);
}
tft.endWrite();
lv_disp_flush_ready(disp);
}
// --- READ RFID TAG ---
void read_RFID() {
if (mfrc522.PICC_IsNewCardPresent()) {
if (mfrc522.PICC_ReadCardSerial()) {
Serial.print("UID:");
for (int i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
mfrc522.PICC_HaltA();
update_menu_screen();
}
}
}
// --- UPDATE MENU SCREEN ---
void update_menu_screen() {
lv_label_set_text(label_color, color.c_str());
lv_label_set_text(label_type, type.c_str());
}
// --- CREATE MENU SCREEN ---
void create_menu_screen() {
lv_obj_clean(lv_scr_act());
label_color = lv_label_create(lv_scr_act());
lv_label_set_text(label_color, "Waiting...");
lv_obj_align(label_color, LV_ALIGN_TOP_LEFT, 100, 10);
label_type = lv_label_create(lv_scr_act());
lv_label_set_text(label_type, "Waiting...");
lv_obj_align(label_type, LV_ALIGN_TOP_LEFT, 100, 50);
label_temp = lv_label_create(lv_scr_act());
lv_label_set_text(label_temp, "Temperature: Waiting...");
lv_obj_align(label_temp, LV_ALIGN_TOP_LEFT, 100, 90);
label_hum = lv_label_create(lv_scr_act());
lv_label_set_text(label_hum, "Humidity: Waiting...");
lv_obj_align(label_hum, LV_ALIGN_TOP_LEFT, 100, 130);
label_weight = lv_label_create(lv_scr_act());
lv_label_set_text(label_weight, "Weight: Waiting...");
lv_obj_align(label_weight, LV_ALIGN_TOP_LEFT, 100, 170);
}
// --- UPDATE SENSOR DATA ---
void update_sensor_data() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
float weight = scale.get_units(10);
char temp_str[10], hum_str[10], weight_str[10];
snprintf(temp_str, sizeof(temp_str), "%.2f C", temp);
snprintf(hum_str, sizeof(hum_str), "%.2f %%", hum);
snprintf(weight_str, sizeof(weight_str), "%.2f g", weight);
lv_label_set_text(label_temp, temp_str);
lv_label_set_text(label_hum, hum_str);
lv_label_set_text(label_weight, weight_str);
}
// --- SETUP FUNCTION ---
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
dht.begin();
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
lv_init();
tft.begin();
tft.setRotation(1);
// Dynamically allocate buffer based on display resolution
size_t buf_size = LV_HOR_RES * LV_VER_RES * sizeof(lv_color_t);
buf1 = (lv_color_t*)malloc(buf_size);
buf2 = (lv_color_t*)malloc(buf_size);
// Initialize display
disp = lv_display_create(LV_HOR_RES, LV_VER_RES);
// Set flush callback and buffers
lv_display_set_flush_cb(disp, my_disp_flush);
lv_display_set_buffers(disp, buf1, buf2, buf_size, LV_DISPLAY_RENDER_MODE_FULL);
// Optional: Set color format if needed
lv_display_set_color_format(disp, LV_COLOR_FORMAT_NATIVE); create_menu_screen();
}
// --- LOOP FUNCTION ---
void loop() {
lv_timer_handler(); // Handle LVGL tasks
read_RFID(); // Read the RFID tag
update_sensor_data(); // Update sensor data
delay(2000); // Delay to control the update rate
}
it succesfully complies and uploads but i just get the backlight and a black screen
im wondering how to fix it and run the code propperly