Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added address for solder-bridged setting 0x41 #6

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions adafruit_htu31d.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HTU31D.git"

_HTU31D_DEFAULT_ADDR = const(0x40) # HTU31D default I2C Address
_HTU31D_SECONDARY_ADDR = const(0x41) # HTU31D alternate I2C Address
_HTU31D_ADDRESSES = (_HTU31D_DEFAULT_ADDR, _HTU31D_SECONDARY_ADDR)

_HTU31D_READSERIAL = const(0x0A) # Read Out of Serial Register
_HTU31D_SOFTRESET = const(0x1E) # Soft Reset
Expand All @@ -56,6 +58,7 @@ class HTU31D:
A driver for the HTU31D temperature and humidity sensor.

:param ~busio.I2C i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
:param int address: (optional) The I2C address of the device. Defaults to :const:`0x40`

**Quickstart: Importing and using the device**

Expand Down Expand Up @@ -86,8 +89,10 @@ class HTU31D:

"""

def __init__(self, i2c_bus):
self.i2c_device = i2c_device.I2CDevice(i2c_bus, _HTU31D_DEFAULT_ADDR)
def __init__(self, i2c_bus, address=_HTU31D_DEFAULT_ADDR):
if address not in _HTU31D_ADDRESSES:
raise ValueError("Invalid address: 0x%x" % (address))
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
self._conversion_command = _HTU31D_CONVERSION
self._buffer = bytearray(6)
self.reset()
Expand Down