DatabaseOnSD.h Test advice needed, library edit

I am trying to test the DatabseOnSD library with the 'test' example.

The example looks like it should create the necessary CSV files if they don't exist, but it doesn't seem to. So I created a test.csv file manually in the SD card. Its not recognizing my file (created by Notepad).

Its repeatedly displaying:

-------------read all table content cell by cell ----------------------

-------------read all table content at once ----------------------
/test.csv does not exist

Its curious that there is not setup for 'Card number' like 4, 10, etc.

My Ethernet/SD Card shield works perfect with the other SD example in the IDE.

If this works for anyone else please let me know what your setup is...

sounds like the lib fails to start the sd??
did you try to roll your own??

saving a structure to the sd is pretty straight forward..
played with it a while back..

Write Struct to SD

have fun.. ~q

I found the problem.
The
#define CHIP_SELECT_PIN 10

And my SD shield is a 4.
Now, how to edit my library...

DBonSD_prob

Changed the 10 to 4, still nothing...

can you just #undef then #define it correctly in your sketch..

can you just #undef then #define it correctly in your sketch..

#undef then #define what in my sketch?
The sketch is this test file provided by DatabaseOnSD.h author. Below.

//the table name should be short (less than 8 characters)

//note: the csv files created by this library will be compartible with ms excel program
// but csv files generated from ms excel are not compartible with this library
// from version 1.1.0, all will be compartible.
#include <DatabaseOnSD.h>

MyTable testTable("test.csv");  //this will create or open a table named test.csv in the root of the SD card

// MyTable testTable("testfolder/test.csv"); //if table is in a folder.

//it could be any extension instead of .csv

void setup(){
Serial.begin(115200); //start serial monitor with a baud rate of 115200
testTable.begin(3, 2); //if table is empty, append a table with 3 empty rows with 2 colummns each to the table
//testTable.begin(); //for completely empty tables or filled tables
// testTable.emptyTable(); //empty table content

/*  
    0       1
0     NAME    AGE
1     Divino      22
2     Fire      21

The table above has 3 rows and 2 columns
NAME is in cell (0, 0) and 21 is in cell (2, 1)
*/

//write table content
testTable.writeCell(0, 0, "NAME");   testTable.writeCell(0, 1, "AGE");
testTable.writeCell(1, 0, "Divino"); testTable.writeCell(1, 1, "23");
testTable.writeCell(2, 0, "Fire");   testTable.writeCell(2, 1, "22");

//the max size of each cell is 20 characters for the sake of memory,
//the max cell size can be changed in header file [but I do not recommend it]

}

void loop(){
  //read all table content cell by cell
  int numRows = testTable.countRows();
  int numCols = testTable.countCols();
  Serial.println("-------------read all table content cell by cell ----------------------");

  for (int i = 0; i < numRows; ++i)
  {
    for (int j = 0; j < numCols; ++j)
    {
      Serial.println(testTable.readCell(i, j));
      delay(1000); // one second delay after each read
    }
  }

  Serial.println("\n\n\n\n\n"); // space separate the next serial print by 5 empty lines

  delay(3000);

  //read all table content at once
  Serial.println("-------------read all table content at once ----------------------");
  testTable.printTable(); //print entire table content to serial monitor

  Serial.println("\n\n\n\n\n"); // space separate the next serial print by 5 empty lines

  //to erase the data in a cell, parse in an empty string as the data content
  //when you read a cell, it returns a String object, if it is a number, you can convert using toint or toFloat method on the String

  delay(10000);
  
}

If I edited the library code, will it reload? on compile, or on removal reopen and re-add or how can I know the revised library is the one in-play, not the previous version?

like that, just after the include but before you create the object..
should work..

yes, if you loaded the lib and edited that copy..
should be a folder in your libraries..
change it in there and you won't have to redefine things..

either way should work..

Added:

#undef CHIP_SELECT_PIN 10
#define CHIP_SELECT_PIN 4

Same problem.

you can debug a lib, put in a serial print to see what's happening..
by the output you posted, looks like it fails on sd.begin??
idk, sorry couldn't be more help..
~q

I will try the serial.prints in the library.
There was one other test that wouldn't work it responds with "Initializing SD card...initialization failed!
"
Here is that code.

/*
  SD card read/write

  This example shows how to read and write data to and from an SD card file
  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

  created   Nov 2010
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

I have another type of SD card shield coming.

Maybe you can SIM it..
UnoSaveConfigSD

have fun.. ~q

Hey @Ashton, I'm the author of the library DatabaseOnSD. I made a few updates. Everything should be fine now and the example should work just fine.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.