Skip to content

Commit 96e278a

Browse files
authored
Merge pull request #6 from gmparis/main
Added address for solder-bridged setting 0x41
2 parents e74a036 + 9d37608 commit 96e278a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

adafruit_htu31d.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HTU31D.git"
4040

4141
_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)
4244

4345
_HTU31D_READSERIAL = const(0x0A) # Read Out of Serial Register
4446
_HTU31D_SOFTRESET = const(0x1E) # Soft Reset
@@ -56,6 +58,7 @@ class HTU31D:
5658
A driver for the HTU31D temperature and humidity sensor.
5759
5860
: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`
5962
6063
**Quickstart: Importing and using the device**
6164
@@ -86,8 +89,10 @@ class HTU31D:
8689
8790
"""
8891

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)
9196
self._conversion_command = _HTU31D_CONVERSION
9297
self._buffer = bytearray(6)
9398
self.reset()

0 commit comments

Comments
 (0)