Skip to content

Commit 0eed6c8

Browse files
authored
Merge pull request #19 from raquo/main
Expose `resistance` property
2 parents 49e9f48 + 0d9fd24 commit 0eed6c8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

adafruit_thermistor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def __init__(
102102
self.high_side = high_side
103103

104104
@property
105-
def temperature(self):
106-
"""The temperature of the thermistor in Celsius"""
105+
def resistance(self):
106+
"""The resistance of the thermistor in Ohms"""
107107
if self.high_side:
108108
# Thermistor connected from analog input to high logic level.
109109
reading = self.pin.value / 64
@@ -112,8 +112,12 @@ def temperature(self):
112112
else:
113113
# Thermistor connected from analog input to ground.
114114
reading = self.series_resistor / (65535.0 / self.pin.value - 1.0)
115+
return reading
115116

116-
steinhart = reading / self.nominal_resistance # (R/Ro)
117+
@property
118+
def temperature(self):
119+
"""The temperature of the thermistor in Celsius"""
120+
steinhart = self.resistance / self.nominal_resistance # (R/Ro)
117121
steinhart = math.log(steinhart) # ln(R/Ro)
118122
steinhart /= self.b_coefficient # 1/B * ln(R/Ro)
119123
steinhart += 1.0 / (self.nominal_temperature + 273.15) # + (1/To)

0 commit comments

Comments
 (0)