I am having problems with an Elecrow 5 inch ESP32S3 display. I have followed their Wiki tutorial ( CrowPanel ESP32 HMI 5.0-inch Display - Elecrow Wiki ), it compiles and when uploaded I have a working display. Drop downs, sliders, buttons all work. However, it crashes somewhere as it is not running the loop.
In their code, the last line of setup is Serial.println("Setup done"); and I have added Serial.println("Looping…"); at the start of the loop. No output on the serial monitor after the boot messages. I have enabled USB CDC on boot.
Boot messages are:
18:08:27.241 -> ESP-ROM:esp32s3-20210327
18:08:27.241 -> Build:Mar 27 2021
18:08:27.241 -> rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
18:08:27.241 -> SPIWP:0xee
18:08:27.241 -> mode:DIO, clock div:1
18:08:27.241 -> load:0x3fce3808,len:0x4bc
18:08:27.241 -> load:0x403c9700,len:0xbd8
18:08:27.241 -> load:0x403cc700,len:0x2a0c
18:08:27.241 -> entry 0x403c98d0
18:08:27.370 -> E (131) esp_core_dump_flash: No core dump partition found!
18:08:27.370 -> E (132) esp_core_dump_flash: No core dump partition found!
18:08:27.738 -> E (388) gpio: gpio_set_level(227): GPIO output gpio_num error
18:08:27.738 -> E (389) gpio: gpio_set_level(227): GPIO output gpio_num error
18:08:27.738 -> E (399) gpio: gpio_set_level(227): GPIO output gpio_num error
18:08:27.778 -> E (400) gpio: gpio_set_level(227): GPIO output gpio_num error
18:08:27.778 -> E (405) gpio: gpio_set_level(227): GPIO output gpio_num error
The code generated by Squareline Studio is below. I have used the libraries they provide and ESP32 2.0.15 which is the one they suggest. Any ideas would be much appreciated. Thanks.
#include <Arduino.h>
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
#include <lvgl.h>
#include <ui.h>
/*Don't forget to set Sketchbook location in File/Preferences to the path of your UI project (the parent foder of this INO file)*/
enum BoardConstants { TFT_BL = 2,
SERIAL_BAUD = 9600,
LVGL_BUFFER_RATIO = 6 };
class LGFX : public lgfx::LGFX_Device {
public:
lgfx::Bus_RGB _bus_instance;
lgfx::Panel_RGB _panel_instance;
LGFX(void) {
{
auto cfg = _bus_instance.config();
cfg.panel = &_panel_instance;
cfg.pin_d0 = GPIO_NUM_8; // B0
cfg.pin_d1 = GPIO_NUM_3; // B1
cfg.pin_d2 = GPIO_NUM_46; // B2
cfg.pin_d3 = GPIO_NUM_9; // B3
cfg.pin_d4 = GPIO_NUM_1; // B4
cfg.pin_d5 = GPIO_NUM_5; // G0
cfg.pin_d6 = GPIO_NUM_6; // G1
cfg.pin_d7 = GPIO_NUM_7; // G2
cfg.pin_d8 = GPIO_NUM_15; // G3
cfg.pin_d9 = GPIO_NUM_16; // G4
cfg.pin_d10 = GPIO_NUM_4; // G5
cfg.pin_d11 = GPIO_NUM_45; // R0
cfg.pin_d12 = GPIO_NUM_48; // R1
cfg.pin_d13 = GPIO_NUM_47; // R2
cfg.pin_d14 = GPIO_NUM_21; // R3
cfg.pin_d15 = GPIO_NUM_14; // R4
cfg.pin_henable = GPIO_NUM_40;
cfg.pin_vsync = GPIO_NUM_41;
cfg.pin_hsync = GPIO_NUM_39;
cfg.pin_pclk = GPIO_NUM_0;
cfg.freq_write = 15000000;
cfg.hsync_polarity = 0;
cfg.hsync_front_porch = 8;
cfg.hsync_pulse_width = 4;
cfg.hsync_back_porch = 43;
cfg.vsync_polarity = 0;
cfg.vsync_front_porch = 8;
cfg.vsync_pulse_width = 4;
cfg.vsync_back_porch = 12;
cfg.pclk_active_neg = 1;
cfg.de_idle_high = 0;
cfg.pclk_idle_high = 0;
_bus_instance.config(cfg);
}
{
auto cfg = _panel_instance.config();
cfg.memory_width = 800;
cfg.memory_height = 480;
cfg.panel_width = 800;
cfg.panel_height = 480;
cfg.offset_x = 0;
cfg.offset_y = 0;
_panel_instance.config(cfg);
}
_panel_instance.setBus(&_bus_instance);
setPanel(&_panel_instance);
}
};
LGFX lcd;
/*Change to your screen resolution*/
static const uint16_t screenWidth = 800;
static const uint16_t screenHeight = 480;
enum { SCREENBUFFER_SIZE_PIXELS = screenWidth * screenHeight / LVGL_BUFFER_RATIO };
static lv_color_t buf[SCREENBUFFER_SIZE_PIXELS];
#include "touch.h"
#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(const char* buf) {
Serial.printf(buf);
Serial.flush();
}
#endif
/* Display flushing */
void my_disp_flush(lv_display_t* disp, const lv_area_t* area, uint8_t* pixelmap) {
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
//if (LV_COLOR_16_SWAP) {
// size_t len = lv_area_get_size( area );
// lv_draw_sw_rgb565_swap( pixelmap, len );
//}
lcd.pushImageDMA(area->x1, area->y1, w, h, (lgfx::rgb565_t*)pixelmap);
lv_disp_flush_ready(disp);
}
//Read the touchpad
void my_touchpad_read(lv_indev_t* indev, lv_indev_data_t* data) {
if (touch_has_signal()) {
if (touch_touched()) {
data->state = LV_INDEV_STATE_PR;
//Set the coordinates
data->point.x = touch_last_x;
data->point.y = touch_last_y;
//Serial.print( "Data x :" );
//Serial.println( touch_last_x );
//Serial.print( "Data y :" );
//Serial.println( touch_last_y );
} else if (touch_released()) {
data->state = LV_INDEV_STATE_REL;
}
} else {
data->state = LV_INDEV_STATE_REL;
}
delay(15);
}
/*Set tick routine needed for LVGL internal timings*/
static uint32_t my_tick_get_cb(void) {
return millis();
}
void setup() {
Serial.begin(115200); /* prepare for possible serial debug */
//Init Display
lcd.begin();
lcd.fillScreen(TFT_BLACK);
delay(200);
lv_init();
delay(100);
touch_init();
static lv_disp_t* disp;
disp = lv_display_create(screenWidth, screenHeight);
lv_display_set_buffers(disp, buf, NULL, SCREENBUFFER_SIZE_PIXELS * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_PARTIAL);
lv_display_set_flush_cb(disp, my_disp_flush);
static lv_indev_t* indev;
indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_touchpad_read);
lv_tick_set_cb(my_tick_get_cb);
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
ui_init();
//lcd.fillScreen(TFT_BLACK);
Serial.println("Setup done");
}
void loop() {
Serial.println("Looping...");
lv_timer_handler(); /* let the GUI do its work */
delay(5);
}