hi all, well my project its quite simple, an arduino uno, with and sd module and a RTC for datalog 3 DHT11 sensors, all since to compile and work ok but the SD only open 4 and sometimes 5 files out of 6, temperature and humidity are saved on differentes files, but i cant manage to open all files, i got a message from the compiler that im using 78% of the dinamic memory so the bord could be unestable, maybe my code its too large and maybe i need to make it more simple.
[code]
/*
*
*/
#include <SPI.h> //for the SD card module
#include <SD.h> // for the SD card
#include <DHT.h> // for the DHT sensor
#include <RTClib.h> // for the RTC
//define DHT pin
#define DHTPIN A0 // what pin we're connected to
#define DHTPIN A1
#define DHTPIN A2
// uncomment whatever type you're using
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// initialize DHT sensor for normal 16mhz Arduino
DHT dhta(A0, DHTTYPE);
DHT dhtb(A1, DHTTYPE);
DHT dhtc(A2, DHTTYPE);
// change this to match your SD shield or module;
// Arduino Ethernet shield and modules: pin 4
// Data loggin SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
// Create a file to store the data
File myFile1;
File myFile2;
File myFile3;
File humedad1;
File humedad2;
File humedad3;
// RTC
RTC_DS3231 rtc;//RTC_DS1307 rtc; //uncoment for type
void setup() {
//initializing the DHT sensor
dhta.begin();
dhtb.begin();
dhtc.begin();
//initializing Serial monitor
Serial.begin(9600);
// setup for the RTC
while(!Serial); // for Leonardo/Micro/Zero
if(! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
else {
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
if(! rtc.begin()) {//change rtc.isrunning() //for the DS1307
Serial.println("RTC is NOT running!");
}
// setup for the SD card
Serial.print("Initializing SD card...");
if(!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
//open file
myFile1=SD.open("DATA1.txt", FILE_WRITE);
humedad1=SD.open("Humedad1.txt", FILE_WRITE);
myFile2=SD.open("DATA2.txt", FILE_WRITE);
humedad2=SD.open("Humedad2.txt", FILE_WRITE);
myFile3=SD.open("DATA3.txt", FILE_WRITE);
humedad3=SD.open("Humedad3.txt", FILE_WRITE);
// if the file opened ok, write to it:
if (myFile1) {
Serial.println("File opened ok");
// print the headings for our data
myFile1.println("Date,Time,Temperature ºC");
}
myFile1.close();
if (humedad1) {
Serial.println("File opened ok");
// print the headings for our data
humedad1.println("Date,Time,humidity %");
}
humedad1.close();
// if the file opened ok, write to it:
if (myFile2) {
Serial.println("File opened ok");
// print the headings for our data
myFile2.println("Date,Time,Temperature ºC");
}
myFile2.close();
if (humedad2) {
Serial.println("File opened ok");
// print the headings for our data
humedad2.println("Date,Time,humidity %");
}
humedad2.close();
// if the file opened ok, write to it:
if (myFile3) {
Serial.println("File opened ok");
// print the headings for our data
myFile3.println("Date,Time,Temperature ºC");
}
myFile3.close();
if (humedad3) {
Serial.println("File opened ok");
// print the headings for our data
humedad3.println("Date,Time,humidity %");
}
humedad3.close();
}
void loggingTime() {
DateTime now = rtc.now();
myFile1 = SD.open("DATA1.txt", FILE_WRITE);
if (myFile1) {
myFile1.print(now.year(), DEC);
myFile1.print('/');
myFile1.print(now.month(), DEC);
myFile1.print('/');
myFile1.print(now.day(), DEC);
myFile1.print(',');
myFile1.print(now.hour(), DEC);
myFile1.print(':');
myFile1.print(now.minute(), DEC);
myFile1.print(':');
myFile1.print(now.second(), DEC);
myFile1.print(",");
}
humedad1 = SD.open("Humedad1.txt", FILE_WRITE);
if (humedad1) {
humedad1.print(now.year(), DEC);
humedad1.print('/');
humedad1.print(now.month(), DEC);
humedad1.print('/');
humedad1.print(now.day(), DEC);
humedad1.print(',');
humedad1.print(now.hour(), DEC);
humedad1.print(':');
humedad1.print(now.minute(), DEC);
humedad1.print(':');
humedad1.print(now.second(), DEC);
humedad1.print(",");
}
myFile2 = SD.open("DATA2.txt", FILE_WRITE);
if (myFile2) {
myFile2.print(now.year(), DEC);
myFile2.print('/');
myFile2.print(now.month(), DEC);
myFile2.print('/');
myFile2.print(now.day(), DEC);
myFile2.print(',');
myFile2.print(now.hour(), DEC);
myFile2.print(':');
myFile2.print(now.minute(), DEC);
myFile2.print(':');
myFile2.print(now.second(), DEC);
myFile2.print(",");
}
humedad2 = SD.open("Humedad2.txt", FILE_WRITE);
if (humedad2) {
humedad2.print(now.year(), DEC);
humedad2.print('/');
humedad2.print(now.month(), DEC);
humedad2.print('/');
humedad2.print(now.day(), DEC);
humedad2.print(',');
humedad2.print(now.hour(), DEC);
humedad2.print(':');
humedad2.print(now.minute(), DEC);
humedad2.print(':');
humedad2.print(now.second(), DEC);
humedad2.print(",");
}
myFile3 = SD.open("DATA3.txt", FILE_WRITE);
if (myFile3) {
myFile3.print(now.year(), DEC);
myFile3.print('/');
myFile3.print(now.month(), DEC);
myFile3.print('/');
myFile3.print(now.day(), DEC);
myFile3.print(',');
myFile3.print(now.hour(), DEC);
myFile3.print(':');
myFile3.print(now.minute(), DEC);
myFile3.print(':');
myFile3.print(now.second(), DEC);
myFile3.print(",");
}
humedad3 = SD.open("Humedad3.txt", FILE_WRITE);
if (humedad3) {
humedad3.print(now.year(), DEC);
humedad3.print('/');
humedad3.print(now.month(), DEC);
humedad3.print('/');
humedad3.print(now.day(), DEC);
humedad3.print(',');
humedad3.print(now.hour(), DEC);
humedad3.print(':');
humedad3.print(now.minute(), DEC);
humedad3.print(':');
humedad3.print(now.second(), DEC);
humedad3.print(",");
}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.println(now.day(), DEC);
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
myFile1.close();
myFile2.close();
myFile3.close();
humedad1.close();
humedad2.close();
humedad3.close();
delay(9000);
}
[/code]
since the code its too long im not showing how i read the sensors
datalogger3sensores.ino (11.6 KB)