The SD/SDHC Card Module is an electronic component that allows microcontrollers to interface with Secure Digital (SD) or Secure Digital High Capacity (SDHC) memory cards. These cards are widely used for data storage and transfer in portable devices. The module is commonly used in embedded systems for logging data, storing configurations, or even for multimedia storage purposes.
Common applications include:
Pin Name | Description |
---|---|
CS | Chip Select, active low |
MOSI | Master Out Slave In, SPI data input |
MISO | Master In Slave Out, SPI data output |
SCK | Serial Clock, SPI clock input |
VCC | Supply Voltage, 3.3V to 5V |
GND | Ground |
To use the SD/SDHC Card Module with a microcontroller like an Arduino UNO, follow these steps:
#include <SPI.h>
#include <SD.h>
File myFile;
const int chipSelect = 10; // Chip select pin for the SD card module
void setup() {
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect.
}
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// Open a new file and immediately close it to create it.
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.println("Writing to test.txt...");
myFile.println("Hello, SD card!");
myFile.close(); // Close the file
Serial.println("Done.");
} else {
// If the file didn't open, print an error
Serial.println("error opening test.txt");
}
}
void loop() {
// Nothing here for now.
}
SD.cardType()
function to check if the card is recognized by the module.Q: Can I use a microSD card with this module? A: Yes, with a microSD to SD adapter, you can use microSD cards.
Q: What is the maximum size of SD card I can use? A: The module supports SD cards up to 2GB and SDHC cards up to 32GB.
Q: How do I create directories or multiple files on the SD card?
A: You can use the SD.mkdir()
function to create directories and SD.open()
with different filenames to create multiple files.
Q: Can I use this module with other microcontrollers? A: Yes, as long as the microcontroller supports SPI communication and operates at a compatible voltage level.