Skip to content

Commit 272e908

Browse files
author
brentru
committed
switch to buffer, float, power saving with delay, add neopixel for viz. indicator
1 parent e3d1e19 commit 272e908

File tree

1 file changed

+61
-38
lines changed

1 file changed

+61
-38
lines changed

Wearable_BLE_Temperature_Monitor/ble_temp_monitor.ino

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,30 @@
1313
#include <Adafruit_LittleFS.h>
1414
#include <InternalFileSystem.h>
1515
#include <Wire.h>
16+
#include <Adafruit_NeoPixel.h>
1617
#include "Adafruit_MCP9808.h"
1718

1819
// Read temperature in degrees Fahrenheit
1920
#define TEMPERATURE_F
2021
// uncomment the following line if you want to read temperature in degrees Celsius
2122
// #define TEMPERATURE_C
2223

24+
// Feather NRF52840 Built-in NeoPixel
25+
#define PIN 16
26+
Adafruit_NeoPixel pixels(1, PIN, NEO_GRB + NEO_KHZ800);
27+
28+
// Maximum temperature value for armband's fever indicator
29+
// NOTE: This is in degrees Fahrenheit, please adjust
30+
float fever_temp = 100.4;
31+
32+
// offset is +0.5-1.0 degrees to make
33+
// axillary temperature comparible to ear or temporal.
34+
float temp_offset = 0.5;
35+
2336
// Sensor read timeout, in minutes
2437
// NOTE: Measuring your armpit temperature for a minimum
2538
// of 12 minutes is equivalent to measuring your core body temperature.
26-
const long interval = 60000;
27-
28-
// last time the temperature was read
29-
unsigned long prv_ms = 0;
39+
const long interval = 1;
3040

3141
// BLE Service
3242
BLEDfu bledfu; // OTA DFU service
@@ -87,47 +97,60 @@ void setup() {
8797
startAdv();
8898

8999
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
90-
Serial.println("Once connected, enter character(s) that you wish to send");
100+
101+
// initialize neopixel object
102+
pixels.begin();
103+
104+
// set all pixel colors to 'off'
105+
pixels.clear();
91106

92107
}
93108

94109
void loop() {
95110

96-
unsigned long current_ms = millis();
97-
98-
if (current_ms - prv_ms >= (1000*5)) {
99-
prv_ms = current_ms;
100-
101-
// wakes up MCP9808 - power consumption ~200 mikro Ampere
102-
Serial.println("Wake up MCP9808");
103-
tempsensor.wake();
104-
105-
// read and print the temperature
106-
Serial.print("Temp: ");
107-
#ifdef TEMPERATURE_F
108-
float temp = tempsensor.readTempF();
109-
Serial.print(temp);
110-
Serial.println("*F.");
111-
#endif
112-
113-
#ifdef TEMPERATURE_C
114-
float temp = tempsensor.readTempC();
115-
Serial.print(temp);
116-
Serial.println("*C.");
117-
#endif
118-
119-
char buffer [8];
120-
//itoa(temp, buffer, 10);
121-
snprintf(buffer, sizeof(buffer) - 1, "%0.*f", 2, temp);
122-
bleuart.write(buffer);
123-
bleuart.write("\n");
124-
125-
// shutdown MSP9808 - power consumption ~0.1 mikro Ampere
126-
// stops temperature sampling
127-
Serial.println("Shutting down MCP9808");
128-
tempsensor.shutdown_wake(1);
111+
// wakes up MCP9808 - power consumption ~200 mikro Ampere
112+
Serial.println("Wake up MCP9808");
113+
tempsensor.wake();
114+
115+
// read and print the temperature
116+
Serial.print("Temp: ");
117+
#ifdef TEMPERATURE_F
118+
float temp = tempsensor.readTempF();
119+
Serial.print(temp);
120+
Serial.println("*F.");
121+
#endif
122+
123+
#ifdef TEMPERATURE_C
124+
float temp = tempsensor.readTempC();
125+
Serial.print(temp);
126+
Serial.println("*C.");
127+
#endif
128+
129+
// add temp_offset
130+
temp += temp_offset;
131+
132+
if (temp >= fever_temp) {
133+
pixels.setPixelColor(1, pixels.Color(255, 0, 0));
134+
pixels.show();
135+
}
136+
else {
137+
pixels.clear();
129138
}
130139

140+
char buffer [8];
141+
snprintf(buffer, sizeof(buffer) - 1, "%0.*f", 2, temp);
142+
bleuart.write(buffer);
143+
144+
// shutdown MSP9808 - power consumption ~0.1 mikro Ampere
145+
// stops temperature sampling
146+
Serial.println("Shutting down MCP9808");
147+
tempsensor.shutdown_wake(1);
148+
149+
// sleep for interval minutes
150+
// NOTE: NRF delay puts the MCU into a sleep mode:
151+
// (https://www.freertos.org/low-power-tickless-rtos.html)
152+
delay(1000*60*interval);
153+
131154
}
132155

133156

0 commit comments

Comments
 (0)