adafruit-circuitpython-ds3231


Nameadafruit-circuitpython-ds3231 JSON
Version 2.4.18 PyPI version JSON
download
home_page
SummaryCircuitPython library for DS3231 precision real-time clock.
upload_time2023-05-16 17:51:36
maintainer
docs_urlNone
author
requires_python
licenseMIT
keywords adafruit precision real-time real time clock breakout hardware micropython circuitpython
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Introduction
=============

.. image:: https://readthedocs.org/projects/adafruit-micropython-ds3231/badge/?version=latest
    :target: https://docs.circuitpython.org/projects/ds3231/en/latest/
    :alt: Documentation Status

.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg
    :target: https://adafru.it/discord
    :alt: Discord

.. image:: https://github.com/adafruit/Adafruit_CircuitPython_DS3231/workflows/Build%20CI/badge.svg
    :target: https://github.com/adafruit/Adafruit_CircuitPython_DS3231/actions/
    :alt: Build Status

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black
    :alt: Code Style: Black

The datasheet for the DS3231 explains that this part is an
"Extremely Accurate I²C-Integrated RTC/TCXO/Crystal". And,
hey, it does exactly what it says on the tin! This Real Time
Clock (RTC) is the most precise you can get in a small, low
power package.

Most RTCs use an external 32kHz timing crystal that is used
to keep time with low current draw. And that's all well and
good, but those crystals have slight drift, particularly when
the temperature changes (the temperature changes the oscillation
frequency very very very slightly but it does add up!) This
RTC is in a beefy package because the crystal is inside the
chip! And right next to the integrated crystal is a temperature
sensor. That sensor compensates for the frequency changes by
adding or removing clock ticks so that the timekeeping stays
on schedule.

This is the finest RTC you can get, and now we have it in a
compact, breadboard-friendly breakout. With a coin cell
plugged into the back, you can get years of precision
timekeeping, even when main power is lost. Great for
datalogging and clocks, or anything where you need to
really know the time.

.. image:: ../docs/_static/3013-01.jpg
    :alt: DS3231 Product Image

Dependencies
=============
This driver depends on:

* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
* `Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_

Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.

Installing from PyPI
====================

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI <https://pypi.org/project/adafruit-circuitpython-ds3231/>`_. To install for current user:

.. code-block:: shell

    pip3 install adafruit-circuitpython-ds3231

To install system-wide (this may be required in some cases):

.. code-block:: shell

    sudo pip3 install adafruit-circuitpython-ds3231

To install in a virtual environment in your current project:

.. code-block:: shell

    mkdir project-name && cd project-name
    python3 -m venv .venv
    source .venv/bin/activate
    pip3 install adafruit-circuitpython-ds3231

Usage Notes
===========

Basics
------

Of course, you must import the library to use it:

.. code:: python3

    import adafruit_ds3231
    import time

All the Adafruit RTC libraries take an instantiated and active I2C object
(from the ``board`` library) as an argument to their constructor. The way to
create an I2C object depends on the board you are using. For boards with labeled
SCL and SDA pins, you can:

.. code:: python3

    import board

Now, to initialize the I2C bus:

.. code:: python3

    i2c = board.I2C()  # uses board.SCL and board.SDA

Once you have created the I2C interface object, you can use it to instantiate
the RTC object:

.. code:: python3

    rtc = adafruit_ds3231.DS3231(i2c)

Date and time
-------------

To set the time, you need to set ``datetime`` to a ``time.struct_time`` object:

.. code:: python3

    rtc.datetime = time.struct_time((2017,1,9,15,6,0,0,9,-1))

After the RTC is set, you retrieve the time by reading the ``datetime``
attribute and access the standard attributes of a struct_time such as ``tm_year``,
``tm_hour`` and ``tm_min``.

.. code:: python3

    t = rtc.datetime
    print(t)
    print(t.tm_hour, t.tm_min)

Alarm
-----

To set the time, you need to set ``alarm1`` or ``alarm2`` to a tuple with a
``time.struct_time`` object and string representing the frequency such as "hourly":

.. code:: python3

    rtc.alarm1 = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily")

After the RTC is set, you retrieve the alarm status by reading the corresponding
``alarm1_status`` or ``alarm2_status`` attributes. Once True, set it back to False
to reset.

.. code:: python3

    if rtc.alarm1_status:
        print("wake up!")
        rtc.alarm1_status = False

Documentation
=============

API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/ds3231/en/latest/>`_.

For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.

Contributing
============

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_DS3231/blob/main/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "adafruit-circuitpython-ds3231",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "adafruit,precision,real-time,real,time,clock,breakout,hardware,micropython,circuitpython",
    "author": "",
    "author_email": "Adafruit Industries <circuitpython@adafruit.com>",
    "download_url": "https://files.pythonhosted.org/packages/79/ed/d8cc291bc9004eab69b0774f0ff2377cb1bfbfa3be772fed1cd2f6232eca/adafruit-circuitpython-ds3231-2.4.18.tar.gz",
    "platform": null,
    "description": "Introduction\n=============\n\n.. image:: https://readthedocs.org/projects/adafruit-micropython-ds3231/badge/?version=latest\n    :target: https://docs.circuitpython.org/projects/ds3231/en/latest/\n    :alt: Documentation Status\n\n.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg\n    :target: https://adafru.it/discord\n    :alt: Discord\n\n.. image:: https://github.com/adafruit/Adafruit_CircuitPython_DS3231/workflows/Build%20CI/badge.svg\n    :target: https://github.com/adafruit/Adafruit_CircuitPython_DS3231/actions/\n    :alt: Build Status\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n    :alt: Code Style: Black\n\nThe datasheet for the DS3231 explains that this part is an\n\"Extremely Accurate I\u00b2C-Integrated RTC/TCXO/Crystal\". And,\nhey, it does exactly what it says on the tin! This Real Time\nClock (RTC) is the most precise you can get in a small, low\npower package.\n\nMost RTCs use an external 32kHz timing crystal that is used\nto keep time with low current draw. And that's all well and\ngood, but those crystals have slight drift, particularly when\nthe temperature changes (the temperature changes the oscillation\nfrequency very very very slightly but it does add up!) This\nRTC is in a beefy package because the crystal is inside the\nchip! And right next to the integrated crystal is a temperature\nsensor. That sensor compensates for the frequency changes by\nadding or removing clock ticks so that the timekeeping stays\non schedule.\n\nThis is the finest RTC you can get, and now we have it in a\ncompact, breadboard-friendly breakout. With a coin cell\nplugged into the back, you can get years of precision\ntimekeeping, even when main power is lost. Great for\ndatalogging and clocks, or anything where you need to\nreally know the time.\n\n.. image:: ../docs/_static/3013-01.jpg\n    :alt: DS3231 Product Image\n\nDependencies\n=============\nThis driver depends on:\n\n* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_\n* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_\n* `Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_\n\nPlease ensure all dependencies are available on the CircuitPython filesystem.\nThis is easily achieved by downloading\n`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.\n\nInstalling from PyPI\n====================\n\nOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from\nPyPI <https://pypi.org/project/adafruit-circuitpython-ds3231/>`_. To install for current user:\n\n.. code-block:: shell\n\n    pip3 install adafruit-circuitpython-ds3231\n\nTo install system-wide (this may be required in some cases):\n\n.. code-block:: shell\n\n    sudo pip3 install adafruit-circuitpython-ds3231\n\nTo install in a virtual environment in your current project:\n\n.. code-block:: shell\n\n    mkdir project-name && cd project-name\n    python3 -m venv .venv\n    source .venv/bin/activate\n    pip3 install adafruit-circuitpython-ds3231\n\nUsage Notes\n===========\n\nBasics\n------\n\nOf course, you must import the library to use it:\n\n.. code:: python3\n\n    import adafruit_ds3231\n    import time\n\nAll the Adafruit RTC libraries take an instantiated and active I2C object\n(from the ``board`` library) as an argument to their constructor. The way to\ncreate an I2C object depends on the board you are using. For boards with labeled\nSCL and SDA pins, you can:\n\n.. code:: python3\n\n    import board\n\nNow, to initialize the I2C bus:\n\n.. code:: python3\n\n    i2c = board.I2C()  # uses board.SCL and board.SDA\n\nOnce you have created the I2C interface object, you can use it to instantiate\nthe RTC object:\n\n.. code:: python3\n\n    rtc = adafruit_ds3231.DS3231(i2c)\n\nDate and time\n-------------\n\nTo set the time, you need to set ``datetime`` to a ``time.struct_time`` object:\n\n.. code:: python3\n\n    rtc.datetime = time.struct_time((2017,1,9,15,6,0,0,9,-1))\n\nAfter the RTC is set, you retrieve the time by reading the ``datetime``\nattribute and access the standard attributes of a struct_time such as ``tm_year``,\n``tm_hour`` and ``tm_min``.\n\n.. code:: python3\n\n    t = rtc.datetime\n    print(t)\n    print(t.tm_hour, t.tm_min)\n\nAlarm\n-----\n\nTo set the time, you need to set ``alarm1`` or ``alarm2`` to a tuple with a\n``time.struct_time`` object and string representing the frequency such as \"hourly\":\n\n.. code:: python3\n\n    rtc.alarm1 = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), \"daily\")\n\nAfter the RTC is set, you retrieve the alarm status by reading the corresponding\n``alarm1_status`` or ``alarm2_status`` attributes. Once True, set it back to False\nto reset.\n\n.. code:: python3\n\n    if rtc.alarm1_status:\n        print(\"wake up!\")\n        rtc.alarm1_status = False\n\nDocumentation\n=============\n\nAPI documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/ds3231/en/latest/>`_.\n\nFor information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.\n\nContributing\n============\n\nContributions are welcome! Please read our `Code of Conduct\n<https://github.com/adafruit/Adafruit_CircuitPython_DS3231/blob/main/CODE_OF_CONDUCT.md>`_\nbefore contributing to help this project stay welcoming.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "CircuitPython library for DS3231 precision real-time clock.",
    "version": "2.4.18",
    "project_urls": {
        "Homepage": "https://github.com/adafruit/Adafruit_CircuitPython_DS3231"
    },
    "split_keywords": [
        "adafruit",
        "precision",
        "real-time",
        "real",
        "time",
        "clock",
        "breakout",
        "hardware",
        "micropython",
        "circuitpython"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63291b82e567c2e433a89c3303bb696db607659245e3f396d94328c19a3cb46d",
                "md5": "f6a2980298dbf56edf72c2fb24b7f80c",
                "sha256": "048a07a0c3916320a214af1e568eca1ab7f4e1fd5fe65e95158a7dfb71b6aa8b"
            },
            "downloads": -1,
            "filename": "adafruit_circuitpython_ds3231-2.4.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f6a2980298dbf56edf72c2fb24b7f80c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6754,
            "upload_time": "2023-05-16T17:51:35",
            "upload_time_iso_8601": "2023-05-16T17:51:35.120529Z",
            "url": "https://files.pythonhosted.org/packages/63/29/1b82e567c2e433a89c3303bb696db607659245e3f396d94328c19a3cb46d/adafruit_circuitpython_ds3231-2.4.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79edd8cc291bc9004eab69b0774f0ff2377cb1bfbfa3be772fed1cd2f6232eca",
                "md5": "b4cf774a76d5adb0ad19a6410859caf3",
                "sha256": "ff765ec1e308f52462fd80f7013d9cde37677c34ef6b954087789a1a96c80a3d"
            },
            "downloads": -1,
            "filename": "adafruit-circuitpython-ds3231-2.4.18.tar.gz",
            "has_sig": false,
            "md5_digest": "b4cf774a76d5adb0ad19a6410859caf3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 297840,
            "upload_time": "2023-05-16T17:51:36",
            "upload_time_iso_8601": "2023-05-16T17:51:36.713406Z",
            "url": "https://files.pythonhosted.org/packages/79/ed/d8cc291bc9004eab69b0774f0ff2377cb1bfbfa3be772fed1cd2f6232eca/adafruit-circuitpython-ds3231-2.4.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-16 17:51:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adafruit",
    "github_project": "Adafruit_CircuitPython_DS3231",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "adafruit-circuitpython-ds3231"
}
        
Elapsed time: 0.06777s