I bought two displays recently and just found your wonderful library. I've successfully identified my displays as being of the ESP32_2432S028R type and I've been trying to get them to work correctly.
#include <Arduino.h>
#include <ArduinoOTA.h>
#include "esp32_smartdisplay.h"
// LVGL Objects
static lv_obj_t *label_cds;
static lv_obj_t *label_date;
static lv_obj_t *label_ipaddress;
void display_update() {
char buffer[32];
itoa(millis(), buffer, 10);
lv_label_set_text(label_date, buffer);
lv_label_set_text(label_ipaddress, WiFi.localIP().toString().c_str());
lv_label_set_text(label_cds, String(smartdisplay_get_light_intensity()).c_str());
}
void btn_event_cb(lv_event_t *e) {
const std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
auto code = lv_event_get_code(e);
auto btn = lv_event_get_target(e);
if (code == LV_EVENT_CLICKED) {
static uint8_t cnt = 0;
cnt++;
smartdisplay_beep(1000, 50);
auto label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
void mainscreen() {
const std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
// Clear screen
lv_obj_clean(lv_scr_act());
// Create a buttom
auto btn = lv_btn_create(lv_scr_act());
lv_obj_set_pos(btn, 10, 10);
lv_obj_set_size(btn, 120, 50);
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
// Set label to Button
auto label = lv_label_create(btn);
lv_label_set_text(label, "Button");
lv_obj_center(label);
// Create a label for the date
label_date = lv_label_create(lv_scr_act());
lv_obj_set_style_text_font(label_date, &lv_font_montserrat_22, LV_STATE_DEFAULT);
lv_obj_align(label_date, LV_ALIGN_BOTTOM_MID, 0, -50);
// Create a label for the IP Address
label_ipaddress = lv_label_create(lv_scr_act());
lv_obj_set_style_text_font(label_ipaddress, &lv_font_montserrat_22, LV_STATE_DEFAULT);
lv_obj_align(label_ipaddress, LV_ALIGN_BOTTOM_MID, 0, -80);
// Create a label for the CDS Sensor
label_cds = lv_label_create(lv_scr_act());
lv_obj_set_style_text_font(label_cds, &lv_font_montserrat_22, LV_STATE_DEFAULT);
lv_obj_align(label_cds, LV_ALIGN_TOP_RIGHT, 0, 0);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
smartdisplay_init();
WiFi.begin();
// Set the time servers
configTime(0, 0, "pool.ntp.org");
mainscreen();
}
void loop() {
// put your main code here, to run repeatedly:
// Red if no wifi, otherwise green
bool connected = WiFi.isConnected();
smartdisplay_set_led_color(connected ? lv_color32_t({.ch = {.green = 0xFF}}) : lv_color32_t({.ch = {.red = 0xFF}}));
ArduinoOTA.handle();
display_update();
lv_timer_handler();
}
Having worked with displays before, this seemed to me like the width/height pixel sizes were wrong, so I switched them in esp32_smartdisplay.h
:
#ifdef ESP32_2432S028R
#define TFT_WIDTH 320 // Switched
#define TFT_HEIGHT 240 // Switched
#define ILI9431
#define ILI9431_SPI_SCLK 14
Any idea what could be causing this, and what I can do to solve it? Maybe there's some #define I can change? I looked through lv_conf.h
and esp32_smartdisplay.h
and didn't find anything that seemed useful.