Bake Mate - Pi Chef Blog #4 - Monitoring oven temperature: Type K Thermocouple + MAX31856
Status Update:
More parts are here!
- For the weighing scale:
- 5KG Load Cell
- Avia Semiconductor HX711 24 bit ADC (Load Cell Amplifier) breakout board
- For the Oven Temperature Sensor:
- Type K Thermocouple
- Maxim MAX31856 Thermocouple Digitizer breakout board
- For the weighing scale:
- I cleaned up some of the code that I've already written.
- I tested out the HX711 & load cell with an Arduino Uno with a simple sketch to verify that it was working, I initially planned on covering the weighing scale in this blog post, but since it needs a little more work which would involve mounting the load cell and calibrating it, I'll keep it for the next post and cover the oven's temperature sensor instead.
Thermocouples:
Typical temperatures in an oven range from 30 °C (~80°F) to around 300 °C (~570°F), which is out of the range of typical temperature sensors that are typically used.
To measure these temperatures, I will be using a Type K thermocouple like this one:
A thermocouple consists of two dissimilar metals which are connected at one end (the hot junction). Due to the Seebeck effect, a thermoelectric current is generated which causes a small voltage difference between the cold junctions, which essentially makes produces a temperature dependent voltage. Texas Instruments has a nice & short (7 page) application report on thermocouple measurements.
The 'Type' of the thermocouple refers to the alloy used, which in turn influences the range, sensitivity, stability etc.
I'll be using a Type 'K' thermocouple (the most common type) which is made of a Chromel - Alumel alloy and has a range of −250 °C to +1300 °C with an accuracy of around +/- 2.2°C.
Maxim's MAX31856:
I'll also be using a Maxim's MAX31856 which is a Precision Thermocouple to Digital Converter that includes cold junction compensation and compensation for non-linear effects. The internal 19-bit ADC first digitizes the voltage at the thermocouple terminals and converts it ot a temperature depending on the 'Type' of thermocouple used (since the MAX31856 supports different types). Cold junction compensation is used to offset the error caused by the unintentional thermocouple junction caused at the terminals of the connector/terminal block on the PCB to which the ends of the thermocouple are connected. This is performed by measuring the temperature of the cold junction using an internal temperature sensor. The MAX31856 can be connected to any microcontroller using SPI.
Since the 4DPi-24-HAT uses the hardware SPI port on the Raspberry Pi 3 to send data to the display, I decided to use software serial (by bitbanging GPIO pins) to prevent the MAX31856 from interfering the display.
The 4DPi-24-HAT doesn't use all the GPIO pins on the header, but since it is mounted directly onto the Pi, it blocks access to the unused pins too.
Here's the pinout of the display HAT (from the datasheet):
I bought a GPIO breakout board like the one shown below and first proceeded to connect the pins on the display HAT's header( that were needed for the display HAT to function) to the header on the Pi 3.
I booted up the Pi once to ensure that I hadn't made a mistake with the connections and that the display was working. Once I did this, I connected the SPI data lines of the MAX31856 board to some unused GPIO pins. The MAX31856 board only needs 6 connections to function: +3.3V, GND and the 4 serial lines: CS, MISO, MOSI & SCLK.
The MAX31856 datasheet contains details on the 16 registers, of which only a few are actually needed to read the temperature of the thermocouple:
- CR0 is used to set the conversion mode (off or every 100 msec), one shot mode, to enable/disable the open circuit detection, cold junction sensing & noise rejection and to clear faults.
- CR1 is used to select the voltage averaging conversion mode and thermocouple type.
- MASK is the fault mask register that is used to mask the possible faults that can assert the FAULT output line.
- The next 6 registers store the temperature limits that trigger the respective faults.
- Registers CJTO, CJTH & CJTL are used for cold junction compensation and store offset value, MSB and LSB of the temperature sensor that is used to measure cold junction temperature.
- Registers LTCBH, LTCBM & LTCBL collectively store the 19 bit value of the linearized and cold-junction-compensated thermocouple temperature.
- SR is the fault status register that indicates the fault conditions (the respective bits get asserted).
The MAX31856 isn't very difficult to use (in terms of registers that need to be read from and written to), but I used Stephen Smith's Python based MAX31856 library for the Raspberry Pi because it was simpler & easier than writing everything from scratch.
Getting the MAX31856 took a little more work than I expected, not because it's difficult to use, but because Python was giving me silly errors for some reason.
After half an hour of debugging, I rebooted the Pi and got valid readings immediately.
I occasionally get a "Overvoltage or Undervoltage Input Fault", which according to the data sheet occurs when the input voltage is negative or greater than VDD, but I'll need to have a closer look at why this happens, and whether I can simply ignore this flag.
I wrote a short Python script that polls the sensor every second so that it would be easy to test it out.
The first (and easiest) test involved simply touching the thermocouple to check if the temperature increased above the ambient temperature reading. After this I tested it out with an electric iron (which went upto 200 °C).
I noticed that the Pi was running a bit warm, so I first measured the temperature of the SoC package (which was around 40 °C at idle) and then increased the load of the CPU to around 70% by streaming a 1080p video from Youtube, which took the temperature to 57 °C, though in reality it's probably higher because the thermocouple wasn't making very good contact with the package.
I do not have a temperature sensor that can be used to verify the entire range of temperatures (upto around 300 °C) that this thermocouple will be measuring in an oven, but I will try to cross-check it using a TMP006 (upto 125°C) and a sugar thermometer (upto 200 °C).
Next on the list:
- Building the weighing scale: I'll need to drill holes and mount the load cell between two plates using screws.
- Interfacing the HX711 with the Pi: I've used the HX711 with an Arduino Uno, but I'll now need to get it to work with the Raspberry Pi 3.
- Calibration & integration: The weighing scale will need to be calibrated, and I'll need to decide exactly how to keep track of the weight & conversions of the ingredients.
- Testing the thermocouple in the oven: I'll need to mount the thermocouple inside the oven (which shouldn't be too difficult) and test it out! I'm looking forward to seeing how accurate the oven's mechanical thermostat (that lowers the gas when it reaches the temperature) is.