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 ![]()
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.0analogRead(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 .......................