Hello I need your help . I can´t copilated the program . I think that I will need any library how FileIO.h Could you tell me where is the mistake. I attachment the program.
Thanks for you comment.
#include <SD.h>
#include <SPI.h>
#include <SD.h>
#include <Bridge.h>
#include <Console.h>
#include <SoftwareSerial.h>
File myFile;
SoftwareSerial bluetooth(10, 11); // RX, TX
int led = 13;
int numero,CRepo,Volt,Ampe,Cons,Poten,VAH=0; // **** Variables de Conteo
float PVolt,PCosf,PKwah,CVolt,CCosf,CKwah= 0; // **** Variables Promedio de salida
float MaxVolt,MinVolt,MaxCosf,MinCosf=0; // **** Variables de Maxima y Minimas de salida
float VMaxVolt,VMaxCosf; // **** Variable patron de Maxima y Minimas
float VMinVolt=300; // **** Seteo de Variable Minima de Volt
float VMinCosf=1; // **** Seteo de Variable Minima de Cosf
float Precio= 15.45; // **** Precio estimade KwaH
String Alarma,Estado;
float ValorKwah=0.407;
int horas=1440; // **** Cantidad de Horas equivalentes a 60 dias
float Kwahale=0;
float Cosf=0;
float Kwah=0;
int tiempo=0;
int HORA[]={9,59,0};
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600); //115200
bluetooth.begin(9600);
pinMode(led, OUTPUT); // Funcion Reporte de ALERTA de REPORTE Tension y Coseno Fi//
pinMode(53, OUTPUT);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
if (!SD.begin()) {
Serial.println("Inicializacion Fallo!");
return;
}
else{
Serial.println("Inicializacion OK");
}
myFile=SD.open("alertas",FILE_WRITE);
}
void loop() {
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
tiempo=tiempo+1;
if ( bluetooth.available()){
Serial.write( bluetooth.read());
if (Serial.available()){
bluetooth.write(Serial.read());
}
}
// Asigancion de Valores aleatoreos a Variables Voltaje, Amperaje,
// KiloWattAmperHora, Coseno Fi y Consumo en Pesos
String Ent=SalidaPowerMeter(); // Entrada de String frl Power Meter - RS232
Serial.println(" Valor de entrada del Power Meter ");
Serial.println(Ent);
Volt=VariablesEntrada(Ent,3).toInt();
Ampe=VariablesEntrada(Ent,4).toInt();
Poten=VariablesEntrada(Ent,5).toInt();
VAH=VariablesEntrada(Ent,6).toInt();
Cosf=StringToFloat(VariablesEntrada(Ent,7));
Kwah=StringToFloat(VariablesEntrada(Ent,8));
Kwah=StringToFloat(VariablesEntrada(Ent,8));
Cons=StringToFloat(VariablesEntrada(Ent,9));
// ********* MANEJO DEL TIEMPO corrida PROGRAMA ***********//
HORA[2]=tiempo+HORA[2];
if(HORA[2]>=60){
HORA[1]=HORA[1]+1;
HORA[2]=HORA[2]-60;
}
if(HORA[1]>=60){
HORA[0]=HORA[0]+1;
HORA[1]=HORA[1]-60;
}
// MuestraHora(HORA);
tiempo=0;
// ************ Presentacion de salida ***********
/* Serial.print("Valor del KwahAle :");
Serial.println(Kwahale);
Serial.print(" Valor del Real:");
Serial.println(Kwah);
*/
// Muestra(Volt,Ampe,Kwah,Cosf,Cons);
VMaxVolt=Maxima(Volt,VMaxVolt);
VMaxCosf=Maxima(Cosf,VMaxCosf);
VMinVolt=Minima(Volt,VMinVolt);
VMinCosf=Minima(Cosf,VMinCosf);
CRepo++;1;
CVolt=CVolt+Volt;
CCosf=CCosf+Cosf;
CKwah=CKwah+Kwah;
//***********************************************************************************//
//******** Presentacion de Reporte de Calidad y consumo Energetico ********** //
//***********************************************************************************//
if(CRepo==30){
MuestraHora(HORA);
PKwah=Promedio(CKwah,CRepo);
PresentacionReporte();
ReporteEstadistico(VMinVolt,Volt,VMaxVolt,"Valores de Tension = ");
ReporteEstadistico(VMinCosf,Cosf,VMaxCosf,"Valores de CosenFi = ");
ReporteConsumoPromedio("Consumo KWah= ",PKwah," costo por Hora: $ ",ValorKwah);
CVolt=0;
CCosf=0;
CKwah=0; VMaxVolt,VMaxCosf,PVolt,PCosf,CRepo=0;
VMinVolt=300;
VMinCosf=1;
}
//***********************************************************************************//
//**************** ALERTA Control de la Tension entre 210 y 225 Volt ************* //
//***********************************************************************************//
if(Volt==195){
Alarma="VOLTAJE ";
Estado=" Voltaje por DEBAJO de lo Normal";
AlarmaVoltaje(Alarma,Volt,Estado);
GuardarDato(Ent);
}
if(Volt==229){
Alarma="VOLTAJE ";
Estado=" Voltaje por ENCIMA de lo Normal";
AlarmaVoltaje(Alarma,Volt,Estado);
GuardarDato(Ent);
}
//***********************************************************************************//
//************** ALERTA Control del Coseno Fi por debajo 0.89 ********************//
//***********************************************************************************//
if(Cosf==0.87){
Alarma="COSENO FI ";
Estado=" POR DEBAJO 0,89";
AlarmaCosenoFi(Alarma,Cosf,Estado);
GuardarDato(Ent);
CCosf++;
// PCosf=PromedioFalla(CCosf,Cosf,PCosf);
}
}
/****************************************/
/************* FUNCIONES ****************/
/****************************************/
/************ FUNCIONES ******************/
void GuardarDato(String dato){
File mio=SD.open("alertas.txt", FILE_WRITE);
if(SD.exists("Alertas.txt")){
Serial.println("Existe el archivo Alertas.txt");
}else{
Serial.println("No existe el archivo");
}
if(mio){
Serial.print("Escribiendo en Archivo Alertas.txt...");
mio.print("Registro de la Hora: ");
mio.println(dato);
mio.flush();
Serial.print("Se guardo registro ");
Serial.println(dato);
} else {
Serial.println("No se pudo abrir archivo Alertas.txt");
}
mio.flush();
mio.close();
delay(2000);
}[table]
[tr]
[td][/td]
[/tr]
[/table]
Error1.txt (33 KB)