- refactored
This commit is contained in:
@@ -36,29 +36,26 @@ class TempSensor_max31865(ATemperatureSensor):
|
||||
msb = self.read_reg(0x01)
|
||||
lsb = self.read_reg(0x02)
|
||||
if lsb & 0x01 == 0x00:
|
||||
digits = float(256*msb + lsb)/2
|
||||
digits = (256*msb + lsb) >> 1
|
||||
|
||||
self.write_reg(0x00, 0xA3)
|
||||
return digits
|
||||
|
||||
def temperature(self):
|
||||
return self.__tempRaw() + self.temp_offset
|
||||
|
||||
def __tempRaw(self):
|
||||
T = 0
|
||||
try:
|
||||
digits = self.read_digits()
|
||||
R = TempSensor_max31865.calc_R(430, digits)
|
||||
T = TempSensor_max31865.vanDusen_temp(R)
|
||||
# print("Digits={}, R={:.3f} Ohm, T={:.2f} degC".format(digits,$
|
||||
except:
|
||||
pass
|
||||
return self.temp_offset + self.to_temperature(digits)
|
||||
|
||||
@staticmethod
|
||||
def to_temperature(digits):
|
||||
T = 0
|
||||
R = __class__.calc_R(430, digits)
|
||||
T = __class__.vanDusen_temp(R)
|
||||
|
||||
return T
|
||||
|
||||
@staticmethod
|
||||
def calc_R(Rref, digits):
|
||||
k = digits / 32768
|
||||
k = float(digits) / 32768
|
||||
R = k*Rref
|
||||
|
||||
return R
|
||||
@@ -86,7 +83,7 @@ class TempSensor_max31865(ATemperatureSensor):
|
||||
|
||||
@staticmethod
|
||||
def vanDusen_temp(Rmeas):
|
||||
RLut, TLut = TempSensor_max31865.vanDusenLut(100, -150, +500, 1.0)
|
||||
RLut, TLut = __class__.vanDusenLut(100, -150, +500, 1.0)
|
||||
|
||||
# Find candidate
|
||||
i = 0
|
||||
@@ -117,10 +114,14 @@ class TempSensor_max31865(ATemperatureSensor):
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
TempSensor_max31865 = TempSensor_max31865()
|
||||
sensor = TempSensor_max31865()
|
||||
for k in range (0, 100):
|
||||
for i in range (0, 8):
|
||||
print("Reg[0x{}]: 0x{:02X}".format(i, TempSensor_max31865.read_reg(i)))
|
||||
print(TempSensor_max31865.temperature())
|
||||
print("Reg[0x{}]: 0x{:02X}".format(i, sensor.read_reg(i)))
|
||||
|
||||
digits = sensor.read_digits()
|
||||
print("Digits = {:04X}".format(digits))
|
||||
print("Temperature = {} °C".format(TempSensor_max31865.to_temperature(digits)))
|
||||
time.sleep(0.1)
|
||||
|
||||
print("End of program")
|
||||
|
||||
Reference in New Issue
Block a user