Hello there,
I have a simple setup that logs temperature over time.
I use the RTC from my board https://support.sodaq.com/Boards/ExpLoRer/ and the onboard temp sensor.
formatting my log file is important, so here is the code i wrote from the examples
#include <Wire.h>
#include "SparkFun_Qwiic_OpenLog_Arduino_Library.h"
#define debugSerial SerialUSB
OpenLog myLog; //Create instance
#include <RTCZero.h>
/* Create an rtc object */
RTCZero rtc;
/* Change these values to set the current initial time */
byte seconds = 0;
byte minutes = 0;
byte hours = 0;
/* Change these values to set the current initial date */
byte day = 1;
byte month = 1;
byte year = 1970;
void setup() {
// put your setup code here, to run once:
delay(10000);
debugSerial.begin(9600);
debugSerial.println("starting logger...waiting for 10 sec");
Wire.begin(); //Initialize I2C
myLog.begin(); //Open connection to OpenLog (no pun intended)
rtc.begin(); // initialize RTC
rtc.setEpoch(0);
myLog.println("format descriptor : heures, minutes, secondes,Temp °C");
//Set the temperature sensor pin as input
pinMode(TEMP_SENSOR, INPUT) ;
//Set ADC resolution to 12 bits
analogReadResolution(12) ;
//myLog.println(rtc.getMinutes());
//debugSerial.println(rtc.getSeconds());
}
void loop() {
// put your main code here, to run repeatedly:
float temperature = getTemperature();
myLog.print(String(rtc.getHours()));
myLog.print(",");
myLog.print(String(rtc.getMinutes()));
myLog.print(",");
myLog.syncFile();
myLog.print(String(rtc.getSeconds()));
myLog.print(",");
myLog.println(String(temperature));
delay(15);
myLog.syncFile();
debugSerial.println(temperature);
delay(6000);
}
void print2digits(int number) {
if (number < 10) {
debugSerial.print("0"); // print a 0 before if the number is < than 10
}
debugSerial.print(number);
}
float getTemperature()
{
uint8_t samples = 10;
float sum = 0.0 ; // reset averaged reading to start at 0
// This loop does 10 readings of the voltage, and adds this to the variable
for(int i = 0; i < samples; i++)
sum += 3.3/4095.0 * (float)analogRead(TEMP_SENSOR) ;
// Divide the voltage to get average
float voltage = sum / samples ;
// Convert voltage to temperature
double temperature = (voltage - 0.5) * 100.0 ;
return temperature;
}
it records well, but from time to time the println is not taken into account and produces inconsictency in my file
EX : See Attached logfile
Any help appreciated
LOG00171.TXT (4.64 KB)