Automeat - Part 2: Temperature Measurement Hardware and Calibration

a breadboard with components and wires stuck in it

I chose to use thermistor probes for automeat for their ready availability and low cost but wanted to try to minimize errors in order to be able to end up with a system that is both accurate and precise.

MAX6682

As explained in part 1, the MAX6682 is tasked with reading the thermistors and returning digital data back. The datasheet gives a complete explanation of how to do this and it was quick to write a library to handle it. Some early difficulties and errors occurred but were generally my fault and resolved by reading the documentation for ESP-IDF as well as C++ language references in general.

The current state of max6682probe.cpp involves creating probe objects who handle interfacing with the chip and returning calibrated data on request. Each probe object comes with semaphores that enforce the datasheet’s timing requirements to avoid returning junk data from attempting to read too fast, as well as keeping things safe when multiple tasks are calling updates and requesting data.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class max6682probe
{
    private:
        int rawData;
        float calibrationFixedOffset;
        gpio_num_t sda;
        gpio_num_t scl;
        gpio_num_t cs;
        SemaphoreHandle_t rawDataSemaphore;
        SemaphoreHandle_t degreesSemaphore;

Creating LUTs

With the ability to read raw data I now needed a way to turn that into accurate temperature measurements. I set up a test rig using two probes immersed in an oil bath on the stove where one probe was hooked into a Thermoworks Dot and the other into a MAX6682+esp32 circuit. I printed the raw thermistor data to a console on my laptop and wrote a file by hand correlating the Dot’s readings in degrees Fahrenheit to the raw data reported by my circuit. With the test rig running, I slowly ramped the oil from room temperature to 350F while typing values into a text editor on my dangerously perched X220.

two temperature probes stuck into a pot of oil on a stove with a thinkpad laptop sitting on an inactive burner

The resulting file covered every degree across my range of interest but not every possible raw value in that range. I threw the data into LibreOffice Calc and plotted a chart, along with a few guesses at polynomials that could approximate the data. A 7th-order polynomial was the best fit and so I used that polynomial to create a new set of data covering every possible raw data value in the relevant range.

a graph of temperature measurements and polynomial equations

It Works!

Using the shiny and smooth lookup table hewn from hot oily testing, the temperatures flying around are at least as accurate as the quality commercial thermometer I would otherwise be using. For our purposes this is great.

The only error in need of resolution now is in the lookup table itself. When I was recording the oil tests I had not noticed an error in the bitshifting part of the code that translates the binary output of the chip into an integer so my values wrap in a strange way and all subsequent data does the same. I know about this bug but have opted to leave it in place for now as it does not affect anything upstream. When I move to surface mount components on a custom PCB I will want to create new calibration data with the new reference resistors in place, that will be a good time to fix the bitshifting error in my raw data.

With the ability to accurately measure temperature using thermistor probes, the next post in this series will focus on the next most important thing: airflow.


stan
WRITTEN BY
stan
serial project starter