SD Card Module (HCARDU0008)

Modules for interfacing including USB to serial and SD adaptors.
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

SD Card Module (HCARDU0008)

Post by admin » Mon Aug 20, 2012 5:00 pm

Image

Features Allows reading and writing to an SD card from a microcontroller such as an Arduino development board.
Application Data logging, data storage

PLEASE NOTE that when used with 5V TTL an additional level shifter may be required to covert from 5V to 3.3V TTL levels (see HCCOIC0005) or for an alternative see item HCMODU0044.
  • PINOUT
    1.....GND
    2.....+3.3V
    3.....+5V
    4.....CS
    5.....MOSI
    6.....SCK
    7.....MISO
    8.....GND

Schematic:
Image

ARD_SD_CARD_MODULE_HCARDU0008_Write_Example.pde

Code: Select all

/* FILE:    ARD_SD_CARD_MODULE_HCARDU0008_Write_Example.pde
   DATE:    09/07/12
   VERSION: 0.1
   
REVISIONS:

09/07/12 Created version 0.1
   
01/08/12 Updated comments to include more instructions of how to 
         interface to module.


This is an example of how to use the HobbyComponents SD card reader module 
(HCARDU0008). This module allows reading and writing of data to a standard 
SD card and is useful for applications such as 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 create a test file on the SD card called test.txt
If the file already exists it will first delete it and then create a new 
one.

MODULE PINOUT:

PIN 1: GND    --->  Arduino GND
PIN 2: +3.3V  --->  N/A
PIN 3: +5V    --->  Arduino 5V
PIN 4: CS     --->  Arduino DIO 4
PIN 5: MOSI   --->  Arduino DIO 11
PIN 6: SCLK   --->  Arduino DIO 13
PIN 7: MISO   --->  Arduino DIO 12
PIN 8: GND    --->  N/A


IMPORTANT: The modules 5V pin supplies an onboard 3.3V regulator that powers
the SD card. The output of this regulator is brought out to the 3.3V pin. You
may power the module via the 5V or 3.3V pins but you must not supply power to
both as this could damage the on board regulator. If interfacing to the module 
with 5V DIO it is recommended that you level shift the 5V DIO down to 3.3V
for the MOSI, SCLK, and CS pins. You can do this by using an appropriate level
shifter or a resistor divider. Disclaimer: We can not be held responsible for any
damage cause to an SD card by improper interfacing with the module.

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 directly for the purpose of 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()
{

  /* Initialise 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 already exists */
   while(SD.exists("test.txt"))
   {
     /* If so then delete it */
     Serial.println("test.txt already exists...DELETING");
     SD.remove("test.txt");
   }
 
  /* Create a new text file on the SD card */
  Serial.println("Creating test.txt");
  SDFileData = SD.open("test.txt", FILE_WRITE);
  
  /* If the file was created ok then add come content */
  if (SDFileData)
  {
    SDFileData.println("It worked !!!");
  
    /* Close the file */
    SDFileData.close();   
    
    Serial.println("done.");
  }else
  {
      Serial.println("Error writing to file !");
  }
  
  /* Do nothing */
  while (1);
}

ARD_SD_CARD_MODULE_HCARDU0008_Read_Example.pde

Code: Select all

/* FILE:    ARD_SD_CARD_MODULE_HCARDU0008_Read_Example.pde
   DATE:    09/07/12
   VERSION: 0.1

REVISIONS:

09/07/12 Created version 0.1
   
01/08/12 Updated comments to include more instructions of how to 
         interface to module.


This is an example of how to use the HobbyComponents SD card reader module 
(HCARDU0008). This module allows reading and writing of data to a standard 
SD card and is useful for applications such as 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. 

MODULE PINOUT:

PIN 1: GND    --->  Arduino GND
PIN 2: +3.3V  --->  N/A
PIN 3: +5V    --->  Arduino 5V
PIN 4: CS     --->  Arduino DIO 4
PIN 5: MOSI   --->  Arduino DIO 11
PIN 6: SCLK   --->  Arduino DIO 13
PIN 7: MISO   --->  Arduino DIO 12
PIN 8: GND    --->  N/A

IMPORTANT: The modules 5V pin supplies an onboard 3.3V regulator that powers
the SD card. The output of this regulator is brought out to the 3.3V pin. You
may power the module via the 5V or 3.3V pins but you must not supply power to
both as this could damage the on board regulator. If interfacing to the module 
with 5V DIO it is recommended that you level shift the 5V DIO down to 3.3V
for the MOSI, SCLK, and CS pins. You can do this by using an appropriate level
shifter or a resistor divider. Disclaimer: We can not be held responsible for any
damage cause to an SD card by improper interfacing with the module.


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 directly for the purpose of 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 uesd 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);
} 

Benpointer
Posts: 4
Joined: Sat Jan 12, 2013 5:15 pm

Re: SD Card Module (HCARDU0008)

Post by Benpointer » Mon Jan 14, 2013 9:46 am

I have just got one of these cards but I cannot get it to work - appears to be a faulty card. I am using the ARD_SD_CARD_MODULE_HCARDU0008_Write_Example code and have wired it correctly (checked and double-checked) but all I get is "Card failed, or not present". Faulty card? or is there something more fundamental here?

Searching more widely on the internet these LCSoft SD cards seem to have been problematic for lots of people.

PS The JY-MCU bluetooth card I purchased from you at the same time works fine!

Any ideas?

Thanks

admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Re: SD Card Module (HCARDU0008)

Post by admin » Mon Jan 14, 2013 8:56 pm

Hi,

Sorry to hear you are having a problem, have you tired any other card with the module in case it’s some weird incompatibility with your card? What is the SD card formatted to?
This is a pretty passive device with not a lot to go wrong. Is it possible for you to visually examine the SD card socket for any physical problems?

Regards

Andrew

Benpointer
Posts: 4
Joined: Sat Jan 12, 2013 5:15 pm

Re: SD Card Module (HCARDU0008)

Post by Benpointer » Mon Jan 14, 2013 10:14 pm

I have tried 2 different 2Gb cards and 1 8Gb card. I formatted one of the cards to FAT16 on my MacBook but it made no difference. all the cards were readable in my MacBook and in a Panasonic camera.

I have taken a look at the card but I can't see anything wrong - though I am not really sure what I am looking for. There are no obvious lose or missing connections. I am a bit baffled?!

I am using it with a Leonard's arduino card, I assume that doesn't make any difference?

Thanks

Benpointer
Posts: 4
Joined: Sat Jan 12, 2013 5:15 pm

Re: SD Card Module (HCARDU0008)

Post by Benpointer » Mon Jan 14, 2013 10:22 pm

Sorry that should read a Leonardo arduino card, of course.

Should I be worrying about this comment in the demo code?

"If interfacing to the module with 5V DIO it is recommended that you level shift the 5V DIO down to 3.3V
for the MOSI, SCLK, and CS pins. You can do this by using an appropriate level shifter or a resistor divider."

Tbh I would not know how to do that as my background is in coding not electronics. As the arduino supplies 5v I just connected that up and ignored the 3.3v connection.

Thanks

admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Re: SD Card Module (HCARDU0008)

Post by admin » Tue Jan 15, 2013 1:41 pm

Hi,

We have not yet tested the code and module with a Leonardo but there should be no reason why that combination should work. We will do this later today just to be sure.

SD cards operate at 3.3V including their DIO. I would suggest that you check the manufactures data sheet for your make of card to see if the DIO is spec’d to be 5V tolerant. With our experience we find SD cards to be quite robust so we think it’s unlikely that you will have damaged your SD card (so long as you have correctly connected the module’s 3.3V supply pin to the 3.3V on the Leonardo). However we can’t guarantee this because it depends on the make of SD card which is why we include that comment.

If you don’t want to chance any damage, one quick and dirty way around the problem would be to level shift from the 5V IO on your Leonardo to the 3.3 on the SD card using some potential divider resistors on the MOSI, SCLK, and CS pins. The diagram below is an example of how you may go about doing this. You may need to adjust one of the resistor values to compensate on the loading effect of the SD card. Ideally you want to see 3.3V on the SD card pins give or take a few points of a volt.

Image
You do not have the required permissions to view the files attached to this post.

Benpointer
Posts: 4
Joined: Sat Jan 12, 2013 5:15 pm

Re: SD Card Module (HCARDU0008)

Post by Benpointer » Sun Jan 20, 2013 4:38 pm

Well, I followed your instructions to level shift from the 5V IO on my Leonardo to the 3.3 on the SD card using some potential divider resistors on the MOSI, SCLK, and CS pins.

But all to no avail - still not working. I am going to return the item, which I bought from you via eBay.

admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Re: SD Card Module (HCARDU0008)

Post by admin » Sun Jan 20, 2013 5:02 pm

Ok, we have accepted your return request. Sorry for any inconvenience caused. We normally test returned items within the same day as receiving them.

Regards

Andrew

Lymnmubmamb

Need help

Post by Lymnmubmamb » Sun Jul 14, 2013 3:10 pm

Now all is clear, many thanks for the help in this question. How to me you to thank?

sixbacon
Posts: 1
Joined: Thu Oct 24, 2013 4:07 pm

Re: SD Card Module (HCARDU0008)

Post by sixbacon » Thu Oct 24, 2013 4:10 pm

Just to be clear if using a 5V Arduino Uno, do I have to put level shifter on all the SPI lines?

Thanks

Post Reply

Return to “Adaptor”