Skip to content

Expose resistance property #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions adafruit_thermistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def __init__(
self.high_side = high_side

@property
def temperature(self):
"""The temperature of the thermistor in Celsius"""
def resistance(self):
"""The resistance of the thermistor in Ohms"""
if self.high_side:
# Thermistor connected from analog input to high logic level.
reading = self.pin.value / 64
Expand All @@ -112,8 +112,12 @@ def temperature(self):
else:
# Thermistor connected from analog input to ground.
reading = self.series_resistor / (65535.0 / self.pin.value - 1.0)
return reading

steinhart = reading / self.nominal_resistance # (R/Ro)
@property
def temperature(self):
"""The temperature of the thermistor in Celsius"""
steinhart = self.resistance / self.nominal_resistance # (R/Ro)
steinhart = math.log(steinhart) # ln(R/Ro)
steinhart /= self.b_coefficient # 1/B * ln(R/Ro)
steinhart += 1.0 / (self.nominal_temperature + 273.15) # + (1/To)
Expand Down