Last active
December 9, 2018 14:16
-
-
Save vishnumaiea/b9e4a1182006229332e9fba1e7c29929 to your computer and use it in GitHub Desktop.
Catalex Micro SD card module initialization code for Arduino.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -----------------------------------------------------// | |
// | |
// Micro SD Card initialization code. | |
// Type "i" or "I" in the serial terminal to | |
// initialize the card. | |
// | |
// Author : Vishnu M Aiea | |
// Web : www.vishnumaiea.in | |
// IST 4:04 PM 28-02-2017, Tuesday | |
// | |
//------------------------------------------------------// | |
#include <SPI.h> | |
#include <SD.h> //include the SD library | |
byte inByte; | |
bool sdInitSuccess = false; //card init status | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) { | |
; //wait for the serial port to connect. | |
} | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
inByte = Serial.read(); | |
if (inByte == 'i' || inByte == 'I') | |
{ | |
if (sdInitSuccess) { | |
Serial.println("Already initialized."); | |
Serial.println(); | |
} | |
else if (!sdInitSuccess) { //if not already initialized | |
Serial.println("Initializing SD Card.."); | |
if (!SD.begin(10)) { //using pin 10 (SS) | |
Serial.println("Initialization failed!"); | |
Serial.println(); | |
sdInitSuccess = false; | |
return; | |
} | |
else { | |
Serial.println("Intitialization success."); | |
Serial.println(); | |
sdInitSuccess = true; | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment