From 8491940d7c16b5e23ec519db24c593511ae7581b Mon Sep 17 00:00:00 2001 From: Markus Kasten Date: Mon, 26 Oct 2020 16:17:06 +0000 Subject: [PATCH] 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. --- adafruit_tlv493d.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 9d9dffb..c9b582c 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -59,6 +59,7 @@ class TLV493D: :param busio.I2C i2c_bus: The I2C bus the TLV493D is connected to. :param int address: The I2C address of the TLV493D. Defaults to 0x5E. + :param int addr_reg: Initial value of the I2C address register. Defaults to 0. """ @@ -93,7 +94,7 @@ class TLV493D: "RES3": (3, 0x1F, 0), } - def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS): + def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS, addr_reg=0): self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address) self.read_buffer = bytearray(10) self.write_buffer = bytearray(4) @@ -101,6 +102,9 @@ def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS): # read in data from sensor, including data that must be set on a write self._setup_write_buffer() + # write correct i2c address + self._set_write_key("ADDR", addr_reg) + # setup MASTERCONTROLLEDMODE which takes a measurement for every read self._set_write_key("PARITY", 1) self._set_write_key("PARITY", 1)