JChristensen / DS3232RTC

Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks
GNU General Public License v3.0
392 stars 135 forks source link

Set different I2C pins in RTC.begin() ? #82

Closed sheffieldnikki closed 3 years ago

sheffieldnikki commented 3 years ago

For architectures that can use configurable SDA/SCL pins for I2C communications (eg. the ESP32) is there a recommended way of initialising your library to use those pins? I'd expect something like:

#include <DS3232RTC.h>
DS3232RTC RTC(false);
...
RTC.begin(GPIO_NUM_4, GPIO_NUM_16);

but RTC.begin() doesn't accept optional arguments. Since all it does is call the underlying Wire.begin() function, could it just pass on those arguments, if provided? The ESP32 Wire.begin() can take up to 3 optional arguments.

At the moment I'm doing this instead, which does work:

#include <DS3232RTC.h>
#include <Wire.h>
DS3232RTC RTC(false);
...
// RTC.begin(); don't call this
Wire.begin(GPIO_NUM_4, GPIO_NUM_16);

Many thanks

JChristensen commented 3 years ago

I don't use the ESP devices and this is probably not something I'll get around to anytime soon; very sorry about that. Actually your workaround seems fine, there's probably not a lot to be improved on over that.