Bonjour,
Je me casse les dents sur un lecteur de carte SD depuis un moment.
J'utilisais un datalogguer sur carte UNO mais je dois passer sur carte MEGA car je manque de port I/O.
j'ai donc acheté une carte SD simple connecté comme l'image.
Carte SD valide utilisée et encore utilisable sur l'ancien montage.
Je suis revenu à une carte UNO (pour l'instant)
Une carte SD (comme l'image le montre)
Les connections sont les suivantes
MISO : 12
MOSI : 11
SCK : 13
CS : 4
Le sketch est le suivant:
#include <SD.h>
const int chipSelect = 4;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(4, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else {
Serial.println("error opening datalog.txt");
}
}
La réponse est invariablement la suivante:
Initializing SD card...Card failed, or not present
error opening datalog.txt
J'avais essayé sur la MEGA en mettant le câblage suivant:
MISO : 50
MOSI : 51
SCK : 52
CS : 53
avec le code:
if (!SD.begin(4)) // essayé aussi avec 53
Serial.println("Erreur de demarrage!");
Initializing SD card...Card failed, or not present
error opening datalog.txt
Ma question est la suivante: pourquoi tant de haine!
