{"id":45964370,"url":"https://github.com/bitbank2/bb_rtc","last_synced_at":"2026-02-28T14:02:32.967Z","repository":{"id":174172522,"uuid":"648268541","full_name":"bitbank2/bb_rtc","owner":"bitbank2","description":"A cross-platform, embedded RealTime Clock library with device auto-detection","archived":false,"fork":false,"pushed_at":"2025-11-03T17:44:42.000Z","size":527,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-03T19:26:24.574Z","etag":null,"topics":["ds3231","pcf8563","rtc","rv3032"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitbank2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-06-01T15:20:19.000Z","updated_at":"2025-11-03T17:44:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"edf4241f-5ded-4ac9-bcff-1d8f4056f75a","html_url":"https://github.com/bitbank2/bb_rtc","commit_stats":null,"previous_names":["bitbank2/bb_rtc"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/bitbank2/bb_rtc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitbank2%2Fbb_rtc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitbank2%2Fbb_rtc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitbank2%2Fbb_rtc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitbank2%2Fbb_rtc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitbank2","download_url":"https://codeload.github.com/bitbank2/bb_rtc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitbank2%2Fbb_rtc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29936364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:49:17.081Z","status":"ssl_error","status_checked_at":"2026-02-28T13:48:50.396Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ds3231","pcf8563","rtc","rv3032"],"created_at":"2026-02-28T14:02:01.483Z","updated_at":"2026-02-28T14:02:32.932Z","avatar_url":"https://github.com/bitbank2.png","language":"C++","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=SR4F44J2UR8S4"],"categories":[],"sub_categories":[],"readme":"# BitBank Realtime Clock Library\n\nCopyright (c) 2023-2025 BitBank Software, Inc.\u003cbr\u003e\nWritten by Larry Bank\u003cbr\u003e\nbitbank@pobox.com\u003cbr\u003e\n\u003cbr\u003e\nMy focus lately has been to make embedded programming as simple as possible (for myself and everyone else). One of my ideas to simplify project code is to create device libraries that work as a category instead of for a specific device. What this means in this case is that there are several popular I2C realtime clock chips that share a lot of common functionality. By combining the code for all of them into a single library with a simple and consistent API, the device-specific details can be managed without the user worrying about them. This library currently supports the DS3231, RV-3032, PCF85063A and PCF8563 RTC modules; the four most popular devices currently in use. Each has slightly different capabilities, but I was able to create a single API which covers all of the important features of each. This code is basically portable C++, but needs a bit of target-specific code for the I2C communication. It currently includes wrapper functions to allow it to work on Arduino, esp-idf and Linux. Examples are included for each system. To use it on other hardware (e.g. STM32), is simply a matter of writing wrapper functions for I2C init, test, read and write.\n\n## Capabilities\nThe common capabilities of I2C realtime clock chips are the following:\n- Keep the current time and date in 1 second increments\n- Maintain accurate time over periods of weeks or months (\u003c 30 parts per million error)\n- Offer a digital square wave output signal which can generate different frequencies (shared with the interrupt pin on some)\n- Set wakeup alarms as a countdown or at a specific time and date (not all support all options)\n- Internal temperature sensor (which can be read) to reduce temperature induced frequency deviations (not all support this feature)\n\n## Auto-detection...how?\nI2C devices normally adhere to a de-facto standard of using a set of internal registers and having a fixed address. With this information, and sometimes a bit of probing of the register behavior, it is possible to automatically find and identify them. With bb_rtc, you only need to specify the GPIO pins used and if you will be using hardware I2C support or bit banging (provided by my BitBank_I2C libraru). With this information the library can identify and use your RTC. This feature also gives you the freedmom to change devices while developing your project without having to modify your software. If your RTC is not covered by this library, please let me know and I'll add support for it.\n\n## The bb_rtc API\nThe library defines the BBRTC class which makes use of the POSIX 'struct tm' aka broken-out time structure. This allows you to specify the individual time and date fields as member variables. You also can use 32-bit epoch time (seconds since January 1, 1970). For a detailed look at the API, see the Wiki. The class  methods (overview):\n- \u003cb\u003einit\u003c/b\u003e Detect and turn on the RTC. If no parameters are passed, it assumes that the I2C bus has already been initialized by other code\n- \u003cb\u003egetType\u003c/b\u003e Returns the specific type of RTC (e.g. DS3231)\n- \u003cb\u003egetStatus\u003c/b\u003e Returns the current alarm and interrupt status\n- \u003cb\u003egetBB\u003c/b\u003e Returns a pointer to the internal I2C structure to share with other libraries\n- \u003cb\u003esetBB\u003c/b\u003e Allows setting the internal I2C structure\n- \u003cb\u003esetFreq\u003c/b\u003e Enable/disable and set the square wave output frequency\n- \u003cb\u003esetVBackup\u003c/b\u003e Enable or disable the built-in charge circuitry for backup batteries or capacitors\n- \u003cb\u003esetAlarm\u003c/b\u003e Set the type and time of an alarm\n- \u003cb\u003egetTemp\u003c/b\u003e Read the current ambient temperature\n- \u003cb\u003esetTime\u003c/b\u003e Set the current time and date from a tm structure\n- \u003cb\u003egetTime\u003c/b\u003e Get the current time and date into a tm structure\n- \u003cb\u003esetCountdownAlarm\u003c/b\u003e Set a countdown alarm in seconds\n- \u003cb\u003eclearAlarms\u003c/b\u003e Clear any pending alarm\n- \u003cb\u003egetEpoch\u003c/b\u003e Get the time as a 32-bit epoch value\n- \u003cb\u003esetEpoch\u003c/b\u003e Set the time as a 32-bit epoch value\n- \u003cb\u003estop\u003c/b\u003e Stop the clock for low power standby\n  \n## Alarms and Interrupts\nThe interrupt pin (normally open-collector and used with a pull-up resistor) is enabled for the alarms and countdown timer functions. It's up to you to act on the changing state of the pin. When you set an alarm, the IRQ feature is enabled and when you disable an alarm, it's disabled. You can also read the status register to see if an alarm caused your MCU to awaken.\u003cbr\u003e\n\nThe photo below shows the Arduino Nano 33 BLE example sketch running on my Nano+Feather breakout PCB (https://github.com/bitbank2/KiCad_Projects) \u003cbr\u003e\n\u003cbr\u003e\n![bb_rtc](/bb_rtc_demo.jpg?raw=true \"bb_rtc\")\n\u003cbr\u003e\n\nIf you find this code useful, please consider sending a donation or becoming a Github sponsor.\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=SR4F44J2UR8S4)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitbank2%2Fbb_rtc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitbank2%2Fbb_rtc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitbank2%2Fbb_rtc/lists"}