Erratic averaging after reboot after uploading

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)

Quite a few differences between a reset and a power up.

Have you tried pressing the reset button after power up and seeing if the readings stabilize?

...
      if (smoothReadingsPosition = 0) {
...

That looks suspicious.

It will take 30 seconds for the pipe to fill with values. Are you waiting that long before declaring a failure?

Yes I have it running for 10 hours a day

Slumpert:
Quite a few differences between a reset and a power up.

Have you tried pressing the reset button after power up and seeing if the readings stabilize?

Yes. I haven't tried it enough to say for sure but the few times I've tried it works normally after resetting. But if its already been power cycled, reset has no effect.

I tried a completely different averaging library today and it still does the same thing.

At this point I believe there are two potential problems: 1. corrupt memory as a result of a software bug; 2. hardware (e.g. a wiring mistake).

I suggest you build a simple program that reads just the temperature, outputs the values to Serial Monitor, and calculate a few averages using a spreadsheet (e.g. Google Sheets or Microsoft Excel). If that produces the results you expect then #1 is the most likely culprit. If that does not produce the results you expect then #2 is most likely the culprit.

If I use the Adafruit example sketch, it works fine, so I'm hesitant to call it a hardware problem (though its not out of the question). But a few minutes ago, I changed the program to print the temperatures before and after averaging on the serial monitor. I let it run as soon as it reset after uploading, since that's usually the only time that it works, but even after a few minutes it wouldn't settle down. I opened the serial monitor and after it reset, it stabilized more so than it ever had and still is working well after power cycling a few times... I'll have it running all day tomorrow to see if it continues to work.

But that reminds me- I just got this Due a few weeks ago for this project (its a genuine board) but I was having issues with the first program I tried to run on it that was working well on an Uno. I wrote it off as something to do with the different processor, but if there was a problem with the board, is there any way I can test it to find out?