Buen día.
Estoy teniendo problemas para poder guardar archivos en la microSD usando el OPLÁ IoT KIT ya que cuando conecto la micro en el shield, me dice dice que no detecta la misma, he probado varios códigos y configuraciones y no logro hacerlo funcionar.
Ojala me puedan ayudar adjunto códigos usados y captura de panta del error
Código 1
#include <SPI.h>
#include <SD.h>
const int chipSelect = SDCARD_SS_PIN;
const int chipSelect = SDCARD_CS_PIN;
const int chipSelect = 0;
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("Initializing SD card...");
// 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:
while (1);
}
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 += ",";
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
delay(1000);
}
Código 2
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
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
}
// Init the entire Carrier
CARRIER_CASE = false;
carrier.begin();
// 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("datalog.csv", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("datalog.csv");
if (myFile) {
Serial.println("datalog.csv:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}