Description:
A microSD card reader module with built in 3.3V level shifter which allows safe interfacing to any microSD cards that support an SPI interface. This module has primarily been designed to work with our RAMPS compatible 3D printer shield (See HC3DPR0002 in our shop). The module will directly interface with the AUX-3 connector on the RAMPS shield.

Although designed for this purpose in mind, this module will work fine with any microcontoller with 5V tolerant DIO that supports a hardware or software SPI interface (see example Arduino sketch below)

26/02/2015 Please note: We are currently chipping an alternative SD ramps version with a slightly different connector. However pinout is in the same order. Please see diagram below for more information:

/* FILE: ARD_SDRAMPS_MICROSD_MODULE_HCMODU0041_READ_EXAMPLE
DATE: 11/10/13
VERSION: 0.1
REVISIONS:
11/10/13 Created version 0.1
This is an example of how to use the HobbyComponents SDramps microSD card
reader module (HCMODU0041). This module allows reading and writing of data
to a standard microSD card and is useful for applications such as 3D printers,
data loggers where a large amount of data needs to be stored. The module works
with the standard Arduino SD card library.
This example program will attempt to read a text file named text.txt and
output its contents to the serial port.
PINOUT:
Module UNO/NANO
PIN 1: VCC ---> +5V
PIN 2: N/A ---> N/A
PIN 3: MISO ---> D12
PIN 4: MOSI ---> D11
PIN 5: SCLK ---> D13
PIN 6: CS ---> D4
PIN 7: GND ---> GND
PIN 8: N/A ---> N/A
PIN 9: N/A ---> N/A
PIN 10: N/A ---> N/A
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used for the purpose of premoting or selling products
that directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER. */
/* Include the standard SD card library */
#include <SD.h>
#define SD_CARD_CD_DIO 4 /* DIO pin used to control the modules CS pin */
File SDFileData;
/* Initialise serial and DIO */
void setup()
{
Serial.begin(9600);
/* DIO pin used for the CS function. Note that even if you are not driving this
function from your Arduino board, you must still configure this as an output
otherwise the SD library functions will not work. */
pinMode(10, OUTPUT);
}
/* Main program loop */
void loop()
{
/* Initiliase the SD card */
if (!SD.begin(SD_CARD_CD_DIO))
{
/* If there was an error output this to the serial port and go no further */
Serial.println("ERROR: SD card failed to initiliase");
while(1);
}else
{
Serial.println("SD Card OK");
}
/* Check if the text file exists */
if(SD.exists("test.txt"))
{
Serial.println("test.txt exists, attempting to read file...");
/* The file exists so open it */
SDFileData = SD.open("test.txt");
/* Sequentially read the data from the file and output it's
contents to the UART */
while (SDFileData.available())
{
Serial.write(SDFileData.read());
}
/* Close the file */
SDFileData.close();
}
/* Do nothing */
while (1);
}

When I check the SD card in the computer, it creates a LOG.txt despite the program code is File dataFile = SD.open("log.txt", FILE_WRITE); Basically, looks like is case sensitive. The word hello is also present in the created LOG.txt file. Looks like that for some reason is not closing the file after writing on it and then cannot open it again?

I also check the example provided in this forum and the result is that the card is OK but the test.txt file is not created in the card. So when I plug the card in the computer, there is nothing there.

How would I go about reading individual lines of the SD card of varying length? (From 9 to 12 characters) I'd imagine I can use a break variable when I save the data then use the Seek() to choose the line to read? But I'm not sure how to tell it to stop reading at the break variable. Or is there a readLine() method of some kind which I can use?
Thanks.