Joshtan
December 18, 2018, 7:34am
1
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 rtc;
char buf1[20];
void setup()
{
Serial.begin(9600);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
}
void loop()
{
DateTime now = rtc.now();
sprintf(buf1, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
Serial.print(F("Date/Time: "));
Serial.println(buf1);
delay(1000);
}
I don't know why the output of the code is always "Date/Time: 165:165:85 165/165/216", and it doesn't change.I am using ESP8266.
char buf1[20];
0123456789012345678901234
165:165:85 165/165/216
For starters, I have a feeling that your sprintf()
statement is overflowing buf1
.
Before anything else, you should change char buf1[20];
to char buf1[25];
And you might want to double-check that your DS1307 is wired up correctly, has power, etc.
Joshtan
December 18, 2018, 8:57am
3
odometer:
char buf1[20];
0123456789012345678901234
165:165:85 165/165/216
For starters, I have a feeling that your `sprintf()` statement is overflowing `buf1`.
Before anything else, you should change `char buf1[20];` to `char buf1[25];`
And you might want to double-check that your DS1307 is wired up correctly, has power, etc.
yea same thing
shown "Date/Time: 165:165:85 2165/165/165"
Inadequate power? The display you get implies that. Assuming the code is standard stuff, the RTC per se may not be the problem.
system
December 18, 2018, 2:47pm
5
Hmmm, I think there somewhere in the beginning should be a
#define "ADDRESS" for rtc , for example 0x68