je voudrais utiliser le RTC dans mon code.
donc j'ai telechargé la lib RTClib, avant de l'inclure à mon projet j'ai eu l'idée de tester l'exemple pour me familiariser avec le module et etre sur que ca marche.
malheuresement je compile et je televerse à mon arduino uno et là j'ai cela en port serial :
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
while (!Serial); // for Leonardo/Micro/Zero
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 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(2014, 1, 21, 3, 0, 0));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year());
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}
pour le cablage : j'ai bien mis : Data vers SDA , SLC vers CLK
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 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(2014, 1, 21, 3, 0, 0));
}
Lis les messages épinglés en haut du forum : l'un d'eux explique les données à fournir pour qu'on puisse t'aider. Précise ton matériel, branchement, code, etc.
lgabed420:
j'arrive pas à faire fonctionner le DS1307; meme pas avec l'example fournit avec la lib
P**ain, c'est quand même pas difficile de décrire ce qui se passe.
Est ce que tu as un message affiché? si oui lequel?
Est ce que l'heure est incorrecte?
...
Oulaaaa on se calme un peu non ?
c'est pas parce que tu m'aides que tu vas me manquer du respect je prefere ne pas avoir de repondre que entendre des Pu**ain ... En plus depuis toute a lheure je vous explique mon probleme j'ai le message " RTC .. is not running" et j'ai donné le code , le branchement et le materiel, soyez un peu gentil messieurs, on est là pour apprendre
je reformule tout :
(voltage pile 2,8 V)
le material : arduino UNO , module RTC DS1307
branchement :Data vers SDA , SLC vers CLK
code : voir ci-dessous
Problemes : j'arrive pas à afficher l'heure, ca bloque sur la condition de la fonction setup() :
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 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(2014, 1, 21, 3, 0, 0));
}