Autre module de gestion du temps qui a l’avantage d’utiliser le bus I2C
Les broches utilisées sont :
- SCL à la broche A4
- SDA à la broche A5
- VCC à la broche 5V
- GND à la broche GND
Sketch :
///////////////////////////////////////////////
// Micro module : GND/vide/SCL/SDA/+5v //
///////////////////////////////////////////////
#include <Wire.h>
#include <ds3231.h> //https://github.com/rodan/ds3231
struct ts t; //déclaration variable t
void setup() {
Serial.begin(9600);
Wire.begin();
DS3231_init(DS3231_INTCN);
//-- données pour mettre à l'heure l'horloge
/*
t.hour=22;
t.min=27;
t.sec=0;
t.mday=27;
t.mon=9;
t.year=2020;
DS3231_set(t); // mise à l'heure de l'horloge
*/
//////////////////////////////////////////////
}
void loop() {
// put your main code here, to run repeatedly:
DS3231_get(&t);
Serial.print("date : ");
Serial.print(t.mday);
Serial.print("/");
Serial.print(t.mon);
Serial.print("/");
Serial.print(t.year);
Serial.print("\t Heure : ");
Serial.print(t.hour);
Serial.print(":");
Serial.print(t.min);
Serial.print(".");
Serial.println(t.sec);
delay(500);
}
Utilisez la librairie :
https://github.com/NorthernWidget/DS3231
Références :