Go Down

Topic: [SOLVED] Datalogger example sketch problem with LC Studio SD module (Read 12620 times) previous topic - next topic

nightcrawler218

Dec 20, 2013, 07:00 pm Last Edit: Jan 07, 2014, 08:42 pm by nightcrawler218 Reason: 1
Hello,
I am trying to plot gps data in text file. I started with the datalogger example sketch of the SDcard libraary.
After uploading the sketch, when I open the serial monitor, it says "Initializing SD card...Card failed, or not present"

Then closing & reopening the serial monitor for about a couple of times the serial monitor shows the correct output.

The SDcard Module

This is the example sketch
Code: [Select]
/*
 SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.

The circuit:
* SD card attached to SPI bus as follows:
** UNO:  MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed)
 and pin #10 (SS) must be an output
** Mega:  MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed)
 and pin #52 (SS) must be an output
** Leonardo: Connect to hardware SPI via the ICSP header
 Pin 4 used here for consistency with other Arduino examples

created  24 Nov 2010
modified 9 Apr 2012 by Tom Igoe

This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

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

 Serial.print("Initializing SD card...");
 // make sure that the default chip select pin is set to
 // output, even if you don't use it:
 pinMode(SS, OUTPUT);
 
 // see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
   Serial.println("Card failed, or not present");
   // don't do anything more:
   while (1) ;
 }
 Serial.println("card initialized.");
 
 // Open up the file we're going to log to!
 dataFile = SD.open("datalog.txt", FILE_WRITE);
 if (! dataFile) {
   Serial.println("error opening datalog.txt");
   // Wait forever since we cant write data
   while (1) ;
 }
}

void loop()
{
 // make a string for assembling the data to log:
 String dataString = "";

 // read three sensors and append to the string:
 for (int analogPin = 0; analogPin < 3; analogPin++) {
   int sensor = analogRead(analogPin);
   dataString += String(sensor);
   if (analogPin < 2) {
     dataString += ",";
   }
 }

 dataFile.println(dataString);

 // print to the serial port too:
 Serial.println(dataString);
 
 // The following line will 'save' the file to the SD card after every
 // line of data - this will use more power and slow down how much data
 // you can read but it's safer!
 // If you want to speed up the system, remove the call to flush() and it
 // will save the file only every 512 bytes - every time a sector on the
 // SD card is filled with data.
 dataFile.flush();
 
 // Take 1 measurement every 500 milliseconds
 delay(500);
}


I have doublechecked the connections. Can you please help me to find out what may be the probable reason for such behaviour of the system?
Thanking you in anticipation.
"Imagination is more important than knowledge."<br />-Einstein

nightcrawler218

#1
Dec 20, 2013, 07:26 pm Last Edit: Dec 20, 2013, 11:04 pm by nightcrawler218 Reason: 1
When I try to open the text file via card reader, windows says
Code: [Select]
---------------------------
Notepad
---------------------------
The file or directory is corrupted and unreadable.
---------------------------
OK   
---------------------------


But the file size shows 33 kB
"Imagination is more important than knowledge."<br />-Einstein

Sayedurrchowdhury

#2
Dec 21, 2013, 02:06 am Last Edit: Dec 21, 2013, 02:10 am by Sayedurrchowdhury Reason: 1
I am having one of these same LC Studio SD breakout, but never had any problem the card being detected. Would you try reformatting your SD card using SD Formatter (https://www.sdcard.org/downloads/formatter_4/) from SD Association? Some people have reported it to be better than Windows formatter.

And see what the SDinfo example sketch that comes with the SD library yields.

fat16lib

The LC Studio module fails with many SD cards since the module does not have proper IC level shifters.

Formatting will not fix the problem.

nightcrawler218

My bad luck!
Ishall try to fix it by using a proper level shifter chip with the module. Get to go to the market to grab one. Buying a LS chip should be more reasonable than buying another sd shield.
Thanks fat16lib & Sayedurrchowdhury for your response.
"Imagination is more important than knowledge."<br />-Einstein

nightcrawler218

After a long research finally found the solution. It works like a charm. Now the datalogger is working absolutely fine. Tested.
http://apcmag.com/arduino-project-5-digital-audio-player.htm
The solution is using 1N4148 signal diodes that will do the voltage manipulation by dropping out the voltage without any level-shifting chip.. Less complicated & very less expensive solution.

"Imagination is more important than knowledge."<br />-Einstein

nightcrawler218

#6
Jan 08, 2014, 09:28 pm Last Edit: Jan 08, 2014, 10:15 pm by nightcrawler218 Reason: 1
Homemade SD card shield without any external Level Shifter chip...
"Imagination is more important than knowledge."<br />-Einstein

fat16lib

The diode trick will not work with all SD cards.

The only sure solution is to use appropriate level shifters  with correct levels and timing.

The Arduino company, Adafruit,  Sparkfun and several other companies produce excellent products for using SD cards with 5V Arduinos.

I am the author of SdFat which is also the base for the official Arduino library.  Marginal solutions that use resistors, diodes and other tricks cause problems for many users.  I suspect this post will add to my email load.

nightcrawler218

#8
Jan 09, 2014, 12:07 pm Last Edit: Jan 09, 2014, 12:32 pm by nightcrawler218 Reason: 1
Tried this one with 4050 level shifter. It also worked.
http://www.instructables.com/id/Arduino-DIY-SD-Card-Logging-Shield/
4148 costs 25 times lesser than 4050 & it also works with the LC studio modules, so I opted for the second solution.
"Imagination is more important than knowledge."<br />-Einstein

fat16lib

#9
Jan 09, 2014, 07:05 pm Last Edit: Jan 09, 2014, 07:37 pm by fat16lib Reason: 1
Quote

4148 costs 25 times lesser than 4050 & it also works with the LC studio modules, so I opted for the second solution.

I use a SN74HC125N at $0.43  from Digi-Key.  For most people, buying diode in low quantity is not going to save much.

The diodes do not meet the SD signal spec.  Cards do fail with diodes.  Data over the SPI bus is not checked by CRC by the Arduino so marginal "solutions" are not worth a few pennies.

I have bought modules from ebay that have IC level shifters.  Here is a microSD module for $2.48 + $1.00 shipping . Much nicer than your "solution".  I have bought standard size SD modules for about the same amount.

http://www.ebay.com/itm/Micro-SD-Storage-Board-Mciro-SD-TF-Card-Memory-Shield-Module-SPI-For-Arduino-/200958993125?pt=LH_DefaultDomain_0&hash=item2eca16e2e5

Edit: even better,  $2.42 and free shipping:

http://www.ebay.com/itm/Micro-SD-Storage-Board-Mciro-SD-TF-Card-Memory-Shield-Module-SPI-For-Arduino-TR-/181297142721?pt=LH_DefaultDomain_0&hash=item2a3626dbc1

These use "125" IC level shifters.


nightcrawler218

Thanks fat16lib for the links. Those modules are really low priced. Hoping to grab a few. :)
cheers.
"Imagination is more important than knowledge."<br />-Einstein

Dreamer932


Go Up