Skip to content

Commit 4d763c5

Browse files
committed
all done?
1 parent 210777a commit 4d763c5

File tree

7 files changed

+87
-46
lines changed

7 files changed

+87
-46
lines changed

.travis.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ python:
1111
cache:
1212
pip: true
1313

14-
# TODO: if deployment to PyPi is desired, change 'DEPLOY_PYPI' to "true",
15-
# or remove the env block entirely and remove the condition in the
16-
# deploy block.
1714
env:
18-
- DEPLOY_PYPI="false"
15+
- DEPLOY_PYPI="true"
1916

2017
deploy:
2118
- provider: releases
@@ -26,12 +23,10 @@ deploy:
2623
overwrite: true
2724
on:
2825
tags: true
29-
# TODO: Use 'travis encrypt --com -r adafruit/<repo slug>' to generate
30-
# the encrypted password for adafruit-travis. Paste result below.
3126
- provider: pypi
3227
user: adafruit-travis
3328
password:
34-
secure: #-- PASTE ENCRYPTED PASSWORD HERE --#
29+
secure: ihb28n7IEXjCri2SMDcLtZulWEJCef9+UziSK8qgBgZG33s/Zdt/1EMPpcxvV2SBSVhmJR0zXBOj5+qsJxbxEDURjSaapehL8Pp0zz0CnpZjyxjoKyaHK7Z+8ExiRjo2YR584wl8vRg9qB7hM1ZyS6BsBRwQ2EzMYFMj4UOkyU0djTPbZ/DXCwCiScZZXvpIRiG7D74QI0eKcCvesC2wkXV3cisqwJnqwDsT/ab0Jk5w3nsswuUF+vatLz0d3n27ggkmPy/OlgaIrVQTeV55QbBmh/Cr8815LKT1C1ucindyxT+lKNH1aaEeKoySVOg8wCtpWgnhgqVwzJAF5I+NT+zaqAueVkIOmbqaJibA9H8Jh9iGFyP2HBXlUCjp8SVfamKx/ya0FZZoIJrK+R/IL6Dkf2mweTOYR5E3qxdeF3SSE/FtpktqqefV/XSBiAHxmKfcB1KR/Nu6M8aqLAcA5wzowpJvNeL6usxFQpNqRoKHYSI5TtscGFPk+40ViAsgltABD85RR+AP+Q7gNAHwMx706+0eSUoLlGwDcSIe/DLfwKIvcjEUqbrNLcLwcGwcirk5/X8LJPoMU8i/IpL0SJI452eUqnwmQgEtJvS2dwaM+RPAxQpbFuxoqUb1UZvoKruiXj5eE0cH0CM5gjiKZXgmRqwiUF4lyKJblKC95so=
3530
on:
3631
tags: true
3732
condition: $DEPLOY_PYPI = "true"

README.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ This is easily achieved by downloading
3030

3131
Installing from PyPI
3232
=====================
33-
.. note:: This library is not available on PyPI yet. Install documentation is included
34-
as a standard element. Stay tuned for PyPI availability!
35-
36-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
37-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
38-
3933
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
4034
PyPI <https://pypi.org/project/adafruit-circuitpython-pct2075/>`_. To install for current user:
4135

@@ -61,7 +55,20 @@ To install in a virtual environment in your current project:
6155
Usage Example
6256
=============
6357

64-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
58+
.. code-block:: python
59+
60+
import time
61+
import board
62+
import busio
63+
import adafruit_pct2075
64+
i2c = busio.I2C(board.SCL, board.SDA)
65+
66+
pct = adafruit_pct2075.PCT2075(i2c)
67+
68+
while True:
69+
print("Temperature: %.2f C"%pct.temperature)
70+
time.sleep(0.5)
71+
6572
6673
Contributing
6774
============

adafruit_pct2075.py

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
3434
**Hardware:**
3535
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
3837
3938
**Software and Dependencies:**
4039
@@ -48,53 +47,72 @@
4847
"""
4948

5049
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
5352
import adafruit_bus_device.i2c_device as i2cdevice
5453
__version__ = "0.0.0-auto.0"
5554
__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
5657

57-
#PCT2075_DEFAULT_ADDRESS = 0x37 # Address is configured with pins A0-A2
58-
PCT2075_DEFAULT_ADDRESS = 0x48 # Address is configured with pins A0-A2
5958
PCT2075_REGISTER_TEMP = 0 # Temperature register (read-only)
6059
PCT2075_REGISTER_CONFIG = 1 # Configuration register
6160
PCT2075_REGISTER_THYST = 2 # Hysterisis register
6261
PCT2075_REGISTER_TOS = 3 # OS register
6362
PCT2075_REGISTER_TIDLE = 4 # Measurement idle time register
6463

6564
class Mode:
65+
"""Options for `mode`"""
6666
INTERRUPT = 1
6767
COMPARITOR = 0
6868

6969
class FaultCount:
70+
"""Options for `faults_to_alert`"""
7071
FAULT_1 = 0
7172
FAULT_2 = 1
7273
FAULT_4 = 3
7374
FAULT_6 = 4
7475

76+
# pylint: enable=bad-whitespace, too-few-public-methods
7577

7678
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+
"""
7883
def __init__(self, i2c_bus, address=PCT2075_DEFAULT_ADDRESS):
7984
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
8085

8186
_temperature = ROUnaryStruct(PCT2075_REGISTER_TEMP, ">h")
8287
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"""
8394

8495
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"""
8599
_fault_queue_length = RWBits(2, PCT2075_REGISTER_CONFIG, 5, register_width=1)
86100
_high_temperature_threshold = UnaryStruct(PCT2075_REGISTER_TOS, ">h")
87101
_temp_hysteresis = UnaryStruct(PCT2075_REGISTER_THYST, ">h")
88102
_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."""
90106

91107
@property
92108
def temperature(self):
93-
"""WHAT DO YOU THINK THIS RETURNS?"""
109+
"""Returns the current temperature in degress celsius. Resolution is 0.125 degrees C"""
94110
return (self._temperature>>5) * 0.125
95111

96112
@property
97113
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."""
98116
return (self._high_temperature_threshold >> 7) * 0.5
99117

100118
@high_temperature_threshold.setter
@@ -103,19 +121,43 @@ def high_temperature_threshold(self, value):
103121

104122
@property
105123
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+
"""
106128
return (self._temp_hysteresis >> 7) * 0.5
107129

108130
@temperature_hysteresis.setter
109131
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")
111134
self._temp_hysteresis = (int(value * 2) << 7)
112135

113136
@property
114137
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+
115144
return self._fault_queue_length
116145

117146
@faults_to_alert.setter
118147
def faults_to_alert(self, value):
119148
if value > 4 or value < 1:
120149
raise ValueError("faults_to_alert must be an adafruit_pct2075.FaultCount")
121150
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)

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
'sphinx.ext.todo',
1717
]
1818

19-
# TODO: Please Read!
19+
2020
# Uncomment the below if you use native CircuitPython modules such as
2121
# digitalio, micropython and busio. List the modules you use. Without it, the
2222
# autodoc module docs will fail to generate with a warning.
23-
# autodoc_mock_imports = ["digitalio", "busio"]
23+
autodoc_mock_imports = ["adafruit_register", "adafruit_bus_device"]
2424

2525

2626
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}

docs/index.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
28-
2926
.. toctree::
3027
:caption: Related Products
3128

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
29+
.. Adafruit PCT2075 Breakout <https://www.adafruit.com/products/4369>
3430
3531
.. toctree::
3632
:caption: Other Links

examples/high_temp_alert_example.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
import board
33
import busio
44
import adafruit_pct2075
5-
i2c = busio.I2C(board.SCL, board.SDA)
65

6+
i2c = busio.I2C(board.SCL, board.SDA)
77
pct = adafruit_pct2075.PCT2075(i2c)
8+
89
pct.high_temperature_threshold = 35.5
910
pct.temperature_hysteresis = 30.0
10-
pct.high_temp_active_low = False
11-
print("High temp alert active low? %s"%pct.high_temp_active_low)
11+
pct.high_temp_active_high = False
12+
print("High temp alert active high? %s"%pct.high_temp_active_high)
1213

1314
# Attach an LED with the Cathode to the INT pin and Anode to 3.3V with a current limiting resistor
1415

1516
while True:
1617
print("Temperature: %.2f C"%pct.temperature)
17-
time.sleep(0.5)
18+
time.sleep(0.5)

examples/pct2075_simpletest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import time
2-
import board
3-
import busio
4-
import adafruit_pct2075
5-
i2c = busio.I2C(board.SCL, board.SDA)
6-
7-
pct = adafruit_pct2075.PCT2075(i2c)
8-
9-
while True:
10-
print(pct.temperature)
11-
time.sleep(0.5)
1+
import time
2+
import board
3+
import busio
4+
import adafruit_pct2075
5+
i2c = busio.I2C(board.SCL, board.SDA)
6+
7+
pct = adafruit_pct2075.PCT2075(i2c)
8+
9+
while True:
10+
print("Temperature: %.2f C"%pct.temperature)
11+
time.sleep(0.5)

0 commit comments

Comments
 (0)