1

There are multiple RTC libraries available, can I load several RTC libraries into my code and then use the functions I like from each one? Will there be some conflict if for example I include DS1307.h and RTCLib.h and other RTCXXXX.h libraries as well?

  • I think that in case of the RTCs it might actually work, but it's not advised, and may introduce some really weird problems. – Gerben Jul 19 '16 at 12:09
  • 1
    Thanks guys, the real issue is that the functions available from just one RTC library are often lacking. I haven't found a "super" RTC library that incorporates the best ideas of the many libraries out there. I don't feel like writing or editing a library so I'll just convert my sketch to deal with the present best of breed. – Allan Bowman Jul 31 '16 at 21:46
1

If you want to load multiple RTC libraries I guess you are connecting to multiple RTCs.

If they use the same interface to communicate, i.e. I2C there is a possibility you will initialise the bus multiple times.

You should be OK with the functions not clashing, because they are within classes, but its possible some of the referenced structures/ classes my clash. You might be able to resolve this by namespacing the libraries.

An alternative might be to write your own library that handles all of the RTCs that you are interested in. This will force you to consider what each RTC requires and identify problems.

At the end of the day I agree with what Gerben is saying. Don't do it unless you really have to.

1

can I load several RTC libraries into my code and then use the functions I like from each one?

It will depend on the libraries. Most likely they had some persistent variables, global to the routines, that help information exchange. If only some of the routines are used and others not, values in those variables may not be consistent.

Will there be some conflict

That will depend on the way those libraries are implemented. No way of telling without seeing the code.

The point of doing this is a little bit suspect. It is not clear to me why you would want to have more than 1 RTC in an environment. If you are thinking about giving your program the option to function with multiple RTCs (but using one RTC at any given time), you can use either macro (at compile time) or wrap the RTCs in a logic layer (at run time).

For example, you can have a rtc_init() to reset different RTCs; and rtc_read() to return the time from the rtc. rtc_read() can be implemented based on which RTC is detected during initialization...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.