Bonjour,
Je souhaite utiliser mon RTC DS3231 et j'ai vu que l'on pouvait le faire à partir de la libraire DS1307RTC (seulement on n'utilise pas le capteur de température du DS3231 mais pour le moment je ne souhaite pas m'en servir).
J'ai donc téléchargé les différentes librairies requises : Time, DS1307RTC, (Wire était déjà présent) sur ce site qui était placé en lien sur le playground arduino :
http://www.pjrc.com/teensy/td_libs_DS1307RTC.html
http://www.pjrc.com/teensy/td_libs_Time.html#ds1307
seulement lorsque j'exécute le programme de SetTime de la librairie DS1307RTC :
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};tmElements_t tm;
void setup() {
bool parse=false;
bool config=false;// get the date and time the compiler was run
if (getDate(DATE) && getTime(TIME)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(TIME);
Serial.print(", Date=");
Serial.println(DATE);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time="");
Serial.print(TIME);
Serial.print("", Date="");
Serial.print(DATE);
Serial.println(""");
}
}void loop() {
}bool getTime(const char *str)
{
int Hour, Min, Sec;if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
J'obtiens alors ce type d'erreur :
In file included from SetTime.ino:3:
C:\Users\Asus\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\DS1307RTC/DS1307RTC.h:17: error: 'time_t' does not name a type
C:\Users\Asus\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\DS1307RTC/DS1307RTC.h:18: error: 'time_t' has not been declared
C:\Users\Asus\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\DS1307RTC/DS1307RTC.h:19: error: 'tmElements_t' has not been declared
C:\Users\Asus\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\DS1307RTC/DS1307RTC.h:20: error: 'tmElements_t' has not been declared
SetTime:10: error: 'tmElements_t' does not name a type
Le problème semble venir de la librairie où les type de variable time_t et tmElements_t ne sont pas déclarés ?
J'ai voulu testé alors la librairie DS3231 téléchargée sur ce site : Hardware Hacks: DS3231 Real-Time Clock et j'ai testé le programme DS3231_set :
/*
DS3231_set.pde
Eric Ayars
4/11
Test of set-time routines for a DS3231 RTC
*/
#include <DS3231.h>
#include <Wire.h>
DS3231 Clock;
byte Year;
byte Month;
byte Date;
byte DoW;
byte Hour;
byte Minute;
byte Second;
void GetDateStuff(byte& Year, byte& Month, byte& Day, byte& DoW,
byte& Hour, byte& Minute, byte& Second) {
// Call this if you notice something coming in on
// the serial port. The stuff coming in should be in
// the order YYMMDDwHHMMSS, with an 'x' at the end.
boolean GotString = false;
char InChar;
byte Temp1, Temp2;
char InString[20];
byte j=0;
while (!GotString) {
if (Serial.available()) {
InChar = Serial.read();
InString[j] = InChar;
j += 1;
if (InChar == 'x') {
GotString = true;
}
}
}
Serial.println(InString);
// Read Year first
Temp1 = (byte)InString[0] -48;
Temp2 = (byte)InString[1] -48;
Year = Temp1*10 + Temp2;
// now month
Temp1 = (byte)InString[2] -48;
Temp2 = (byte)InString[3] -48;
Month = Temp1*10 + Temp2;
// now date
Temp1 = (byte)InString[4] -48;
Temp2 = (byte)InString[5] -48;
Day = Temp1*10 + Temp2;
// now Day of Week
DoW = (byte)InString[6] - 48;
// now Hour
Temp1 = (byte)InString[7] -48;
Temp2 = (byte)InString[8] -48;
Hour = Temp1*10 + Temp2;
// now Minute
Temp1 = (byte)InString[9] -48;
Temp2 = (byte)InString[10] -48;
Minute = Temp1*10 + Temp2;
// now Second
Temp1 = (byte)InString[11] -48;
Temp2 = (byte)InString[12] -48;
Second = Temp1*10 + Temp2;
}
void setup() {
// Start the serial port
Serial.begin(9600);
// Start the I2C interface
Wire.begin();
}
void loop() {
// If something is coming in on the serial line, it's
// a time correction so set the clock accordingly.
if (Serial.available()) {
GetDateStuff(Year, Month, Date, DoW, Hour, Minute, Second);
Clock.setClockMode(false); // set to 24h
//setClockMode(true); // set to 12h
Clock.setYear(Year);
Clock.setMonth(Month);
Clock.setDate(Date);
Clock.setDoW(DoW);
Clock.setHour(Hour);
Clock.setMinute(Minute);
Clock.setSecond(Second);
// Test of alarm functions
// set A1 to one minute past the time we just set the clock
// on current day of week.
Clock.setA1Time(DoW, Hour, Minute+1, Second, 0x0, true,
false, false);
// set A2 to two minutes past, on current day of month.
Clock.setA2Time(Date, Hour, Minute+2, 0x0, false, false,
false);
// Turn off both alarms
Clock.turnOffAlarm(1);
Clock.turnOffAlarm(2);
}
delay(1000);
}
et je rencontre le même type d'erreur à savoir un type de variable non déclaré :
DS3231_set:13: error: 'DS3231' does not name a type
DS3231_set.pde: In function 'void loop()':
DS3231_set:88: error: 'Clock' was not declared in this scope
Peut être bien que le problème vient de moi finalement ! J'ai pourtant téléchargé les fichiers puis dézipé, et placé dans le dossier librairie (j'ai fait de même pour une librairie DHT22 et cela fonctionne très bien pourtant)
Merci pour vos conseils !