9
9
CircuitPython driver for reading temperature from the Analog Devices ADT7410
10
10
precision temperature sensor
11
11
12
- * Author(s): ladyada
12
+ * Author(s): ladyada, Jose David M.
13
13
14
14
Implementation Notes
15
15
--------------------
48
48
_ADT7410_TEMPLSB = const (0x1 )
49
49
_ADT7410_STATUS = const (0x2 )
50
50
_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 )
51
58
_ADT7410_ID = const (0xB )
52
59
_ADT7410_SWRST = const (0x2F )
53
60
@@ -89,6 +96,10 @@ class ADT7410:
89
96
intpin_polarity = RWBit (_ADT7410_CONFIG , 3 )
90
97
comparator_mode = RWBit (_ADT7410_CONFIG , 4 )
91
98
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 )
92
103
93
104
def __init__ (self , i2c_bus , address = 0x48 ):
94
105
self .i2c_device = I2CDevice (i2c_bus , address )
@@ -120,7 +131,7 @@ def configuration(self):
120
131
121
132
@configuration .setter
122
133
def configuration (self , val ):
123
- return self ._write_register (_ADT7410_CONFIG , val )
134
+ self ._write_register (_ADT7410_CONFIG , val )
124
135
125
136
def reset (self ):
126
137
"""Perform a software reset"""
@@ -143,3 +154,61 @@ def _write_register(self, addr, data=None):
143
154
end = 2
144
155
with self .i2c_device as i2c :
145
156
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