33
33
34
34
**Hardware:**
35
35
36
- .. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
37
- inline format: "* `Link Text <url>`_"
36
+ * Adafruit PCT2075 Breakout: https://www.adafruit.com/products/4369
38
37
39
38
**Software and Dependencies:**
40
39
48
47
"""
49
48
50
49
from adafruit_register .i2c_struct import ROUnaryStruct , UnaryStruct
51
- from adafruit_register .i2c_bits import ROBits , RWBits
52
- from adafruit_register .i2c_bit import RWBit , ROBit
50
+ from adafruit_register .i2c_bits import RWBits
51
+ from adafruit_register .i2c_bit import RWBit
53
52
import adafruit_bus_device .i2c_device as i2cdevice
54
53
__version__ = "0.0.0-auto.0"
55
54
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCT2075.git"
55
+ # pylint: disable=bad-whitespace, too-few-public-methods
56
+ PCT2075_DEFAULT_ADDRESS = 0x37 # Address is configured with pins A0-A2
56
57
57
- #PCT2075_DEFAULT_ADDRESS = 0x37 # Address is configured with pins A0-A2
58
- PCT2075_DEFAULT_ADDRESS = 0x48 # Address is configured with pins A0-A2
59
58
PCT2075_REGISTER_TEMP = 0 # Temperature register (read-only)
60
59
PCT2075_REGISTER_CONFIG = 1 # Configuration register
61
60
PCT2075_REGISTER_THYST = 2 # Hysterisis register
62
61
PCT2075_REGISTER_TOS = 3 # OS register
63
62
PCT2075_REGISTER_TIDLE = 4 # Measurement idle time register
64
63
65
64
class Mode :
65
+ """Options for `mode`"""
66
66
INTERRUPT = 1
67
67
COMPARITOR = 0
68
68
69
69
class FaultCount :
70
+ """Options for `faults_to_alert`"""
70
71
FAULT_1 = 0
71
72
FAULT_2 = 1
72
73
FAULT_4 = 3
73
74
FAULT_6 = 4
74
75
76
+ # pylint: enable=bad-whitespace, too-few-public-methods
75
77
76
78
class PCT2075 :
77
-
79
+ """Driver for the PCT2075 Digital Temperature Sensor and Thermal Watchdog.
80
+ :param ~busio.I2C i2c_bus: The I2C bus the INA260 is connected to.
81
+ :param address: The I2C device address for the sensor. Default is ``0x37``.
82
+ """
78
83
def __init__ (self , i2c_bus , address = PCT2075_DEFAULT_ADDRESS ):
79
84
self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
80
85
81
86
_temperature = ROUnaryStruct (PCT2075_REGISTER_TEMP , ">h" )
82
87
mode = RWBit (PCT2075_REGISTER_CONFIG , 1 , register_width = 1 )
88
+ """Sets the alert mode. In comparitor mode, the sensor acts like a thermostat and will activate
89
+ the INT pin according to `high_temp_active_high` when an alert is triggered. The INT pin will be
90
+ deactiveated when the temperature falls below `temperature_hysteresis`. In interrupt mode the
91
+ INT pin is activated once when a temperature fault is detected, and once more when the
92
+ temperature falls below `temperature_hysteresis`. In interrupt mode, the alert is cleared by
93
+ reading a property"""
83
94
84
95
shutdown = RWBit (PCT2075_REGISTER_CONFIG , 0 , 1 )
96
+ """Set to True to turn off the temperature measurement circuitry in the sensor. While shut down
97
+ the configurations properties can still be read or written but the temperature will not be
98
+ measured"""
85
99
_fault_queue_length = RWBits (2 , PCT2075_REGISTER_CONFIG , 5 , register_width = 1 )
86
100
_high_temperature_threshold = UnaryStruct (PCT2075_REGISTER_TOS , ">h" )
87
101
_temp_hysteresis = UnaryStruct (PCT2075_REGISTER_THYST , ">h" )
88
102
_idle_time = RWBits (5 , PCT2075_REGISTER_TIDLE , 0 , register_width = 1 )
89
- high_temp_active_low = RWBit (PCT2075_REGISTER_CONFIG , 2 , register_width = 1 )
103
+ high_temp_active_high = RWBit (PCT2075_REGISTER_CONFIG , 2 , register_width = 1 )
104
+ """Sets the alert polarity. When False the INT pin will be tied to ground when an alert is
105
+ triggered. If set to True it will be disconnected from ground when an alert is triggered."""
90
106
91
107
@property
92
108
def temperature (self ):
93
- """WHAT DO YOU THINK THIS RETURNS? """
109
+ """Returns the current temperature in degress celsius. Resolution is 0.125 degrees C """
94
110
return (self ._temperature >> 5 ) * 0.125
95
111
96
112
@property
97
113
def high_temperature_threshold (self ):
114
+ """The temperature in degrees celsius that will trigger an alert on the INT pin if it is
115
+ exceeded. Resolution is 0.5 degrees C."""
98
116
return (self ._high_temperature_threshold >> 7 ) * 0.5
99
117
100
118
@high_temperature_threshold .setter
@@ -103,19 +121,43 @@ def high_temperature_threshold(self, value):
103
121
104
122
@property
105
123
def temperature_hysteresis (self ):
124
+ """The temperature hysteresis value defines the bottom of the temperature range in degrees
125
+ C in which the temperature is still considered high". `temperature_hysteresis` must be
126
+ lower than `high_temperature_threshold`. Resolution is 0.5 degrees C.
127
+ """
106
128
return (self ._temp_hysteresis >> 7 ) * 0.5
107
129
108
130
@temperature_hysteresis .setter
109
131
def temperature_hysteresis (self , value ):
110
- # TODO: check that hyst is < threshold
132
+ if value >= self .high_temperature_threshold :
133
+ raise ValueError ("temperature_hysteresis must be less than high_temperature_threshold" )
111
134
self ._temp_hysteresis = (int (value * 2 ) << 7 )
112
135
113
136
@property
114
137
def faults_to_alert (self ):
138
+ """The number of consecutive high temperature faults required to raise an alert. An fault
139
+ is tripped each time the sensor measures the temperature to be greater than
140
+ `high_temperature_threshold`. The rate at which the sensor measures the temperature
141
+ is defined by `delay_between_measurements`.
142
+ """
143
+
115
144
return self ._fault_queue_length
116
145
117
146
@faults_to_alert .setter
118
147
def faults_to_alert (self , value ):
119
148
if value > 4 or value < 1 :
120
149
raise ValueError ("faults_to_alert must be an adafruit_pct2075.FaultCount" )
121
150
self ._fault_queue_length = value
151
+
152
+ @property
153
+ def delay_between_measurements (self ):
154
+ """The amount of time between measurements made by the sensor in milliseconds. The value
155
+ must be between 100 and 3100 and a multiple of 100"""
156
+ return self ._idle_time * 100
157
+
158
+ @delay_between_measurements .setter
159
+ def delay_between_measurements (self , value ):
160
+ if value > 3100 or value < 100 or value % 100 > 0 :
161
+ raise AttributeError (""""delay_between_measurements must be >= 100 or <= 3100\
162
+ and a multiple of 100""" )
163
+ self ._idle_time = int (value / 100 )
0 commit comments