diff --git a/esp32_readout/env.h b/esp32_readout/env.h index 4931d74..1dab3ea 100644 --- a/esp32_readout/env.h +++ b/esp32_readout/env.h @@ -40,7 +40,7 @@ /********************* BLE ********************************/ - #define BLE true + #define BLE false #if BLE #define SERVICE_UUID "9f0dfdb2-e978-494c-8f15-68dbe8d28672" #define MILLIS_UUID "abb92561-a809-453c-8c7c-71d3fff5b86e" diff --git a/esp32_readout/esp32_readout.ino b/esp32_readout/esp32_readout.ino index 6139d67..ccf6df5 100644 --- a/esp32_readout/esp32_readout.ino +++ b/esp32_readout/esp32_readout.ino @@ -54,6 +54,24 @@ void IRAM_ATTR startSleep() { esp_deep_sleep_start(); } +void reset() { + while (! nau.calibrate(NAU7802_CALMOD_INTERNAL)) { + Serial.println("Failed to calibrate internal offset, retrying!"); + delay(1000); + } + + while (! nau.calibrate(NAU7802_CALMOD_OFFSET)) { + Serial.println("Failed to calibrate system offset, retrying!"); + delay(1000); + } + + // Take 10 readings to flush out readings + for (uint8_t i=0; i<10; i++) { + while (! nau.available()) delay(1); + nau.read(); + } +} + void setup() { Serial.begin(115200); display.setup(); @@ -79,15 +97,7 @@ void setup() { nau.read(); } - while (! nau.calibrate(NAU7802_CALMOD_INTERNAL)) { - Serial.println("Failed to calibrate internal offset, retrying!"); - delay(1000); - } - - while (! nau.calibrate(NAU7802_CALMOD_OFFSET)) { - Serial.println("Failed to calibrate system offset, retrying!"); - delay(1000); - } + reset(); #if BLE // initialize the Bluetooth® Low Energy hardware @@ -123,6 +133,16 @@ void setup() { } void loop() { + if (Serial.available() != 0) { + String command = Serial.readString(); //read until timeout + command.trim(); + Serial.println(command); + if (command == "reset") { + reset(); + Serial.println("calibrated"); + } + } //wait for data available + while (!nau.available()) { delay(1); }