sirch
December 6, 2022, 8:15pm
1
I'm trying to get a DS3231 RTC module working with an Arduino Nano but I get strange numbers back for the date time, e.g. "21165 85 165 165 8 16 32 24h T=13.75 O+"
I am just testing with various example sketches and I have tried several DS3231 libraries and associated examples, they all give the same result. Please can someone confirm that the examples work? I note that some don't even compile without modification.
I assume it is either because:
my DS3231 is broken
the data being sent to set the clock is being mangled
or the returned values are getting screwed up
If the examples work for other people then I guess it is 1.
TIA
Choose a library and stick with it
Post an example here that illustrates the problem
sirch
December 6, 2022, 8:21pm
3
Well I would if I found one that worked
Here's one example
/*
DS3231_test.pde
Eric Ayars
4/11
Test/demo of read routines for a DS3231 RTC.
Turn on the serial monitor after loading this to check if things are
working as they should.
*/
#include <DS3231.h>
#include <Wire.h>
DS3231 dsclock;
bool century = false;
bool h12Flag;
bool pmFlag;
byte alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits;
bool alarmDy, alarmH12Flag, alarmPmFlag;
void setup() {
// Start the I2C interface
Wire.begin();
// Start the serial interface
Serial.begin(57600);
}
void loop() {
// send what's going on to the serial monitor.
// Start with the year
Serial.print("2");
if (century) { // Won't need this for 89 years.
Serial.print("1");
} else {
Serial.print("0");
}
Serial.print(dsclock.getYear(), DEC);
Serial.print(' ');
// then the month
Serial.print(dsclock.getMonth(century), DEC);
Serial.print(" ");
// then the date
Serial.print(dsclock.getDate(), DEC);
Serial.print(" ");
// and the day of the week
Serial.print(dsclock.getDoW(), DEC);
Serial.print(" ");
// Finally the hour, minute, and second
Serial.print(dsclock.getHour(h12Flag, pmFlag), DEC);
Serial.print(" ");
Serial.print(dsclock.getMinute(), DEC);
Serial.print(" ");
Serial.print(dsclock.getSecond(), DEC);
// Add AM/PM indicator
if (h12Flag) {
if (pmFlag) {
Serial.print(" PM ");
} else {
Serial.print(" AM ");
}
} else {
Serial.print(" 24h ");
}
// Display the temperature
Serial.print("T=");
Serial.print(dsclock.getTemperature(), 2);
// Tell whether the time is (likely to be) valid
if (dsclock.oscillatorCheck()) {
Serial.print(" O+");
} else {
Serial.print(" O-");
}
// Indicate whether an alarm went off
if (dsclock.checkIfAlarm(1)) {
Serial.print(" A1!");
}
if (dsclock.checkIfAlarm(2)) {
Serial.print(" A2!");
}
// New line on display
Serial.println();
// Display Alarm 1 information
Serial.print("Alarm 1: ");
dsclock.getA1Time(alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);
Serial.print(alarmDay, DEC);
if (alarmDy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(alarmHour, DEC);
Serial.print(' ');
Serial.print(alarmMinute, DEC);
Serial.print(' ');
Serial.print(alarmSecond, DEC);
Serial.print(' ');
if (alarmH12Flag) {
if (alarmPmFlag) {
Serial.print("pm ");
} else {
Serial.print("am ");
}
}
if (dsclock.checkAlarmEnabled(1)) {
Serial.print("enabled");
}
Serial.println();
// Display Alarm 2 information
Serial.print("Alarm 2: ");
dsclock.getA2Time(alarmDay, alarmHour, alarmMinute, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);
Serial.print(alarmDay, DEC);
if (alarmDy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(" ");
Serial.print(alarmHour, DEC);
Serial.print(" ");
Serial.print(alarmMinute, DEC);
Serial.print(" ");
if (alarmH12Flag) {
if (alarmPmFlag) {
Serial.print("pm");
} else {
Serial.print("am");
}
}
if (dsclock.checkAlarmEnabled(2)) {
Serial.print("enabled");
}
// display alarm bits
Serial.println();
Serial.print("Alarm bits: ");
Serial.println(alarmBits, BIN);
Serial.println();
delay(1000);
}
Exactly which library are you using and how did you install it ?
sirch
December 6, 2022, 8:28pm
5
Pardon the silly question, but have you set the date and time on the clock ?
horace
December 6, 2022, 8:46pm
7
using a ESP8266 NodeMCU just ran File>Examples>RTClib>ds3231
20:38:03.002 -> since midnight 1/1/1970 = 1670359007s = 19332d
20:38:03.035 -> now + 7d + 12h + 30m + 6s: 2022/12/14 9:6:53
20:38:03.035 -> Temperature: 23.50 C
20:38:03.035 ->
20:38:06.016 -> 2022/12/6 (Tuesday) 20:36:50
20:38:06.016 -> since midnight 1/1/1970 = 1670359010s = 19332d
20:38:06.016 -> now + 7d + 12h + 30m + 6s: 2022/12/14 9:6:56
20:38:06.049 -> Temperature: 23.50 C
20:38:06.049 ->
20:38:09.037 -> 2022/12/6 (Tuesday) 20:36:53
20:38:09.037 -> since midnight 1/1/1970 = 1670359013s = 19332d
20:38:09.037 -> now + 7d + 12h + 30m + 6s: 2022/12/14 9:6:59
20:38:09.037 -> Temperature: 23.50 C
does the I2C scanner work? e.g.
20:53:02.390 -> Scanning (SDA : SCL) - GPIO4 : GPIO5 - I2C device found at address 0x57 !
20:53:02.390 -> I2C device found at address 0x68 !
1 Like
sirch
December 6, 2022, 8:51pm
8
I have tried, again via various means, I can get it to change but it is still of the form "85 165 165" for YY MM DD
sirch
December 6, 2022, 8:57pm
9
I2C Scanner gives
Scanning...
I2C device found at address 0x57 !
I2C device found at address 0x68 !
done
File>Examples>RTClib>ds3231 says "Couldn't find RTC" however the example posted above seems to find it and read it just with the wrong values but those values do increment by one every second
horace
December 6, 2022, 9:10pm
10
just tried another device labled TinyRTC
21:08:03.015 -> since midnight 1/1/1970 = 1670360859s = 19332d
21:08:03.048 -> now + 7d + 12h + 30m + 6s: 2022/12/14 9:37:45
21:08:03.048 -> Temperature: 45.00 C
21:08:03.048 ->
21:08:06.020 -> 2022/12/6 (Tuesday) 21:7:42
21:08:06.020 -> since midnight 1/1/1970 = 1670360862s = 19332d
21:08:06.054 -> now + 7d + 12h + 30m + 6s: 2022/12/14 9:37:48
21:08:06.054 -> Temperature: 45.00 C
21:08:06.054 ->
temperature is incorrect otherwise OK?
1 Like
sirch
December 6, 2022, 9:10pm
11
Thanks all for the replies. Looks like it was a bad ground connection
system
Closed
June 4, 2023, 9:11pm
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.