From 8cbfe48e0f0ceb8e793c3f4c3bc29369d7b5c537 Mon Sep 17 00:00:00 2001 From: siddacious Date: Fri, 21 Feb 2020 13:07:23 -0800 Subject: [PATCH] fetching calibration consts --- README.rst | 19 ++-- adafruit_hts221.py | 157 ++++++++++------------------------ docs/conf.py | 123 +++++++++++++++----------- docs/index.rst | 5 +- examples/hts221_simpletest.py | 5 +- setup.py | 56 ++++++------ 6 files changed, 161 insertions(+), 204 deletions(-) diff --git a/README.rst b/README.rst index 2519b58..8c96612 100644 --- a/README.rst +++ b/README.rst @@ -30,11 +30,6 @@ This is easily achieved by downloading Installing from PyPI ===================== -.. note:: This library is not available on PyPI yet. Install documentation is included - as a standard element. Stay tuned for PyPI availability! - -.. todo:: Remove the above note if PyPI version is/will be available at time of release. - If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section. On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from PyPI `_. To install for current user: @@ -61,7 +56,19 @@ To install in a virtual environment in your current project: Usage Example ============= -.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst. +.. code-block:: python3 + + import time + import board + import busio + import adafruit_hts221 + + i2c = busio.I2C(board.SCL, board.SDA) + hts = adafruit_hts221.HTS221(i2c) + while True: + print("Humidity: %.2f percent rH" % hts.humidity) + print("Temperature: %.2f C" % hts.temperature) + time.sleep(1) Contributing ============ diff --git a/adafruit_hts221.py b/adafruit_hts221.py index aa8447f..c18df79 100644 --- a/adafruit_hts221.py +++ b/adafruit_hts221.py @@ -37,7 +37,7 @@ Implementation Notes **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: - https://circuitpythohn.org/downloads + https://circuitpython.org/downloads * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register @@ -55,27 +55,24 @@ _WHO_AM_I = const(0x0F) _CTRL_REG1 = const(0x20) _CTRL_REG2 = const(0x21) -_CTRL_REG3 = const(0x22) #Third control regsiter; DRDY_H_L, DRDY +_CTRL_REG3 = const(0x22) -_HUMIDITY_OUT_L = const(0x28 | 0x80) #Humidity output register (LSByte) -_TEMP_OUT_L = const(0x2A | 0x80) #Temperature output register (LSByte) +# some addresses are anded to set the top bit so that multi-byte reads will work +_HUMIDITY_OUT_L = const(0x28 | 0x80) # Humidity output register (LSByte) +_TEMP_OUT_L = const(0x2A | 0x80) # Temperature output register (LSByte) -_H0_RH_X2 = const(0x30) #Humididy calibration LSB values -_H1_RH_X2 = const(0x31) #Humididy calibration LSB values +_H0_RH_X2 = const(0x30) # Humididy calibration LSB values +_H1_RH_X2 = const(0x31) # Humididy calibration LSB values -_T0_DEGC_X8 = const(0x32) #First byte of T0, T1 calibration values -_T1_DEGC_X8 = const(0x33) #First byte of T0, T1 calibration values -_T1_T0_MSB = const(0x35) #Top 2 bits of T0 and T1 (each are 10 bits) +_T0_DEGC_X8 = const(0x32) # First byte of T0, T1 calibration values +_T1_DEGC_X8 = const(0x33) # First byte of T0, T1 calibration values +_T1_T0_MSB = const(0x35) # Top 2 bits of T0 and T1 (each are 10 bits) -_H0_T0_OUT = const(0x36|0x80) #Humididy calibration Time 0 value -_H1_T1_OUT = const(0x3A|0x80) #Humididy calibration Time 1 value +_H0_T0_OUT = const(0x36 | 0x80) # Humididy calibration Time 0 value +_H1_T1_OUT = const(0x3A | 0x80) # Humididy calibration Time 1 value -_T0_OUT = const(0x3C|0x80) #T0_OUT LSByte -_T1_OUT = const(0x3E|0x80) #T1_OUT LSByte - - -# _PRESS_OUT_XL = const(0x28 | 0x80) # | 0x80 to set auto increment on multi-byte read -# _TEMP_OUT_L = const(0x2B | 0x80) # | 0x80 to set auto increment on multi-byte read +_T0_OUT = const(0x3C | 0x80) # T0_OUT LSByte +_T1_OUT = const(0x3E | 0x80) # T1_OUT LSByte _HTS221_CHIP_ID = 0xBC _HTS221_DEFAULT_ADDRESS = 0x5F @@ -132,8 +129,8 @@ Rate.add_values( ) ) -def bp(val): - return format(val, "#010b") +# def bp(val): +# return format(val, "#010b") class HTS221: # pylint: disable=too-many-instance-attributes """Library for the ST LPS2x family of humidity sensors @@ -152,7 +149,6 @@ class HTS221: # pylint: disable=too-many-instance-attributes _raw_temperature = ROUnaryStruct(_TEMP_OUT_L, ">= 3 #// divide by 8 (as documented) - # self._T1 |= buffer[1] - # self._T1 >>= 3 - + self.t0_deg_c = self._t0_deg_c_x8_lsbyte + self.t0_deg_c |= (t1_t0_msbs & 0b0011) << 8 + self.t1_deg_c = self._t1_deg_c_x8_lsbyte + self.t1_deg_c |= (t1_t0_msbs & 0b1100) << 6 + self.t0_out = self._t0_out + self.t1_out = self._t1_out + self.h0_rh = self._h0_rh_x2 + self.h1_rh = self._h1_rh_x2 + self.h0_out = self._h0_t0_out + self.h1_out = self._h1_t0_out def _correct_humidity(self): - pass - # hum = ((int16_t)(H1) - (int16_t)(H0)) / 2.0; // remove x2 multiple + pass - # // Calculate humidity in decimal of grade centigrades i.e. 15.0 = 150. - # h_temp = (float)(((int16_t)raw_humidity - (int16_t)H0_T0_OUT) * hum) / - # (float)((int16_t)H1_T0_OUT - (int16_t)H0_T0_OUT); - # hum = (float)((int16_t)H0) / 2.0; // remove x2 multiple - # corrected_humidity = (hum + h_temp); // provide signed % measurement unit + # hum = ((int16_t)(H1) - (int16_t)(H0)) / 2.0; // remove x2 multiple + + # // Calculate humidity in decimal of grade centigrades i.e. 15.0 = 150. + # h_temp = (float)(((int16_t)raw_humidity - (int16_t)H0_T0_OUT) * hum) / + # (float)((int16_t)H1_T0_OUT - (int16_t)H0_T0_OUT); + # hum = (float)((int16_t)H0) / 2.0; // remove x2 multiple + # corrected_humidity = (hum + h_temp); // provide signed % measurement unit def _correct_temp(self): - pass - # corrected_temp = - # (float) - # // measured temp(LSB) - offset(LSB) * (calibration measurement delta) - # (float)((int16_t)raw_temperature - (int16_t)T0_OUT) * - # (float)((int16_t)T1 - (int16_t)T0) / // divided by.. - # // Calibration LSB delta + Calibration offset? - # (float)((int16_t)T1_OUT - (int16_t)T0_OUT) + - # (int16_t)T0; + pass + + # corrected_temp = + # (float) + # // measured temp(LSB) - offset(LSB) * (calibration measurement delta) + # (float)((int16_t)raw_temperature - (int16_t)T0_OUT) * + # (float)((int16_t)T1 - (int16_t)T0) / // divided by.. + # // Calibration LSB delta + Calibration offset? + # (float)((int16_t)T1_OUT - (int16_t)T0_OUT) + + # (int16_t)T0; def boot(self): """Reset the sensor, restoring all configuration registers to their defaults""" self._boot = True @@ -306,4 +243,4 @@ class HTS221: # pylint: disable=too-many-instance-attributes if not Rate.is_valid(value): raise AttributeError("data_rate must be a `Rate`") - self._data_rate = value \ No newline at end of file + self._data_rate = value diff --git a/docs/conf.py b/docs/conf.py index c04624e..41d7b99 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,42 +11,52 @@ sys.path.insert(0, os.path.abspath('..')) # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] -# TODO: Please Read! # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -# autodoc_mock_imports = ["digitalio", "busio"] +autodoc_mock_imports = ["micropython", "adafruit_bus_device", "adafruit_register"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "Register": ( + "https://circuitpython.readthedocs.io/projects/register/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit HTS221 Library' -copyright = u'2020 Bryan Siepert' -author = u'Bryan Siepert' +project = "Adafruit HTS221 Library" +copyright = "2020 Bryan Siepert" +author = "Bryan Siepert" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -57,7 +68,7 @@ language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -69,7 +80,7 @@ default_role = "any" add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -84,59 +95,62 @@ napoleon_numpy_docstring = False # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitHts221Librarydoc' +htmlhelp_basename = "AdafruitHts221Librarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitHTS221Library.tex', u'AdafruitHTS221 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitHTS221Library.tex", + "AdafruitHTS221 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +158,13 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitHTS221library', u'Adafruit HTS221 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitHTS221library", + "Adafruit HTS221 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +173,13 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitHTS221Library', u'Adafruit HTS221 Library Documentation', - author, 'AdafruitHTS221Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitHTS221Library", + "Adafruit HTS221 Library Documentation", + author, + "AdafruitHTS221Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/docs/index.rst b/docs/index.rst index 1366bbb..289f99a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,14 +23,11 @@ Table of Contents .. toctree:: :caption: Tutorials -.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave - the toctree above for use later. .. toctree:: :caption: Related Products -.. todo:: Add any product links here. If there are none, then simply delete this todo and leave - the toctree above for use later. + * `HTS221 Breakout `_ .. toctree:: :caption: Other Links diff --git a/examples/hts221_simpletest.py b/examples/hts221_simpletest.py index ca3ec59..91cbb5e 100644 --- a/examples/hts221_simpletest.py +++ b/examples/hts221_simpletest.py @@ -2,11 +2,10 @@ import time import board import busio import adafruit_hts221 -print("poop") + i2c = busio.I2C(board.SCL, board.SDA) hts = adafruit_hts221.HTS221(i2c) -print("got out of init") while True: print("Humidity: %.2f percent rH" % hts.humidity) print("Temperature: %.2f C" % hts.temperature) - time.sleep(1) \ No newline at end of file + time.sleep(1) diff --git a/setup.py b/setup.py index 0048fb6..cf82c91 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ https://github.com/pypa/sampleproject """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,54 +14,45 @@ from os import path here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-hts221', - + name="adafruit-circuitpython-hts221", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Helper library for the HTS221 Humidity and Temperature Sensor', + setup_requires=["setuptools_scm"], + description="Helper library for the HTS221 Humidity and Temperature Sensor", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_HTS221', - + url="https://github.com/adafruit/Adafruit_CircuitPython_HTS221", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=[ - 'Adafruit-Blinka', - 'adafruit-circuitpython-busdevice', - 'adafruit-circuitpython-register' + "Adafruit-Blinka", + "adafruit-circuitpython-busdevice", + "adafruit-circuitpython-register", ], - # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython hts221 relative humidity temperature ' - 'ST', - + keywords="adafruit blinka circuitpython micropython hts221 relative humidity temperature " + "ST", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=['adafruit_hts221'], + py_modules=["adafruit_hts221"], )