Skip to content

Commit 8491940

Browse files
committed
Allow setting the I2C address register as kwargs
With this kwarg, multiple sensors can be used on one bus without fiddling with the ADDR/SDA line. Each sensors VCC has to be connected to a GPIO pin. Sensors can then be enabled one by one, setting a new address each time. Up to 4 sensors can be used on one bus this way.
1 parent 1594054 commit 8491940

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

adafruit_tlv493d.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TLV493D:
5959
6060
:param busio.I2C i2c_bus: The I2C bus the TLV493D is connected to.
6161
:param int address: The I2C address of the TLV493D. Defaults to 0x5E.
62+
:param int addr_reg: Initial value of the I2C address register. Defaults to 0.
6263
6364
"""
6465

@@ -93,14 +94,17 @@ class TLV493D:
9394
"RES3": (3, 0x1F, 0),
9495
}
9596

96-
def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS):
97+
def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS, addr_reg=0):
9798
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
9899
self.read_buffer = bytearray(10)
99100
self.write_buffer = bytearray(4)
100101

101102
# read in data from sensor, including data that must be set on a write
102103
self._setup_write_buffer()
103104

105+
# write correct i2c address
106+
self._set_write_key("ADDR", addr_reg)
107+
104108
# setup MASTERCONTROLLEDMODE which takes a measurement for every read
105109
self._set_write_key("PARITY", 1)
106110
self._set_write_key("PARITY", 1)

0 commit comments

Comments
 (0)