Hello everyone,
I'm currently working on a project involving an Arduino Nano ESP32 to create a remote control that communicates via Bluetooth BLE. The communication works perfectly, but I'm facing an issue with the startup speed of the board.
When a button is pressed, I wake up the Arduino, send data to my LED driver (also an Arduino Nano ESP32), and then enter deep sleep mode until the next button press. However, there is a small RGB LED animation during startup (likely due to the bootloader), which takes about 1 second. This 1-second delay is noticeable and quite long for my application.
I've been trying for several days to find a solution to modify the bootloader or any other method to reduce or eliminate this delay, but I haven't had any luck.
Has anyone experienced something similar or have any suggestions on how to address this startup delay issue?
Any help would be greatly appreciated!
Thank you in advance!
Here is my code :
#include "driver/rtc_io.h"
#include <ArduinoBLE.h>
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // GPIO_NUMBER in hex
#define GPIO_5 GPIO_NUM_5 // Only RTC IO are allowed - ESP32 Pin example
#define GPIO_6 GPIO_NUM_6 // Only RTC IO are allowed - ESP32 Pin example
#define GPIO_7 GPIO_NUM_7 // Only RTC IO are allowed - ESP32 Pin example
// Define bitmask for multiple GPIOs
uint64_t bitmask = BUTTON_PIN_BITMASK(GPIO_5) | BUTTON_PIN_BITMASK(GPIO_6) | BUTTON_PIN_BITMASK(GPIO_7);
int wakeUpPin = -1;
void setup() {
BLE.begin();
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
esp_log_level_set("*", ESP_LOG_ERROR);
esp_deep_sleep_disable_rom_logging();
digitalWrite(LEDR, LOW);
digitalWrite(LED_BUILTIN, LOW);
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
if(wakeup_reason == ESP_SLEEP_WAKEUP_EXT1){
int GPIO_reason = esp_sleep_get_ext1_wakeup_status();
wakeUpPin = ((log(GPIO_reason))/log(2))-4;
}
pinMode(GPIO_5, INPUT);
}
void loop() {
if(wakeUpPin > 0){
handle();
}
deepSleep();
}
void handle(){
BLEDevice peripheral;
while(!peripheral && millis() < 5000){
peripheral = BLE.available();
delay(1);
}
if(peripheral){
BLE.stopScan();
peripheral.connect();
peripheral.discoverAttributes();
BLECharacteristic onCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214");
BLECharacteristic offCharacteristic = peripheral.characteristic("19b10002-e8f2-537e-4f6c-d104768a1214");
BLECharacteristic detectCharacteristic = peripheral.characteristic("19b10003-e8f2-537e-4f6c-d104768a1214");
if (wakeUpPin == 1) {
onCharacteristic.writeValue((byte)0x01);
delay(200);
while(digitalRead(GPIO_5)){}
onCharacteristic.writeValue((byte)0x00);
}
else if (wakeUpPin == 2) {
offCharacteristic.writeValue((byte)0x01);
delay(200);
}
else if (wakeUpPin == 3) {
detectCharacteristic.writeValue((byte)0x01);
delay(200);
}
peripheral.disconnect();
}
}
void deepSleep(){
BLE.end();
esp_sleep_enable_ext1_wakeup(bitmask, ESP_EXT1_WAKEUP_ANY_HIGH);
esp_deep_sleep_start();
}