Hi I have been working on a high precision PT100 based thermometer to use at work. Its running on a Due with a modified Adafruit Max31865 board and a 1/10 DIN PT100 probe. Its set up to use the CVD equation to convert resistance to temperature and am displaying it to 0.001°F. Because that's more resolution than the ADC provides, I'm using a simple moving average with the Smoothed library @ 30 samples. Whenever I upload the program to the board, it works great and will settle to within +/- 0.005°. But as soon as I shut it off and on again, the temperature never settles and constantly jumps around by as much as 0.1° and will continue to do so until I re-upload the program (even if its unchanged). My programming knowledge leaves a lot to be desired, so its totally within the realm of possibility that I'm missing something obvious, but I can't figure it out. Any help would be appreciated... full code below and library attached. Thanks!
#include <Smoothed.h>
#include <UTFT.h>
#include <SPI.h>
#include <Adafruit_MAX31865.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
extern uint8_t frank[];
extern uint8_t Grobig[];
extern uint8_t Gro[];
UTFT myGLCD(CTE32HR, 38, 39, 40, 41);
Adafruit_BME680 bme; // I2C
Adafruit_MAX31865 max = Adafruit_MAX31865(10, 11, 12, 13);
//Hardware SPI:
//Adafruit_MAX31865 max = Adafruit_MAX31865(10);
//Adafruit_BME680 bme(BME_CS); // hardware SPI
// The value of the Rref resistor. Upgraded to 499.0
#define RREF 499.0
#define RNOMINAL 100.0
#define SEALEVELPRESSURE_HPA (1013.25)
int hum;
unsigned int voc;
float airt, pres;
unsigned long probeinterval = 150;
unsigned long previousMillisprobe = 0;
unsigned long displayinterval = 1000;
unsigned long previousMillisdisplay = 0;
unsigned long ambientinterval = 5000;
unsigned long previousMillisambient = 0;
Smoothed <double> mySensor;
void setup() {
max.begin(MAX31865_4WIRE);
//filter
mySensor.begin(SMOOTHED_AVERAGE, 30);
//Serial.begin(57600) ;
//Display boot screen
myGLCD.InitLCD();
myGLCD.setFont(Grobig);
myGLCD.fillScr(0, 0, 0);
myGLCD.setColor(VGA_SILVER);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("NFG Industrial", CENTER, 20);
delay(1000);
myGLCD.setFont(Gro);
myGLCD.setColor(VGA_RED);
myGLCD.print("High Precision", CENTER, 102);
myGLCD.print("Temperature Monitoring", CENTER, 144);
myGLCD.print("System", CENTER, 186);
myGLCD.setFont(frank);
myGLCD.setColor(VGA_WHITE);
myGLCD.print("Powered by:", CENTER, 245);
myGLCD.print("Arduino", CENTER, 259);
delay(2000);
myGLCD.fillScr(0, 0, 0);
myGLCD.setBackColor(0, 0, 0);
// Display Labels
myGLCD.setFont(Gro);
myGLCD.setColor(VGA_RED);
myGLCD.print("Temp:", 40, 58);
myGLCD.print("F", 320, 58);
myGLCD.setFont(frank);
myGLCD.setColor(VGA_RED);
myGLCD.print("Relative", LEFT, 170);
myGLCD.print("Humidity:", LEFT, 190);
myGLCD.print("Barometric", CENTER, 170);
myGLCD.print("Pressure:", CENTER, 190);
myGLCD.print("VOC ", RIGHT, 170);
myGLCD.print("Content:", RIGHT, 190);
myGLCD.print("%", 94, 275);
myGLCD.print("mbar", 290, 295);
myGLCD.print("100-0", RIGHT, 295);
myGLCD.print("Ambient", 70, 145);
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop() { //*********loop***********
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillisprobe) >= probeinterval) {
readprobe();
previousMillisprobe = currentMillis;
}
if ((unsigned long)(currentMillis - previousMillisambient) >= ambientinterval) {
ambient();
previousMillisambient = currentMillis;
}
if ((unsigned long)(currentMillis - previousMillisdisplay) >= displayinterval) {
updatedisplay();
previousMillisdisplay = currentMillis;
}
}
void readprobe() {
double rtd, tempr, tpf, tempc;
double ratio = rtd;
rtd = max.readRTD();
ratio /= 32768;
tempr = max.temperature(RNOMINAL, RREF);
tpf = ((9 * tempr / 5) + 32) ;
double currentSensorValue = tpf;
// Add the new value to sensor value store
mySensor.add(currentSensorValue);
}
void updatedisplay() {
float temprobe;
temprobe = mySensor.get();
myGLCD.setFont(Grobig);
myGLCD.setColor(VGA_WHITE);
myGLCD.printNumF(temprobe, 3, CENTER, 30);
myGLCD.setFont(Gro);
myGLCD.setColor(VGA_WHITE);
myGLCD.printNumF(airt, 2, CENTER, 120);
myGLCD.printNumI(hum, 20, 230, 2);
myGLCD.printNumI(voc, 400, 230, 3);
if (pres > 999.99) {
myGLCD.printNumF(pres, 1, CENTER, 230);
}
else {
myGLCD.printNumF(pres, 2, CENTER, 230);
}
}
void ambient() {
float cel, gas;
bme.performReading();
cel = bme.temperature;
airt = cel * 9 / 5 + 32;
pres = bme.pressure / 100.0;
hum = bme.humidity;
gas = map(bme.gas_resistance, 0, 100, 100, 0);
voc = bme.gas_resistance / 1000;
}
Smoothed.h (4.85 KB)