adafruit / RTClib

A fork of Jeelab's fantastic RTC Arduino library
MIT License
794 stars 703 forks source link

ESP32 #98

Closed rakhmaevao closed 5 years ago

rakhmaevao commented 6 years ago

For remaping pins SDA and SCL correct file RTClib.cpp:

https://github.com/adafruit/RTClib/blob/82d00a1a15bcf738b001e42bf26a3d1f1a15be32/RTClib.cpp#L240

Use: Wire.begin(RTC_SDA, RTC_SCL);

lemonbuzz commented 5 years ago

I have an ESP32 project and I cant seem to get my DS3231 to work....I've remapped the SDA and SCL pins as you suggest here but to no avail

rakhmaevao commented 5 years ago

Remaping can only help configuration I2C in ESP32. Problem can be in DC3231, in wire or another. Can you view the SDA and SLC line with an oscilloscope or logic analyzer?

cbpdk commented 5 years ago

I have just tested a RTClib, DC3231, with a LoadLin32 Lite clone which does not have pin 21. To make it work for DS3231, I made the following changes in the RTClib.cpp:

//////////////////////////////////////////////////////////////////////////////// // RTC_DS3231 implementation

if defined( ESP32 ) || defined(ARDUINO_ARCH_ESP32)

boolean RTC_DS3231::begin(int sda, int scl) { Wire.begin(sda,scl); return true; }

else

boolean RTC_DS3231::begin(void) { Wire.begin(); return true; }

endif

And in the RTClib.h:

EDIT: After further investigation, -1 is used as standard value for pin number in Wire. In that case, the pin numbers defined for the architecture are used. So boolean begin(int sda = 21, int scl = 22); should be replaced by boolean begin(int sda = -1, int scl = -1); NOTE: -1 is not tested.

class RTC_DS3231 { public:

if defined( ESP32 ) || defined(ARDUINO_ARCH_ESP32)

boolean begin(int sda = -1, int scl = -1);  //EDITED

else

boolean begin(void);

endif

static void adjust(const DateTime& dt);:

And the DS3231 works with RTClib.