Open fabsenet opened 4 years ago
I think, the ble keyboard uses 130kb of ram, can this be true?
Serial.printf("RAM left %d\n", esp_get_free_heap_size());
bleKeyboard.begin();
delay(1000);
Serial.printf("RAM left %d\n", esp_get_free_heap_size());
yields
RAM left 139200
RAM left 8828
is there a way to reduce this?
I'm actually not sure why it is so big in size. Maybe there is some sort of memory leak in my code or the issue is actually the underlying BLE libraries. You could try this gist: https://gist.github.com/manuelbl/66f059effc8a7be148adb1f104666467
It would be nice to see how RAM usage compares.
@fabsenet Him, did you ever figure this out? I have the same experience when combining this library with others (IRRemote. PubSubCLient, ArduinoJson). I don't think this is a memory issue, rather there is a hidden interrupt somewhere in this library. @T-vK , do you have some interrupts in these libraries? The panic I receive points to this
Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)
14:05:54.619 -> Core 1 register dump:
14:05:54.619 -> PC : 0x400d2f70 PS : 0x00060034 A0 : 0x40084afc A1 : 0x3ffbe960
14:05:54.619 -> A2 : 0x00000001 A3 : 0x00000002 A4 : 0x000000ff A5 : 0x40091100
14:05:54.619 -> A6 : 0xc0100000 A7 : 0x00013ffc A8 : 0x80081648 A9 : 0x3ff5f024
14:05:54.619 -> A10 : 0x3ffbedcc A11 : 0x20000000 A12 : 0x00000400 A13 : 0x3ffdba40
14:05:54.619 -> A14 : 0x00000000 A15 : 0x3ffdba7c SAR : 0x00000018 EXCCAUSE: 0x00000007
14:05:54.619 -> EXCVADDR: 0x00000000 LBEG : 0x4000164d LEND : 0x40001667 LCOUNT : 0xfffffffc
14:05:54.664 -> Core 1 was running in ISR context:
14:05:54.664 -> EPC1 : 0x400985a6 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400d2f70
14:05:54.664 ->
14:05:54.664 -> Backtrace: 0x400d2f70:0x3ffbe960 0x40084af9:0x3ffbe980 0x400985a3:0x3ffdbaa0 0x40098d75:0x3ffdbac0 0x40087720:0x3ffdbae0 0x400ec3a1:0x3ffdbb50 0x400eac6d:0x3ffdbb70 0x400eb0bb:0x3ffdbb90 0x400eb249:0x3ffdbc00 0x400e9fb6:0x3ffdbc80 0x400e8f79:0x3ffdbce0 0x400e955d:0x3ffdbd20 0x400e0065:0x3ffdbd40 0x400e0504:0x3ffdbdb0 0x400e089a:0x3ffdbde0 0x4013831a:0x3ffdbe10 0x400dc3f6:0x3ffdbe30 0x400d89b5:0x3ffdbe70 0x400d6161:0x3ffdbea0 0x4008e99d:0x3ffdbee0
14:05:54.709 ->
This points to an interrupt issue: 14:05:54.664 -> Core 1 was running in ISR context:
I've used the BleKeyboard with a few projects without issue but my latest one has also run into a problem related to what @TheStigh was saying, where my program cant even seem to get analog reads from a couple of pins after calling begin()
. I feel it is related to an interrupt or something to that like. I've tried modifying the library to use some of the modifications @rousir has mentioned without any luck.
After calling begin()
the analog pins no longer get any reading. I'm using it with the Arduino FFT library to do a simple audio visualization. Removing the begin()
call and the program works fine.
After calling
begin()
the analog pins no longer get any reading. I'm using it with the Arduino FFT library to do a simple audio visualization. Removing thebegin()
call and the program works fine.
@jason-kong, if it doesn't crash/panic, I don't think it is interrupt issues, perhaps the pins are overrun somehow? For me, the solution was to discard the custom IRRemote library and use the official one. Now it runs smoothly.
Hello, i'm using BLECombo library derived from your library and i have the same issue, around 130kb ram used after begin(); Any news on this? Anyone know how to free memory?
I think #53 might help reduce RAM usage.
Hi @T-vK thanks for your fast reply. I just tested id and it free around 20kb of 130. Good but not not enough yet for my project. Thanks anyway!
I'm not sure if the RAM usage can be further reduced. I don't really know to figure out where it is coming from. It could be the BLE libraries, it could be the HID libraries, ... but it could also be that I'm just using them wrong.
#define USE_NIMBLE
to the top of your code, it will use the NimBLE libraries which have a much lower memory foot print to reduce memory consumption even further.If you want to use the USE_NIMBLE
option, you need to install the NimBLE library first:
Sketch -> Include Library -> Manage Libraries -> Search "NimBLE-Arduino" - > install
We still need people with Mac OS and iOS devices to test it before we can create an official release.
Hi,
I try to build a ble keyboard which is controlled via a webserver over wifi.
I had your sample script running and controlling the ble keyboard via serial. Also I had a webserver running and sending commands via web sockets. Combining both is where I fail.
Whenever I call
blekeyboard.begin()
, it crashes, when it leaves the setup() method. I decoded the stack trace:it feels to me like the ram is full, because
new
fails, but the build process shows only 11.3% used.platform.io ini file:
relevant part of my main.cpp:
and a sample serial log:
notice the spaces in the backtrace? seems wrong to me.
I do not know where I should continue at all with this.