Estoy intentando conectar el rtc a una placa Leonardo para configurar su fecha y hora.
El pin SDA lo tengo conectado al puerto A4 y el SCL al puerto A5, pero al compilar y subir el código no me muestra nada. ¿Que podría ser?
Cabe destacar que ya descargue la libreria de RTC.
Este es el codigo que estoy usando:
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
void setup() {
rtc.begin();
rtc.adjust(DateTime(__DATE__, __TIME__));
/* The rest of the code is not necessary to set the time,
* we're just making sure it was set correctly: */
Serial.begin(9600);
DateTime now = rtc.now();
printDate(now);
}
void loop() {
}
void printDate(DateTime date) {
Serial.print(date.year(), DEC);
Serial.print('/');
Serial.print(date.month(), DEC);
Serial.print('/');
Serial.print(date.day(), DEC);
Serial.print(" ");
Serial.print(date.hour(), DEC);
Serial.print(':');
Serial.print(date.minute(), DEC);
Serial.print(':');
Serial.print(date.second(), DEC);
Serial.println();
}
Yo uso este codigo y no me da problemas con NANO y UNO con DS3231..
//de los ejemplos RTlib
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"DOMINGO", "LUNES", "MARTES", "MIERCOLES", "JUEVES", "VIERNES", "SABADO"};
void setup () {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(9600);
delay(3000); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2019, 11, 18, 3, 0, 0));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(" ");
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
// calculate a date which is 7 days and 30 seconds into the future
//DateTime future (now + TimeSpan(7,12,30,6));
Serial.println();
delay(3000);
}