Hi guys,
After trying couple of weeks to enable all features that I need on the Arduino Nano 33 BLE Sense, I bought and tested the classic Arduino Nano 33 BLE (without Sense part) in order to try to reach all features that were verified before as successful enabled. First feature is related to very low power consumption (around 11 microAmpere) by implementing this sketch:
//Ultra Low Power blink example. Tested on Arduino nano 33 BLE board and nRF528x (Mbed OS) V1.1.6 core
//Override the default main function to remove USB CDC feature - @farome contribution
int main(void){
init();
initVariant();
//Disabling UART0 (saves around 300-500µA) - @Jul10199555 contribution
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->TASKS_STOPRX = 1;
NRF_UART0->ENABLE = 0;
*(volatile uint32_t *)0x40002FFC = 0;
*(volatile uint32_t *)0x40002FFC;
*(volatile uint32_t *)0x40002FFC = 1; //Setting up UART registers again due to a library issue
//Removing USB CDC feature
//#if defined(SERIAL_CDC)
// PluggableUSBD().begin();
// SerialUSB.begin(115200);
//#endif
setup();
for(;;){
loop();
//If you won't be using serial communication comment next line
// if(arduino::serialEventRun) arduino::serialEventRun();
}
return 0;
}
void setup(){
//pinMode(pin, OUTPUT) is already set for these 3 pins on variants.cpp
digitalWrite(LED_PWR, LOW); // @pert contribution
//Pins are currently swapped. Lower current achieved if setting both pins to HIGH
digitalWrite(PIN_ENABLE_SENSORS_3V3, LOW); //PIN_ENABLE_I2C_PULLUP - @pert contribution
digitalWrite(PIN_ENABLE_I2C_PULLUP, LOW); //PIN_ENABLE_SENSORS_3V3 - @pert contribution
}
void loop(){
delay(5*1000); //22µA USB cable, 11 µA USB cable unplugged
digitalWrite(LED_PWR, HIGH);
delay(5*1000);
digitalWrite(LED_PWR, LOW);
}
I tried the same sketch and before that I also cut the jumper (photo below) in order to decrease the current consumption even more.
After measuring, the current consumption during the sleep state is still around 300 microAmpere, which is not close to verified 11 microAmpere on this thread even if the same code was used (Setting up the arduino BLE board for low power applications [Compilation]).
//Ultra Low Power blink example. Tested on Arduino nano 33 BLE board and nRF528x (Mbed OS) V1.1.6 core
//Override the default main function to remove USB CDC feature - @farome contribution
int main(void){
init();
initVariant();
//Disabling UART0 (saves around 300-500µA) - @Jul10199555 contribution
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->TASKS_STOPRX = 1;
NRF_UART0->ENABLE = 0;
*(volatile uint32_t *)0x40002FFC = 0;
*(volatile uint32_t *)0x40002FFC;
*(volatile uint32_t *)0x40002FFC = 1; //Setting up UART registers again due to a library issue
//Removing USB CDC feature
//#if defined(SERIAL_CDC)
// PluggableUSBD().begin();
// SerialUSB.begin(115200);
//#endif
setup();
for(;;){
loop();
//If you won't be using serial communication comment next line
// if(arduino::serialEventRun) arduino::serialEventRun();
}
return 0;
}
void setup(){
//pinMode(pin, OUTPUT) is already set for these 3 pins on variants.cpp
digitalWrite(LED_PWR, LOW); // @pert contribution
//Pins are currently swapped. Lower current achieved if setting both pins to HIGH
digitalWrite(PIN_ENABLE_SENSORS_3V3, HIGH); //PIN_ENABLE_I2C_PULLUP - @pert contribution
digitalWrite(PIN_ENABLE_I2C_PULLUP, HIGH); //PIN_ENABLE_SENSORS_3V3 - @pert contribution
}
void loop(){
delay(60*1000); //22µA USB cable, 11 µA USB cable unplugged
digitalWrite(LED_PWR, HIGH);
delay(5*1000);
digitalWrite(LED_PWR, LOW);
}
I tried also to keep 3V3 and I2C PULLUP to HIGH but then the consumption is even higher.
The other reason why I ordered the Arduino Nano 33 BLE was to enable BLE begin/end cycles, which was also confirmed as enabled in this thread CordioHCILoop: properly terminate bleLoop thread by facchinm · Pull Request #92 · arduino-libraries/ArduinoBLE · GitHub. When I tried, I was able to perfom only 2 successful cycles after which my device was stuck every time. This is the code:
#include <ArduinoBLE.h>
BLEService TestService("DEAD");
BLECharacteristic TestData("BEEF", BLEIndicate | BLENotify, 2, true);
BLEDescriptor TestDescriptor("BEEF", "Test");
uint32_t genericTimer = 0;
bool wasConnected = false;
void setup(){
initBLE();
}
void loop(){
BLEDevice central = BLE.central(); // begin listening for centrals to connect
if(central){
genericTimer = millis();
while(central.connected()){
if(millis() - genericTimer >= 10000){ // Wait 10 seconds after connect
BLE.disconnect(); // Disconnect BLE
BLE.end(); // End BLE service
wasConnected = true;
}
}
}
if(wasConnected){
genericTimer = millis();
while(millis() - genericTimer <= 15000){} // Wait 15 seconds after disconnect
wasConnected = false;
initBLE();
}
}
void initBLE(void){
BLE.begin();
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
BLE.setLocalName("TestName");
BLE.setDeviceName("Test Device Name");
TestService.addCharacteristic(TestData);
TestData.addDescriptor(TestDescriptor);
BLE.addService(TestService);
BLE.setAdvertisedService(TestService);
BLE.advertise();
}
Can you maybe propose me some advice or possible solutions that can help me to achieve both goals, lowest possible current consumption during the sleep state and a bit flexible BLE implementation where I can turn on and off BLE when it's needed.
Thanks in advance! Cheers