Skip to content

Commit 4e6ba64

Browse files
authored
Merge pull request #47 from brian-eng/tref
Speed up temperature readings
2 parents ea1cb8d + d03ab19 commit 4e6ba64

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

adafruit_mlx90393.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ def __init__( # pylint: disable=too-many-arguments
226226
self._osr = oversampling
227227
self._gain_current = gain
228228
self._temperature_compensation = temperature_compensation
229+
# Typical value according the application note
230+
self._tref = 0xB668
229231
self._off_x = self._off_y = self._off_z = offset
230232

231233
# Put the device in a known state to start
@@ -519,6 +521,12 @@ def reset(self) -> None:
519521
print("Resetting sensor")
520522
time.sleep(0.002)
521523
self._transceive(bytes([_CMD_RT]))
524+
525+
# Read the temperature reference from register 0x24
526+
self._tref = self.read_reg(0x24)
527+
if self._debug:
528+
print("Tref = {}".format(hex(self._tref)))
529+
522530
# burn a read post reset
523531
try:
524532
self.magnetic
@@ -614,9 +622,6 @@ def temperature(self) -> float:
614622
Reads a single temperature sample from the magnetometer.
615623
Temperature value in Celsius
616624
"""
617-
# Read the temperature reference from register 0x24
618-
treference = self.read_reg(0x24)
619-
620625
# Value taken from maximum time of temperature conversion on the datasheet section 12.
621626
# maximum time for temperature conversion = 1603 us
622627
delay = 0.1
@@ -637,4 +642,4 @@ def temperature(self) -> float:
637642
tvalue = struct.unpack(">H", data[1:3])[0]
638643
# See previous link for conversion formula
639644

640-
return 35 + ((tvalue - treference) / 45.2)
645+
return 35 + ((tvalue - self._tref) / 45.2)

0 commit comments

Comments
 (0)