/ README.rst
README.rst
1 2 Introduction 3 ============ 4 5 .. image:: https://readthedocs.org/projects/adafruit-circuitpython-sht31d/badge/?version=latest 6 :target: https://circuitpython.readthedocs.io/projects/sht31d/en/latest/ 7 :alt: Documentation Status 8 9 .. image :: https://img.shields.io/discord/327254708534116352.svg 10 :target: https://adafru.it/discord 11 :alt: Discord 12 13 .. image:: https://github.com/adafruit/Adafruit_CircuitPython_SHT31D/workflows/Build%20CI/badge.svg 14 :target: https://github.com/adafruit/Adafruit_CircuitPython_SHT31D/actions/ 15 :alt: Build Status 16 17 CircuitPython module for the SHT31-D temperature and humidity sensor. 18 19 Dependencies 20 ============= 21 This driver depends on: 22 23 * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ 24 * `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_ 25 26 27 Please ensure all dependencies are available on the CircuitPython filesystem. 28 This is easily achieved by downloading 29 `the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_. 30 31 Installing from PyPI 32 ==================== 33 34 On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 35 PyPI <https://pypi.org/project/adafruit-circuitpython-sht31d/>`_. To install for current user: 36 37 .. code-block:: shell 38 39 pip3 install adafruit-circuitpython-sht31d 40 41 To install system-wide (this may be required in some cases): 42 43 .. code-block:: shell 44 45 sudo pip3 install adafruit-circuitpython-sht31d 46 47 To install in a virtual environment in your current project: 48 49 .. code-block:: shell 50 51 mkdir project-name && cd project-name 52 python3 -m venv .env 53 source .env/bin/activate 54 pip3 install adafruit-circuitpython-sht31d 55 56 Usage Example 57 ============= 58 You must import the library to use it: 59 60 .. code:: python 61 62 import adafruit_sht31d 63 64 This driver takes an instantiated and active I2C object (from the `busio` or 65 the `bitbangio` library) as an argument to its constructor. The way to create 66 an I2C object depends on the board you are using. For boards with labeled SCL 67 and SDA pins, you can: 68 69 .. code:: python 70 71 from busio import I2C 72 from board import SCL, SDA 73 74 i2c = I2C(SCL, SDA) 75 76 Once you have created the I2C interface object, you can use it to instantiate 77 the sensor object: 78 79 .. code:: python 80 81 sensor = adafruit_sht31d.SHT31D(i2c) 82 83 84 And then you can start measuring the temperature and humidity: 85 86 .. code:: python 87 88 print(sensor.temperature) 89 print(sensor.relative_humidity) 90 91 You can instruct the sensor to periodically measure the temperature and 92 humidity, storing the result in its internal cache: 93 94 .. code:: python 95 96 sensor.mode = adafruit_sht31d.MODE_PERIODIC 97 98 You can adjust the frequency at which the sensor periodically gathers data to: 99 0.5, 1, 2, 4 or 10 Hz. The following adjusts the frequency to 2 Hz: 100 101 .. code:: python 102 103 sensor.frequency = adafruit_sht31d.FREQUENCY_2 104 105 The sensor is capable of storing eight results. The sensor stores these 106 results in an internal FILO cache. Retrieving these results is simlilar to 107 taking a measurement. The sensor clears its cache once the stored data is read. 108 The sensor always returns eight data points. The list of results is backfilled 109 with the maximum output values of 130.0 ÂșC and 100.01831417975366 % RH: 110 111 .. code:: python 112 113 print(sensor.temperature) 114 print(sensor.relative_humidity) 115 116 The sensor will continue to collect data at the set interval until it is 117 returned to single shot data acquisition mode: 118 119 .. code:: python 120 121 sensor.mode = adafruit_sht31d.MODE_SINGLE 122 123 Contributing 124 ============ 125 126 Contributions are welcome! Please read our `Code of Conduct 127 <https://github.com/adafruit/Adafruit_CircuitPython_SHT31D/blob/master/CODE_OF_CONDUCT.md>`_ 128 before contributing to help this project stay welcoming. 129 130 Documentation 131 ============= 132 133 For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.