我目前正在使用 Adafruit_MAX31855 IC 和 K 型热电偶。出于某种原因,我在串行监视器中得到了这个......
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
现在我知道所有的接线都正确,因为我得到了内部温度。除此之外,.readCelcius() 命令有时会返回正确的读数。起初我以为可能是最高温度超出了芯片的能力范围,但即使在 40 摄氏度下运行时,我有时也会得到这个。
#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;
}
我已经检查了我所有的电压和 PWM 输出等。以及对热电偶进行基准测试。当它在室温下工作时,它是正确的。当加热器打开时我得到读数而不是 Nan 时,我似乎得到了非常高的数字,以千计,这显然是不正确的。它应该在65摄氏度左右。
有任何想法吗?