21
21
# https://github.com/adafruit/Adafruit_VEML6070
22
22
23
23
"""
24
- `adafruit_veml6070` - VEML6070 UV Sensor
24
+ `adafruit_veml6070`
25
25
====================================================
26
26
27
27
CircuitPython library to support VEML6070 UV Index sensor.
38
38
39
39
**Software and Dependencies:**
40
40
41
- * Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
42
- https://github.com/adafruit/circuitpython/releases
43
- * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
41
+ * Adafruit CircuitPython firmware for the supported boards:
42
+ https://circuitpython.org/downloads
43
+
44
+ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
44
45
45
46
**Notes:**
46
47
@@ -84,34 +85,44 @@ class VEML6070:
84
85
"""
85
86
Driver base for the VEML6070 UV Light Sensor
86
87
87
- :param i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
88
- :param str _veml6070_it: The integration time you'd like to set initially. Availble
89
- options: ``VEML6070_HALF_T``, ``VEML6070_1_T``, ``VEML6070_2_T``, and
90
- ``VEML6070_4_T``. The higher the '_x_' value, the more accurate
88
+ :param ~busio.I2C i2c_bus: The I2C bus the device is connected to
89
+ :param str _veml6070_it: The integration time you'd like to set initially. Available
90
+ options: :const:`VEML6070_HALF_T`, :const:`VEML6070_1_T`,
91
+ :const:`VEML6070_2_T`, and
92
+ :const:`VEML6070_4_T`. The higher the '_x_' value, the more accurate
91
93
the reading is (at the cost of less samples per reading).
92
- Defaults to ``VEML6070_1_T`` if parameter not passed. To change
93
- setting after intialization, use
94
- ``[veml6070].set_integration_time(new_it)``.
95
- :param bool ack: The inital setting of ``ACKnowledge`` on alert. Defaults to ``False``
96
- if parameter not passed. To change setting after intialization,
97
- use ``[veml6070].set_ack(new_ack)``.
94
+ Defaults to :const:`VEML6070_1_T` if parameter not passed. To change
95
+ setting after initialization,
96
+ ``VEML6070.set_integration_time(new_it)``.
97
+ :param bool ack: The initial setting of ``ACKnowledge`` on alert. Defaults to `False`
98
+ if parameter not passed. To change setting after initialization,
99
+ use ``VEML6070.set_ack(new_ack)``.
100
+
101
+
102
+ **Quickstart: Importing and using the device VEML6070**
103
+
104
+ Here is an example of using the :class:`VEML6070` class.
105
+ First you will need to import the libraries to use the sensor
106
+
107
+ .. code-block:: python
98
108
99
- Example:
109
+ import board
110
+ import adafruit_veml6070
100
111
101
- .. code-block:: python
112
+ Once this is done you can define your `board.I2C` object and define your sensor object
102
113
103
- from board import *
104
- import busio, veml6070, time
114
+ .. code-block:: python
105
115
106
- with busio.I2C(SCL, SDA) as i2c:
107
- uv = veml6070.VEML6070(i2c, 'VEML6070_1_T', True)
116
+ i2c = board.I2C() # uses board.SCL and board.SDA
117
+ uv = adafruit_veml6070.VEML6070(i2c)
118
+
119
+ Now you have access to the :attr:`uv_raw` attribute and the calculate the risk level
120
+
121
+ .. code-block:: python
122
+
123
+ uv_raw = uv.uv_raw
124
+ risk_level = uv.get_index(uv_raw)
108
125
109
- # take 10 readings
110
- for j in range(10):
111
- uv_raw = uv.uv_raw
112
- risk_level = uv.get_index(uv_raw)
113
- print('Reading: ', uv_raw, ' | Risk Level: ', risk_level)
114
- time.sleep(1)
115
126
"""
116
127
117
128
def __init__ (self , i2c_bus , _veml6070_it = "VEML6070_1_T" , ack = False ):
@@ -191,8 +202,8 @@ def ack(self, new_ack):
191
202
def ack_threshold (self ):
192
203
"""
193
204
The ACKnowledge Threshold, which alerts the host controller to value changes
194
- greater than the threshold. Available settings are: ``0`` = 102 steps; ``1`` = 145 steps.
195
- ``0` ` is the default setting.
205
+ greater than the threshold. Available settings are: :const:`0` = 102 steps;
206
+ :const:`1` = 145 steps. :const:`0 ` is the default setting.
196
207
"""
197
208
return self ._ack_thd
198
209
@@ -215,8 +226,8 @@ def integration_time(self):
215
226
"""
216
227
The Integration Time of the sensor, which is the refresh interval of the
217
228
sensor. The higher the refresh interval, the more accurate the reading is (at
218
- the cost of less sampling). The available settings are: `` VEML6070_HALF_T` `,
219
- `` VEML6070_1_T``, `` VEML6070_2_T``, `` VEML6070_4_T` `.
229
+ the cost of less sampling). The available settings are: :const:` VEML6070_HALF_T`,
230
+ :const:` VEML6070_1_T`, :const:` VEML6070_2_T`, :const:` VEML6070_4_T`.
220
231
"""
221
232
return self ._it
222
233
@@ -249,7 +260,7 @@ def sleep(self):
249
260
250
261
def wake (self ):
251
262
"""
252
- Wakes the VEML6070 from sleep. ``[veml6070] .uv_raw` ` will also wake from sleep.
263
+ Wakes the VEML6070 from sleep. :class:`VEML6070 .uv_raw` will also wake from sleep.
253
264
"""
254
265
self .buf [0 ] = (
255
266
self ._ack << 5
@@ -262,17 +273,20 @@ def wake(self):
262
273
263
274
def get_index (self , _raw ):
264
275
"""
265
- Calculates the UV Risk Level based on the captured UV reading. Requres the ``_raw``
266
- argument (from `` veml6070.uv_raw` `). Risk level is available for Integration Times (IT)
276
+ Calculates the UV Risk Level based on the captured UV reading. Requires the ``_raw``
277
+ argument (from :meth:` veml6070.uv_raw`). Risk level is available for Integration Times (IT)
267
278
1, 2, & 4. The result is automatically scaled to the current IT setting.
268
279
269
- LEVEL* UV Index
270
- ===== ========
280
+ ========= ========
281
+ LEVEL* UV Index
282
+ ========= ========
271
283
LOW 0-2
272
284
MODERATE 3-5
273
285
HIGH 6-7
274
286
VERY HIGH 8-10
275
287
EXTREME >=11
288
+ ========= ========
289
+
276
290
277
291
* Not to be considered as accurate condition reporting.
278
292
Calculation is based on VEML6070 Application Notes:
0 commit comments