datalogger proyect problem ARDUINOuno+rtc1307+SDv3+LCD

Hi everyone
I have this problam and have stoked on it
I have errors on data saving and I do not now why first data has to be “int”?
please helpme

tks
juandagali_g m a i l or appreciate from here :wink:

CODE --PROBLEM ROWS 119-150********************************


#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 9, 3, 5, 6, 7);
#include <DS1307RTC.h>
#include <Wire.h>
#include <RTClib.h>
#include <Time.h>
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4; //VER3.0 =4 ROJO =8
String bot,cadena,fecha;
String dataString;
int boton,menu,pp=0,idia,imes,iano,ihora,imin,iseg,ix,entrandoM,Deltat=5;
float ical,idc,tempe,tempi;
RTC_DS1307 rtc;

void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
entrandoM=1;
menu=0;
bot=“0”;
ical=18.0;
pinMode(10, OUTPUT); //enciende luz LCD
pinMode(A0, INPUT); // IN TECLADO
pinMode(A1, INPUT); // IN tempi
pinMode(A2, INPUT); // IN tempi
pinMode(A3, INPUT); // IN Idc

//pinMode(chipSelect, OUTPUT);//ESTO ES PARA LA SD (8)
digitalWrite(10, HIGH);
lcd.setCursor(0, 0);
lcd.print(“E&P Log Nev v7”);
lcd.setCursor(0, 1);
lcd.print(“Iniciando…”);
delay(100);
//see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Falla de SD…”);
cadena=“problema”;
delay(1500);
return;
}
else {lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“OK SD inic MENU”);
delay(1000);
}
delay(100);
Wire.begin();
rtc.begin();
setSyncProvider(RTC.get);
setSyncInterval(60); // establecer el número de segundos entre resincronización
if(timeStatus()!= timeSet)
{ lcd.print(“Unable sync RTC”);
delay(10000);
}
else { lcd.print(“Ok sync con RTC”);
delay(100);
}
if (! rtc.isrunning())
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“RTC NOT run”);
delay(950*Deltat); //ver filas 60,111,177
cadena=“problema”;//escribaproblema();
//rtc.adjust(DateTime(F(DATE), F(TIME)));
DateTime now = rtc.now();
}
else DateTime now = rtc.now();
ver();
delay(100);
lcd.clear(); //Muestra por un momento la hora actual antes de empezar a loguear
lcd.print(“Verificando SD…”);
delay(100);

}
void loop() {
if (cadena==“problema”) {escribaproblema();}
else
{
menu=1;
//BOTONPRES();//siempre leo el boton

//-------------------------------------------------------------------menu 0-------
if(menu==0) //MENU 0= MENU PRINCIPAL ****************
{
if (entrandoM==1)
{
lcd.clear();
entrandoM=0;
}
lcd.setCursor(1, 0);
lcd.print("Registrar "); //menu=1
lcd.setCursor(1, 1);
lcd.print("Reloj "); //menu=2
if(bot==“U”) pp=0;
if(bot==“D”) pp=1;
if(bot==“S”)
{
menu=pp+1; //menu= 1->Registrar, 2->Reloj
pp=0;
bot=“0”;
delay(500);
entrandoM=1;
}
SERAreinicio();
verBM();// aqui va a ver menu—
} //MENU 0= MENU PRINCIPAL ****************
//-------------------------------------------------------------------menu 1-------
if(menu==1) //MENU 1= registrar datos ENTRANDO AL LOGGER**************
{
//if (entrandoM==1)
// { lcd.clear();
// delay(1000);
// entrandoM=0;
// pp=0;
// bot=“0”;
// }
// make a string for assembling the data to log:
String dataString = “”;
tempi = (495.0analogRead(A1))/1024.00; //SENSOR DE temperatura con LM35
tempe = (495.0
analogRead(A2))/1024.00; //SENSOR DE temperatura con LM35
idc=((2.00ical(analogRead(A3))/1023.00)-ical); //SENSOR DE corriente DC de -5A
dataString = String(1) + “,” + String(idc,1) + “,” + String(tempi,1) + “,” + String(tempe,1);
delay(500);
// 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(“nevera8.csv”, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
delay(500);
// print to the serial port too:
Serial.println(dataString);
lcd.clear();//imprima en LCD tambien
lcd.setCursor(0,0);
lcd.print(dataString);
Serial.println(dataString);
dataString = “”;
delay(500);
}
// if the file isn’t open, pop up an error:
else
{Serial.println(“error nevera8.csv”);
}
//tempe = ( 4.95100.0(analogRead(A2)) ) / 1024.0; //SENSOR DE temperatura con LM35
//Vdc = 12; //Voltios lo supongo constante para no medirlo
//DateTime now = rtc.now();
// iano=now.year();
// imes=now.month();
// idia=now.day();
// ihora=now.hour();
// imin=now.minute();
// iseg=now.second();

//Serial.println(fecha);
//lcd.setCursor(0, 0);
//lcd.print(“I=”);
//lcd.print(String(Idc));
//lcd.print(“A “+ String(printDigits(ihora))+”:”+String(printDigits(imin))+":"+String(printDigits(iseg)));
//lcd.setCursor(0, 1);
//lcd.print(“Ti=”);
//lcd.print(String(tempi,1));
//lcd.print(" Te=");
//lcd.print(String(tempe,1));
// delay(2000);
//}
//else //(!Archivo) //else
// { lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print(“Err nevera.csv”);
// delay(10000);
// cadena=“problema”;
//BOTONPRES();
//SERAreinicio();
// }
//BOTONPRES();
//if(bot==“L”)
// { menu=0;
// pp=0;
// bot=“0”;
// entrandoM=1;
// lcd.clear();
// lcd.setCursor(0, 1);
// lcd.print("Parando… ");
// delay(1000);
// dataFile.close();
// delay(100);
// }
//SERAreinicio();
//delay(970*Deltat);
// verBM();// aqui va a ver menu---------------
//incio del calculo de la temperatura
} //MENU 1= ENTRANDO AL LOGGER**************

}//… F I N DEL L O O P …

Datalogger_UNO_Nevera_30nov_JDHRver008.ino (19.5 KB)

You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.

ie Your code and any error messages should always be placed between code tags. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis. (And after 17 posts on these forums you should already be aware of this.)

It's still not too late to edit your post and do this. You'll make potential helpers much happier. :)

And once you've done that, perhaps you should post the errors you received, (also between code tags).

//CODE --PROBLEM ROWS arrond menu==1

#include <LiquidCrystal.h> 
LiquidCrystal lcd(2, 9, 3, 5, 6, 7);
#include <DS1307RTC.h>
#include <Wire.h>      
#include <RTClib.h>  
#include <Time.h>  
#include <SPI.h> 
#include <SD.h> 
const int chipSelect = 4; 
String bot,cadena,hora;
int boton,menu,pp=0,idia,imes,iano,ihora,imin,iseg,ix,entrandoM,Deltat=2;
float ical,idc,tempe,tempi;
RTC_DS1307 rtc;

void setup() {
 Serial.begin(9600);
 lcd.begin(16, 2);
 lcd.clear();
 entrandoM=1;
 menu=0;
 bot="0";
 ical=18.0;
 //pinMode(10, OUTPUT);
 pinMode(chipSelect, OUTPUT);
 //digitalWrite(10, HIGH); 
 lcd.setCursor(0, 0);
 lcd.print("E&P Log Nev v7");
 lcd.setCursor(0, 1);
 lcd.print("Iniciando...");
 delay(111);
if (!SD.begin(chipSelect)) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Falla de SD...");
  cadena="problema";
  delay(5000); 
  return;
  }
 else {lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("OK SD  ...(50%)");
    delay(111); 
    }
 delay(100);   
 Wire.begin();
 rtc.begin();
 setSyncProvider(RTC.get);
 setSyncInterval(60);    
 lcd.clear();
 if(timeStatus()!= timeSet)
       { lcd.print("Unable sync RTC");
        delay(10000);
       }
    else { lcd.print("Ok RTC ...(100%)");
        delay(111);
       }
  if (! rtc.isrunning()) 
  { lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("RTC NOT run");
   delay(950*Deltat); 
   cadena="problema";//escribaproblema(); 
   //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
   DateTime now = rtc.now();
  }
  else 
  { DateTime now = rtc.now();
   ver();
   delay(1000);
   cadena="";
   }
}
void loop() {
 if (cadena=="problema") {escribaproblema();}
 else
 {
 menu=1;
 BOTONPRES();


 if(menu==1) 
  {  
    if (entrandoM==1)
    { lcd.clear();
     delay(1000);
     entrandoM=0;
     pp=0;
     bot="0";
    }
 String dataString = "";
 tempi=0;
 tempe=0;
 idc=0;
 hora="";
 cadena="";
 for (int i=0 ; i<1000 ; i++)  
 { tempi = tempi + (495.0*analogRead(A1))/1023.00; 
   tempe = tempe + (495.0*analogRead(A2))/1023.00; 
   idc = idc + (((2.00*ical*(analogRead(A3))/1023.00)-ical) + 0.1); 
 }
 tempi=tempi/1000;
 tempe=tempe/1000;
 idc=idc/1000;  
  //dataString = String(1) + "," + String(idc,1) + "," + String(tempi,1) + "," + String(tempe,1);
  dataString = ""+String(fh()) + "," + String(tempi,1) + "," + String(tempe,1) + "," + String(idc,1)+",";//+String(fh());
  //dataString = "," +String(fh());
 File dataFile = SD.open("nevera8.csv", FILE_WRITE);
  if (dataFile) {
   //dataFile.println(dataString);
   //dataFile.println("22.1");
   //dataFile.println();
   dataFile.println(""+String(dataString));
   //dataFile.print(",");
   //dataFile.print(String(tempi,1));
   //dataFile.print(",");
   //dataFile.print(String(tempe,1));
   //dataFile.print(",");
   //dataFile.println(String(idc,1));
   dataFile.close();
   // print to the serial port too: //Serial.println(dataString);
   //Serial.println("22");
   //Serial.println(dataString);
   //Serial.println();
   Serial.println(""+String(dataString));
   //Serial.print(",");
   //Serial.print(String(tempi,1));
   //Serial.print(",");
   //Serial.print(String(tempe,1));
   //Serial.print(",");
   //Serial.println(String(idc,1));
   lcd.clear();
    lcd.setCursor(0, 0);
     lcd.print(""+String(dataString));
     //lcd.print("I=");
     //lcd.print(String(idc,1));
     //lcd.print("A ");
     //lcd.print(String(hora));
    lcd.setCursor(0, 1);
     lcd.print("Ti=");
     lcd.print(String(tempi,1));
     lcd.print(" Te=");
     lcd.print(String(tempe,1));
   dataString = "";
   delay(100);
  }
  // if the file isn't open, pop up an error:
  else 
  { Serial.println("Err nevera8.csv");
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Err_nevera8.csv");
   delay(10000);
   cadena="problema";
   BOTONPRES();
   SERAreinicio();
  }
BOTONPRES();
SERAreinicio();
//SERAparo();
delay(900*Deltat);
//verBM();
}

That's better. (Although you could have simply edited your original post as suggested and placed the code between code tags, rather than reposting it.)

You still haven't clearly stated what the actual problem is:-

I have errors on data saving and I do not now why first data has to be "int"?

What do you mean by "first data"? What errors?

If you really want help with this, you need to provide as much information as possible, to make it easier for us to find the problem. We want to help, but you need to help us to help you.

The code you posted does not compile without errors--mostly missing functions. Your first code with the attachment does compile but produces stabilitiy warnings due to its size.

Can you write a simple test program which compiles and demonstrates your issue?