Hi
I am new to embedded coding so don't be to surprised if my questions don't make sense to you experienced forum members.
I have an Arduino Nano 33 BLE Sense which I would like to put into deep sleep mode, waking periodically to read the IMU acceleration and advertise that over BLE. To start with, though, I'd like to just get the board to deep sleep and wake to toggle an LED.
I know that mbed OS will not permit the nRF to enter deep sleep mode if there are any peripheral drivers active which are using high speed clocks (timer, ticker, timeout, SPI, I2C, CAN, PWM, Serial, USB). I managed to write a sketch which puts the board to deep sleep by editing the main.cpp file to comment out the PluggableUSBD().begin(); and _SerialUSB.begin(115200); lines of code. I also had to edit wiring.cpp to comment out timer.start(); from void init().
What I would really like to do, however, is to turn those peripherals off from the Arduino IDE loop() before I call thread_sleep_for().
Can someone explain to me how I turn off peripherals from within the Arduino IDE loop()?
My test sketch is as follows:
#include <mbed.h>
static mbed::LowPowerTicker lpticker;
bool canDeepSleep;
uint32_t sleep_time_ms = 60000;
void blink() {
digitalWrite(LED_PWR, !digitalRead(LED_PWR) );
}
void setup() {
// turn off sensor power supply and I2C pullups enable
digitalWrite(PIN_PDM_PWR, LOW);
digitalWrite(PIN_ENABLE_SENSORS_3V3, LOW);
digitalWrite(PIN_ENABLE_I2C_PULLUP, LOW);
// turn on both LED_PWR and LED_BUILTIN for 1 sec
digitalWrite(LED_PWR, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
// turn off LED_BUILTIN if deep sleep is permitted
canDeepSleep = sleep_manager_can_deep_sleep();
digitalWrite(LED_BUILTIN, !canDeepSleep);
// wake from sleep every 10 sec and toggle LED_PWR state
lpticker.attach(&blink, 10.0f);
}
void loop() {
thread_sleep_for(sleep_time_ms);
}
Thanks in advance
Bob