{"id":13802047,"url":"https://github.com/pangopi/micropython-DS3231-AT24C32","last_synced_at":"2025-05-13T12:32:15.282Z","repository":{"id":44734658,"uuid":"300777370","full_name":"pangopi/micropython-DS3231-AT24C32","owner":"pangopi","description":"MicroPython driver for DS3231 RTC and AT24C32 EEPROM module","archived":false,"fork":false,"pushed_at":"2024-07-25T00:14:35.000Z","size":27,"stargazers_count":28,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-18T17:51:05.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pangopi.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}},"created_at":"2020-10-03T02:11:56.000Z","updated_at":"2024-09-18T18:24:10.000Z","dependencies_parsed_at":"2024-11-18T17:44:25.316Z","dependency_job_id":"5f504320-3622-4e38-a29c-bddb5183f6b2","html_url":"https://github.com/pangopi/micropython-DS3231-AT24C32","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangopi%2Fmicropython-DS3231-AT24C32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangopi%2Fmicropython-DS3231-AT24C32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangopi%2Fmicropython-DS3231-AT24C32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangopi%2Fmicropython-DS3231-AT24C32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pangopi","download_url":"https://codeload.github.com/pangopi/micropython-DS3231-AT24C32/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253942552,"owners_count":21988079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-04T00:01:34.217Z","updated_at":"2025-05-13T12:32:15.041Z","avatar_url":"https://github.com/pangopi.png","language":"Python","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"readme":"# micropython-DS3231-AT24C32\nMicroPython driver for DS3231 RTC and AT24C32 EEPROM module.\n\nEEPROM Driver coming soon!\n\n## DS3231N\nDriver for the Dallas DS3231, a highly accurate RTC IC.\n\nI wrote this driver to make an easier to use and complete driver to access all the functions the DS3231 has. The driver has been designed for use with an ESP8266 but should work on fine on other devices as long as an I2C instance can be given.\n\nSome care has been put into memory use, with most variables buffered when constructing. Checking the alarms and setting the SQW/INT doesn't use memory allocation in the heap and can be used in ISR. This does not imply methods are thread safe.\n\nThis driver implements both alarms and all available match triggers, interrupts and checks.\n\nOscillator Stop Flag (OSF) is checked when displaying the time. Giving an indication of the validity of time data. When not printing to the REPL the OSF can be cheked manually.\n\nSquare wave output and also the crystal output can be set.\n\nThe temperature readout and aging offset options have not been implemented yet. I see no priority to implement temperature data since I can't come up with a plausible use case, but requests are welcome. As soon as I get access to a decent oscilloscope I will start playing with the aging offset features.\n\n## Usage\n\n### Create instance\nCreate an instance of the DS3231 class:\n\n```python\nfrom machine import Pin, I2C\nfrom ds3231 import DS3231\n\ni2c = I2C(sda=Pin(4), scl=Pin(5))\n\nds = DS3231(i2c)\n```\n### Time functions\n\nExample of setting the date and time:\n```python\nyear = 2020 # Can be yyyy or yy format\nmonth = 10\nmday = 3\nhour = 13 # 24 hour format only\nminute = 55\nsecond = 30 # Optional\nweekday = 6 # Optional\n\ndatetime = (year, month, mday, hour, minute, second, weekday)\nds.datetime(datetime)\n```\n\nreturns in format of the ESP8266 RTC:\n`(2020, 10, 3, 6, 13, 55, 30, 0) # (year, month, mday, wday, hour, minute, second, 0)`\n\nSet the ESP8266 internal RTC using the DS3231\n```python\nimport machine\nrtc = machine.RTC()\nrtc.datetime(ds.datetime)\n```\n\n#### Get the date and time\nCall `ds.datetime()` to get the current date and time. This will print a warning on the REPL when the Oscillator Stop Flag (OSF) is set. When not using the REPL the OSF\n\n### Alarm functions\n\nThe DS3231 has 2 internal alarms with can each be set independently to different match conditions.\nThe alarm has match options ranging from every second to every month.\n\nCall an alarm without arguments and it will return the current alarm setting register.\n\n#### alarm 1\nSet alarm 1:\n`DS3231.alarm1([time[, match[, int_en[, weekday]]]])`\n\ntime    : tuple, (second,[ minute[, hour[, day]]])\nweekday : bool, select mday (False) or wday (True)\nmatch   : int, match const\nint_en  : bool, enable interrupt on alarm match on SQW/INT pin (disables SQW output)\n\n\nAlarm 1 has the following match options:\n```python\nds.AL1_EVERY_S      # Alarm every second\nds.AL1_MATCH_S      # Alarm when seconds match (every minute)\nds.AL1_MATCH_MS     # Alarm when minutes, seconds match (every hour)\nds.AL1_MATCH_HMS    # Alarm when hours, minutes, seconds match (every day)\nds.AL1_MATCH_DHMS   # Alarm when day|wday, hour, min, sec match (specific wday / mday) (once per month/week)\n```\n\nExample:\n```python\n# Set alarm 1 for 16:10:15 every day\nds.alarm1((15, 10, 16), match=ds.AL1_MATCH_HMS)\n```\n\n#### alarm 2\nSet alarm 2:\n`DS3231.alarm2([time[, match[, int_en[, weekday]]]])`\n\ntime    : tuple, (minute[, hour[, day]])\nweekday : bool, select mday (False) or wday (True)\nmatch   : int, match const\nint_en  : bool, enable interrupt on alarm match on SQW/INT pin (disables SQW output)\n\n\nAlarm 2 has the following match options:\n```python\nds.AL2_EVERY_M # Alarm every minute on 00 seconds\nds.AL2_MATCH_M # Alarm when minutes match (every hour)\nds.AL2_MATCH_HM # Alarm when hours and minutes match (every day)\nds.AL2_MATCH_DHM # Alarm when day|wday match (once per month/week)\n```\n\nExample:\n```python\n# Set alarm 1 for 19:30 every Tuesday\nds.alarm2((30, 19, 2), match=ds.AL2_MATCH_DHM, weekday=True)\n```\n\n#### Checking and clearing alarms\nYou can manually check to see if an alarm has triggered. This will return True when the alarm has been triggered and False otherwise. The act of checking clears the alarm register automatically.\n\n`DS3231.check_alarm(alarm)`\n\nalarm : alarm number, can be 1 or 2\n\n### Square wave output\nThe DS3231 can output a square wave on the SQW/INT output pin. The following frequencies are availalbe:\n* `FREQ_1`       1 Hz\n* `FREQ_1024` 1024 Hz\n* `FREQ_4096` 4096 Hz\n* `FREQ_8192` 8192 Hz\n\nExample:\n```python\nds.square_wave(freq=ds.FREQ_1024) # Enable 1024 Hz output\nds.square_wave(freq=False) # Disable SQW output\n```\n\nNote:\n* When using the SQW/INT pin to output a square wave, the alarm interrupt is not avaialable. Checking for alarms will have to be done manually.\n* When disabling the SQW output signal, the alarm interrupts (even when set before) remain disabled. They can to be set manually afterwards, if desired with `ds.alarm_int()`.\n\nThe DS3231 can also output the crystal frequency at 32768 Hz on a dedicated pin (32K). This output is enabled by default on powerup and can me changed as follows:\n\n```python\nds.output_32kHz() # Enable 32 kHz output\nds.output_32kHz(False) # Disable 32 kHz output\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpangopi%2Fmicropython-DS3231-AT24C32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpangopi%2Fmicropython-DS3231-AT24C32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpangopi%2Fmicropython-DS3231-AT24C32/lists"}