Sparkfun QWIIC OpenLog sd writer with Arduino R4

I am using this logger in combination with QWIIC BM280 and Clock boards attached to an Arduino R4 wifi. The BM280 and clock boards work fine but nothing (including Wire1)I have tried will induce the OpenLog to respond to the example sketches. This seems to be a common problem judging by other entries on this and other boards.

Have there been any successful uses of ths logger with the R4?

I grabbed my R4 an Qwiic Opelog to test with and can confirm they work together, although I had a hiccup myself: ensure the card is 32gb or smaller (FAT32)…mine was 128gb and caused me some unnecessary tail-chasin’

Here’s a modified version of the openlog example1 that worked for my R4 (note Wire1 changes)

/*
  This example shows how to record various text and variables to Qwiic OpenLog.
  
  Modified for Arduino UNO R4 WiFi - Uses Wire1 for Qwiic connector
  
  By: Nathan Seidle @ SparkFun Electronics
  Date: January 11th, 2020
  Modified: 2024 for Uno R4 WiFi
  License: This code is public domain but you buy me a beer if you use this 
  and we meet someday (Beerware license).

  Feel like supporting our work? Buy a board from SparkFun!
  https://www.sparkfun.com/products/15165

  This example records everything to 'log.txt'. You can change this by changing
  the name of fileName variable. For example, 'data.log' or '1.txt'.

  Recording to other files is as easy as: myLog.print("Hello world!");

  Don't forget to take the SD card out and see the results on your computer!
*/

#include <Wire.h>
#include <SparkFun_Qwiic_OpenLog_Arduino_Library.h>
OpenLog myLog; //Create instance

int fileNumber = 1; //Keeps track of which file number we are on
String fileName; //The file name we will write to

void setup() {
  Serial.begin(115200);
  while (!Serial); // Wait for Serial connection (optional but helpful)
  Serial.println("START");
  Serial.println("OpenLog Example 1 - Writing Log");

  // MODIFIED: Use Wire1.begin() for UNO R4 WiFi Qwiic connector
  Wire1.begin(); 
  
  // ADDED: Small delay to let OpenLog initialize SD card
  delay(100);
  
  Serial.println("Wire1 initialized for Qwiic connector");

  // MODIFIED: Pass the I2C address AND Wire1 to the begin() function
  // Default address is 0x2A (42 in decimal)
  if (myLog.begin(42, Wire1) == false) {
    Serial.println("OpenLog not detected. Freezing...");
    while (1);
  }
  Serial.println("OpenLog detected!");

  // MODIFIED: Removed getFileNumber() call - this method doesn't exist in the library
  // Instead, we'll just use a fixed filename or increment manually
  fileName = "log" + String(fileNumber) + ".txt";
  
  //Create a new file for this logging session
  myLog.create(fileName); //Create file if it does not exist

  Serial.print("Logging to: ");
  Serial.println(fileName);
}

void loop() {
  //Record some strings
  myLog.println("This is recorded to the OpenLog");
  myLog.println("This is the second line");

  //Record some variables
  int temp = 24;
  myLog.print("Temperature: ");
  myLog.println(temp);

  //Record millis
  myLog.print("millis: ");
  myLog.println(millis());

  //Record a comma separated line
  myLog.print(millis());
  myLog.print(",");
  myLog.print(temp);
  myLog.print(",");
  myLog.println("Status: OK");

  Serial.println("Data recorded. Check SD card.");
  
  delay(1000); //Don't pound the I2C bus too hard
}

Also note I did need to push the reset button after uploading before anything appeared in the serial monitor

Thanks so much for taking the trouble to look into this. I won’t be able to get back to it for a couple of days but will let you know the outcome.

JG

Uploaded your program today and added serial.print copies of the myLog.print statements. The program initializes the file “log1” on a newly formatted 8GB SD card but does not write data to it. The stat1 led stays steady, does not blink.
Appreciate any suggestions.

Does the default sketch work as expected?

I replied on the website rather than by direct email. Apologies. The sketch did initiate the log1.txt file on the sd card but did not write to that file. No error messages. SD was newly formatted 8gb. The sd drive was the only board attached to the R4 by QWiiC connector to minimize any pull-up resistor problems.
Any suggestions greatly appreciated.

John

If you hit reset on the R4 while they’re connected/running, does the new/second file seem correct?

I have tried many versions of the reset but to no avail. With the 8gb Verbatim sd it intializes the log1.txt sd file, but does not write data, and adds a config file as follows.
42,26,3,0
i2c_address,escape,esc#,mode

With a 16gb sd card it will not even initialize the log1.txtfile, or write the config file, let alone write data.

Both sd cards read and write in other capacities and I have been using them to record Arduino data for a couple of years (with an Adafruit sd card). I have also cleaned their contacts.

Dare I suggest a faulty Sparkfun drive?

Again, thanks for any suggestions.

Hi again: there being no further suggestions as to how an Openlog QWIIC board can connect to an R4 Arduino, can I return the board?

JohnPG

Gotcha, it does sound like it may be faulty - Was it purchased from us? If so head over to Return Policy - SparkFun Electronics (contact vendor if purchased elsewhere) and we’ll get ya squared away with a replacement unit

instead of create(), which just creates a new file, nothing else

  //Create a new file for this logging session
  myLog.create(fileName); //Create file if it does not exist

use append() which closes any open file, then creates “fileName” if it does not exist yet, and opens it. Any subsequent mylog.write() or mylog.println() is now done to “fileName”

  //Create a new file for this logging session
  myLog.append(fileName); //Create file if it does not exist and starts using it

ANOTHER CHANGE : While doing further tests, it failed often. Turns out that as Openlog is using clock stretch, you need to set Wire1 to cope with that. After Wire1.begin() add Wire1.setWireTimeout(100000);



// MODIFIED: Use Wire1.begin() for UNO R4 WiFi Qwiic connector
Wire1.begin(); 

// ADDED: to cope with clock stretching
Wire1.setWireTimeout(100000);

// ADDED: Small delay to let OpenLog initialize SD card
delay(100);

Serial.println("Wire1 initialized for Qwiic connector");

// MODIFIED: Pass the I2C address AND Wire1 to the begin() function
// Default address is 0x2A (42 in decimal)

if (myLog.begin(42, Wire1) == false) {
   Serial.println("OpenLog not detected. Freezing...");
   while (1);
}

Attached txt-file contains the sketch code I used to test. Press ENTER to write to a file and after pressing ENTER again it will read and display the contents.

I had already created a filemanager for the Qwiic Openlog and I have updated and tested it today for the Arduino R4 wifi. apollo3/Qwicc_filemanager at master · paulvha/apollo3 · GitHub

testopenlog.txt (4.1 KB)

Thanks for that Paulvha. While that change by itself did not do the trick, adding a “myLog.append(filename)” at the end of the write loop did result in data being written to the sd card. Adding this to the library examples like WritingLog.ino also makes them operational where they were not (for me) as they stood. I am no programming expert but it does remind me that in many years using other sd cards I always had to open and close the working file in each iteration of the loop. It seemed clumsy, but it worked!
So I will not be returning the OpenLog breakout board to Sparkfun!

Indeed you have to apply BOTH ( append & setWireTimeout) in order for it to work.

Make sure after final writing and before turning off, to include a syncFile() call as well. It will flush any pending buffers to the file. Alternative you could call an append() for a dummy file, which will sync any pending and close the current open file. There is NO close call :face_without_mouth: