Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
documentation:microcontroleurs:arduino:modules:sdcard:index [2021/06/24 16:01] – f1sls | documentation:microcontroleurs:arduino:modules:sdcard:index [2022/09/13 08:29] (Version actuelle) – [PINOUTS] f1sls | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
====== MODULES SD CARD ====== | ====== MODULES SD CARD ====== | ||
- | ===== PINOUT | + | ===== PINOUTS |
{{: | {{: | ||
+ | ---- | ||
+ | {{: | ||
===== SD-CARD + ARDUINO ===== | ===== SD-CARD + ARDUINO ===== | ||
{{: | {{: | ||
- | + | ---- | |
+ | {{: | ||
+ | ---- | ||
+ | {{: | ||
===== CODE ===== | ===== CODE ===== | ||
- | < | + | |
+ | ==== WRITING ==== | ||
+ | < | ||
#include < | #include < | ||
#include < | #include < | ||
+ | |||
File myFile; | File myFile; | ||
+ | |||
void setup() { | void setup() { | ||
- | // Open serial communications and wait for port to open: | + | |
- | Serial.begin(9600); | + | |
- | while (!Serial) { | + | Serial.begin(9600); |
- | ; // wait for serial port to connect. Needed for native USB port only | + | while (!Serial) { |
+ | | ||
+ | } | ||
+ | |||
+ | Serial.print(" | ||
+ | |||
+ | if (!SD.begin(10)) { | ||
+ | Serial.println(" | ||
+ | while (1); | ||
+ | } | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | // open the file. note that only one file can be open at a time, | ||
+ | // so you have to close this one before opening another. | ||
+ | myFile = SD.open(" | ||
+ | |||
+ | // if the file opened okay, write to it: | ||
+ | if (myFile) { | ||
+ | Serial.print(" | ||
+ | myFile.println(" | ||
+ | myFile.println(" | ||
+ | |||
+ | for (int i = 0; i < 20; i++) { | ||
+ | myFile.println(i); | ||
+ | } | ||
+ | |||
+ | // close the file: | ||
+ | myFile.close(); | ||
+ | |||
+ | Serial.println(" | ||
+ | } else { | ||
+ | // if the file didn't open, print an error: | ||
+ | Serial.println(" | ||
+ | } | ||
} | } | ||
- | Serial.print(" | + | |
- | if (!SD.begin(10)) { | + | void loop() { |
- | Serial.println(" | + | // |
- | while (1); | + | |
- | } | + | |
- | Serial.println(" | + | |
- | // open the file. note that only one file can be open at a time, | + | |
- | // so you have to close this one before opening another. | + | |
- | myFile = SD.open(" | + | |
- | // if the file opened okay, write to it: | + | |
- | if (myFile) { | + | |
- | Serial.print(" | + | |
- | myFile.println(" | + | |
- | myFile.println(" | + | |
- | for (int i = 0; i < 20; i++) { | + | |
- | myFile.println(i); | + | |
- | } | + | |
- | // close the file: | + | |
- | myFile.close(); | + | |
- | Serial.println(" | + | |
- | } else { | + | |
- | // if the file didn't open, print an error: | + | |
- | Serial.println(" | + | |
} | } | ||
+ | </ | ||
+ | |||
+ | ==== READING ==== | ||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | File myFile; | ||
+ | |||
+ | void setup() { | ||
+ | |||
+ | // Open serial communications and wait for port to open: | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | while (!Serial) { | ||
+ | ; // wait for serial port to connect. Needed for native USB port only | ||
+ | } | ||
+ | |||
+ | Serial.print(" | ||
+ | if (!SD.begin(10)) { | ||
+ | Serial.println(" | ||
+ | while (1); | ||
+ | } | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | // open the file for reading: | ||
+ | myFile = SD.open(" | ||
+ | | ||
+ | if (myFile) { | ||
+ | Serial.println(" | ||
+ | |||
+ | // read from the file until there' | ||
+ | while (myFile.available()) { | ||
+ | Serial.write(myFile.read()); | ||
+ | } | ||
+ | |||
+ | // close the file: | ||
+ | myFile.close(); | ||
+ | | ||
+ | } else { | ||
+ | // if the file didn't open, print an error: | ||
+ | Serial.println(" | ||
+ | } | ||
} | } | ||
+ | |||
void loop() { | void loop() { | ||
- | // nothing happens after setup | + | |
} | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== READING LINE BY LINE ==== | ||
+ | <code cpp> | ||
</ | </ |