Skip to content
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
13 changes: 9 additions & 4 deletions adafruit_mlx90393.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def __init__( # pylint: disable=too-many-arguments
self._osr = oversampling
self._gain_current = gain
self._temperature_compensation = temperature_compensation
# Typical value according the application note
self._tref = 0xB668
self._off_x = self._off_y = self._off_z = offset

# Put the device in a known state to start
Expand Down Expand Up @@ -519,6 +521,12 @@ def reset(self) -> None:
print("Resetting sensor")
time.sleep(0.002)
self._transceive(bytes([_CMD_RT]))

# Read the temperature reference from register 0x24
self._tref = self.read_reg(0x24)
if self._debug:
print("Tref = {}".format(hex(self._tref)))

# burn a read post reset
try:
self.magnetic
Expand Down Expand Up @@ -614,9 +622,6 @@ def temperature(self) -> float:
Reads a single temperature sample from the magnetometer.
Temperature value in Celsius
"""
# Read the temperature reference from register 0x24
treference = self.read_reg(0x24)

# Value taken from maximum time of temperature conversion on the datasheet section 12.
# maximum time for temperature conversion = 1603 us
delay = 0.1
Expand All @@ -637,4 +642,4 @@ def temperature(self) -> float:
tvalue = struct.unpack(">H", data[1:3])[0]
# See previous link for conversion formula

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