Skip to content

Instantly share code, notes, and snippets.

@aovestdipaperino
Created November 20, 2021 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aovestdipaperino/93046099eb2dbf4b116592f1bf52aceb to your computer and use it in GitHub Desktop.
Save aovestdipaperino/93046099eb2dbf4b116592f1bf52aceb to your computer and use it in GitHub Desktop.
Log Battery voltage vs. time
#include <Arduino.h>
#include <ArduinoNvs.h>
const bool LOG = true;
uint16_t minutesSinceBoot = 0;
bool doLogging = false;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(35, INPUT);
pinMode(34, INPUT);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
NVS.begin();
uint16_t currentDuration = NVS.getInt("LOG");
Serial.printf("Minutes since boot: %d \n", currentDuration);
doLogging = currentDuration < 10 && LOG;
Serial.println(doLogging ? "LOGGING" : "CHARGING");
for(int i=0; i<currentDuration; i++) {
Serial.print(currentDuration - i);
Serial.print(' ');
Serial.println(NVS.getFloat("NFL-" + (i+1)));
}
}
void loop()
{
float v = (float)(analogRead(34)) / 4095 * 2 * 3.3 * 1.1;
if (!doLogging)
{
Serial.println(v);
delay(1000);
}
else
{
delay(60000);
NVS.setInt("LOG", ++minutesSinceBoot);
NVS.setFloat("NFL-" + minutesSinceBoot, v);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment