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
--------------------
16
16
17
17
**Hardware:**
18
18
19
- * `Adafruit's ADT7410 analog temperature Sensor Breakout:
19
+ * `Adafruit ADT7410 analog temperature Sensor Breakout
20
20
<https://www.adafruit.com/product/4089>`_ (Product ID: 4089)
21
21
22
+
22
23
**Software and Dependencies:**
23
24
24
25
* Adafruit CircuitPython firmware for the supported boards:
25
- https://github.com/adafruit/circuitpython/releases
26
+ https://circuitpython.org/downloads
27
+
28
+ * Adafruit's Bus Device library:
29
+ https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
26
30
27
- * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
31
+ * Adafruit's Register library:
32
+ https://github.com/adafruit/Adafruit_CircuitPython_Register
28
33
29
- * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
30
34
"""
31
35
32
36
44
48
_ADT7410_TEMPLSB = const (0x1 )
45
49
_ADT7410_STATUS = const (0x2 )
46
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 )
47
58
_ADT7410_ID = const (0xB )
48
59
_ADT7410_SWRST = const (0x2F )
49
60
@@ -85,6 +96,10 @@ class ADT7410:
85
96
intpin_polarity = RWBit (_ADT7410_CONFIG , 3 )
86
97
comparator_mode = RWBit (_ADT7410_CONFIG , 4 )
87
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 )
88
103
89
104
def __init__ (self , i2c_bus , address = 0x48 ):
90
105
self .i2c_device = I2CDevice (i2c_bus , address )
@@ -116,7 +131,7 @@ def configuration(self):
116
131
117
132
@configuration .setter
118
133
def configuration (self , val ):
119
- return self ._write_register (_ADT7410_CONFIG , val )
134
+ self ._write_register (_ADT7410_CONFIG , val )
120
135
121
136
def reset (self ):
122
137
"""Perform a software reset"""
@@ -139,3 +154,61 @@ def _write_register(self, addr, data=None):
139
154
end = 2
140
155
with self .i2c_device as i2c :
141
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