SDFAT 1.0.16, ParticleSoftSerial 0.0.8

I would appreciate the community’s help on this odd outcome:

I made an exact copy of a program. Before making any changes to it, I tried to compile it and ended up with errors related to SDFat and ParticleSerial libraries(please see below).

I checked the library versions I was using on the old program (which continues to compile fine) and found the following:

  1. SDFat library used in new program (1.0.16), SDFat library used on old program (0.0.7).

  2. ParticleSoftLibrary library used in new program (0.0.8), ParticleSoftLibrary library used on old program ( (0.0.6).

What may be causing this and how can I use the older libraries?

Share the link to your project - when you make that a habit, you may get your answer quicker :wink:

Thank you @ScruffR, I would have but do not have permission this time.

How can one use the older library versions?

How is that?

To use previous versions of a library you click the "i" icon and then select the version you want
image

1 Like

THANK YOU @Scruffr.

I fixed the problems with the help above and here is what I found out:

  1. Going to the older SDFat library (0.0.7) fixed the two SDFat errors reported.

  2. The new ParticleSoftLibrary appears to compile fine. I had copied my old code which was lacking the #include statement for that library. That code compiled fine with an older firmware but not with 1.0.0.

Hello @ScruffR,

Thanks again for your help.

Per your request, the code is below. I am getting with SDFat (1.0.16) the error:

fgets.ino:8:11: invalid conversion from ‘int’ to ‘SPIClass*’ [-fpermissive]

// Demo of fgets function to read lines from a file.
#include <SPI.h>
#include "SdFat.h"
#include "sdios.h"

// Secondary SPI with DMA
// SCK => D4, MISO => D3, MOSI => D2, SS => D5 (changed from D1)
SdFat sd(1);
const uint8_t chipSelect = D5;   //<-------------------- Use D5

// print stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
// store error strings in flash memory
#define error(s) sd.errorHalt(F(s))
//------------------------------------------------------------------------------
void demoFgets() {
  char line[25];
  int n;
  // open test file
  SdFile rdfile("fgets.txt", O_RDONLY);

  // check for open error
  if (!rdfile.isOpen()) {
    error("demoFgets");
  }

  cout << endl << F(
         "Lines with '>' end with a '\\n' character\n"
         "Lines with '#' do not end with a '\\n' character\n"
         "\n");

  // read lines from the file
  while ((n = rdfile.fgets(line, sizeof(line))) > 0) {
    if (line[n - 1] == '\n') {
      cout << '>' << line;
    } else {
      cout << '#' << line << endl;
    }
  }
}
//------------------------------------------------------------------------------
void makeTestFile() {
  // create or open test file
  SdFile wrfile("fgets.txt", O_WRONLY | O_CREAT | O_TRUNC);

  // check for open error
  if (!wrfile.isOpen()) {
    error("MakeTestFile");
  }

  // write test file
  wrfile.print(F(
                 "Line with CRLF\r\n"
                 "Line with only LF\n"
                 "Long line that will require an extra read\n"
                 "\n"  // empty line
                 "Line at EOF without NL"
               ));
  wrfile.close();
}
//------------------------------------------------------------------------------
void setup(void) {
  Serial.begin(9600);
  
  // Wait for USB Serial 
  while (!Serial) {
    SysCall::yield();
  }

  cout << F("Type any character to start\n");
  while (!Serial.available()) {
    SysCall::yield();
  }
  delay(400);  // catch Due reset problem

  // Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors occur.
  if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
    sd.initErrorHalt();
  }

  makeTestFile();

  demoFgets();

  cout << F("\nDone\n");
}
void loop(void) {}

If you looked at the raw error message you’d have seen this

__test.ino:7:11: error: invalid conversion from 'int' to 'SPIClass*' [-fpermissive]
In file included from __test.ino:2:0:
lib/SdFat/src/SdFat.h:319:12: note:   initializing argument 1 of 'SdFat::SdFat(SPIClass*)'
   explicit SdFat(SPIClass* spiPort) {

This tells you that you cannot just pass a 1 to the constructor but you need to do this

// either
SdFat sd;        // for the default SPI interface
// or
SdFat sd(&SPI1); // for an alternative SPI interface

The selection of the CS pin follows in the sd.begin() call.

BTW, what did you intend to achieve with the 1 as parameter?

1 Like

Thanks again @ScruffR

I will try it. But to answer your question, with version 0.0.7 of the library, SdFat sd(1) was needed to get the SD card to work. The program then compiled fine and the SD card was working.

//==================================================================================
//SD Stuff
//===========================================================================================================
// Pick an SPI configuration.
// See SPI configuration section below (comments are for photon).
#define SPI_CONFIGURATION 1
//-------------------------------
// Setup SPI configuration.
#if SPI_CONFIGURATION == 0
// Primary SPI with DMA
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFat sd;
const uint8_t chipSelect = SS;

#elif SPI_CONFIGURATION == 1
// Secondary SPI with DMA
// SCK => D4, MISO => D3, MOSI => D2, SS => D5 (changed from D1)
SdFat sd(1);
//const uint8_t chipSelect = D1;
const uint8_t chipSelect = D5;   //<-------------------- Use D5

#elif SPI_CONFIGURATION == 2
// Primary SPI with Arduino SPI library style byte I/O.
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFatLibSpi sd;
const uint8_t chipSelect = SS;
#elif SPI_CONFIGURATION == 3
// Software SPI.  Use any digital pins.
// MISO => D5, MOSI => D6, SCK => D7, SS => D0
SdFatSoftSpi<D5, D6, D7> sd;
const uint8_t chipSelect = D0;
#endif  // SPI_CONFIGURATION

SdFile myFile;
String myLogFile;
String myFilename;
String myProfile;

//==================================================================================

Using

uint8_t chipSelect = D5;   //<-------------------- Use D5

SdFat sd(&SPI1);

Still gives the error: invalid conversion from 'SPIClass*' to 'uint8_t {aka unsigned char}' [-fpermissive]"

It doesn’t for me.
You should look at the SHOW RAW output.

Or you not using 1.0.16 of the SdFat library?

Thank you, I brought a fresh version of Fgets and now it is compiling.

Thank you so much for this you just solved an issue I have been fighting for 2 days. I could not figure out why I was unable to switch to SPI 1 or 2. Thank you so much.