Hola, tengo un problema. Soy nueva usando Arduino. Tengo dos Arduino Uno para le medición de sensores, los datos los almaceno en .TXT en una micro SD. He dejado mis pruebas corriendo por más de 24 horas (el intervalo de tiempo de adquisición de los datos es de 60seg), pero he notado que después de ciertas horas de trabajo ambos arduinos dejan de registrar datos como si se apagaran y vuelven a registrar los datos después de unas horas.
Leí en una pregunta que hicieron en el foro que tal vez tiene que ver con la capacidad de memoria que le quedó al arduino después de subir el sketch. Si es así, me gustaría saber que puedo hacer. Había pensado en decirle que despues de ciertos números de datos se guardara el archivo e iniciara otro, para así no sobre escribir y no perder mis datos anteriores.
Incluyo el código que estoy utilizando.
// ----------------------------------------------------------------------------------
// LIBRERIAS PARA FUNCIONAMIENTO DE MODULOS Y SENSORES
// ----------------------------------------------------------------------------------
#include <Arduino.h>
#include <math.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h> // incluye libreria para interfaz I2C
#include "RTClib.h"
#include <DHT.h>
#include <Adafruit_MLX90614.h>
// ----------------------------------------------------------------------------------
// DECLARACIÓN
// ----------------------------------------------------------------------------------
// Variable de tipo reloj
RTC_DS1307 RTC;
// Pin para el guardado en memoria SD
#define SSpin 10
// Pin para lectura del sensor digital de temperatura y humedad relativa
#define DHTPIN 2
// Creación de variable tipo DHT11 o sensor de temperatura y humedad relativa
#define DHTTYPE DHT11
// Llamado de librerias de sensor DHT11
DHT dht(DHTPIN, DHTTYPE);
// Variable para guardado de datos de prueba de datos en tarjet SD
File archivo,D_sensores;
// I2C para Infrarrojo MLX90614
#define I2C_ADDR 0x5A //I2C adress
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
// ----------------------------------------------------------------------------------
// CUERPO PRINCIPAL DEL CODIGO
// ----------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600);
// ----------------------------------------------------------------------------------
// INICIALIZACIÓN Y AJUSTE DE RELOJ CON HORA DE PC
// ----------------------------------------------------------------------------------
Wire.begin(); // Inicia el puerto I2C
RTC.begin(); // Inicia la comunicaci¢n con el RTC
// RTC.adjust(DateTime(__DATE__, __TIME__)); // Comentar cuando se trabaja arduino desconectado de PC y el reloj ya registro la hora alguna vez
// ----------------------------------------------------------------------------------
// CREACIÓN Y ESCRITURA DE ENCABEZADO DE ARCHIVO DE DATOS DE SALIDA
// ----------------------------------------------------------------------------------
//++++++++++++++++++++++++++++ Lectura y guardado de sensores en tarjeta SD
if (!SD.begin(SSpin))
{
Serial.println("Fallo en inicialización");
return;
}
Serial.println("Inicialización correcta");
// Creación de archivo de datos
D_sensores = SD.open("EXT.txt", FILE_WRITE); // Nota: Hacer archivos con nombres simples y sin usar guion bajo
D_sensores.println("F,HH,Text,HRext,TAI,TOI,");
D_sensores.close();
// ----------------------------------------------------------------------------------
// INICIALIZACIÓN DE SENSORES
// ----------------------------------------------------------------------------------
// Inicialización de sensor de DHT11
dht.begin();
// Inicializacion de sensor BMP180
//wait for serial connection to open (only necessary on some boards)
while (!Serial);
Wire.begin();
// Inicialización MLX90614
mlx.begin();
// ----------------------------------------------------------------------------------
// DECLARACIÓN DE INTERVALO DE MEDICIÓN Y GUARDADO DE TIEMPO INICIAL
// ----------------------------------------------------------------------------------
// Paso de tiempo entre mediciones de sensor
int Dt = 60; // Contador: {2,3,4,5,...} segundos
DateTime fecha = RTC.now();
int t1_o = fecha.hour();
int t2_o = fecha.minute();
int t3_o = fecha.second();
while (true)
{
DateTime fecha = RTC.now();
int t1 = fecha.hour();
int t2 = fecha.minute();
int t3 = fecha.second();
int dif = ( (t1*3600) + (t2*60) + t3 ) - ( (t1_o*3600) + (t2_o*60) + t3_o );
if ( dif == Dt )
{
float HR = dht.readHumidity(); // Lectura de humedad relativa
float Temp = dht.readTemperature(); // Lectura de temperatura en °C
float TempAmbInfra = mlx.readAmbientTempC();
float TempObjInfra = mlx.readObjectTempC();
// Impresión en Monitor serie Arduino IDE
Serial.print (fecha.day(),DEC);
Serial.print ("/");
Serial.print (fecha.month(),DEC);
Serial.print ("/");
Serial.print (fecha.year(),DEC);
Serial.print (",");
Serial.print (fecha.hour(),DEC);
Serial.print (":");
Serial.print (fecha.minute(),DEC);
Serial.print (":");
Serial.print (fecha.second(),DEC);
Serial.print (", Text= ");
Serial.print(Temp);
Serial.print("°C");
Serial.print (", Hrext= ");
Serial.print(HR);
Serial.print(" %");
Serial.print(",Tai= ");
Serial.print(TempAmbInfra);
Serial.print("°C");
Serial.print(",Toi= ");
Serial.print(TempObjInfra);
Serial.println("°C");
// Escritura en tarejta SD
D_sensores = SD.open("EXT.txt", FILE_WRITE);
D_sensores.print (fecha.day(),DEC);
D_sensores.print ("/");
D_sensores.print (fecha.month(),DEC);
D_sensores.print ("/");
D_sensores.print (fecha.year(),DEC);
D_sensores.print (",");
D_sensores.print (fecha.hour(),DEC);
D_sensores.print (":");
D_sensores.print (fecha.minute(),DEC);
D_sensores.print (":");
D_sensores.print (fecha.second(),DEC);
D_sensores.print (",");
D_sensores.print (Temp);
D_sensores.print (",");
D_sensores.print (HR);
D_sensores.print (",");
D_sensores.print (TempAmbInfra);
D_sensores.print (",");
D_sensores.print (TempObjInfra);
D_sensores.println (",");
D_sensores.close();
// Guardado de tiempo de ultima medición
t1_o = t1;
t2_o = t2;
t3_o = t3;
// Espera de 1 segundo antes de continuar con el siguiente paso de tiempo
delay (1000);
}// End iF
}// End while
}// End void setup
void loop()
{
//
}