SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Qwiic category should be posted in this forum. To learn more about Qwiic, consider checking out our pillar page on the Qwiic system.
User avatar
By laurentchivot
Hello there,

I have a simple setup that logs temperature over time.

I use the RTC from my board and the onboard temp sensor.
formatting my log file is important, so here is the code i wrote from the examples
Code: Select all
#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:
    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
    myLog.println("format descriptor : heures, minutes, secondes,Temp °C");
    //Set the temperature sensor pin as input
  //Set ADC resolution to 12 bits
  analogReadResolution(12) ;


void loop() {
  // put your main code here, to run repeatedly:
  float temperature = getTemperature();

void print2digits(int number) {
  if (number < 10) {
    debugSerial.print("0"); // print a 0 before if the number is < than 10
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
You do not have the required permissions to view the files attached to this post.
User avatar
By TS-Mark
Hi laurentchivot,

If you can, try adding some short delays in between each print to the OpenLog and that should help with the inconsistency. The Troubleshooting Section of our Hookup Guide for the Qwiic OpenLog has a good example of that along with some other helpful troubleshooting tips for the board.
User avatar
By TS-Mark
Ah, v2.0 firmware could also be an issue here since the syncfile command only works on v3.0. Luckily, the Qwiic OpenLog can have its firmware updated fairly easily if you have a serial to USB converter. We briefly cover how to update the firmware in the Qwiic OpenLog Hookup Guide.

Let us know if adding delays does not help and if you need any assistance updating the firmware and we would be happy to help.