From ba6b6fe4cd9c5626f70db977f4b8ca09ba71f6b2 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Sun, 4 Sep 2022 16:13:34 -0700 Subject: [PATCH 1/2] Update adafruit_tlv493d.py Fixed units in docstring. Alternatively, multiple the returned values by 1000 in `_unpack_and_scale` to report microteslas (what all the other magnetic sensors from adafruit report) --- adafruit_tlv493d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 3f0c954..91ac58a 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -158,7 +158,7 @@ def _set_write_key(self, key: str, value: int) -> None: @property def magnetic(self) -> Tuple[float, float, float]: """The processed magnetometer sensor values. - A 3-tuple of X, Y, Z axis values in microteslas that are signed floats. + A 3-tuple of X, Y, Z axis values in milliteslas that are signed floats. """ self._read_i2c() # update read registers x_top = self._get_read_key("BX1") From 42f70d750d4ccd5293f55d3ff9af8b182425ba6a Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Thu, 8 Sep 2022 09:58:36 -0700 Subject: [PATCH 2/2] fix reported milliteslas to microtesla --- README.rst | 2 +- adafruit_tlv493d.py | 4 ++-- examples/tlv493d_simpletest.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index da27e93..2a8886b 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ Usage Example tlv = adafruit_tlv493d.TLV493D(i2c) while True: - print("X: %s, Y:%s, Z:%s mT"%tlv.magnetic) + print("X: %s, Y:%s, Z:%s uT"%tlv.magnetic) time.sleep(1) Documentation diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 91ac58a..8296e66 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -158,7 +158,7 @@ def _set_write_key(self, key: str, value: int) -> None: @property def magnetic(self) -> Tuple[float, float, float]: """The processed magnetometer sensor values. - A 3-tuple of X, Y, Z axis values in milliteslas that are signed floats. + A 3-tuple of X, Y, Z axis values in microteslas that are signed floats. """ self._read_i2c() # update read registers x_top = self._get_read_key("BX1") @@ -178,4 +178,4 @@ def magnetic(self) -> Tuple[float, float, float]: def _unpack_and_scale(top: int, bottom: int) -> float: binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 - return binval * 0.098 + return binval * 98.0 diff --git a/examples/tlv493d_simpletest.py b/examples/tlv493d_simpletest.py index b505748..2e2d27a 100644 --- a/examples/tlv493d_simpletest.py +++ b/examples/tlv493d_simpletest.py @@ -9,5 +9,5 @@ tlv = adafruit_tlv493d.TLV493D(i2c) while True: - print("X: %s, Y: %s, Z: %s mT" % tlv.magnetic) + print("X: %s, Y: %s, Z: %s uT" % tlv.magnetic) time.sleep(1)