pBLEScan locks my screen

Hello partners!

How are you? I haven’t had a problem for a few days. I will try to be as specific as possible.

I am creating a UI interface (it works correctly).
I want to add listening to advertising messages via Bluetooth (by itself it works, I listen and translate the payload correctly), in fact on a m5stick without lvgl it worked correctly.

Now I am in the problem that I have a project with a touch screen ESP32-S3 (SC01-plus), that as soon as I add pBLEScan the screen stops working.

I am creating the project with Platformio.

I am attaching relevant info, please if more information is needed to find the problem I am attaching it.

plaftormio.ini:
[env:WT32-SC01-PLUS]

platform = espressif32

board = um_tinys3

;board = esp32s3box

board_build.mcu = esp32s3

framework = arduino

upload_speed = 921600

monitor_speed = 115200

build_flags =

-DARDUINO_USB_CDC_ON_BOOT

-DLV_CONF_INCLUDE_SIMPLE

-DLV_COMP_CONF_INCLUDE_SIMPLE

-DLV_LVGL_H_INCLUDE_SIMPLE

-DCONFIG_ARDUINO_LOOP_STACK_SIZE=32768

-DBOARD_HAS_PSRAM

-mfix-esp32-psram-cache-issue

-I src/ui/

-I src/

lib_deps =

SPI

Wire

lovyan03/LovyanGFX@^1.1.8

lvgl/lvgl@^8.3.7

me-no-dev/AsyncTCP@^1.1.1

arduino-libraries/ArduinoBLE@^1.2.3

;h2zero/NimBLE-Arduino@^1.4.0

board_upload.flash_size = 16MB

board_build.partitions = default_16MB.csv

main.cpp:
#define LGFX_USE_V1
#include <Arduino.h>
#include <WebServer.h>
#include <LovyanGFX.hpp>
#include “stdio.h”
#include “WiFi.h”
#include “webserver_setup.h”

#include <BLEDevice.h>
#include <BLEAdvertisedDevice.h>
#include <Wire.h>

BLEScan* pBLEScan;

// Crear una instancia de WebServer
//WebServer server(80);

void decodePayload(const uint8_t* payload, size_t payloadLength) {
if (payloadLength < 5) {
return;
}

if (payload[0] != 0x52 || payload[1] != 0x41 || payload[2] != 0x50 || payload[3] != 0x54 || payload[4] != 0x02) {
return;
}

uint16_t rawTemperature = (payload[11] << 8) | payload[12];
float temperature = (float)(rawTemperature / 128.0 - 273.15);

union FloatIntUnion {
uint32_t i;
float f;
};
FloatIntUnion data;
data.i = (payload[13] << 24) | (payload[14] << 16) | (payload[15] << 8) | payload[16];
float gravity = data.f;

uint8_t batteryPercentage = *(payload + 23);

Serial.printf(“Temp: %.2f C\n”, temperature);
Serial.printf(“Gravedad: %.3f\n”, gravity);
Serial.printf(“Bateria: %d %%\n”, batteryPercentage);
Serial.print("Payload sin tratar: “);
for(int i = 0; i < payloadLength; i++){
Serial.print(payload[i], HEX);
Serial.print(” ");
}
Serial.println();
}

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
std::string manufacturerData = advertisedDevice.getManufacturerData();
const uint8_t* payload = (const uint8_t*)manufacturerData.c_str();
size_t payloadLength = manufacturerData.length();
decodePayload(payload, payloadLength);
Serial.print("MAC del dispositivo: ");
Serial.println(advertisedDevice.getAddress().toString().c_str());

}
};

void setupBluetooth() {
BLEDevice::init(“AllBrewSensors”);
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(false);

}
// SETUP LGFX PARAMETERS FOR WT32-SC01-PLUS
class LGFX : public lgfx::LGFX_Device
{

lgfx::Panel_ST7796 _panel_instance;
lgfx::Bus_Parallel8 _bus_instance;
lgfx::Light_PWM _light_instance;
lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436

public:
LGFX(void)
{
{
auto cfg = _bus_instance.config();

  cfg.freq_write = 20000000;    
  cfg.pin_wr = 47; // pin number connecting WR
  cfg.pin_rd = -1; // pin number connecting RD
  cfg.pin_rs = 0;  // Pin number connecting RS(D/C)
  cfg.pin_d0 = 9;  // pin number connecting D0
  cfg.pin_d1 = 46; // pin number connecting D1
  cfg.pin_d2 = 3;  // pin number connecting D2
  cfg.pin_d3 = 8;  // pin number connecting D3
  cfg.pin_d4 = 18; // pin number connecting D4
  cfg.pin_d5 = 17; // pin number connecting D5
  cfg.pin_d6 = 16; // pin number connecting D6
  cfg.pin_d7 = 15; // pin number connecting D7
  //cfg.i2s_port = I2S_NUM_0; // (I2S_NUM_0 or I2S_NUM_1)

  _bus_instance.config(cfg);                    // Apply the settings to the bus.
  _panel_instance.setBus(&_bus_instance);       // Sets the bus to the panel.
}

{ // Set display panel control.
  auto cfg = _panel_instance.config(); // Get the structure for display panel settings.

  cfg.pin_cs = -1;   // Pin number to which CS is connected (-1 = disable)
  cfg.pin_rst = 4;   // pin number where RST is connected (-1 = disable)
  cfg.pin_busy = -1; // pin number to which BUSY is connected (-1 = disable)

  // * The following setting values ​​are set to general default values ​​for each panel, and the pin number (-1 = disable) to which BUSY is connected, so please try commenting out any unknown items.

  cfg.memory_width = 320;  // Maximum width supported by driver IC
  cfg.memory_height = 480; // Maximum height supported by driver IC
  cfg.panel_width = 320;   // actual displayable width
  cfg.panel_height = 480;  // actual displayable height
  cfg.offset_x = 0;        // Panel offset in X direction
  cfg.offset_y = 0;        // Panel offset in Y direction
  cfg.offset_rotation = 0;  // was 2
  cfg.dummy_read_pixel = 8;
  cfg.dummy_read_bits = 1;
  cfg.readable = true;     // was false
  cfg.invert = true;
  cfg.rgb_order = false;
  cfg.dlen_16bit = false;
  cfg.bus_shared = true; // was false something to do with SD?

  _panel_instance.config(cfg);
}

{ // Set backlight control. (delete if not necessary)
  auto cfg = _light_instance.config(); // Get the structure for backlight configuration.

  cfg.pin_bl = 45;     // pin number to which the backlight is connected
  cfg.invert = false;  // true to invert backlight brightness
  cfg.freq = 44100;    // backlight PWM frequency
  cfg.pwm_channel = 0; // PWM channel number to use (7??)

  _light_instance.config(cfg);
  _panel_instance.setLight(&_light_instance); // Sets the backlight to the panel.
}

//*
{ // Configure settings for touch screen control. (delete if not necessary)
auto cfg = _touch_instance.config();

  cfg.x_min = 0;   // Minimum X value (raw value) obtained from the touchscreen
  cfg.x_max = 319; // Maximum X value (raw value) obtained from the touchscreen
  cfg.y_min = 0;   // Minimum Y value obtained from touchscreen (raw value)
  cfg.y_max = 479; // Maximum Y value (raw value) obtained from the touchscreen
  cfg.pin_int = 7; // pin number to which INT is connected
  cfg.bus_shared = false; // set true if you are using the same bus as the screen
  cfg.offset_rotation = 0;

  // For I2C connection
  cfg.i2c_port = 0;    // Select I2C to use (0 or 1)
  cfg.i2c_addr = 0x38; // I2C device address number
  cfg.pin_sda = 6;     // pin number where SDA is connected
  cfg.pin_scl = 5;     // pin number to which SCL is connected
  cfg.freq = 400000;   // set I2C clock

  _touch_instance.config(cfg);
  _panel_instance.setTouch(&_touch_instance); // Set the touchscreen to the panel.
}

//*/
setPanel(&_panel_instance); // Sets the panel to use.
}
};

#include <lvgl.h>
#include “ui/ui.h” // this is the ui generated with lvgl / squareline editor
#include “ui_panel1.h”
#include “ui_sensores1.h”
#include “ui_densidad1.h”
#include “ui_graficas1.h”
//#include “ui_ajustes1.h”
//#include “ui_raptpill.h”
//#include “ui_ispindel.h”
//#include “ui_tilth.h”

LGFX tft;

#define screenWidth 480
#define screenHeight 320

// lv debugging can be set in lv_conf.h
//#if LV_USE_LOG != 0
/* Serial debugging */
//void my_print(const char * buf)
//{
// Serial.printf(buf);
// Serial.flush();
//}
//#endif

// create buffer for display
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[screenWidth * 10];

/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
tft.endWrite();
lv_disp_flush_ready(disp);
}

/Read the touchpad/
void my_touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) {
uint16_t touchX, touchY;
bool touched = tft.getTouch(&touchX, &touchY);
if (!touched) { data->state = LV_INDEV_STATE_REL; }
else {
data->state = LV_INDEV_STATE_PR;
data->point.x = touchX;
data->point.y = touchY;

  #if DEBUG_TOUCH !=1
  Serial.print( "Data x " ); Serial.println( touchX );
  Serial.print( "Data y " ); Serial.println( touchY );
  #endif
}

}

void setupTouchscreen() {
tft.begin();
tft.setRotation(3);
tft.setBrightness(255);

 lv_init();

//#if LV_USE_LOG != 0
// lv_log_register_print_cb( my_print ); /* register print function for debugging */
//#endif

lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * 10);

/Initialize the display/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);

/Initialize the input device driver/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touch_read;
lv_indev_drv_register(&indev_drv);

}

void setup() {
Serial.begin(115200);
setupTouchscreen();
ui_init();
setupBluetooth();
}

void loop() {

pBLEScan->start(120);
delay(5);
pBLEScan->stop();
lv_timer_handler();
delay(5);

}

Attached debug message:

Rebooting…
▒ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x420cc376
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x42033978 PS : 0x00060730 A0 : 0x8203224a A1 : 0x3fced1e0
A2 : 0x00000024 A3 : 0x3fced250 A4 : 0xc75fa831 A5 : 0x3fcab9c0
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x82031e20 A9 : 0x3fced1e0
A10 : 0x3fced258 A11 : 0x3c0dd305 A12 : 0x3c0dd30a A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000008 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000060 LBEG : 0x40056fc5 LEND : 0x40056fe7 LCOUNT : 0xffffffff

Backtrace: 0x42033975:0x3fced1e0 0x42032247:0x3fced230 0x420323cb:0x3fced290 0x42007322:0x3fced2d0 0x420379e5:0x3fced310

ELF file SHA256: d6fee5287ac5d63c

Rebooting…
▒ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x420cc376
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4

primary enable backtrace decoder in platform ini

monitor_filters = esp32_exception_decoder, default

Thank you! but since the ESP restarts I am not able to see anything in the log.

I am see the series if I remove the BLE scan. or if I only have the BLE and I see the messages correctly.

ok leave as is when you dont need see why restarts

any idea what could happen?

I managed to get more details of the errors

␀�ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x420cc376
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x42033978 PS : 0x00060730 A0 : 0x8203224a A1 : 0x3fced010
A2 : 0x00000024 A3 : 0x3fced080 A4 : 0xbaaf5a65 A5 : 0x3fcab9c8
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x82031e20 A9 : 0x3fced010
A10 : 0x3fced088 A11 : 0x3c0dd305 A12 : 0x3c0dd30a A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000008 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000060 LBEG : 0x40056fc5 LEND : 0x40056fe7 LCOUNT : 0xffffffff

Backtrace: 0x42033975:0x3fced010 0x42032247:0x3fced060 0x420323cb:0x3fced0c0 0x42007322:0x3fced100 0x420379e5:0x3fced140

#0 0x42033975:0x3fced010 in FreeRTOS::Semaphore::take(std::__cxx11::basic_string<char, std::char_traits, std::allocator >) at C:/Users/dbravo/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src/FreeRTOS.cpp:188
#1 0x42032247:0x3fced060 in BLEScan::start(unsigned int, void ()(BLEScanResults), bool) at C:/Users/dbravo/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src/BLEScan.cpp:387
#2 0x420323cb:0x3fced0c0 in BLEScan::start(unsigned int, bool) at C:/Users/dbravo/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src/BLEScan.cpp:428
#3 0x42007322:0x3fced100 in loop() at src/main.cpp:307
#4 0x420379e5:0x3fced140 in loopTask(void
) at C:/Users/dbravo/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50

1 Like