arduinoadafruitarduino-due

Adafruit_MAX31855 Thermopile IC readcelcius() command returning nan


I am currently using an Adafruit_MAX31855 IC along with a K type thermocouple. For some reason I am getting this in the serial monitor...

Internal Temp = 32.44
nan // printed from thermocouple.readCelcius()
Internal Temp = 32.44
nan
Internal Temp = 32.44
nan
Internal Temp = 32.44
nan
Internal Temp = 32.38
nan
Internal Temp = 32.38
nan
Internal Temp = 32.38
nan
Internal Temp = 32.38
nan
Internal Temp = 32.31

Now i know it's all wired up correctly as I am getting an internal temperature. As well as this the .readCelcius() command does sometimes return a correct reading. I thought at first it may be the max temp is outside the capabilities of the chip but evn when running at 40 degrees C i sometimes get this.

#include <SPI.h>
#include "Adafruit_MAX31855.h"

int HeaterPWM = 12;
int LEDPin = 13;
long _startTime;
long _currentTime;

#define MAXDO   3
#define MAXCS   4
#define MAXCLK  5

Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);


void setup() {
  while (!Serial); // wait for Serial on Leonardo/Zero, etc

  Serial.begin(9600);
  pinMode(HeaterPWM, OUTPUT);
  pinMode(LEDPin, OUTPUT);

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {

  _startTime = millis();
  while (_currentTime - _startTime < 3000) // heater on for 3 seconds at a time
  {
    Serial.print("Internal Temp = ");
    Serial.println(thermocouple.readInternal());

    _currentTime = millis();
    analogWrite(HeaterPWM, 150);
    digitalWrite(LEDPin, HIGH);
    double c = sampleCelcius(1);
    Serial.println(c);
    delay(10);
  }

  _startTime = millis();

  while (_currentTime - _startTime < 10000) // heater on for 3 seconds at a time
  {
    Serial.print("Internal Temp = ");
    Serial.println(thermocouple.readInternal());

    _currentTime = millis();
    analogWrite(HeaterPWM, 0);
    digitalWrite(LEDPin, LOW);
    double c = sampleCelcius(1);
    Serial.println(c);
    delay(10);
  }
}

double sampleCelcius(int maxSamples)
{
  double result = NAN;
  for (int i = 0; i < maxSamples; i++)
  {
    result = thermocouple.readCelsius();
    if (!isnan(result)) // exit on first good reading.
      break;
    delay(10);
  }
  return result;
}

I have checked all my voltages and PWM outputs etc.. as well as benchmarking the thermocouple. When it works at room temperature it is correct. when i do get a reading instead of Nan when the heater is on I seem to be getting really high numbers, in the thousands, which obivously is incorrect. It should be around 65 degrees c.

Any ideas?


Solution

  • It turns out the Adafruit_MAX31855 IC is not compatible to be used on conductive surface and the 'heating up' was also sending a voltage down the thermocouple, throwing off the readings.