From 1269bf6f0e61466fa4f1cb59548a67d3e41964ff Mon Sep 17 00:00:00 2001 From: Magnus Date: Sun, 11 Apr 2021 11:29:15 +0200 Subject: [PATCH] Set max interval for sleep + use first gyro temp --- README.md | 7 +++++-- data/config.htm | 2 +- data/config.min.htm | 2 +- src/gyro.cpp | 8 +++++++- src/gyro.h | 4 ++++ src/main.cpp | 7 +++---- src/tempsensor.cpp | 3 ++- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5865c1c..c17ab2f 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,10 @@ I started this project out of curiosity for how a motion sensor is working and s * Add support for https connections (push) - [need to reduce memory usage for this to work, gets out of memory error] * Add support for https web server (will require certificates to be created as part of build process) * Add iSpindle 3D print cradle + small PCB (what I use for my builds) -* Validate max sleep time to 70 min (max time for ESP) +* [done] Validate max sleep time to 70 min (max time for ESP) * Validate the power consumption of the device using amp meter (integrated and/or separate) -* Add option to use temperature readings from motion sensor (longer battery life) +* [done] Add option to use temperature readings from motion sensor (longer battery life) +* [done] When using temp from motion sensor the value should be the initial read or the value will not be accurate. * Testing, Testing and more testing...... # Functionallity @@ -57,6 +58,8 @@ http://gravmon.local/config.htm * This page is divided into several categories of settings. The first one contains device settings, mDNS name, temperature format, sleep interval and gyro calibration data. The interval setting is the amount of time the device will be in sleep mode between readings (interval is in seconds). To simplify this you can also see the conversion to minutes / seconds next to the input field. +* The sleep interval can be set between 10 - 3600 seconds (60 minutes). + * Calibration needs to be done or the device will not work correctly. Place the device flat on a surface with gyro up and press the calibrate button when it's stable. If no calibration data exist the device will not enter sleep-mode. ![Config - Device](img/config1.png) diff --git a/data/config.htm b/data/config.htm index 8250204..979e766 100644 --- a/data/config.htm +++ b/data/config.htm @@ -108,7 +108,7 @@
- +
diff --git a/data/config.min.htm b/data/config.min.htm index 2ae55b0..b0c839c 100644 --- a/data/config.min.htm +++ b/data/config.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Temperature Format:




(C) Copyright 2021 Magnus Persson
\ No newline at end of file +Beer Gravity Monitor

Temperature Format:




(C) Copyright 2021 Magnus Persson
\ No newline at end of file diff --git a/src/gyro.cpp b/src/gyro.cpp index 62e4bd3..9f2ac51 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -211,10 +211,16 @@ bool GyroSensor::read() { } else { validValue = true; angle = calculateAngle( raw ); - sensorTemp = ((float) raw.temp) / 340 + 36.53; //Log.notice(F("GYRO: Calculated angle %F" CR), angle ); } + sensorTemp = ((float) raw.temp) / 340 + 36.53; + + // The first read value is close to the DS18 value according to my tests, if more reads are + // done then the gyro temp will increase to much + if( initialSensorTemp == INVALID_TEMPERATURE ) + initialSensorTemp = sensorTemp; + return validValue; } diff --git a/src/gyro.h b/src/gyro.h index 97d9be5..a8be180 100644 --- a/src/gyro.h +++ b/src/gyro.h @@ -45,6 +45,8 @@ struct RawGyroDataL { // Used for average multiple readings long temp; // Only for information (temperature of chip) }; +#define INVALID_TEMPERATURE -273 + class GyroSensor { private: MPU6050 accelgyro; @@ -52,6 +54,7 @@ class GyroSensor { bool validValue = false; double angle = 0; float sensorTemp = 0; + float initialSensorTemp = INVALID_TEMPERATURE; RawGyroData calibrationOffset; void debug(); @@ -68,6 +71,7 @@ class GyroSensor { double getAngle() { return angle; }; float getSensorTempC() { return sensorTemp; }; + float getInitialSensorTempC() { return initialSensorTemp; }; bool isConnected() { return sensorConnected; }; bool hasValue() { return validValue; }; void enterSleep(); diff --git a/src/main.cpp b/src/main.cpp index f033d1a..c2ab1de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,12 +180,11 @@ void loop() { // if( myGyro.hasValue() ) { angle = myGyro.getAngle(); // Gyro angle - sensorTemp = myGyro.getSensorTempC(); // Temp in the Gyro stableGyroMillis = millis(); // Reset timer LOG_PERF_START("loop-temp-read"); - float temp = myTempSensor.getValueCelcius(); // The code is build around using C for temp. + float temp = myTempSensor.getValueCelcius(); LOG_PERF_STOP("loop-temp-read"); //LOG_PERF_START("loop-gravity-calc"); // Takes less than 2ms , so skip this measurment @@ -193,7 +192,7 @@ void loop() { //LOG_PERF_STOP("loop-gravity-calc"); #if LOG_LEVEL==6 - Log.verbose(F("Main: Sensor values gyro angle=%F gyro temp=%F, temp=%F, gravity=%F." CR), angle, sensorTemp, temp, gravity ); + Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F." CR), angle, temp, gravity ); #endif if( myConfig.isGravityTempAdj() ) { LOG_PERF_START("loop-gravity-corr"); @@ -206,7 +205,7 @@ void loop() { // Limit the printout when sleep mode is not active. if( loopCounter%10 == 0 || sleepModeActive ) { - Log.notice(F("Main: gyro angle=%F, gyro temp=%F, DS18B20 temp=%F, gravity=%F, batt=%F." CR), angle, sensorTemp, temp, gravity, volt ); + Log.notice(F("Main: angle=%F, temp=%F, gravity=%F, batt=%F." CR), angle, temp, gravity, volt ); } LOG_PERF_START("loop-push"); diff --git a/src/tempsensor.cpp b/src/tempsensor.cpp index 546749b..9ff3507 100644 --- a/src/tempsensor.cpp +++ b/src/tempsensor.cpp @@ -97,8 +97,9 @@ float TempSensor::getValue() { #endif #if defined( USE_GYRO_TEMP ) + // When using the gyro temperature only the first read value will be accurate so we will use this for processing. //LOG_PERF_START("temp-get"); - float c = myGyro.getSensorTempC(); + float c = myGyro.getInitialSensorTempC(); //LOG_PERF_STOP("temp-get"); hasSensor = true; return c;