Skip to content

Commit 2064958

Browse files
authored
Merge pull request #6 from manuelzomer/low-power
Add Low Power Capability
2 parents 1ae793c + 1424cc8 commit 2064958

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "Arduino.h"
2+
#include "ArduinoBLE.h"
3+
#include "LowPower.h"
4+
5+
#include "nrf_power.h"
6+
#include "nrf_uarte.h"
7+
#include "nrf_uart.h"
8+
9+
void lowPower()
10+
{
11+
// Disable UARTE0 which is initially enabled by the bootloader
12+
nrf_uarte_task_trigger(NRF_UARTE0, NRF_UARTE_TASK_STOPRX);
13+
while (!nrf_uarte_event_check(NRF_UARTE0, NRF_UARTE_EVENT_RXTO)) ;
14+
NRF_UARTE0->ENABLE = 0;
15+
NRF_UART0->ENABLE = 0;
16+
17+
// Enable DCDC
18+
nrf_power_dcdcen_set(true);
19+
20+
// Turn off LED_BUILTIN
21+
digitalWrite(LED_BUILTIN, LOW);
22+
}
23+
24+
void lowPowerWait(unsigned long time)
25+
{
26+
rtos::ThisThread::sleep_for(time);
27+
}
28+
29+
void lowPowerBleWait(unsigned long time)
30+
{
31+
unsigned long timeRef = millis();
32+
while (millis() - timeRef < time) {
33+
BLE.poll(time - (millis() - timeRef));
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef _LOWPOWER_H_
2+
#define _LOWPOWER_H_
3+
4+
void lowPower();
5+
void lowPowerWait(unsigned long time);
6+
void lowPowerBleWait(unsigned long time);
7+
8+
#endif //_LOWPOWER_H_

examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "LowPower.h"
12
#include <arm_math.h>
23

34
#include <Arduino_APDS9960.h>
@@ -148,16 +149,14 @@ void setup() {
148149
BLE.addService(service);
149150
BLE.advertise();
150151

151-
digitalWrite(LED_BUILTIN, HIGH);
152+
lowPower();
152153
}
153154

154155
void loop() {
156+
BLE.poll(1000);
155157
while (BLE.connected()) {
156-
unsigned long now = millis();
157-
if (abs((long) now - (long) lastNotify) >= 100) {
158-
updateSubscribedCharacteristics();
159-
lastNotify = now;
160-
}
158+
lowPowerBleWait(100);
159+
updateSubscribedCharacteristics();
161160
}
162161
}
163162

0 commit comments

Comments
 (0)