Hola, dispongo de un ESP32 y quiero obtener la hora, los minutos y los segundos de un dispositivo MCP7940 (es un RTC de Microchip por I2C) y mostrarlos en un LCD (conectado por I2c) .
He encontrado la siguiente librería en el enlace:
github.com
Con ella puedo leer los datos anteriormente citados, el problema es que los segundos van muy lentos. Lo he probado en dos PCBs que tengo de prueba, y en ambas va igual de lento, con lo que he descartado problemas de hardware o en la PCB.
Muchas gracias por la ayuda.
He simplificado el código y lo pongo a continuación:
#include <Wire.h>
#include "MCP794xx.h"
#include "LiquidCrystal_I2C.h"
#include <math.h>
MCP794xx rtc1;
////////// LCD //////////////
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
//LiquidCrystal_I2C lcd(0x20, lcdColumns, lcdRows);
//////////////////////////////////////////////////
void setup()
{
lcd.init();
lcd.backlight();
// Start Serial Communication
Serial.begin(9600);
//rtc1.setTime12(11, false, 39, 45); // Set the time in 12h format
// rtc1.setTime24(17, 52, 0); // Para configurar HORAS, MINUTOS, SEGUNDOS en formato 24h
// You can also set the date in a single function call
//rtc1.setCalendar(18, _FEB, 23); // Set the calendar, weekday must be set seperately
//rtc1.setWeekday(_THUR); // Set the weekday.
rtc1.start(); // Turn on the clock, begins tracking time
//delay(1000);
// Set the Multifunction pin to output a square wave.
//rtc1.setMFPinSquareWave(_32kHz);
//delay(3000);
//rtc1.setMFPinSquareWave(_8kHz);
//delay(3000);
//rtc1.setMFPinSquareWave(_4kHz);
//delay(3000);
//rtc1.setMFPinSquareWave(_1Hz);
//delay(3000);
}
// the loop function runs over and over again until power down or reset
void loop()
{
lcd.setCursor(0, 0);
lcd.print(" MCP7940 ");
lcd.setCursor(4, 1);
lcd.print(rtc1.getHours());
lcd.print(+ ":") ;
lcd.print(rtc1.getMinutes());
lcd.print(":") ;
lcd.print(rtc1.getSeconds());
lcd.println(" ");
}
He encontrado la siguiente librería en el enlace:
GitHub - KrazTech/MCP794xx: Arduino Library for Kraztech MCP794xx RTC Module
Arduino Library for Kraztech MCP794xx RTC Module. Contribute to KrazTech/MCP794xx development by creating an account on GitHub.
Con ella puedo leer los datos anteriormente citados, el problema es que los segundos van muy lentos. Lo he probado en dos PCBs que tengo de prueba, y en ambas va igual de lento, con lo que he descartado problemas de hardware o en la PCB.
Muchas gracias por la ayuda.
He simplificado el código y lo pongo a continuación:
#include <Wire.h>
#include "MCP794xx.h"
#include "LiquidCrystal_I2C.h"
#include <math.h>
MCP794xx rtc1;
////////// LCD //////////////
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
//LiquidCrystal_I2C lcd(0x20, lcdColumns, lcdRows);
//////////////////////////////////////////////////
void setup()
{
lcd.init();
lcd.backlight();
// Start Serial Communication
Serial.begin(9600);
//rtc1.setTime12(11, false, 39, 45); // Set the time in 12h format
// rtc1.setTime24(17, 52, 0); // Para configurar HORAS, MINUTOS, SEGUNDOS en formato 24h
// You can also set the date in a single function call
//rtc1.setCalendar(18, _FEB, 23); // Set the calendar, weekday must be set seperately
//rtc1.setWeekday(_THUR); // Set the weekday.
rtc1.start(); // Turn on the clock, begins tracking time
//delay(1000);
// Set the Multifunction pin to output a square wave.
//rtc1.setMFPinSquareWave(_32kHz);
//delay(3000);
//rtc1.setMFPinSquareWave(_8kHz);
//delay(3000);
//rtc1.setMFPinSquareWave(_4kHz);
//delay(3000);
//rtc1.setMFPinSquareWave(_1Hz);
//delay(3000);
}
// the loop function runs over and over again until power down or reset
void loop()
{
lcd.setCursor(0, 0);
lcd.print(" MCP7940 ");
lcd.setCursor(4, 1);
lcd.print(rtc1.getHours());
lcd.print(+ ":") ;
lcd.print(rtc1.getMinutes());
lcd.print(":") ;
lcd.print(rtc1.getSeconds());
lcd.println(" ");
}