Skip to content

Commit 15e2861

Browse files
committed
adding_temp_crit
1 parent b9684b6 commit 15e2861

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

adafruit_adt7410.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
CircuitPython driver for reading temperature from the Analog Devices ADT7410
1010
precision temperature sensor
1111
12-
* Author(s): ladyada
12+
* Author(s): ladyada, Jose David M.
1313
1414
Implementation Notes
1515
--------------------
@@ -48,6 +48,13 @@
4848
_ADT7410_TEMPLSB = const(0x1)
4949
_ADT7410_STATUS = const(0x2)
5050
_ADT7410_CONFIG = const(0x3)
51+
_ADT7410_THIGHMSB = const(0x4)
52+
_ADT7410_THIGHLSB = const(0x5)
53+
_ADT7410_TLOWMSB = const(0x6)
54+
_ADT7410_TLOWLSB = const(0x7)
55+
_ADT7410_TCRITMSB = const(0x8)
56+
_ADT7410_TCRITLSB = const(0x9)
57+
_ADT7410_THYST = const(0x0A)
5158
_ADT7410_ID = const(0xB)
5259
_ADT7410_SWRST = const(0x2F)
5360

@@ -89,6 +96,10 @@ class ADT7410:
8996
intpin_polarity = RWBit(_ADT7410_CONFIG, 3)
9097
comparator_mode = RWBit(_ADT7410_CONFIG, 4)
9198
high_resolution = RWBit(_ADT7410_CONFIG, 7)
99+
# Status Information configuration
100+
temp_over_critiq = ROBit(_ADT7410_STATUS, 6)
101+
temp_over_high = ROBit(_ADT7410_STATUS, 5)
102+
temp_under_low = ROBit(_ADT7410_STATUS, 4)
92103

93104
def __init__(self, i2c_bus, address=0x48):
94105
self.i2c_device = I2CDevice(i2c_bus, address)
@@ -120,7 +131,7 @@ def configuration(self):
120131

121132
@configuration.setter
122133
def configuration(self, val):
123-
return self._write_register(_ADT7410_CONFIG, val)
134+
self._write_register(_ADT7410_CONFIG, val)
124135

125136
def reset(self):
126137
"""Perform a software reset"""
@@ -143,3 +154,61 @@ def _write_register(self, addr, data=None):
143154
end = 2
144155
with self.i2c_device as i2c:
145156
i2c.write(self._buf, end=end)
157+
158+
@property
159+
def high_temperature(self):
160+
"""The over temperature limit value in Celsius"""
161+
temp = self._read_register(_ADT7410_THIGHMSB, 2)
162+
return struct.unpack(">h", temp)[0] / 128
163+
164+
@high_temperature.setter
165+
def high_temperature(self, value):
166+
value = struct.pack(">h", int(value * 128))
167+
self._write_register(_ADT7410_THIGHMSB, value[0])
168+
self._write_register(_ADT7410_THIGHLSB, value[1])
169+
170+
@property
171+
def low_temperature(self):
172+
"""The over temperature limit value in Celsius. Only works when
173+
comparator mode is selected"""
174+
temp = self._read_register(_ADT7410_TLOWMSB, 2)
175+
return struct.unpack(">h", temp)[0] / 128
176+
177+
@low_temperature.setter
178+
def low_temperature(self, value):
179+
value = struct.pack(">h", int(value * 128))
180+
self._write_register(_ADT7410_TLOWMSB, value[0])
181+
self._write_register(_ADT7410_TLOWLSB, value[1])
182+
183+
@property
184+
def critical_temperature(self):
185+
"""The critical temperature limit value in Celsius. Only works when
186+
comparator mode is selected"""
187+
temp = self._read_register(_ADT7410_TCRITMSB, 2)
188+
return struct.unpack(">h", temp)[0] / 128
189+
190+
@critical_temperature.setter
191+
def critical_temperature(self, value):
192+
"""The over temperature limit value in Celsius
193+
There is a bug in the sensor, so the address 0x09 could no be written to 0x00
194+
for this reason only odd numbers could be given. We could make the 0x09 with
195+
a value of 0x01, however make the logic more complex. Only works when
196+
comparator mode is selected
197+
"""
198+
value = struct.pack(">h", int(value * 128))
199+
self._write_register(_ADT7410_TCRITMSB, value[0])
200+
self._write_register(_ADT7410_TCRITLSB, value[1])
201+
202+
@property
203+
def hysteresis(self):
204+
"""The hysteresis temperature limit value in Celsius. Only works when
205+
comparator mode is selected. From 0 to 15 Celsius"""
206+
temp = self._read_register(_ADT7410_THYST)[0]
207+
return temp
208+
209+
@hysteresis.setter
210+
def hysteresis(self, value):
211+
if value > 15 or isinstance(value, float):
212+
raise Exception("Hysteresis value must be an integer lower than 15 Celsius")
213+
214+
self._write_register(_ADT7410_THYST, value)

0 commit comments

Comments
 (0)