Hi, someone could tell me if have made the DS3231 RTC work on the Arduino-Pico, I have connected both boards using the I2C bus but I am not getting a response from the RTC, could someone tell me what the problem could be, this is my code:
#include <RTClib.h>
#include <Wire.h>
RTC_DS3231 rtc;
char t[32];
#define Pin_SDA1 4
#define Pin_SCL1 5
void setup() {
Serial.begin(115200);
bool setSDA(Pin_SDA1);
bool setSCL(Pin_SCL1);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(2024, 6, 1, 5, 31, 45));
}
void loop() {
DateTime now = rtc.now();
sprintf(t, "%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(t);
delay(1000);
}
Surely this
ought to be this?
Wire.setSDA(Pin_SDA1):
Wire.setSCL(Pin_SCL1);
Wire.setSDA(Pin_SDA1):
Wire.setSCL(Pin_SCL1);
I have also tried it but the problem is the same
And this is usually the point where someone asks to see a schematic.
5V to the DS3231, but the Pico is a 3.3V board. Probably not a good idea to be pulling the Pico's output pins up to 5V.
This sketch, uploaded to a Pico with a DS3231 board connected to GP4 & GP5:
#include <RTClib.h>
#include <Wire.h>
RTC_DS3231 rtc;
char t[32];
#define Pin_SDA1 4
#define Pin_SCL1 5
void setup() {
Serial.begin(115200);
Wire.setSDA(Pin_SDA1);
Wire.setSCL(Pin_SCL1);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(2024, 6, 1, 5, 31, 45));
}
void loop() {
DateTime now = rtc.now();
sprintf(t, "%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(t);
delay(1000);
}
with the DS3231 powered by 3.3V rather than 5V, produced this output:
Monitor port settings:
baudrate=115200
Connected to /dev/ttyACM0! Press CTRL-C to exit.
Date/Time: 05:31:59 01/06/2024
Date/Time: 05:32:00 01/06/2024
Date/Time: 05:32:01 01/06/2024
Date/Time: 05:32:02 01/06/2024
Date/Time: 05:32:03 01/06/2024
Date/Time: 05:32:04 01/06/2024
system
Closed
November 28, 2024, 5:27am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.