Hola y gracias por vuestro tiempo.
Estoy intentando grabar cada minuto la temperatura de un sensor DHT11 en una eeprom de 512kb cada minuto, y un rtc Pcf8563.
El problema es que siempre me graba la hora y los minutos como 0. La temperatura y la humedad las graba bien.
La primera vez que lo cargo pongo en hora y fecha actual el reloj y luego comento las lineas.
El sketch es un refrito de varios, grabo los datos el void escribir_eeprom() y leo con void leer_eeprom().
Alguna idea de porque no graba ?
#include "Wire.h" // for I2C
#define chip1 0x50 // direccion de la eeprom
#include <Rtc_Pcf8563.h>
//init the real time clock
Rtc_Pcf8563 rtc;
Pcf8563
#include "DHT.h" //Añadimos la libreria con la cual trabaja nuestro sensor
#define DHTPIN 2 // Indicamos el pin digital donde conectaremos la patilla data de nuestro sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
byte hora=0;
int minutos=0;
int dia=0;
int mes=0;
int anio=0;
unsigned int direccion=0;
int h=0;
int t=0;
void setup()
{
Serial.begin(9600); // for screen output
Wire.begin(); // inicia, I2C!
// rtc.initClock();
//set a time to start with.
//day, weekday, month, century, year
// rtc.setDate(21, 3, 3, 0, 14);
// //hr, min, sec
//rtc.setTime(22, 30, 00);
}
void writeData(int device, unsigned int add, byte data)
// writes a byte of data 'data' to the chip at I2C address 'device', in memory location 'add'
{
Wire.beginTransmission(device);
Wire.write((int)(add >> 8)); // left-part of pointer address
Wire.write((int)(add & 0xFF)); // and the right
Wire.write(data);
Wire.endTransmission();
delay(10);
}
byte readData(int device, unsigned int add)
// reads a byte of data from memory location 'add' in chip at I2C address 'device'
{
byte result; // returned value
Wire.beginTransmission(device); // these three lines set the pointer position in the EEPROM
Wire.write((int)(add >> 8)); // left-part of pointer address
Wire.write((int)(add & 0xFF)); // and the right
Wire.endTransmission();
Wire.requestFrom(device,1); // now get the byte of data...
result = Wire.read();
return result; // and return it as a result of the function readData
}
void loop()
{
escribir_eeprom();
//leer_eeprom();
}
void escribir_eeprom(){
writeData(chip1,direccion,rtc.getHour());
direccion++;
writeData(chip1,direccion,rtc.getMinute());
direccion++;
writeData(chip1,direccion,dht.readHumidity());
direccion++;
writeData(chip1,direccion,dht.readTemperature());
direccion++;
delay(60000);
}
void leer_eeprom(){
hora=readData(chip1,direccion);
if (hora<10) {
Serial.print("0");
}
Serial.print(hora, DEC);
Serial.print(":");
direccion++;
minutos=readData(chip1,direccion);
if (minutos<10) {
Serial.print("0");
}
Serial.print(minutos, DEC);
direccion++;
Serial.print(" ");
h=readData(chip1,direccion);
Serial.print("Humedad relativa: ");
Serial.print(h, DEC);
Serial.print(" %\t");
direccion++;
t=readData(chip1,direccion);
Serial.print("Temperatura: ");
Serial.print(t, DEC);
Serial.println(" *C");
direccion++;
}