Problemas con reloj en arduino

4 Sep 2008
172
España
Provincia
Madrid
Hola
He tenido un problema con el reloj de arduino y es que el reloj que tenia puesto se ha quemado por problemas de calentamiento ( mia culpa ) . He comprado otro reloj y la verdad es uqe ahora no consigo hacelo funcionar.

Los dos relojes son rtc 1307 pero en distintas formas.
Lo he conectado al arduino sin modificar el codigo y se vuelve loco.

Tengo otro arduino por casa y estoy haciendo pruebas con el para poder configurarlo correctamente pero no lo consigo.

Este es el codigo que he conseguido que me muestre cosas por serial monitor aunque no consigo hacerle funcionar.

#include <Wire.h> // Esta es la libreria de comunicacion I2C
#define DS1307_I2C_ADDRESS 0x68
// declaramos la libreria del LCD
#include <LiquidCrystal.h>

// Inicializamos el LCD dandole los pines a usar
LiquidCrystal lcd(7,8, 9, 10, 11, 12);
// Convierte números normales decimales a BCD (binario decimal codificado)
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

// Convierte BCD (binario decimal codificado) a números normales decimales
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock

void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second));
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}

// Establece la fecha y la hora del reloj
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control

*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}

void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
lcd.begin(20, 4);


// la primera vez debemos poner en hora, active esta parte y luego vuelva a quitarla
second = 00;
minute = 15;
hour = 21;
dayOfWeek = 6;
dayOfMonth = 19;
month = 9;
year = 9;

setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

}

void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

Serial.print("20");
if (year < 10) Serial.print("0");
Serial.print(year, DEC);
Serial.print("/");
if (month < 10) Serial.print("0");
Serial.print(month, DEC);
Serial.print("/");
if (dayOfMonth < 10) Serial.print("0");
Serial.print(dayOfMonth, DEC);
Serial.print(" ");
if (hour < 10) Serial.print("0");
Serial.print(hour, DEC);
Serial.print(":");
if (minute < 10) Serial.print("0");
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10) Serial.print("0");
Serial.print(second, DEC);
Serial.print(" Dia de la semana:");
Serial.println(dayOfWeek, DEC);
switch (dayOfWeek)
{
case 1:
Serial.println(" Lunes");
break;
case 2:
Serial.println(" Martes");
break;
case 3:
Serial.println(" Miercoles");
break;
case 4:
Serial.println(" Jueves");
break;
case 5:
Serial.println(" Viernes");
break;
case 6:
Serial.println(" Sabado");
break;
case 7:
Serial.println(" Domingo");
break;
}


delay(1000); //Pausa durante 1 segundo
}

esto es lo que hace este codigo
relojn.png

Las conexiones son las siguientes:

rtc arduino
slc 5
sda 4
vcc +5v
gnd masa

Este es el reloj que he comprado

rtct.jpg
Tengo arduino duemilanove

A ver si me podeis hechar una mano

Gracias
 
Arriba