├── adafruit_ads1x15 ├── py.typed ├── __init__.py ├── ads1015.py ├── ads1115.py ├── analog_in.py └── ads1x15.py ├── docs ├── _static │ ├── favicon.ico │ ├── favicon.ico.license │ └── custom.css ├── api.rst.license ├── examples.rst.license ├── index.rst.license ├── requirements.txt ├── examples.rst ├── api.rst ├── index.rst └── conf.py ├── README.rst.license ├── optional_requirements.txt ├── requirements.txt ├── .gitattributes ├── .github ├── workflows │ ├── build.yml │ ├── release_pypi.yml │ ├── release_gh.yml │ └── failure-help-text.yml └── PULL_REQUEST_TEMPLATE │ └── adafruit_circuitpython_pr.md ├── .readthedocs.yaml ├── .pre-commit-config.yaml ├── examples ├── ads1x15_simpletest.py ├── ads1x15_ads1115_simpletest.py ├── ads1x15_gain_example.py ├── ads1x15_comparator_example.py └── ads1x15_fast_read.py ├── LICENSE ├── LICENSES ├── MIT.txt ├── Unlicense.txt └── CC-BY-4.0.txt ├── pyproject.toml ├── .gitignore ├── ruff.toml ├── README.rst └── CODE_OF_CONDUCT.md /adafruit_ads1x15/py.typed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_ADS1x15/HEAD/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries 2 | 3 | SPDX-License-Identifier: CC-BY-4.0 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | sphinx 6 | sphinxcontrib-jquery 7 | sphinx-rtd-theme 8 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | adafruit-circuitpython-busdevice 7 | typing-extensions~=4.0 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /docs/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* SPDX-FileCopyrightText: 2025 Sam Blenny 2 | * SPDX-License-Identifier: MIT 3 | */ 4 | 5 | /* Monkey patch the rtd theme to prevent horizontal stacking of short items 6 | * see https://github.com/readthedocs/sphinx_rtd_theme/issues/1301 7 | */ 8 | .py.property{display: block !important;} 9 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/ads1x15_simpletest.py 7 | :caption: examples/ads1x15_ads1015_simpletest.py 8 | :linenos: 9 | 10 | .. literalinclude:: ../examples/ads1x15_ads1115_simpletest.py 11 | :caption: examples/ads1x15_ads1115_simpletest.py 12 | :linenos: 13 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | API Reference 5 | ############# 6 | 7 | .. automodule:: adafruit_ads1x15.ads1x15 8 | :members: 9 | 10 | .. automodule:: adafruit_ads1x15.ads1015 11 | :members: 12 | 13 | .. automodule:: adafruit_ads1x15.ads1115 14 | :members: 15 | 16 | .. automodule:: adafruit_ads1x15.analog_in 17 | :members: 18 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-lts-latest 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /adafruit_ads1x15/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 | # SPDX-FileCopyrightText: 2025 Asadullah Shaikh 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | `adafruit_ads1x15` 8 | ==================================================== 9 | 10 | Support for the ADS1x15 series of analog-to-digital converters. 11 | 12 | * Author(s): Carter Nelson 13 | """ 14 | 15 | from .ads1015 import ADS1015 16 | from .ads1115 import ADS1115 17 | from .analog_in import AnalogIn 18 | 19 | __all__ = ["ADS1015", "ADS1115", "AnalogIn"] 20 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /examples/ads1x15_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | 8 | from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15 9 | 10 | # Create the I2C bus 11 | i2c = board.I2C() 12 | 13 | # Create the ADC object using the I2C bus 14 | ads = ADS1015(i2c) 15 | 16 | # Create single-ended input on channel 0 17 | chan = AnalogIn(ads, ads1x15.Pin.A0) 18 | 19 | # Create differential input between channel 0 and 1 20 | # chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1) 21 | 22 | print("{:>5}\t{:>5}".format("raw", "v")) 23 | 24 | while True: 25 | print(f"{chan.value:>5}\t{chan.voltage:>5.3f}") 26 | time.sleep(0.5) 27 | -------------------------------------------------------------------------------- /examples/ads1x15_ads1115_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | 8 | from adafruit_ads1x15 import ADS1115, AnalogIn, ads1x15 9 | 10 | # Create the I2C bus 11 | i2c = board.I2C() 12 | 13 | # Create the ADC object using the I2C bus 14 | ads = ADS1115(i2c) 15 | # you can specify an I2C adress instead of the default 0x48 16 | # ads = ADS.ADS1115(i2c, address=0x49) 17 | 18 | # Create single-ended input on channel 0 19 | chan = AnalogIn(ads, ads1x15.Pin.A0) 20 | 21 | # Create differential input between channel 0 and 1 22 | # chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1) 23 | 24 | print("{:>5}\t{:>5}".format("raw", "v")) 25 | 26 | while True: 27 | print(f"{chan.value:>5}\t{chan.voltage:>5.3f}") 28 | time.sleep(0.5) 29 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Carter Nelson for Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /examples/ads1x15_gain_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | 8 | from adafruit_ads1x15 import ADS1115, AnalogIn, ads1x15 9 | 10 | # Create the I2C bus 11 | i2c = board.I2C() 12 | 13 | # Create the ADS object 14 | # ads = ADS.ADS1015(i2c) 15 | ads = ADS1115(i2c) 16 | 17 | # Create a single-ended channel on Pin A0 18 | # Max counts for ADS1015 = 2047 19 | # ADS1115 = 32767 20 | chan = AnalogIn(ads, ads1x15.Pin.A0) 21 | 22 | # The ADS1015 and ADS1115 both have the same gain options. 23 | # 24 | # GAIN RANGE (V) 25 | # ---- --------- 26 | # 2/3 +/- 6.144 27 | # 1 +/- 4.096 28 | # 2 +/- 2.048 29 | # 4 +/- 1.024 30 | # 8 +/- 0.512 31 | # 16 +/- 0.256 32 | # 33 | gains = (2 / 3, 1, 2, 4, 8, 16) 34 | 35 | while True: 36 | ads.gain = gains[0] 37 | print(f"{chan.value:5} {chan.voltage:5.3f}", end="") 38 | for gain in gains[1:]: 39 | ads.gain = gain 40 | print(f" | {chan.value:5} {chan.voltage:5.3f}", end="") 41 | print() 42 | time.sleep(0.5) 43 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and successors. We intend this dedication to 11 | be an overt act of relinquishment in perpetuity of all present and future 12 | rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 19 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, 20 | please refer to 21 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-ads1x15" 14 | description = "CircuitPython library for controlling an ADS1x15 ADC." 15 | version = "0.0.0+auto.0" 16 | readme = "README.rst" 17 | authors = [ 18 | {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} 19 | ] 20 | urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15"} 21 | keywords = [ 22 | "adafruit", 23 | "ads1x115", 24 | "adc", 25 | "hardware", 26 | "micropython", 27 | "circuitpython", 28 | ] 29 | license = {text = "MIT"} 30 | classifiers = [ 31 | "Intended Audience :: Developers", 32 | "Topic :: Software Development :: Libraries", 33 | "Topic :: Software Development :: Embedded Systems", 34 | "Topic :: System :: Hardware", 35 | "License :: OSI Approved :: MIT License", 36 | "Programming Language :: Python :: 3", 37 | ] 38 | dynamic = ["dependencies", "optional-dependencies"] 39 | 40 | [tool.setuptools] 41 | packages = ["adafruit_ads1x15"] 42 | 43 | [tool.setuptools.dynamic] 44 | dependencies = {file = ["requirements.txt"]} 45 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 46 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | .. toctree:: 27 | :caption: Related Products 28 | 29 | ADS1015 12-Bit ADC - 4 Channel with Programmable Gain Amplifier 30 | 31 | ADS1115 16-Bit ADC - 4 Channel with Programmable Gain Amplifier 32 | 33 | .. toctree:: 34 | :caption: Other Links 35 | 36 | Download from GitHub 37 | Download Library Bundle 38 | CircuitPython Reference Documentation 39 | CircuitPython Support Forum 40 | Discord Chat 41 | Adafruit Learning System 42 | Adafruit Blog 43 | Adafruit Store 44 | 45 | Indices and tables 46 | ================== 47 | 48 | * :ref:`genindex` 49 | * :ref:`modindex` 50 | * :ref:`search` 51 | -------------------------------------------------------------------------------- /adafruit_ads1x15/ads1015.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ads1015` 7 | ==================================================== 8 | 9 | CircuitPython driver for ADS1015 ADCs. 10 | 11 | * Author(s): Carter Nelson 12 | """ 13 | 14 | import struct 15 | 16 | try: 17 | from typing import Dict, List 18 | 19 | from typing_extensions import Literal 20 | except ImportError: 21 | pass 22 | 23 | from .ads1x15 import ADS1x15 24 | 25 | # Data sample rates 26 | _ADS1015_CONFIG_DR = { 27 | 128: 0x0000, 28 | 250: 0x0020, 29 | 490: 0x0040, 30 | 920: 0x0060, 31 | 1600: 0x0080, 32 | 2400: 0x00A0, 33 | 3300: 0x00C0, 34 | } 35 | 36 | 37 | class ADS1015(ADS1x15): 38 | """Class for the ADS1015 12 bit ADC.""" 39 | 40 | @property 41 | def bits(self) -> Literal[12]: 42 | """The ADC bit resolution.""" 43 | return 12 44 | 45 | @property 46 | def rates(self) -> List[int]: 47 | """Possible data rate settings.""" 48 | r = list(_ADS1015_CONFIG_DR.keys()) 49 | r.sort() 50 | return r 51 | 52 | @property 53 | def rate_config(self) -> Dict[int, int]: 54 | """Rate configuration masks.""" 55 | return _ADS1015_CONFIG_DR 56 | 57 | def _data_rate_default(self) -> Literal[1600]: # noqa: PLR6301 58 | """Default data rate setting is 1600 samples per second""" 59 | return 1600 60 | 61 | def _conversion_value(self, raw_adc: int) -> int: # noqa: PLR6301 62 | value = struct.unpack(">h", raw_adc.to_bytes(2, "big"))[0] 63 | return value 64 | -------------------------------------------------------------------------------- /adafruit_ads1x15/ads1115.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ads1115` 7 | ==================================================== 8 | 9 | CircuitPython driver for 1115 ADCs. 10 | 11 | * Author(s): Carter Nelson 12 | """ 13 | 14 | import struct 15 | 16 | try: 17 | from typing import Dict, List 18 | 19 | from typing_extensions import Literal 20 | except ImportError: 21 | pass 22 | 23 | from .ads1x15 import ADS1x15 24 | 25 | # Data sample rates 26 | _ADS1115_CONFIG_DR = { 27 | 8: 0x0000, 28 | 16: 0x0020, 29 | 32: 0x0040, 30 | 64: 0x0060, 31 | 128: 0x0080, 32 | 250: 0x00A0, 33 | 475: 0x00C0, 34 | 860: 0x00E0, 35 | } 36 | 37 | 38 | class ADS1115(ADS1x15): 39 | """Class for the ADS1115 16 bit ADC.""" 40 | 41 | @property 42 | def bits(self) -> Literal[16]: 43 | """The ADC bit resolution.""" 44 | return 16 45 | 46 | @property 47 | def rates(self) -> List[int]: 48 | """Possible data rate settings.""" 49 | r = list(_ADS1115_CONFIG_DR.keys()) 50 | r.sort() 51 | return r 52 | 53 | @property 54 | def rate_config(self) -> Dict[int, int]: 55 | """Rate configuration masks.""" 56 | return _ADS1115_CONFIG_DR 57 | 58 | def _data_rate_default(self) -> Literal[128]: # noqa: PLR6301 59 | """Default data rate setting is 128 samples per second""" 60 | return 128 61 | 62 | def _conversion_value(self, raw_adc: int) -> int: # noqa: PLR6301 63 | value = struct.unpack(">h", raw_adc.to_bytes(2, "big"))[0] 64 | return value 65 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /examples/ads1x15_comparator_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import countio 8 | 9 | from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15 10 | 11 | # Create the I2C bus 12 | i2c = board.I2C() 13 | 14 | # Create the ADS object 15 | ads = ADS1015(i2c) 16 | # ads = ADS.ADS1115(i2c) 17 | 18 | # Create a single-ended channel on Pin A0 19 | # Max counts for ADS1015 = 2047 20 | # ADS1115 = 32767 21 | chan = AnalogIn(ads, ads1x15.Pin.A0) 22 | 23 | # Create Interrupt-driven input to track comparator changes 24 | int_pin = countio.Counter(board.GP9, edge=countio.Edge.RISE) 25 | 26 | # Set ADC to continuously read new data 27 | ads.mode = ads1x15.Mode.CONTINUOUS 28 | # Set comparator to assert after 1 ADC conversion 29 | ads.comparator_queue_length = 1 30 | # Set comparator to use traditional threshold instead of window 31 | ads.comparator_mode = ads1x15.Comp_Mode.TRADITIONAL 32 | # Set comparator output to de-assert if readings no longer above threshold 33 | ads.comparator_latch = ads1x15.Comp_Latch.NONLATCHING 34 | # Set comparator output to logic LOW when asserted 35 | ads.comparator_polarity = ads1x15.Comp_Polarity.ACTIVE_LOW 36 | # Gain should be explicitly set to ensure threshold values are calculated correctly 37 | ads.gain = 1 38 | # Set comparator low threshold to 2V 39 | ads.comparator_low_threshold = chan.convert_to_value(2.000) 40 | # Set comparator high threshold to 2.002V. High threshold must be above low threshold 41 | ads.comparator_high_threshold = chan.convert_to_value(2.002) 42 | 43 | count = 0 44 | while True: 45 | print(chan.value, chan.voltage) # This initiates new ADC reading 46 | if int_pin.count > count: 47 | print("Comparator Triggered") 48 | count = int_pin.count 49 | time.sleep(2) 50 | -------------------------------------------------------------------------------- /examples/ads1x15_fast_read.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import busio 8 | 9 | from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15 10 | 11 | # Data collection setup 12 | RATE = 3300 13 | SAMPLES = 1000 14 | 15 | # Create the I2C bus with a fast frequency 16 | # NOTE: Your device may not respect the frequency setting 17 | # Raspberry Pis must change this in /boot/config.txt 18 | 19 | i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000) 20 | 21 | # Create the ADC object using the I2C bus 22 | ads = ADS1015(i2c) 23 | 24 | # Create single-ended input on channel 0 25 | chan = AnalogIn(ads, ads1x15.Pin.A0) 26 | 27 | # ADC Configuration 28 | ads.mode = ads1x15.Mode.CONTINUOUS 29 | ads.data_rate = RATE 30 | 31 | # First ADC channel read in continuous mode configures device 32 | # and waits 2 conversion cycles 33 | _ = chan.value 34 | 35 | sample_interval = 1.0 / ads.data_rate 36 | 37 | repeats = 0 38 | skips = 0 39 | 40 | data = [None] * SAMPLES 41 | 42 | start = time.monotonic() 43 | time_next_sample = start + sample_interval 44 | 45 | # Read the same channel over and over 46 | for i in range(SAMPLES): 47 | # Wait for expected conversion finish time 48 | while time.monotonic() < (time_next_sample): 49 | pass 50 | 51 | # Read conversion value for ADC channel 52 | data[i] = chan.value 53 | 54 | # Loop timing 55 | time_last_sample = time.monotonic() 56 | time_next_sample = time_next_sample + sample_interval 57 | if time_last_sample > (time_next_sample + sample_interval): 58 | skips += 1 59 | time_next_sample = time.monotonic() + sample_interval 60 | 61 | # Detect repeated values due to over polling 62 | if data[i] == data[i - 1]: 63 | repeats += 1 64 | 65 | end = time.monotonic() 66 | total_time = end - start 67 | 68 | rate_reported = SAMPLES / total_time 69 | rate_actual = (SAMPLES - repeats) / total_time 70 | # NOTE: leave input floating to pickup some random noise 71 | # This cannot estimate conversion rates higher than polling rate 72 | 73 | print(f"Took {total_time:5.3f} s to acquire {SAMPLES:d} samples.") 74 | print("") 75 | print("Configured:") 76 | print(f" Requested = {RATE:5d} sps") 77 | print(f" Reported = {ads.data_rate:5d} sps") 78 | print("") 79 | print("Actual:") 80 | print(f" Polling Rate = {rate_reported:8.2f} sps") 81 | print(f" {rate_reported / RATE:9.2%}") 82 | print(f" Skipped = {skips:5d}") 83 | print(f" Repeats = {repeats:5d}") 84 | print(f" Conversion Rate = {rate_actual:8.2f} sps (estimated)") 85 | -------------------------------------------------------------------------------- /adafruit_ads1x15/analog_in.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `analog_in` 7 | ============================== 8 | AnalogIn for single-ended and 9 | differential ADC readings. 10 | 11 | * Author(s): Carter Nelson, adapted from MCP3xxx original by Brent Rubell 12 | """ 13 | 14 | try: 15 | from typing import Optional 16 | 17 | from .ads1x15 import ADS1x15 18 | except ImportError: 19 | pass 20 | 21 | _ADS1X15_DIFF_CHANNELS = {(0, 1): 0, (0, 3): 1, (1, 3): 2, (2, 3): 3} 22 | _ADS1X15_PGA_RANGE = {2 / 3: 6.144, 1: 4.096, 2: 2.048, 4: 1.024, 8: 0.512, 16: 0.256} 23 | 24 | 25 | class AnalogIn: 26 | """AnalogIn Mock Implementation for ADC Reads. 27 | 28 | :param ADS1x15 ads: The ads object. 29 | :param int positive_pin: Required pin for single-ended. 30 | :param int negative_pin: Optional pin for differential reads. 31 | """ 32 | 33 | def __init__(self, ads: ADS1x15, positive_pin: int, negative_pin: Optional[int] = None): 34 | self._ads = ads 35 | self._pin_setting = positive_pin 36 | self._negative_pin = negative_pin 37 | self.is_differential = False 38 | if negative_pin is not None: 39 | pins = (self._pin_setting, self._negative_pin) 40 | if pins not in _ADS1X15_DIFF_CHANNELS: 41 | raise ValueError( 42 | f"Differential channels must be one of: {list(_ADS1X15_DIFF_CHANNELS.keys())}" 43 | ) 44 | self._pin_setting = _ADS1X15_DIFF_CHANNELS[pins] 45 | self.is_differential = True 46 | 47 | @property 48 | def value(self) -> int: 49 | """The value on the analog pin between 0 and 65535 50 | inclusive (16-bit). (read-only) 51 | 52 | Even if the underlying analog to digital converter (ADC) is 53 | lower resolution, the value is 16-bit. 54 | """ 55 | pin = self._pin_setting if self.is_differential else self._pin_setting + 0x04 56 | return self._ads.read(pin) 57 | 58 | @property 59 | def voltage(self) -> float: 60 | """Returns the voltage from the ADC pin as a floating point value.""" 61 | volts = self.convert_to_voltage(self.value) 62 | return volts 63 | 64 | def convert_to_value(self, volts: float) -> int: 65 | """Calculates a standard 16-bit integer value for a given voltage""" 66 | 67 | lsb = _ADS1X15_PGA_RANGE[self._ads.gain] / (1 << (self._ads.bits - 1)) 68 | value = int(volts / lsb) 69 | 70 | # Need to bit shift if value is only 12-bits 71 | value <<= 16 - self._ads.bits 72 | return value 73 | 74 | def convert_to_voltage(self, value_int: int) -> float: 75 | """Calculates voltage from 16-bit ADC reading""" 76 | 77 | lsb = _ADS1X15_PGA_RANGE[self._ads.gain] / (1 << (self._ads.bits - 1)) 78 | 79 | # Need to bit shift if value is only 12-bits 80 | value_int >>= 16 - self._ads.bits 81 | volts = value_int * lsb 82 | 83 | return volts 84 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | preview = true 10 | select = ["I", "PL", "UP"] 11 | 12 | extend-select = [ 13 | "D419", # empty-docstring 14 | "E501", # line-too-long 15 | "W291", # trailing-whitespace 16 | "PLC0414", # useless-import-alias 17 | "PLC2401", # non-ascii-name 18 | "PLC2801", # unnecessary-dunder-call 19 | "PLC3002", # unnecessary-direct-lambda-call 20 | "PLE0101", # return-in-init 21 | "F706", # return-outside-function 22 | "F704", # yield-outside-function 23 | "PLE0116", # continue-in-finally 24 | "PLE0117", # nonlocal-without-binding 25 | "PLE0241", # duplicate-bases 26 | "PLE0302", # unexpected-special-method-signature 27 | "PLE0604", # invalid-all-object 28 | "PLE0605", # invalid-all-format 29 | "PLE0643", # potential-index-error 30 | "PLE0704", # misplaced-bare-raise 31 | "PLE1141", # dict-iter-missing-items 32 | "PLE1142", # await-outside-async 33 | "PLE1205", # logging-too-many-args 34 | "PLE1206", # logging-too-few-args 35 | "PLE1307", # bad-string-format-type 36 | "PLE1310", # bad-str-strip-call 37 | "PLE1507", # invalid-envvar-value 38 | "PLE2502", # bidirectional-unicode 39 | "PLE2510", # invalid-character-backspace 40 | "PLE2512", # invalid-character-sub 41 | "PLE2513", # invalid-character-esc 42 | "PLE2514", # invalid-character-nul 43 | "PLE2515", # invalid-character-zero-width-space 44 | "PLR0124", # comparison-with-itself 45 | "PLR0202", # no-classmethod-decorator 46 | "PLR0203", # no-staticmethod-decorator 47 | "UP004", # useless-object-inheritance 48 | "PLR0206", # property-with-parameters 49 | "PLR0904", # too-many-public-methods 50 | "PLR0911", # too-many-return-statements 51 | "PLR0912", # too-many-branches 52 | "PLR0913", # too-many-arguments 53 | "PLR0914", # too-many-locals 54 | "PLR0915", # too-many-statements 55 | "PLR0916", # too-many-boolean-expressions 56 | "PLR1702", # too-many-nested-blocks 57 | "PLR1704", # redefined-argument-from-local 58 | "PLR1711", # useless-return 59 | "C416", # unnecessary-comprehension 60 | "PLR1733", # unnecessary-dict-index-lookup 61 | "PLR1736", # unnecessary-list-index-lookup 62 | 63 | # ruff reports this rule is unstable 64 | #"PLR6301", # no-self-use 65 | 66 | "PLW0108", # unnecessary-lambda 67 | "PLW0120", # useless-else-on-loop 68 | "PLW0127", # self-assigning-variable 69 | "PLW0129", # assert-on-string-literal 70 | "B033", # duplicate-value 71 | "PLW0131", # named-expr-without-context 72 | "PLW0245", # super-without-brackets 73 | "PLW0406", # import-self 74 | "PLW0602", # global-variable-not-assigned 75 | "PLW0603", # global-statement 76 | "PLW0604", # global-at-module-level 77 | 78 | # fails on the try: import typing used by libraries 79 | #"F401", # unused-import 80 | 81 | "F841", # unused-variable 82 | "E722", # bare-except 83 | "PLW0711", # binary-op-exception 84 | "PLW1501", # bad-open-mode 85 | "PLW1508", # invalid-envvar-default 86 | "PLW1509", # subprocess-popen-preexec-fn 87 | "PLW2101", # useless-with-lock 88 | "PLW3301", # nested-min-max 89 | ] 90 | 91 | ignore = [ 92 | "PLR2004", # magic-value-comparison 93 | "UP030", # format literals 94 | "PLW1514", # unspecified-encoding 95 | "PLR0913", # too-many-arguments 96 | "PLR0915", # too-many-statements 97 | "PLR0917", # too-many-positional-arguments 98 | "PLR0904", # too-many-public-methods 99 | "PLR0912", # too-many-branches 100 | "PLR0916", # too-many-boolean-expressions 101 | ] 102 | 103 | [format] 104 | line-ending = "lf" 105 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ads1x15/badge/?version=latest 5 | :target: https://docs.circuitpython.org/projects/ads1x15/en/latest/ 6 | :alt: Documentation Status 7 | 8 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 9 | :target: https://adafru.it/discord 10 | :alt: Discord 11 | 12 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/workflows/Build%20CI/badge.svg 13 | :target: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/actions/ 14 | :alt: Build Status 15 | 16 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 17 | :target: https://github.com/astral-sh/ruff 18 | :alt: Code Style: Ruff 19 | 20 | Support for the ADS1x15 series of analog-to-digital converters. Available in 12-bit (ADS1015) 21 | and 16-bit (ADS1115) versions. 22 | 23 | Installation & Dependencies 24 | =========================== 25 | 26 | This driver depends on: 27 | 28 | * `Adafruit CircuitPython `_ 29 | * `Bus Device `_ 30 | 31 | Please ensure all dependencies are available on the CircuitPython filesystem. 32 | This can be most easily achieved by downloading and installing 33 | `the Adafruit library and driver bundle `_ on 34 | your device. 35 | 36 | Installing from PyPI 37 | -------------------- 38 | 39 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 40 | PyPI `_. To install for current user: 41 | 42 | .. code-block:: shell 43 | 44 | pip3 install adafruit-circuitpython-ads1x15 45 | 46 | To install system-wide (this may be required in some cases): 47 | 48 | .. code-block:: shell 49 | 50 | sudo pip3 install adafruit-circuitpython-ads1x15 51 | 52 | To install in a virtual environment in your current project: 53 | 54 | .. code-block:: shell 55 | 56 | mkdir project-name && cd project-name 57 | python3 -m venv .venv 58 | source .venv/bin/activate 59 | pip3 install adafruit-circuitpython-ads1x15 60 | 61 | Usage Example 62 | ============= 63 | 64 | Single Ended 65 | ------------ 66 | 67 | .. code-block:: python 68 | 69 | import time 70 | 71 | import board 72 | 73 | from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15 74 | 75 | # Create the I2C bus 76 | i2c = board.I2C() 77 | 78 | # Create the ADC object using the I2C bus 79 | ads = ADS1015(i2c) 80 | 81 | # Create single-ended input on channel 0 82 | chan = AnalogIn(ads, ads1x15.Pin.A0) 83 | 84 | # Create differential input between channel 0 and 1 85 | # chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1) 86 | 87 | print("{:>5}\t{:>5}".format("raw", "v")) 88 | 89 | while True: 90 | print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage)) 91 | time.sleep(0.5) 92 | 93 | Documentation 94 | ============= 95 | 96 | API documentation for this library can be found on `Read the Docs `_. 97 | 98 | For information on building library documentation, please check out `this guide `_. 99 | 100 | Contributing 101 | ============ 102 | 103 | Contributions are welcome! Please read our `Code of Conduct 104 | `_ 105 | before contributing to help this project stay welcoming. 106 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | import datetime 6 | import os 7 | import sys 8 | 9 | sys.path.insert(0, os.path.abspath("..")) 10 | 11 | # -- General configuration ------------------------------------------------ 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | extensions = [ 17 | "sphinx.ext.autodoc", 18 | "sphinxcontrib.jquery", 19 | "sphinx.ext.intersphinx", 20 | "sphinx.ext.viewcode", 21 | ] 22 | 23 | intersphinx_mapping = { 24 | "python": ("https://docs.python.org/3", None), 25 | "BusDevice": ( 26 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 27 | None, 28 | ), 29 | "Register": ( 30 | "https://docs.circuitpython.org/projects/register/en/latest/", 31 | None, 32 | ), 33 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 34 | } 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ["_templates"] 38 | 39 | source_suffix = ".rst" 40 | 41 | # The master toctree document. 42 | master_doc = "index" 43 | 44 | # General information about the project. 45 | project = "Adafruit CIRCUITPYTHON_ADS1X15 Library" 46 | creation_year = "2017" 47 | current_year = str(datetime.datetime.now().year) 48 | year_duration = ( 49 | current_year if current_year == creation_year else creation_year + " - " + current_year 50 | ) 51 | copyright = year_duration + " Carter Nelson" 52 | author = "Carter Nelson" 53 | 54 | # The version info for the project you're documenting, acts as replacement for 55 | # |version| and |release|, also used in various other places throughout the 56 | # built documents. 57 | # 58 | # The short X.Y version. 59 | version = "1.0" 60 | # The full version, including alpha/beta/rc tags. 61 | release = "1.0" 62 | 63 | # The language for content autogenerated by Sphinx. Refer to documentation 64 | # for a list of supported languages. 65 | # 66 | # This is also used if you do content translation via gettext catalogs. 67 | # Usually you set "language" from the command line for these cases. 68 | language = "en" 69 | 70 | # List of patterns, relative to source directory, that match files and 71 | # directories to ignore when looking for source files. 72 | # This patterns also effect to html_static_path and html_extra_path 73 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 74 | 75 | # The reST default role (used for this markup: `text`) to use for all 76 | # documents. 77 | # 78 | default_role = "any" 79 | 80 | # If true, '()' will be appended to :func: etc. cross-reference text. 81 | # 82 | add_function_parentheses = True 83 | 84 | # The name of the Pygments (syntax highlighting) style to use. 85 | pygments_style = "sphinx" 86 | 87 | # If true, `todo` and `todoList` produce output, else they produce nothing. 88 | todo_include_todos = False 89 | 90 | # If this is True, todo emits a warning for each TODO entries. The default is False. 91 | todo_emit_warnings = True 92 | 93 | 94 | # -- Options for HTML output ---------------------------------------------- 95 | 96 | # The theme to use for HTML and HTML Help pages. See the documentation for 97 | # a list of builtin themes. 98 | # 99 | import sphinx_rtd_theme 100 | 101 | html_theme = "sphinx_rtd_theme" 102 | 103 | # Add any paths that contain custom static files (such as style sheets) here, 104 | # relative to this directory. They are copied after the builtin static files, 105 | # so a file named "default.css" will overwrite the builtin "default.css". 106 | html_static_path = ["_static"] 107 | 108 | # Include extra css to work around rtd theme glitches 109 | html_css_files = ["custom.css"] 110 | 111 | # The name of an image file (relative to this directory) to use as a favicon of 112 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 113 | # pixels large. 114 | # 115 | html_favicon = "_static/favicon.ico" 116 | 117 | # Output file base name for HTML help builder. 118 | htmlhelp_basename = "AdafruitCIRCUITPYTHON_ADS1X15Librarydoc" 119 | 120 | # -- Options for LaTeX output --------------------------------------------- 121 | 122 | latex_elements = { 123 | # The paper size ('letterpaper' or 'a4paper'). 124 | # 125 | # 'papersize': 'letterpaper', 126 | # The font size ('10pt', '11pt' or '12pt'). 127 | # 128 | # 'pointsize': '10pt', 129 | # Additional stuff for the LaTeX preamble. 130 | # 131 | # 'preamble': '', 132 | # Latex figure (float) alignment 133 | # 134 | # 'figure_align': 'htbp', 135 | } 136 | 137 | # Grouping the document tree into LaTeX files. List of tuples 138 | # (source start file, target name, title, 139 | # author, documentclass [howto, manual, or own class]). 140 | latex_documents = [ 141 | ( 142 | master_doc, 143 | "AdafruitCIRCUITPYTHON_ADS1X15Library.tex", 144 | "Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation", 145 | author, 146 | "manual", 147 | ), 148 | ] 149 | 150 | # -- Options for manual page output --------------------------------------- 151 | 152 | # One entry per manual page. List of tuples 153 | # (source start file, name, description, authors, manual section). 154 | man_pages = [ 155 | ( 156 | master_doc, 157 | "adafruitCIRCUITPYTHON_ADS1X15library", 158 | "Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation", 159 | [author], 160 | 1, 161 | ) 162 | ] 163 | 164 | # -- Options for Texinfo output ------------------------------------------- 165 | 166 | # Grouping the document tree into Texinfo files. List of tuples 167 | # (source start file, target name, title, author, 168 | # dir menu entry, description, category) 169 | texinfo_documents = [ 170 | ( 171 | master_doc, 172 | "AdafruitCIRCUITPYTHON_ADS1X15Library", 173 | "Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation", 174 | author, 175 | "AdafruitCIRCUITPYTHON_ADS1X15Library", 176 | "One line description of project.", 177 | "Miscellaneous", 178 | ), 179 | ] 180 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International Creative Commons Corporation 2 | ("Creative Commons") is not a law firm and does not provide legal services 3 | or legal advice. Distribution of Creative Commons public licenses does not 4 | create a lawyer-client or other relationship. Creative Commons makes its licenses 5 | and related information available on an "as-is" basis. Creative Commons gives 6 | no warranties regarding its licenses, any material licensed under their terms 7 | and conditions, or any related information. Creative Commons disclaims all 8 | liability for damages resulting from their use to the fullest extent possible. 9 | 10 | Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions 13 | that creators and other rights holders may use to share original works of 14 | authorship and other material subject to copyright and certain other rights 15 | specified in the public license below. The following considerations are for 16 | informational purposes only, are not exhaustive, and do not form part of our 17 | licenses. 18 | 19 | Considerations for licensors: Our public licenses are intended for use by 20 | those authorized to give the public permission to use material in ways otherwise 21 | restricted by copyright and certain other rights. Our licenses are irrevocable. 22 | Licensors should read and understand the terms and conditions of the license 23 | they choose before applying it. Licensors should also secure all rights necessary 24 | before applying our licenses so that the public can reuse the material as 25 | expected. Licensors should clearly mark any material not subject to the license. 26 | This includes other CC-licensed material, or material used under an exception 27 | or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors 28 | 29 | Considerations for the public: By using one of our public licenses, a licensor 30 | grants the public permission to use the licensed material under specified 31 | terms and conditions. If the licensor's permission is not necessary for any 32 | reason–for example, because of any applicable exception or limitation to copyright–then 33 | that use is not regulated by the license. Our licenses grant only permissions 34 | under copyright and certain other rights that a licensor has authority to 35 | grant. Use of the licensed material may still be restricted for other reasons, 36 | including because others have copyright or other rights in the material. A 37 | licensor may make special requests, such as asking that all changes be marked 38 | or described. Although not required by our licenses, you are encouraged to 39 | respect those requests where reasonable. More considerations for the public 40 | : wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution 41 | 4.0 International Public License 42 | 43 | By exercising the Licensed Rights (defined below), You accept and agree to 44 | be bound by the terms and conditions of this Creative Commons Attribution 45 | 4.0 International Public License ("Public License"). To the extent this Public 46 | License may be interpreted as a contract, You are granted the Licensed Rights 47 | in consideration of Your acceptance of these terms and conditions, and the 48 | Licensor grants You such rights in consideration of benefits the Licensor 49 | receives from making the Licensed Material available under these terms and 50 | conditions. 51 | 52 | Section 1 – Definitions. 53 | 54 | a. Adapted Material means material subject to Copyright and Similar Rights 55 | that is derived from or based upon the Licensed Material and in which the 56 | Licensed Material is translated, altered, arranged, transformed, or otherwise 57 | modified in a manner requiring permission under the Copyright and Similar 58 | Rights held by the Licensor. For purposes of this Public License, where the 59 | Licensed Material is a musical work, performance, or sound recording, Adapted 60 | Material is always produced where the Licensed Material is synched in timed 61 | relation with a moving image. 62 | 63 | b. Adapter's License means the license You apply to Your Copyright and Similar 64 | Rights in Your contributions to Adapted Material in accordance with the terms 65 | and conditions of this Public License. 66 | 67 | c. Copyright and Similar Rights means copyright and/or similar rights closely 68 | related to copyright including, without limitation, performance, broadcast, 69 | sound recording, and Sui Generis Database Rights, without regard to how the 70 | rights are labeled or categorized. For purposes of this Public License, the 71 | rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 72 | 73 | d. Effective Technological Measures means those measures that, in the absence 74 | of proper authority, may not be circumvented under laws fulfilling obligations 75 | under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, 76 | and/or similar international agreements. 77 | 78 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other 79 | exception or limitation to Copyright and Similar Rights that applies to Your 80 | use of the Licensed Material. 81 | 82 | f. Licensed Material means the artistic or literary work, database, or other 83 | material to which the Licensor applied this Public License. 84 | 85 | g. Licensed Rights means the rights granted to You subject to the terms and 86 | conditions of this Public License, which are limited to all Copyright and 87 | Similar Rights that apply to Your use of the Licensed Material and that the 88 | Licensor has authority to license. 89 | 90 | h. Licensor means the individual(s) or entity(ies) granting rights under this 91 | Public License. 92 | 93 | i. Share means to provide material to the public by any means or process that 94 | requires permission under the Licensed Rights, such as reproduction, public 95 | display, public performance, distribution, dissemination, communication, or 96 | importation, and to make material available to the public including in ways 97 | that members of the public may access the material from a place and at a time 98 | individually chosen by them. 99 | 100 | j. Sui Generis Database Rights means rights other than copyright resulting 101 | from Directive 96/9/EC of the European Parliament and of the Council of 11 102 | March 1996 on the legal protection of databases, as amended and/or succeeded, 103 | as well as other essentially equivalent rights anywhere in the world. 104 | 105 | k. You means the individual or entity exercising the Licensed Rights under 106 | this Public License. Your has a corresponding meaning. 107 | 108 | Section 2 – Scope. 109 | 110 | a. License grant. 111 | 112 | 1. Subject to the terms and conditions of this Public License, the Licensor 113 | hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, 114 | irrevocable license to exercise the Licensed Rights in the Licensed Material 115 | to: 116 | 117 | A. reproduce and Share the Licensed Material, in whole or in part; and 118 | 119 | B. produce, reproduce, and Share Adapted Material. 120 | 121 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions 122 | and Limitations apply to Your use, this Public License does not apply, and 123 | You do not need to comply with its terms and conditions. 124 | 125 | 3. Term. The term of this Public License is specified in Section 6(a). 126 | 127 | 4. Media and formats; technical modifications allowed. The Licensor authorizes 128 | You to exercise the Licensed Rights in all media and formats whether now known 129 | or hereafter created, and to make technical modifications necessary to do 130 | so. The Licensor waives and/or agrees not to assert any right or authority 131 | to forbid You from making technical modifications necessary to exercise the 132 | Licensed Rights, including technical modifications necessary to circumvent 133 | Effective Technological Measures. For purposes of this Public License, simply 134 | making modifications authorized by this Section 2(a)(4) never produces Adapted 135 | Material. 136 | 137 | 5. Downstream recipients. 138 | 139 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed 140 | Material automatically receives an offer from the Licensor to exercise the 141 | Licensed Rights under the terms and conditions of this Public License. 142 | 143 | B. No downstream restrictions. You may not offer or impose any additional 144 | or different terms or conditions on, or apply any Effective Technological 145 | Measures to, the Licensed Material if doing so restricts exercise of the Licensed 146 | Rights by any recipient of the Licensed Material. 147 | 148 | 6. No endorsement. Nothing in this Public License constitutes or may be construed 149 | as permission to assert or imply that You are, or that Your use of the Licensed 150 | Material is, connected with, or sponsored, endorsed, or granted official status 151 | by, the Licensor or others designated to receive attribution as provided in 152 | Section 3(a)(1)(A)(i). 153 | 154 | b. Other rights. 155 | 156 | 1. Moral rights, such as the right of integrity, are not licensed under this 157 | Public License, nor are publicity, privacy, and/or other similar personality 158 | rights; however, to the extent possible, the Licensor waives and/or agrees 159 | not to assert any such rights held by the Licensor to the limited extent necessary 160 | to allow You to exercise the Licensed Rights, but not otherwise. 161 | 162 | 2. Patent and trademark rights are not licensed under this Public License. 163 | 164 | 3. To the extent possible, the Licensor waives any right to collect royalties 165 | from You for the exercise of the Licensed Rights, whether directly or through 166 | a collecting society under any voluntary or waivable statutory or compulsory 167 | licensing scheme. In all other cases the Licensor expressly reserves any right 168 | to collect such royalties. 169 | 170 | Section 3 – License Conditions. 171 | 172 | Your exercise of the Licensed Rights is expressly made subject to the following 173 | conditions. 174 | 175 | a. Attribution. 176 | 177 | 1. If You Share the Licensed Material (including in modified form), You must: 178 | 179 | A. retain the following if it is supplied by the Licensor with the Licensed 180 | Material: 181 | 182 | i. identification of the creator(s) of the Licensed Material and any others 183 | designated to receive attribution, in any reasonable manner requested by the 184 | Licensor (including by pseudonym if designated); 185 | 186 | ii. a copyright notice; 187 | 188 | iii. a notice that refers to this Public License; 189 | 190 | iv. a notice that refers to the disclaimer of warranties; 191 | 192 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 193 | 194 | B. indicate if You modified the Licensed Material and retain an indication 195 | of any previous modifications; and 196 | 197 | C. indicate the Licensed Material is licensed under this Public License, and 198 | include the text of, or the URI or hyperlink to, this Public License. 199 | 200 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner 201 | based on the medium, means, and context in which You Share the Licensed Material. 202 | For example, it may be reasonable to satisfy the conditions by providing a 203 | URI or hyperlink to a resource that includes the required information. 204 | 205 | 3. If requested by the Licensor, You must remove any of the information required 206 | by Section 3(a)(1)(A) to the extent reasonably practicable. 207 | 208 | 4. If You Share Adapted Material You produce, the Adapter's License You apply 209 | must not prevent recipients of the Adapted Material from complying with this 210 | Public License. 211 | 212 | Section 4 – Sui Generis Database Rights. 213 | 214 | Where the Licensed Rights include Sui Generis Database Rights that apply to 215 | Your use of the Licensed Material: 216 | 217 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, 218 | reuse, reproduce, and Share all or a substantial portion of the contents of 219 | the database; 220 | 221 | b. if You include all or a substantial portion of the database contents in 222 | a database in which You have Sui Generis Database Rights, then the database 223 | in which You have Sui Generis Database Rights (but not its individual contents) 224 | is Adapted Material; and 225 | 226 | c. You must comply with the conditions in Section 3(a) if You Share all or 227 | a substantial portion of the contents of the database. 228 | 229 | For the avoidance of doubt, this Section 4 supplements and does not replace 230 | Your obligations under this Public License where the Licensed Rights include 231 | other Copyright and Similar Rights. 232 | 233 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 234 | 235 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, 236 | the Licensor offers the Licensed Material as-is and as-available, and makes 237 | no representations or warranties of any kind concerning the Licensed Material, 238 | whether express, implied, statutory, or other. This includes, without limitation, 239 | warranties of title, merchantability, fitness for a particular purpose, non-infringement, 240 | absence of latent or other defects, accuracy, or the presence or absence of 241 | errors, whether or not known or discoverable. Where disclaimers of warranties 242 | are not allowed in full or in part, this disclaimer may not apply to You. 243 | 244 | b. To the extent possible, in no event will the Licensor be liable to You 245 | on any legal theory (including, without limitation, negligence) or otherwise 246 | for any direct, special, indirect, incidental, consequential, punitive, exemplary, 247 | or other losses, costs, expenses, or damages arising out of this Public License 248 | or use of the Licensed Material, even if the Licensor has been advised of 249 | the possibility of such losses, costs, expenses, or damages. Where a limitation 250 | of liability is not allowed in full or in part, this limitation may not apply 251 | to You. 252 | 253 | c. The disclaimer of warranties and limitation of liability provided above 254 | shall be interpreted in a manner that, to the extent possible, most closely 255 | approximates an absolute disclaimer and waiver of all liability. 256 | 257 | Section 6 – Term and Termination. 258 | 259 | a. This Public License applies for the term of the Copyright and Similar Rights 260 | licensed here. However, if You fail to comply with this Public License, then 261 | Your rights under this Public License terminate automatically. 262 | 263 | b. Where Your right to use the Licensed Material has terminated under Section 264 | 6(a), it reinstates: 265 | 266 | 1. automatically as of the date the violation is cured, provided it is cured 267 | within 30 days of Your discovery of the violation; or 268 | 269 | 2. upon express reinstatement by the Licensor. 270 | 271 | c. For the avoidance of doubt, this Section 6(b) does not affect any right 272 | the Licensor may have to seek remedies for Your violations of this Public 273 | License. 274 | 275 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material 276 | under separate terms or conditions or stop distributing the Licensed Material 277 | at any time; however, doing so will not terminate this Public License. 278 | 279 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 280 | 281 | Section 7 – Other Terms and Conditions. 282 | 283 | a. The Licensor shall not be bound by any additional or different terms or 284 | conditions communicated by You unless expressly agreed. 285 | 286 | b. Any arrangements, understandings, or agreements regarding the Licensed 287 | Material not stated herein are separate from and independent of the terms 288 | and conditions of this Public License. 289 | 290 | Section 8 – Interpretation. 291 | 292 | a. For the avoidance of doubt, this Public License does not, and shall not 293 | be interpreted to, reduce, limit, restrict, or impose conditions on any use 294 | of the Licensed Material that could lawfully be made without permission under 295 | this Public License. 296 | 297 | b. To the extent possible, if any provision of this Public License is deemed 298 | unenforceable, it shall be automatically reformed to the minimum extent necessary 299 | to make it enforceable. If the provision cannot be reformed, it shall be severed 300 | from this Public License without affecting the enforceability of the remaining 301 | terms and conditions. 302 | 303 | c. No term or condition of this Public License will be waived and no failure 304 | to comply consented to unless expressly agreed to by the Licensor. 305 | 306 | d. Nothing in this Public License constitutes or may be interpreted as a limitation 307 | upon, or waiver of, any privileges and immunities that apply to the Licensor 308 | or You, including from the legal processes of any jurisdiction or authority. 309 | 310 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative 311 | Commons may elect to apply one of its public licenses to material it publishes 312 | and in those instances will be considered the "Licensor." The text of the 313 | Creative Commons public licenses is dedicated to the public domain under the 314 | CC0 Public Domain Dedication. Except for the limited purpose of indicating 315 | that material is shared under a Creative Commons public license or as otherwise 316 | permitted by the Creative Commons policies published at creativecommons.org/policies, 317 | Creative Commons does not authorize the use of the trademark "Creative Commons" 318 | or any other trademark or logo of Creative Commons without its prior written 319 | consent including, without limitation, in connection with any unauthorized 320 | modifications to any of its public licenses or any other arrangements, understandings, 321 | or agreements concerning use of licensed material. For the avoidance of doubt, 322 | this paragraph does not form part of the public licenses. 323 | 324 | Creative Commons may be contacted at creativecommons.org. 325 | -------------------------------------------------------------------------------- /adafruit_ads1x15/ads1x15.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ads1x15` 7 | ==================================================== 8 | 9 | CircuitPython base class driver for ADS1015/1115 ADCs. 10 | 11 | * Author(s): Carter Nelson 12 | """ 13 | 14 | __version__ = "0.0.0+auto.0" 15 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15.git" 16 | 17 | import time 18 | 19 | from adafruit_bus_device.i2c_device import I2CDevice 20 | from micropython import const 21 | 22 | try: 23 | from typing import Dict, List, Optional 24 | 25 | from busio import I2C 26 | except ImportError: 27 | pass 28 | 29 | _ADS1X15_DEFAULT_ADDRESS = const(0x48) 30 | _ADS1X15_POINTER_CONVERSION = const(0x00) 31 | _ADS1X15_POINTER_CONFIG = const(0x01) 32 | _ADS1X15_POINTER_LO_THRES = const(0x02) 33 | _ADS1X15_POINTER_HI_THRES = const(0x03) 34 | 35 | _ADS1X15_CONFIG_OS_SINGLE = const(0x8000) 36 | _ADS1X15_CONFIG_MUX_OFFSET = const(12) 37 | _ADS1X15_CONFIG_COMP_QUEUE = { 38 | 0: 0x0003, 39 | 1: 0x0000, 40 | 2: 0x0001, 41 | 4: 0x0002, 42 | } 43 | _ADS1X15_CONFIG_GAIN = { 44 | 2 / 3: 0x0000, 45 | 1: 0x0200, 46 | 2: 0x0400, 47 | 4: 0x0600, 48 | 8: 0x0800, 49 | 16: 0x0A00, 50 | } 51 | 52 | 53 | class Pin: 54 | """An enum-like class representing possible ADC pins.""" 55 | 56 | A0 = 0 57 | """Analog Pin 0""" 58 | A1 = 1 59 | """Analog Pin 1""" 60 | A2 = 2 61 | """Analog Pin 2""" 62 | A3 = 3 63 | """Analog Pin 3""" 64 | 65 | 66 | class Mode: 67 | """An enum-like class representing possible ADC operating modes.""" 68 | 69 | # See datasheet "Operating Modes" section 70 | # values here are masks for setting MODE bit in Config Register 71 | CONTINUOUS = 0x0000 72 | """Continuous Mode""" 73 | SINGLE = 0x0100 74 | """Single-Shot Mode""" 75 | 76 | 77 | class Comp_Mode: 78 | """An enum-like class representing possible ADC Comparator operating modes.""" 79 | 80 | # See datasheet "Operating Modes" section 81 | # values here are masks for setting COMP_MODE bit in Config Register 82 | TRADITIONAL = 0x0000 83 | """Traditional Compartor Mode activates above high threshold, de-activates below low""" 84 | WINDOW = 0x0010 85 | """Window Comparator Mode activates when reading is outside of high and low thresholds""" 86 | 87 | 88 | class Comp_Polarity: 89 | """An enum-like class representing possible ADC Comparator polarity modes.""" 90 | 91 | # See datasheet "Operating Modes" section 92 | # values here are masks for setting COMP_POL bit in Config Register 93 | ACTIVE_LOW = 0x0000 94 | """ALERT_RDY pin is LOW when comparator is active""" 95 | ACTIVE_HIGH = 0x0008 96 | """ALERT_RDY pin is HIGH when comparator is active""" 97 | 98 | 99 | class Comp_Latch: 100 | """An enum-like class representing possible ADC Comparator latching modes.""" 101 | 102 | # See datasheet "Operating Modes" section 103 | # values here are masks for setting COMP_LAT bit in Config Register 104 | NONLATCHING = 0x0000 105 | """ALERT_RDY pin does not latch when asserted""" 106 | LATCHING = 0x0004 107 | """ALERT_RDY pin remains asserted until data is read by controller""" 108 | 109 | 110 | class ADS1x15: 111 | """Base functionality for ADS1x15 analog to digital converters. 112 | 113 | :param ~busio.I2C i2c: The I2C bus the device is connected to. 114 | :param float gain: The ADC gain. 115 | :param int data_rate: The data rate for ADC conversion in samples per second. 116 | Default value depends on the device. 117 | :param Mode mode: The conversion mode, defaults to `Mode.SINGLE`. 118 | :param int comparator_queue_length: The number of successive conversions exceeding 119 | the comparator threshold before asserting ALERT/RDY pin. 120 | Defaults to 0 (comparator function disabled). 121 | :param int comparator_low_threshold: Voltage limit under which comparator de-asserts 122 | ALERT/RDY pin. Must be lower than high threshold to use comparator 123 | function. Range of -32768 to 32767, default -32768 124 | :param int comparator_high_threshold: Voltage limit over which comparator asserts 125 | ALERT/RDY pin. Must be higher than low threshold to use comparator 126 | function. Range of -32768 to 32767, default 32767 127 | :param Comp_Mode comparator_mode: Configures the comparator as either traditional or window. 128 | Defaults to 'Comp_Mode.TRADITIONAL' 129 | :param Comp_Polarity comparator_polarity: Configures the comparator output as either active 130 | low or active high. Defaults to 'Comp_Polarity.ACTIVE_LOW' 131 | :param Comp_Latch comparator_latch: Configures the comparator output to only stay asserted while 132 | readings exceed threshold or latch on assertion until data is read. 133 | Defaults to 'Comp_Latch.NONLATCHING' 134 | :param int address: The I2C address of the device. 135 | """ 136 | 137 | def __init__( 138 | self, 139 | i2c: "I2C", 140 | gain: float = 1, 141 | data_rate: Optional[int] = None, 142 | mode: int = Mode.SINGLE, 143 | comparator_queue_length: int = 0, 144 | comparator_low_threshold: int = -32768, 145 | comparator_high_threshold: int = 32767, 146 | comparator_mode: int = Comp_Mode.TRADITIONAL, 147 | comparator_polarity: int = Comp_Polarity.ACTIVE_LOW, 148 | comparator_latch: int = Comp_Latch.NONLATCHING, 149 | address: int = _ADS1X15_DEFAULT_ADDRESS, 150 | ): 151 | self._last_pin_read = None 152 | self.buf = bytearray(3) 153 | self.initialized = False # Prevents writing to ADC until all values are initialized 154 | self.i2c_device = I2CDevice(i2c, address) 155 | self.gain = gain 156 | self.data_rate = self._data_rate_default() if data_rate is None else data_rate 157 | self.mode = mode 158 | self.comparator_queue_length = comparator_queue_length 159 | self.comparator_low_threshold = comparator_low_threshold 160 | self.comparator_high_threshold = comparator_high_threshold 161 | self.comparator_mode = comparator_mode 162 | self.comparator_polarity = comparator_polarity 163 | self.comparator_latch = comparator_latch 164 | self.initialized = True 165 | self._write_config() 166 | 167 | @property 168 | def bits(self) -> int: 169 | """The ADC bit resolution.""" 170 | raise NotImplementedError("Subclass must implement bits property.") 171 | 172 | @property 173 | def data_rate(self) -> int: 174 | """The data rate for ADC conversion in samples per second.""" 175 | return self._data_rate 176 | 177 | @data_rate.setter 178 | def data_rate(self, rate: int) -> None: 179 | possible_rates = self.rates 180 | if rate not in possible_rates: 181 | raise ValueError(f"Data rate must be one of: {possible_rates}") 182 | self._data_rate = rate 183 | if self.initialized: 184 | self._write_config() 185 | 186 | @property 187 | def rates(self) -> List[int]: 188 | """Possible data rate settings.""" 189 | raise NotImplementedError("Subclass must implement rates property.") 190 | 191 | @property 192 | def rate_config(self) -> Dict[int, int]: 193 | """Rate configuration masks.""" 194 | raise NotImplementedError("Subclass must implement rate_config property.") 195 | 196 | @property 197 | def gain(self) -> float: 198 | """The ADC gain.""" 199 | return self._gain 200 | 201 | @gain.setter 202 | def gain(self, gain: float) -> None: 203 | possible_gains = self.gains 204 | if gain not in possible_gains: 205 | raise ValueError(f"Gain must be one of: {possible_gains}") 206 | self._gain = gain 207 | if self.initialized: 208 | self._write_config() 209 | 210 | @property 211 | def gains(self) -> List[float]: 212 | """Possible gain settings.""" 213 | g = list(_ADS1X15_CONFIG_GAIN.keys()) 214 | g.sort() 215 | return g 216 | 217 | @property 218 | def comparator_queue_length(self) -> int: 219 | """The ADC comparator queue length.""" 220 | return self._comparator_queue_length 221 | 222 | @comparator_queue_length.setter 223 | def comparator_queue_length(self, comparator_queue_length: int) -> None: 224 | possible_comp_queue_lengths = self.comparator_queue_lengths 225 | if comparator_queue_length not in possible_comp_queue_lengths: 226 | raise ValueError(f"Comparator Queue must be one of: {possible_comp_queue_lengths}") 227 | self._comparator_queue_length = comparator_queue_length 228 | if self.initialized: 229 | self._write_config() 230 | 231 | @property 232 | def comparator_queue_lengths(self) -> List[int]: 233 | """Possible comparator queue length settings.""" 234 | g = list(_ADS1X15_CONFIG_COMP_QUEUE.keys()) 235 | g.sort() 236 | return g 237 | 238 | @property 239 | def comparator_low_threshold(self) -> int: 240 | """The ADC Comparator Lower Limit Threshold.""" 241 | return self._comparator_low_threshold 242 | 243 | @property 244 | def comparator_high_threshold(self) -> int: 245 | """The ADC Comparator Higher Limit Threshold.""" 246 | return self._comparator_high_threshold 247 | 248 | @comparator_low_threshold.setter 249 | def comparator_low_threshold(self, value: int) -> None: 250 | """Set comparator low threshold value for ADS1x15 ADC 251 | 252 | :param int value: 16-bit signed integer to write to register 253 | """ 254 | if value < -32768 or value > 32767: 255 | raise ValueError("Comparator Threshold value must be between -32768 and 32767") 256 | 257 | self._comparator_low_threshold = value 258 | self._write_register(_ADS1X15_POINTER_LO_THRES, self.comparator_low_threshold) 259 | 260 | @comparator_high_threshold.setter 261 | def comparator_high_threshold(self, value: int) -> None: 262 | """Set comparator high threshold value for ADS1x15 ADC 263 | 264 | :param int value: 16-bit signed integer to write to register 265 | """ 266 | if value < -32768 or value > 32767: 267 | raise ValueError("Comparator Threshold value must be between -32768 and 32767") 268 | 269 | self._comparator_high_threshold = value 270 | self._write_register(_ADS1X15_POINTER_HI_THRES, self.comparator_high_threshold) 271 | 272 | @property 273 | def mode(self) -> int: 274 | """The ADC conversion mode.""" 275 | return self._mode 276 | 277 | @mode.setter 278 | def mode(self, mode: int) -> None: 279 | if mode not in {Mode.CONTINUOUS, Mode.SINGLE}: 280 | raise ValueError("Unsupported mode.") 281 | self._mode = mode 282 | if self.initialized: 283 | self._write_config() 284 | 285 | @property 286 | def comparator_mode(self) -> int: 287 | """The ADC comparator mode.""" 288 | return self._comparator_mode 289 | 290 | @comparator_mode.setter 291 | def comparator_mode(self, comp_mode: int) -> None: 292 | if comp_mode not in {Comp_Mode.TRADITIONAL, Comp_Mode.WINDOW}: 293 | raise ValueError("Unsupported mode.") 294 | self._comparator_mode = comp_mode 295 | if self.initialized: 296 | self._write_config() 297 | 298 | @property 299 | def comparator_polarity(self) -> int: 300 | """The ADC comparator polarity mode.""" 301 | return self._comparator_polarity 302 | 303 | @comparator_polarity.setter 304 | def comparator_polarity(self, comp_pol: int) -> None: 305 | if comp_pol not in {Comp_Polarity.ACTIVE_LOW, Comp_Polarity.ACTIVE_HIGH}: 306 | raise ValueError("Unsupported mode.") 307 | self._comparator_polarity = comp_pol 308 | if self.initialized: 309 | self._write_config() 310 | 311 | @property 312 | def comparator_latch(self) -> int: 313 | """The ADC comparator latching mode.""" 314 | return self._comparator_latch 315 | 316 | @comparator_latch.setter 317 | def comparator_latch(self, comp_latch: int) -> None: 318 | if comp_latch not in {Comp_Latch.NONLATCHING, Comp_Latch.LATCHING}: 319 | raise ValueError("Unsupported mode.") 320 | self._comparator_latch = comp_latch 321 | if self.initialized: 322 | self._write_config() 323 | 324 | def read(self, pin: int) -> int: 325 | """I2C Interface for ADS1x15-based ADCs reads. 326 | 327 | :param int pin: individual or differential pin. 328 | :param bool is_differential: single-ended or differential read. 329 | """ 330 | return self._read(pin) 331 | 332 | def _data_rate_default(self) -> int: 333 | """Retrieve the default data rate for this ADC (in samples per second). 334 | Should be implemented by subclasses. 335 | """ 336 | raise NotImplementedError("Subclasses must implement _data_rate_default!") 337 | 338 | def _conversion_value(self, raw_adc: int) -> int: 339 | """Subclasses should override this function that takes the 16 raw ADC 340 | values of a conversion result and returns a signed integer value. 341 | """ 342 | raise NotImplementedError("Subclass must implement _conversion_value function!") 343 | 344 | def _read(self, pin: int) -> int: 345 | """Perform an ADC read. Returns the signed integer result of the read.""" 346 | # Immediately return conversion register result if in CONTINUOUS mode 347 | # and pin has not changed 348 | if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin: 349 | return self._conversion_value(self.get_last_result(True)) 350 | 351 | # Assign last pin read if in SINGLE mode or first sample in CONTINUOUS mode on this pin 352 | self._last_pin_read = pin 353 | 354 | # Configure ADC every time before a conversion in SINGLE mode 355 | # or changing channels in CONTINUOUS mode 356 | self._write_config(pin) 357 | 358 | # Wait for conversion to complete 359 | # ADS1x1x devices settle within a single conversion cycle 360 | if self.mode == Mode.SINGLE: 361 | # Continuously poll conversion complete status bit 362 | while not self._conversion_complete(): 363 | pass 364 | else: 365 | # Can't poll registers in CONTINUOUS mode 366 | # Wait expected time for two conversions to complete 367 | time.sleep(2 / self.data_rate) 368 | 369 | return self._conversion_value(self.get_last_result(False)) 370 | 371 | def _conversion_complete(self) -> int: 372 | """Return status of ADC conversion.""" 373 | # OS is bit 15 374 | # OS = 0: Device is currently performing a conversion 375 | # OS = 1: Device is not currently performing a conversion 376 | return self._read_register(_ADS1X15_POINTER_CONFIG) & 0x8000 377 | 378 | def get_last_result(self, fast: bool = False) -> int: 379 | """Read the last conversion result when in continuous conversion mode. 380 | Will return a signed integer value. If fast is True, the register 381 | pointer is not updated as part of the read. This reduces I2C traffic 382 | and increases possible read rate. 383 | """ 384 | return self._read_register(_ADS1X15_POINTER_CONVERSION, fast) 385 | 386 | def _write_register(self, reg: int, value: int): 387 | """Write 16 bit value to register.""" 388 | self.buf[0] = reg 389 | self.buf[1] = (value >> 8) & 0xFF 390 | self.buf[2] = value & 0xFF 391 | with self.i2c_device as i2c: 392 | i2c.write(self.buf) 393 | 394 | def _read_register(self, reg: int, fast: bool = False) -> int: 395 | """Read 16 bit register value. If fast is True, the pointer register 396 | is not updated. 397 | """ 398 | with self.i2c_device as i2c: 399 | if fast: 400 | i2c.readinto(self.buf, end=2) 401 | else: 402 | i2c.write_then_readinto(bytearray([reg]), self.buf, in_end=2) 403 | return self.buf[0] << 8 | self.buf[1] 404 | 405 | def _write_config(self, pin_config: Optional[int] = None) -> None: 406 | """Write to configuration register of ADC 407 | 408 | :param int pin_config: setting for MUX value in config register 409 | """ 410 | if pin_config is None: 411 | pin_config = ( 412 | self._read_register(_ADS1X15_POINTER_CONFIG) & 0x7000 413 | ) >> _ADS1X15_CONFIG_MUX_OFFSET 414 | 415 | if self.mode == Mode.SINGLE: 416 | config = _ADS1X15_CONFIG_OS_SINGLE 417 | else: 418 | config = 0 419 | 420 | config |= (pin_config & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET 421 | config |= _ADS1X15_CONFIG_GAIN[self.gain] 422 | config |= self.mode 423 | config |= self.rate_config[self.data_rate] 424 | config |= self.comparator_mode 425 | config |= self.comparator_polarity 426 | config |= self.comparator_latch 427 | config |= _ADS1X15_CONFIG_COMP_QUEUE[self.comparator_queue_length] 428 | self._write_register(_ADS1X15_POINTER_CONFIG, config) 429 | 430 | def _read_config(self) -> None: 431 | """Reads Config Register and sets all properties accordingly""" 432 | config_value = self._read_register(_ADS1X15_POINTER_CONFIG) 433 | 434 | self.gain = next( 435 | key for key, value in _ADS1X15_CONFIG_GAIN.items() if value == (config_value & 0x0E00) 436 | ) 437 | self.data_rate = next( 438 | key for key, value in self.rate_config.items() if value == (config_value & 0x00E0) 439 | ) 440 | self.comparator_queue_length = next( 441 | key 442 | for key, value in _ADS1X15_CONFIG_COMP_QUEUE.items() 443 | if value == (config_value & 0x0003) 444 | ) 445 | self.mode = Mode.SINGLE if config_value & 0x0100 else Mode.CONTINUOUS 446 | self.comparator_mode = Comp_Mode.WINDOW if config_value & 0x0010 else Comp_Mode.TRADITIONAL 447 | self.comparator_polarity = ( 448 | Comp_Polarity.ACTIVE_HIGH if config_value & 0x0008 else Comp_Polarity.ACTIVE_LOW 449 | ) 450 | self.comparator_latch = ( 451 | Comp_Latch.LATCHING if config_value & 0x0004 else Comp_Latch.NONLATCHING 452 | ) 453 | --------------------------------------------------------------------------------