diff --git a/README.rst b/README.rst index 8d7916d..2a4b1c1 100644 --- a/README.rst +++ b/README.rst @@ -55,14 +55,13 @@ To install in a virtual environment in your current project: Usage Example ============= -.. code-block:: python +.. code-block:: python3 import time import board - import busio from adafruit_veml6070 import VEML6070 - with busio.I2C(board.SCL, board.SDA) as i2c: + with board.I2C() as i2c: uv = VEML6070(i2c) # Alternative constructors with parameters #uv = VEML6070(i2c, 'VEML6070_1_T') diff --git a/adafruit_veml6070.py b/adafruit_veml6070.py index 4797b77..4715de2 100644 --- a/adafruit_veml6070.py +++ b/adafruit_veml6070.py @@ -21,7 +21,7 @@ # https://github.com/adafruit/Adafruit_VEML6070 """ -`adafruit_veml6070` - VEML6070 UV Sensor +`adafruit_veml6070` ==================================================== CircuitPython library to support VEML6070 UV Index sensor. @@ -38,9 +38,10 @@ **Software and Dependencies:** -* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards: - https://github.com/adafruit/circuitpython/releases -* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + + * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice **Notes:** @@ -84,34 +85,44 @@ class VEML6070: """ Driver base for the VEML6070 UV Light Sensor - :param i2c_bus: The `busio.I2C` object to use. This is the only required parameter. - :param str _veml6070_it: The integration time you'd like to set initially. Availble - options: ``VEML6070_HALF_T``, ``VEML6070_1_T``, ``VEML6070_2_T``, and - ``VEML6070_4_T``. The higher the '_x_' value, the more accurate + :param ~busio.I2C i2c_bus: The I2C bus the device is connected to + :param str _veml6070_it: The integration time you'd like to set initially. Available + options: :const:`VEML6070_HALF_T`, :const:`VEML6070_1_T`, + :const:`VEML6070_2_T`, and + :const:`VEML6070_4_T`. The higher the '_x_' value, the more accurate the reading is (at the cost of less samples per reading). - Defaults to ``VEML6070_1_T`` if parameter not passed. To change - setting after intialization, use - ``[veml6070].set_integration_time(new_it)``. - :param bool ack: The inital setting of ``ACKnowledge`` on alert. Defaults to ``False`` - if parameter not passed. To change setting after intialization, - use ``[veml6070].set_ack(new_ack)``. + Defaults to :const:`VEML6070_1_T` if parameter not passed. To change + setting after initialization, + ``VEML6070.set_integration_time(new_it)``. + :param bool ack: The initial setting of ``ACKnowledge`` on alert. Defaults to `False` + if parameter not passed. To change setting after initialization, + use ``VEML6070.set_ack(new_ack)``. + + + **Quickstart: Importing and using the device VEML6070** + + Here is an example of using the :class:`VEML6070` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python - Example: + import board + import adafruit_veml6070 - .. code-block:: python + Once this is done you can define your `board.I2C` object and define your sensor object - from board import * - import busio, veml6070, time + .. code-block:: python - with busio.I2C(SCL, SDA) as i2c: - uv = veml6070.VEML6070(i2c, 'VEML6070_1_T', True) + i2c = board.I2C() # uses board.SCL and board.SDA + uv = adafruit_veml6070.VEML6070(i2c) + + Now you have access to the :attr:`uv_raw` attribute and the calculate the risk level + + .. code-block:: python + + uv_raw = uv.uv_raw + risk_level = uv.get_index(uv_raw) - # take 10 readings - for j in range(10): - uv_raw = uv.uv_raw - risk_level = uv.get_index(uv_raw) - print('Reading: ', uv_raw, ' | Risk Level: ', risk_level) - time.sleep(1) """ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False): @@ -191,8 +202,8 @@ def ack(self, new_ack): def ack_threshold(self): """ The ACKnowledge Threshold, which alerts the host controller to value changes - greater than the threshold. Available settings are: ``0`` = 102 steps; ``1`` = 145 steps. - ``0`` is the default setting. + greater than the threshold. Available settings are: :const:`0` = 102 steps; + :const:`1` = 145 steps. :const:`0` is the default setting. """ return self._ack_thd @@ -215,8 +226,8 @@ def integration_time(self): """ The Integration Time of the sensor, which is the refresh interval of the sensor. The higher the refresh interval, the more accurate the reading is (at - the cost of less sampling). The available settings are: ``VEML6070_HALF_T``, - ``VEML6070_1_T``, ``VEML6070_2_T``, ``VEML6070_4_T``. + the cost of less sampling). The available settings are: :const:`VEML6070_HALF_T`, + :const:`VEML6070_1_T`, :const:`VEML6070_2_T`, :const:`VEML6070_4_T`. """ return self._it @@ -249,7 +260,7 @@ def sleep(self): def wake(self): """ - Wakes the VEML6070 from sleep. ``[veml6070].uv_raw`` will also wake from sleep. + Wakes the VEML6070 from sleep. :class:`VEML6070.uv_raw` will also wake from sleep. """ self.buf[0] = ( self._ack << 5 @@ -262,17 +273,20 @@ def wake(self): def get_index(self, _raw): """ - Calculates the UV Risk Level based on the captured UV reading. Requres the ``_raw`` - argument (from ``veml6070.uv_raw``). Risk level is available for Integration Times (IT) + Calculates the UV Risk Level based on the captured UV reading. Requires the ``_raw`` + argument (from :meth:`veml6070.uv_raw`). Risk level is available for Integration Times (IT) 1, 2, & 4. The result is automatically scaled to the current IT setting. - LEVEL* UV Index - ===== ======== + ========= ======== + LEVEL* UV Index + ========= ======== LOW 0-2 MODERATE 3-5 HIGH 6-7 VERY HIGH 8-10 EXTREME >=11 + ========= ======== + * Not to be considered as accurate condition reporting. Calculation is based on VEML6070 Application Notes: diff --git a/docs/index.rst b/docs/index.rst index b517e97..d9060ad 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,8 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit VEML6070 UV Index Sensor Breakout Learning Guide + .. toctree:: :caption: Related Products diff --git a/examples/veml6070_simpletest.py b/examples/veml6070_simpletest.py index 1fef2d3..990ec27 100644 --- a/examples/veml6070_simpletest.py +++ b/examples/veml6070_simpletest.py @@ -4,11 +4,10 @@ # VEML6070 Driver Example Code import time -import busio import board import adafruit_veml6070 -with busio.I2C(board.SCL, board.SDA) as i2c: +with board.I2C() as i2c: uv = adafruit_veml6070.VEML6070(i2c) # Alternative constructors with parameters # uv = adafruit_veml6070.VEML6070(i2c, 'VEML6070_1_T')