Adafruit_MAX31855 热电堆 IC readcelcius() 命令返回 nan
Adafruit_MAX31855 Thermopile IC readcelcius() command returning nan
我目前正在使用 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() 命令有时会 return 正确读数。一开始我以为可能是最高温度超出了芯片的能力范围,但即使在 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 摄氏度左右。
有什么想法吗?
事实证明 Adafruit_MAX31855 IC 不兼容用于导电表面,'heating up' 也在向热电偶发送电压,导致读数不正确。
我目前正在使用 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() 命令有时会 return 正确读数。一开始我以为可能是最高温度超出了芯片的能力范围,但即使在 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 摄氏度左右。
有什么想法吗?
事实证明 Adafruit_MAX31855 IC 不兼容用于导电表面,'heating up' 也在向热电偶发送电压,导致读数不正确。