File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 39
39
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HTU31D.git"
40
40
41
41
_HTU31D_DEFAULT_ADDR = const (0x40 ) # HTU31D default I2C Address
42
+ _HTU31D_SECONDARY_ADDR = const (0x41 ) # HTU31D alternate I2C Address
43
+ _HTU31D_ADDRESSES = (_HTU31D_DEFAULT_ADDR , _HTU31D_SECONDARY_ADDR )
42
44
43
45
_HTU31D_READSERIAL = const (0x0A ) # Read Out of Serial Register
44
46
_HTU31D_SOFTRESET = const (0x1E ) # Soft Reset
@@ -56,6 +58,7 @@ class HTU31D:
56
58
A driver for the HTU31D temperature and humidity sensor.
57
59
58
60
:param ~busio.I2C i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
61
+ :param int address: (optional) The I2C address of the device. Defaults to :const:`0x40`
59
62
60
63
**Quickstart: Importing and using the device**
61
64
@@ -86,8 +89,10 @@ class HTU31D:
86
89
87
90
"""
88
91
89
- def __init__ (self , i2c_bus ):
90
- self .i2c_device = i2c_device .I2CDevice (i2c_bus , _HTU31D_DEFAULT_ADDR )
92
+ def __init__ (self , i2c_bus , address = _HTU31D_DEFAULT_ADDR ):
93
+ if address not in _HTU31D_ADDRESSES :
94
+ raise ValueError ("Invalid address: 0x%x" % (address ))
95
+ self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
91
96
self ._conversion_command = _HTU31D_CONVERSION
92
97
self ._buffer = bytearray (6 )
93
98
self .reset ()
You can’t perform that action at this time.
0 commit comments