1
1
# The MIT License (MIT)
2
2
#
3
3
# Copyright (c) 2019 Dan Cogliano for Adafruit Industries
4
+ # Copyright (c) 2019 Kattni Rembor for Adafruit Industries
4
5
#
5
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
# of this software and associated documentation files (the "Software"), to deal
26
27
CircuitPython driver for the MCP9600 thermocouple I2C amplifier
27
28
28
29
29
- * Author(s): Dan Cogliano
30
+ * Author(s): Dan Cogliano, Kattni Rembor
30
31
31
32
Implementation Notes
32
33
--------------------
63
64
_REGISTER_VERSION = const (0x20 )
64
65
65
66
66
- class BurstModeSamples :
67
- """An enum-like class representing the options for number of burst mode samples."""
67
+ class MCP9600 :
68
+ """Interface to the MCP9600 thermocouple amplifier breakout"""
69
+
70
+ # Shutdown mode options
71
+ NORMAL = 0b00
72
+ SHUTDOWN = 0b01
73
+ BURST = 0b10
74
+
75
+ # Burst mode sample options
68
76
BURST_SAMPLES_1 = 0b000
69
77
BURST_SAMPLES_2 = 0b001
70
78
BURST_SAMPLES_4 = 0b010
@@ -74,17 +82,6 @@ class BurstModeSamples:
74
82
BURST_SAMPLES_64 = 0b110
75
83
BURST_SAMPLES_128 = 0b111
76
84
77
-
78
- class ShutdownModes :
79
- """An enum-like class representing the options for shutdown modes"""
80
- NORMAL = 0b00
81
- SHUTDOWN = 0b01
82
- BURST = 0b10
83
-
84
-
85
- class MCP9600 :
86
- """Interface to the MCP9600 thermocouple amplifier breakout"""
87
-
88
85
# Alert temperature monitor options
89
86
AMBIENT = 1
90
87
THERMOCOUPLE = 0
@@ -101,35 +98,42 @@ class MCP9600:
101
98
INTERRUPT = 1 # Interrupt clear option must be set when using this mode!
102
99
COMPARATOR = 0
103
100
104
- # TODO: Get clarification on this and potentially update names
105
- # Interrupt clear options
106
- CLEAR_INTERRUPT_FLAG = 1
107
- NORMAL_STATE = 0
108
-
109
101
# Ambient (cold-junction) temperature sensor resolution options
110
102
AMBIENT_RESOLUTION_0_0625 = 0 # 0.0625 degrees Celsius
111
103
AMBIENT_RESOLUTION_0_25 = 1 # 0.25 degrees Celsius
112
104
113
105
# STATUS - 0x4
114
106
burst_complete = RWBit (0x4 , 7 )
107
+ """Burst complete"""
115
108
temperature_update = RWBit (0x4 , 6 )
109
+ """Temperature update"""
116
110
input_range = ROBit (0x4 , 4 )
111
+ """Input range"""
117
112
alert_1 = ROBit (0x4 , 0 )
113
+ """Alert 1 status."""
118
114
alert_2 = ROBit (0x4 , 1 )
115
+ """Alert 2 status."""
119
116
alert_3 = ROBit (0x4 , 2 )
117
+ """Alert 3 status."""
120
118
alert_4 = ROBit (0x4 , 3 )
119
+ """Alert 4 status."""
121
120
# Device Configuration - 0x6
122
121
ambient_resolution = RWBit (0x6 , 7 )
122
+ """Ambient (cold-junction) temperature resolution. Options are ``AMBIENT_RESOLUTION_0_0625``
123
+ (0.0625 degrees Celsius) or ``AMBIENT_RESOLUTION_0_25`` (0.25 degrees Celsius)."""
123
124
burst_mode_samples = RWBits (3 , 0x6 , 2 )
125
+ """The number of samples taken during a burst in burst mode. Options are ``BURST_SAMPLES_1``,
126
+ ``BURST_SAMPLES_2``, ``BURST_SAMPLES_4``, ``BURST_SAMPLES_8``, ``BURST_SAMPLES_16``,
127
+ ``BURST_SAMPLES_32``, ``BURST_SAMPLES_64``, ``BURST_SAMPLES_128``."""
124
128
shutdown_mode = RWBits (2 , 0x6 , 0 )
129
+ """Shutdown modes. Options are ``NORMAL``, ``SHUTDOWN``, and ``BURST``."""
125
130
# Alert 1 Configuration - 0x8
126
131
_alert_1_interrupt_clear = RWBit (0x8 , 7 )
127
132
_alert_1_monitor = RWBit (0x8 , 4 )
128
133
_alert_1_temp_direction = RWBit (0x8 , 3 )
129
134
_alert_1_state = RWBit (0x8 , 2 )
130
135
_alert_1_mode = RWBit (0x8 , 1 )
131
136
_alert_1_enable = RWBit (0x8 , 0 )
132
- """Set to ``True`` to enable alert output. Set to ``False`` to disable alert output."""
133
137
# Alert 2 Configuration - 0x9
134
138
_alert_2_interrupt_clear = RWBit (0x9 , 7 )
135
139
_alert_2_monitor = RWBit (0x9 , 4 )
@@ -194,8 +198,54 @@ def __init__(self, i2c, address=_DEFAULT_ADDRESS, tctype="K", tcfilter=0):
194
198
195
199
def alert_config (self , * , alert_number , alert_temp_source , alert_temp_limit , alert_hysteresis ,
196
200
alert_temp_direction , alert_mode , alert_state ):
197
- """ For rising temps, hysteresis is below alert limit; falling temps, above alert limit
198
- Alert is enabled by default when set. To disable, use alert_disable method."""
201
+ """Configure a specified alert pin. Alert is enabled by default when alert is configured.
202
+ To disable an alert pin, use ``alert_disable``.
203
+ :param int alert_number: The alert pin number. Must be 1-4.
204
+ :param alert_temp_source: The temperature source to monitor for the alert. Options are:
205
+ ``THERMOCOUPLE`` or ``AMBIENT``.
206
+ :param float alert_temp_limit: The temperature in degrees Celsius at which the alert should
207
+ trigger. For rising temperatures, the alert will trigger when the
208
+ temperature rises above this limit. For falling temperatures, the
209
+ alert will trigger when the temperature falls below this limit.
210
+ :param float alert_hysteresis: The alert hysteresis range. Must be 0-255 degrees Celsius.
211
+ For rising temperatures, the hysteresis is below alert limit. For
212
+ falling temperatures, the hysteresis is above alert limit. See
213
+ data-sheet for further information.
214
+ :param alert_temp_direction: The direction the temperature must change to trigger the alert.
215
+ Options are ``RISING`` (heating up) or ``FALLING`` (cooling
216
+ down).
217
+ :param alert_mode: The alert mode. Options are ``COMPARATOR`` or ``INTERRUPT``. If setting
218
+ mode to ``INTERRUPT``, use ``alert_interrupt_clear`` to clear the
219
+ interrupt flag.
220
+ :param alert_state: Alert pin output state. Options are ``ACTIVE_HIGH`` or ``ACTIVE_LOW``.
221
+
222
+
223
+ For example, to configure alert 1:
224
+
225
+ .. code-block:: python
226
+
227
+ import board
228
+ import busio
229
+ import digitalio
230
+ import adafruit_mcp9600
231
+
232
+ i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
233
+ mcp = adafruit_mcp9600.MCP9600(i2c)
234
+ alert_1 = digitalio.DigitalInOut(board.D5)
235
+ alert_1.switch_to_input()
236
+
237
+ mcp.burst_mode_samples = mcp.BURST_SAMPLES_1
238
+ mcp.ambient_resolution = mcp.AMBIENT_RESOLUTION_0_25
239
+ mcp.alert_config(alert_number=1, alert_temp_source=mcp.THERMOCOUPLE,
240
+ alert_temp_limit=25, alert_hysteresis=0,
241
+ alert_temp_direction=mcp.RISING, alert_mode=mcp.COMPARATOR,
242
+ alert_state=mcp.ACTIVE_LOW)
243
+
244
+ """
245
+ if alert_number not in (1 , 2 , 3 , 4 ):
246
+ raise ValueError ("Alert pin number must be 1-4." )
247
+ if not (0 <= alert_hysteresis < 256 ):
248
+ raise ValueError ("Hysteresis value must be 0-255." )
199
249
setattr (self , '_alert_%d_monitor' % alert_number , alert_temp_source )
200
250
setattr (self , '_alert_%d_temperature_limit' % alert_number , int (alert_temp_limit / 0.0625 ))
201
251
setattr (self , '_alert_%d_hysteresis' % alert_number , alert_hysteresis )
@@ -205,9 +255,12 @@ def alert_config(self, *, alert_number, alert_temp_source, alert_temp_limit, ale
205
255
setattr (self , '_alert_%d_enable' % alert_number , True )
206
256
207
257
def alert_disable (self , alert_number ):
258
+ """Configuring an alert using ``alert_config()`` enables the specified alert by default.
259
+ Use ``alert_disable`` to disable an alert pin."""
208
260
setattr (self , '_alert_%d_enable' % alert_number , False )
209
261
210
262
def alert_interrupt_clear (self , alert_number , interrupt_clear = True ):
263
+ """Setting ``interrupt_clear==True`` clears the interrupt flag."""
211
264
setattr (self , '_alert_%d_interrupt_clear' % alert_number , interrupt_clear )
212
265
213
266
@property
@@ -225,7 +278,6 @@ def ambient_temperature(self):
225
278
value -= 4096
226
279
return value
227
280
228
-
229
281
@property
230
282
def temperature (self ):
231
283
""" Hot junction temperature in Celsius """
0 commit comments