-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSD_Init.ino
53 lines (47 loc) · 1.26 KB
/
SD_Init.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/ -------------------------------------------------
//
// 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;
}
}
}
}
}