vroland / epdiy

EPDiy is a driver board for affordable e-Paper (or E-ink) displays.
https://vroland.github.io/epdiy-hardware/
GNU Lesser General Public License v3.0
1.3k stars 182 forks source link

Crashed when used in conjunction of NimBLE-Arduino + Wi-Fi #356

Closed rascove closed 1 week ago

rascove commented 1 week ago

Hi, I'm working on a PlatformIO project that requires the ESP32 (LilyGo T5 4.7) to subscribe and publish to an MQTT broker using Wi-Fi and scan nearby BLE devices, while displaying some data on the e-Paper. I'm using NimBLE-Arduino and built-in Wi-Fi libraries in conjunction with the epdiy.

If I use only two of these libraries (epdiy + Wi-Fi, epdiy + NimBLE-Arduino, or NimBLE-Arduino + Wi-Fi), the project can be successfully executed on the device, however as soon as I added all three libraries at the same time, the device keeps on rebooting. These are the source code, the configuration file, and the log from serial monitor for your reference:

#include <Arduino.h>
#include <Epd_Highlevel.h>
#include <Epdiy.h>
#include <FiraSans.h>
#include <NimBLEDevice.h>
#include <WiFi.h>

void setup()
{
    Serial.begin(115200);
    NimBLEDevice::init("");

    NimBLEScan* scanner = NimBLEDevice::getScan();

    scanner->setActiveScan(true);
    WiFi.begin("SSID", "PWD");

    while (WiFi.status() != WL_CONNECTED)
        delay(500);

    epd_init(&epd_board_lilygo_t5_47, &ED047TC1, EPD_LUT_64K);

    EpdiyHighlevelState hl = epd_hl_init(EPD_BUILTIN_WAVEFORM);
    uint8_t* fb = epd_hl_get_framebuffer(&hl);
    int cursor = 0;

    epd_clear();
    epd_write_default(&FiraSans, "Initialising...", &cursor, &cursor, fb);
    epd_poweron();
    epd_hl_update_screen(&hl, MODE_GC16, 27);
    delay(500);
    epd_poweroff();

    NimBLEScanResults foundDevices = scanner->start(10);

    Serial.print("Devices found: ");
    Serial.println(foundDevices.getCount());
}

void loop()
{
}
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
board_build.f_cpu = 240000000L
upload_speed = 921600
monitor_speed = 115200
lib_deps =
    https://github.com/vroland/epdiy.git
    h2zero/NimBLE-Arduino
build_flags =
    -DBOARD_HAS_PSRAM
    -DCONFIG_EPD_DISPLAY_TYPE_ED047TC1
    -DCONFIG_EPD_BOARD_REVISION_LILYGO_T5_47
    -DCONFIG_ESP32_WIFI_SW_COEXIST_ENABLE
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4

assert failed: epd_hl_init highlevel.c:50 (state.dirty_columns != NULL)

Backtrace: 0x40084ae1:0x3ffcd210 0x40096a6d:0x3ffcd230 0x4009cbdd:0x3ffcd250 0x400d356f:0x3ffcd380 0x400d2aee:0x3ffcd3b0 0x400e8c5e:0x3ffcd430

Thank you very much in advance.

martinberlin commented 1 week ago

Hi @rascove

I'm working on a PlatformIO project that requires the ESP32 (LilyGo T5 4.7)

You will be much better off writing an issue in their Repository. Because we do not produce this Hardware and not even their code which is based on epdiy v2 ( And as you can see here the PCB is already version 7 )

You could try the same code in a different hardware maybe. And also make some tests with the latest version of the Firmware of this repository.

rascove commented 1 week ago

Thanks for the feedback @martinberlin , I'll do that as well.

I'm posting this here because the error is caused when the EpdiyHighlevelState is being initialised, as shown in the serial log: assert failed: epd_hl_init highlevel.c:50 (state.dirty_columns != NULL).

Anyway, thank you very much and have a great day ahead.

martinberlin commented 1 week ago

Sure, but you are using a library that is from Lilygo and since long time updated here. If you switch to this repository with the latest library then esp32 version of Lilygo is still supported. (Not S3) Anyways buying a product from Lilygo is the hardware provider who should give support.

rascove commented 6 days ago

Hi @martinberlin , thanks for the response but please refer to my code and PlatformIO configuration. I'm not using LilyGo T5 library at all, in fact, I'm using this repository's own example to build the project.

martinberlin commented 6 days ago

Don't really understand why then:

include

include

Use first letter uppercase. The example code in this repositories are not like this and it won't find the include if you uppercase first letter. I will try when I find sometime your code, but I need to find my Lilygo first. I highly recommend you to switching to a v7 board though, to use the latest code using LCD Module. I've still one v7 unit available in tindie.com if you search for "epdiy"

rascove commented 6 days ago

Ah, I'm so sorry about that. I'm using Windows so the filename is not case-sensitive, and coming from Java background, it's my habit to capitalise the first letter of the library.

But thank you very much for your kind assistance, @martinberlin , I really appreciate that. Unfortunately I don't have a control for the type of e-Paper used as it was purchased by the client.

martinberlin commented 6 days ago

Also this line of the assert where it stops:

state.dirty_columns
    = heap_caps_aligned_alloc(16, epd_width() / 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);

Creates the RAM space to allocate the variable. If it's not allocated then the assert will fail. Try to locate it in PSRAM, but that will be slower, and not sure if it will work. It might be that using this combination of libraries won't work with the hardware. That's why I was suggesting to update to v7. You will need to deep debug this and check how much Heap RAM you have available, I guess this could be the most probable cause.

rascove commented 3 days ago

Hi @martinberlin ,

Sorry for the late response and thank you very much for your advice about the insufficient RAM. It gave me the idea to initialise the BLE stack in the PSRAM instead, which is already provided by the NimBLE-Arduino library. And now, all three libraries can be used altogether.

Once again, thank you very much and have a great day ahead.