Issue when using BLE and display

I’ve a AZ-Touch MOD Display connected to AZ-Delivery az-delivery-devkit-v4 ESP32. Running a more less simple config with the display enabled works fine. Same for a config with only BLE Xiaomi tracker enabled.

If I configure both Display and BLE as shown below I run into Wifi connection issue, means it will not start wifi. I’ve seen message

[16:13:07][V][esp-idf:000]: E (2583) wifi:
[16:13:07][V][esp-idf:000]: Expected to init 16 rx buffer, actual is 8
[16:14:06][V][esp-idf:000]: W (62426) wifi:
[16:14:06][V][esp-idf:000]: wifi_nvs_load: no mem

in log and also found some hints about lowering buffer as this consumes (too much) memory but no idea how to lower value in esphome?

This is the config, of course without wifi credentials:

esphome:
  name: esp32

esp32:
  board: az-delivery-devkit-v4
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:



  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32 Fallback Hotspot"
    password: "Xs6OI6sMvYXL"

esp32_ble_tracker:
sensor:
  - platform: xiaomi_hhccjcy01
    mac_address: 'C4:7C:8D:6A:3E:C9'
    temperature:
      name: "Xiaomi HHCCJCY01 Temperature"
    moisture:
     name: "Xiaomi HHCCJCY01 Moisture"
    illuminance:
      name: "Xiaomi HHCCJCY01 Illuminance"
    conductivity:
     name: "Xiaomi HHCCJCY01 Soil Conductivity"
    battery_level:
      name: "Xiaomi HHCCJCY01 Battery Level"

spi:
 clk_pin: 18
 mosi_pin: 23
 miso_pin: 19

font:
  - file: '/config/esphome/font/slkscr.ttf'
    id: font1
    size: 14
color:
  - id: my_red
    red: 100%
    green: 0%
    
image:
  - file: "img/portrait.png"
    id: my_image
    type: RGB24
    
display:
  - platform: ili9341
    model: TFT 2.4
    rotation: 270
    cs_pin: 5
    dc_pin: 4
    reset_pin: 22

    lambda: |-
      // it.image(20, 20, id(my_image));
      it.print(100, 100, id(font1), id(my_red), TextAlign::TOP_LEFT, "Hello World!");

Unfortunately I’m out of ideas how to further analyse this issue.

I think images take up a lot of room. Try removing that. And make clean.

Thanks for your reply. The Image has only 9kb and the error occurs also without the image.
Do you mean cleaning the build files with your suggestion “make clean”? I’ve done this, without success.
Also selecting a legacy esp32 board instead of (correct) az-delivery-devkit-v4 makes no difference.

Using esptool.py will interrogate how much ram etc in the chip.

Have you tried the other framework? esp-idf ESP32 Platform — ESPHome

I’ve tried esp-idf as well, unfortunately leads directly to next error:

Processing esp-03 (board: az-delivery-devkit-v4; framework: espidf; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
Tool Manager: Installing platformio/toolchain-esp32ulp @ ~1.22851.0
Error: Could not find the package with 'platformio/toolchain-esp32ulp @ ~1.22851.0' requirements for your system 'linux_aarch64'

I’ve played around with settings for board, version and platform but without success.

I assume the issue itself is related to BLE Client as stated here “The BLE software stack on the ESP32 consumes a significant amount of RAM on the device. As such, you may experience frequent crashes due to out-of-memory if you enable many other components.”

I did not really assume that only a display a some ble would use such amount of memory. Bad luck, I wanted to use the ESP32 to gather plant data and having a touchdisplay all in one.

Yeah that is a shame.

Use 2 esp32s. They are so cheap!

Anyway, what did esptool tell you?

For sure I will use 2 esp32, I already have them.

I’m not sure how esptool can assist to read used RAM? Isn’t it more or less only for flashing?

I wasn’t suggesting it for getting used ram, but for testing what the manufacturer installed.

On both ESP32 520KB RAM as exepected.

Sometimes dodgy sellers have products with less ram than the device should have. I bought some so called esp8266 d1 Mini Pros with less than the spec for a D1 Mini Pro, and it failed with being set up in esphome.

Also I have a esp32 with an ssd1326 doing BLE with two different Xiaomi devices, and both BLE and the display work fine. It has less RAM than your boards.

I got exactly the same issue with a ESP32 TTGO T-Display. Till now, I can’t solve it

I am just getting this now after enabling BT proxy on an ESP32-WROOM-32 board and ili9341 2.8" screen:

[17:27:41][D][esp32_ble_tracker:264]: Starting scan...
[17:27:41][C][wifi:037]: Setting up WiFi...
[17:27:41][D][esp-idf:000]: E (2539) wifi:
[17:27:41][D][esp-idf:000]: Expected to init 16 rx buffer, actual is 6
[17:27:41][D][esp-idf:000]: 
[17:27:41]
[17:27:41][E][WiFiGeneric.cpp:137] wifiLowLevelInit(): esp_wifi_init 257
[17:27:41][W][wifi_esp32:057]: Setting WiFi mode failed!
[17:27:41][D][wifi:384]: Starting scan...
[17:27:41][E][WiFiGeneric.cpp:137] wifiLowLevelInit(): esp_wifi_init 257
[17:27:41][W][wifi_esp32:057]: Setting WiFi mode failed!

I have no images only about 4 lines of text.
Both BT proxy and the screen work ok individually but not together.
I assume low memory on the board i.e this:
image

What boards are people using that works with both BT/screen without issues?

Wondering if anyone tried any of these with 4mb ram: D32 Pro — WEMOS documentation

Note that’s PSRAM, not SRAM on the D32. They are not the same, and PSRAM needs to be addressed separately. Not sure if PSRAM is used atm by any ESPHome component, maybe some displays or the camera can use it.
SRAM is still 320kb on models equipped with PSRAM too.
I think with SRAM 512 only ESP32-S3. or ESP32-C6. Good old ESP32 has only 320 of SRAM, regardless of who packages it.
PSRAM is different and can be different size on various boards.

To monitor memory consumption and uptime add to the config:

debug:

sensor:
- platform: template
  name: Free HEAP
  lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
  icon: "mdi:memory"
  entity_category: diagnostic
  state_class: measurement
  unit_of_measurement: "b"
  update_interval: 60s
- platform: uptime
  name: Uptime
- platform: debug
  free:
    name: Free MEM

Ok so at the moment it is not possible to have both an ili9341 and BT proxy running on the same ESP32, regardless of what version of the hardware?

No way. Too much load for one MCU.

Thanks for clarifying, was wondering if I was doing something wrong but it should work fine alongside temp/humidity, lux, motion sensors or is it too much for it too?

Looks like for now an M5stack ATOM lite will have to do until the ESP64 comes out :smile:

Simpler components work along with BT proxy, no problem. Just add the memory monitoring sensors above and see how low can you get by adding them.

I use 11 Time-Based covers, RF transmitter and BT Proxy on an Olimex, no issues.

Tried it with this ESP32 which is supposed to have 512kb memory and tried it with board: az-delivery-devkit-v4 because board: esp32dev seems to default to 320kb but still the same issue.
Maybe I need to use another board in the config?

Any way I can find out the true memory size of the board?

I ordered one of these as they are down as 532kb on the esphome github


Last chance.