adafruit / Adafruit_CircuitPython_MAX31865

CircuitPython module for the MAX31865 thermocouple amplifier.
MIT License
23 stars 11 forks source link

Temperature calculation ignores rtd_nominal for temperatures below zero #11

Closed KlaasH closed 4 years ago

KlaasH commented 5 years ago

The above-zero calculation uses rtd_nominal but the below-zero calculation doesn't. So if rtd_nominal is set to anything but 100, when the resistance drops below that value the reported temperature will abruptly jump to the uncalibrated value.

It seems like the below-zero formula is more complicated and it might not be feasible to incorporate rtd_nominal in it, but giving the wrong answer seems like a bad failure mode. Either returning None or raising an exception in the case where rtd_nominal is overridden and the initial calculation is negative would seem better to me.

osterwood commented 5 years ago

I created a PR a while back that is one fix for this issue. See https://github.com/adafruit/Adafruit_CircuitPython_MAX31865/pull/9

It's based on the logic within Adafruit C++ library for the MAX31865 : https://github.com/adafruit/Adafruit_MAX31865/blob/master/Adafruit_MAX31865.cpp

In my limited testing this past winter it gave reasonable results, but I don't have a great way to generate below-0C temperatures with accurate ground truth to benchmark against.

KlaasH commented 5 years ago

Oh, nice! I looked for open issues but didn't check the open PRs. Looks like those lines were added to the C++ library a few months after this package was ported from it.

I have some wireless air temperature sensors that are accurate below freezing. I could try putting the RTD probe and one of those in the freezer and seeing if they agree. Not exactly rigorous, but I do have 2 different freezers I could try...

In any case, even if it's not that accurate, it's better than the status quo.

kattni commented 4 years ago

Fixed by #9