Hello,
I am trying to use LVGL with the Arduino GIGA R1 WiFi Board (with the GIGA Display Shield) but, especially after using the WiFi library, I keep getting crashes seemingly at random.
After debugging for some time with a simple sketch, I’ve tried to upload it to the board using the Arduino IDE and apparently everything runs fine this way.
Here’s the sketch:
#include <Arduino.h>
#include <Arduino_GigaDisplayTouch.h>
#include <Arduino_GigaDisplay_GFX.h>
#include <WiFi.h>
#include <lvgl.h>
Arduino_H7_Video display(800, 480, GigaDisplayShield);
Arduino_GigaDisplayTouch touchscreen;
lv_obj_t *networkList;
bool wiFiLoopEnabled = false;
lv_obj_t *createWiFiTile(int i) {
auto tile = lv_button_create(networkList);
lv_obj_set_size(tile, lv_pct(100), LV_SIZE_CONTENT);
lv_obj_set_style_bg_color(tile, lv_color_hex(0xFFFFFF), LV_PART_MAIN);
lv_obj_set_style_text_color(tile, lv_color_hex(0x000000), LV_PART_MAIN);
lv_obj_set_style_radius(tile, 0, LV_PART_MAIN);
auto label = lv_label_create(tile);
lv_label_set_text_fmt(label, "%s (Encryption: %d) (%ld dBm)", WiFi.SSID(i), WiFi.encryptionType(i), WiFi.RSSI(i));
lv_obj_add_event_cb(
tile,
[](auto e) {
auto i = (int)lv_event_get_user_data(e);
Serial.println(WiFi.SSID(i));
},
LV_EVENT_CLICKED,
(void *)i
);
return tile;
}
void setup() {
Serial.begin(115200);
display.begin();
touchscreen.begin();
auto screen = lv_screen_active();
lv_obj_set_style_bg_color(screen, lv_color_hex(0x003A57), LV_PART_MAIN);
lv_obj_set_flex_flow(screen, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(screen, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
auto refreshBtn = lv_button_create(screen);
lv_obj_add_flag(refreshBtn, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_style_pad_all(refreshBtn, 16, LV_PART_MAIN);
lv_obj_set_style_margin_all(refreshBtn, 8, LV_PART_MAIN);
lv_obj_add_event_cb(
refreshBtn,
[](auto e) {
auto btn = (lv_obj_t *)lv_event_get_target(e);
wiFiLoopEnabled = lv_obj_has_state(btn, LV_STATE_CHECKED);
},
LV_EVENT_CLICKED,
nullptr
);
auto refreshBtnLabel = lv_label_create(refreshBtn);
lv_label_set_text(refreshBtnLabel, LV_SYMBOL_REFRESH " Toggle scan");
networkList = lv_list_create(screen);
lv_obj_set_size(networkList, lv_pct(100), LV_SIZE_CONTENT);
lv_obj_set_style_radius(networkList, 0, LV_PART_MAIN);
lv_obj_set_style_bg_opa(networkList, 0, LV_PART_MAIN);
lv_obj_set_style_border_side(networkList, LV_BORDER_SIDE_NONE, LV_PART_MAIN);
lv_obj_set_style_pad_all(networkList, 0, LV_PART_MAIN);
}
void loop() {
lv_timer_periodic_handler();
static int time = millis();
if (millis() - time >= 250) {
time = millis();
if (wiFiLoopEnabled) {
int numNetworks = WiFi.scanNetworks();
Serial.println(numNetworks);
lv_obj_clean(networkList);
for (int i = 0; i < numNetworks; i++) {
createWiFiTile(i);
};
}
}
}
Here’s my platform.ini
file:
[env:giga_r1_m7]
platform = ststm32
board = giga_r1_m7
framework = arduino
lib_deps =
arduino-libraries/Arduino_GigaDisplay@^1.0.2
The sketch draws a button that toggles an infinite scan of WiFi networks: when the scan is done a button is created for each network found.
If I run the sketch with PlatformIO, after I start scanning for networks, the sketch will randomly crash between less than a second to a few seconds, but the scan still works (everything is still properly displayed).
If I run the sketch with Arduino IDE though, the sketch seems to never crash and everything works as it should.
What am I doing wrong? And why does everything seem to work when using the Arduino IDE?
Thanks