Qwiic OpenLog recording data intermittently

I am trying to get my new OpenLog device working, and it logs data only intermittently. Below are the bulleted facts for easy reading.

  • I am running it with a RedBoard Qwiic, and have tried examples “Example1_WritingLog”, “Example2_AppendFile”, and “Example3_CreateFile”.
  • - The memory cards used are a SanDisk 16GB formatted FAT32 and SparkFun BrandX 1GB formatted FAT. The same performance is witnessed with both cards.
  • - When the cards are inserted into the OpenLogger, the status LED is a solid red
  • - If I insert a freshly formatted card and reset the RedBoard, a file 'config.txt' loads onto the card. config.txt reads:

    42,26,3,0

    i2c_address,escape,esc#,mode

  • - OpenLog firmware version 3.1 per "Example9_ReadVersion"
  • - I2C data flows readily through the OpenLog. It is the first device in a daisy chain of RedBoard->OpenLog->RTC->Display, and the other devices are communicating with the RedBoard normally.
  • - Intermittent behavior persists if the OpenLog is the only device connected to the RedBoard
  • - Sometimes a file "LOG000xx.TXT" shows up on the card, but it is empty and is reported at file size of 0k
  • - The behavior appears to be related to whether the card is freshly formatted, or if it has the config.txt file present already, but is not entirely consistent
  • - Again, failure to log a file from the RedBoard is intermittent. Sometimes it will and sometimes it won't. When things work, they work as they should
  • Any ideas are much appreciated.

    Hi Aaron,

    I have a couple of quick suggestions here. First, I am a bit confused by your description of the STAT LED. Are you sure you are looking at the correct LED? The STAT LED should be green and will blink when the SPI interface is active so you should only see it blink on startup and when a log is created. If your STAT LED is red then something else is going on here and photos of that would be very helpful.

    Next, the BrandX Card is not going to be a very reliable card for logging since it is Class 4 and its transfer speeds only go up to 4 MB/s. Do you know what Class your SanDisk card is? The OpenLog works best with Class 10 cards like [this but can work with anything down to Class 6 cards.

    Finally, the issue might just be trying to write data to the card too quickly. Depending on what all you are logging, you may want to add delays in your code like we demonstrate in the [Troubleshooting section of the Hookup Guide.](Qwiic OpenLog Hookup Guide - SparkFun Learn)](microSD Card - 16GB (Class 10) - COM-15051 - SparkFun Electronics)

    I apologize for the confusion. It was the red power LED, not the status LED I was referring to. I have a few more questions:

  • - What happens if I power down or eject the card in the middle of a write?
  • - When does the config.txt get written?
  • - Does config.txt get written by the RedBoard, or by the OpenLog board?
  • - Which command do I use to poll the OpenLog to check that it is reading the card OK (not flashing red LED 3 times)?
  • I think I have the problem solved. I added a 1 second delay immediately at startup, and then another 2 second delay on a command to the I2C bus to my display before initiating the OpenLog. I think there was a race condition of some sort on the I2C bus on start-up. If I insert the card before power-up and power down before removing the card, everything seems happy with those delays added (for now).

    #include <Wire.h>                   //I2C Library
    #include <SerLCD.h>                 //Serial LCD Library
    #include "SparkFun_Qwiic_OpenLog_Arduino_Library.h"     //Data logger library
    #include <SparkFun_RV1805.h>        //RTC Library
    
    SerLCD lcd;                         //Initialize the library with default I2C address 0x72
    OpenLog myLog;                      //Initialize data logger
    RV1805 rtc;                         //Initialize real time clock
    
    const int windRawADCInput = A0;     //Sensor wind analog output to board analog input pin A0
    const int tempRawADCInput = A1;     //Sensor temperature analog output to board analog input pin A1
    const float tempCoef = 0.0195;      //Temp sensor coefficient, volts per degC 
    const float temp0C_V = 0.400;       //Temp sensor voltage at 0deg C
    const int zeroWindRaw = 416;        //Value determined experimentally
    uint8_t lastSecond = 60;            //Initialize the seconds compare variable as something that will always be !=  
    
    void setup() {
      delay(1000);                      //Start-up delay makes things run more consistantly
      Wire.begin();                     //Join I2C bus as master
      
      lcd.begin(Wire);                  //Initialize LCD display on I2C
      lcd.clear();                      //Clear the display - this moves the cursor to home position as well
      lcd.setBacklight(255,150,150);    //Set backlight to bright white
    
      rtc.begin();                      //initialize RTC
    
    //Output on LCD that initializations are complete  
      lcd.print("OpenLog Start");
      delay(2000);
        
      myLog.begin();                    //Open connection to OpenLog
    

    Hi again Aaron,

    That’s good to hear adding a couple of delays fixed the issue for now. Let us know if it crops up again and we can troubleshoot further. As for your other questions, I will answer them below:

    What happens if I power down or eject the card in the middle of a write?

  • I am not exactly sure as I have never tested that but depending on where you are writing to (eg. file, directory, root directory) the log may become corrupted if you eject. It will also possibly lock up your I2C bus until you reset the circuit. You may also just notice the string you were writing just ends abruptly or is not written at all since the Qwiic OpenLog holds the clock line low letting the master device know it is busy. It writes character-by-character so most likely, you'll see just an abrupt end to whatever you were writing to the card. You may need to format the card as well.
  • When does the config.txt get written?

  • The config file is constantly checked on an amended each time the loop is performed in the firmware. So, if you were to put in a brand new card the firmware checks for the config.txt file and if it is not present, will write it.
  • Does config.txt get written by the RedBoard, or by the OpenLog board?

  • The config.txt file is written and amended by the OpenLog
  • Which command do I use to poll the OpenLog to check that it is reading the card OK (not flashing red LED 3 times)?

  • To check on the status, you can follow along with [[this example](https://github.com/sparkfun/SparkFun_Qwiic_OpenLog_Arduino_Library/blob/master/examples/Example10_CheckStatus/Example10_CheckStatus.ino) from the Qwiic OpenLog Arduino Library to check the SD status bit with your code. You can check where the firmware checks for the SD card starting on [[this line](https://github.com/sparkfun/Qwiic_OpenLog/blob/master/Firmware/Qwiic_OpenLog/Qwiic_OpenLog.ino#L329) of the firmware sketch.

    I hope this answers your questions thoroughly. As always, if you run into any other issues or have any other questions about the Qwiic OpenLog, let us know and we would be happy to help as much as we can.

  • ](Qwiic_OpenLog/Firmware/Qwiic_OpenLog/Qwiic_OpenLog.ino at master · sparkfun/Qwiic_OpenLog · GitHub)](SparkFun_Qwiic_OpenLog_Arduino_Library/examples/Example10_CheckStatus/Example10_CheckStatus.ino at main · sparkfun/SparkFun_Qwiic_OpenLog_Arduino_Library · GitHub)