Skip to content

Add Low Power Capability #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/Nano33BLESenseFirmware/LowPower.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "Arduino.h"
#include "ArduinoBLE.h"
#include "LowPower.h"

#include "nrf_power.h"
#include "nrf_uarte.h"
#include "nrf_uart.h"

void lowPower()
{
// Disable UARTE0 which is initially enabled by the bootloader
nrf_uarte_task_trigger(NRF_UARTE0, NRF_UARTE_TASK_STOPRX);
while (!nrf_uarte_event_check(NRF_UARTE0, NRF_UARTE_EVENT_RXTO)) ;
NRF_UARTE0->ENABLE = 0;
NRF_UART0->ENABLE = 0;

// Enable DCDC
nrf_power_dcdcen_set(true);

// Turn off LED_BUILTIN
digitalWrite(LED_BUILTIN, LOW);
}

void lowPowerWait(unsigned long time)
{
rtos::ThisThread::sleep_for(time);
}

void lowPowerBleWait(unsigned long time)
{
unsigned long timeRef = millis();
while (millis() - timeRef < time) {
BLE.poll(time - (millis() - timeRef));
}
}
8 changes: 8 additions & 0 deletions examples/Nano33BLESenseFirmware/LowPower.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _LOWPOWER_H_
#define _LOWPOWER_H_

void lowPower();
void lowPowerWait(unsigned long time);
void lowPowerBleWait(unsigned long time);

#endif //_LOWPOWER_H_
11 changes: 5 additions & 6 deletions examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "LowPower.h"
#include <arm_math.h>

#include <Arduino_APDS9960.h>
Expand Down Expand Up @@ -148,16 +149,14 @@ void setup() {
BLE.addService(service);
BLE.advertise();

digitalWrite(LED_BUILTIN, HIGH);
lowPower();
}

void loop() {
BLE.poll(1000);
while (BLE.connected()) {
unsigned long now = millis();
if (abs((long) now - (long) lastNotify) >= 100) {
updateSubscribedCharacteristics();
lastNotify = now;
}
lowPowerBleWait(100);
updateSubscribedCharacteristics();
}
}

Expand Down