Hola, les quería consultar si alguno ya tuvo problemas al respecto,
Estoy usando un arduino mega 2560 para leer/escribir una memoria SD, mediante un módulo.
Cuando ejecuto los ejemplos que trae el IDE anda sin problema, incluso he probado algunas otras librerias (sdFat lib, es MUY similar a la SD nativa)
Al final adjunto el código.
Hasta ahí no hay drama, todo funciona correctamente.
Ahora, cuando tomo ese código de ejemplo y lo paso al programa general con el cual estoy trabajando ya no funciona.
El programa inicializa correctamente, SD.begin(chipSelect) = true, pero al hacer SD.open el micro queda clavado, no responde más y tengo que reiniciar.
En un principio creí que era problema de memoria dinámica ya que estoy usando un 60%, pero he hecho la prueba de bajarla a un 30% y sigue colgando el micro.
En el programa utilizo otras librerías, me queda el interrogante si estas afectan a la SD, estoy revisando y no encuentro motivo por el cuál deba tener problemas.
Otras librerías que uso en el código son:
#include <openGLCD.h>
#include <DallasTemperature.h>
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <TimerThree.h>
#include <EEPROM.h>
Hay algo más que deba tener el cuenta? Tengo prácticamente todos los pines digitales ocupado y solo me quedan algunos analógicos sin usar. Al utlizar la SD y SPI, debo debar libre algún otro pin además de los estrictamente de la SD (50, 51, 52, 53)?
Dejo el código,
/*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
SD card attached to SPI bus as follows:
** MISO - pin 50
** MOSI - pin 51
** CLK - pin 52
** CS - pin 53 (SS)
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 53;
File dataFile;
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:
return;
}
Serial.println("card initialized.");
}
void loop() {
// make a string for assembling the data to log:
String dataString = "HOLA";
// 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);
// 8.3 filename
dataFile = SD.open("Chillit.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print(dataString);
dataFile.print(" ");
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
delay(1000);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
delay(1000);
}
}