How to sleep Arduino Nano BLE 33…
Arduino Nano BLE 33… (sense or nonsense :-) ) is based on mBed stack and it is not compatible with some Arduino standard library.
One of these is the sleep library (avr/sleep.h and avr/power.h ).
In order to put to sleep the Nano BLE, reducing current to 1mA at maximum, you can use mBed (NRF) register directly.
Here is an example:
void setup() {
pinMode(2, INPUT_PULLUP);
attachInterrupt(2,interrupt,FALLING);pinMode(LED_BUILTIN,OUTPUT);}void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(10000);
digitalWrite(LED_BUILTIN, LOW);
go_to_sleep();
}void go_to_sleep(){
pinMode(PIN_ENABLE_SENSORS_3V3, OUTPUT);
pinMode(PIN_ENABLE_I2C_PULLUP, OUTPUT);
digitalWrite(PIN_ENABLE_SENSORS_3V3, LOW); // turn off sensors
digitalWrite(PIN_ENABLE_I2C_PULLUP, LOW);
NRF_POWER->SYSTEMOFF = 1;
}void interrupt(){
}
The function go_to_sleep() put the microcontroller in sleeping condition. It wakes up when the button on pin 2 (which is configured ad interrupt on the falling edge) is pressed.
You can configure the button on pin 2 as turnoff/on for the entire system.
Please consider that BLE can be automatically disconnected when you put the system on sleep mode.