NodeMCU & Max31865 Strange Behaviour

I am using a NodeMCU v3 + Max 31865 PT100 interface board

I am seeing some strange behaviour that I don’t understand and would appreciate some assistance if anybody has any insight?

I can get Max31865 to interface perfectly using the basic example Library code as below.


#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(D0, D1 , D2, D3);//(16, 5 , 4, 0)
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  100.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");

  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
}


void loop() {
  uint16_t rtd = thermo.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));

  // Check and print any faults
  uint8_t fault = thermo.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold"); 
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold"); 
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias"); 
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage"); 
    }
    thermo.clearFault();
  }
  Serial.println();
  delay(1000);
}  

I also have used successfully Blynk for projects and can get NodeMCU send datato Blynk Virtual pins. But as soon as I try to integrate the too sets of code the Max31865 fails to take a successful RTD measurement for processing. It is as though the there is a clash in the SPI bus. My code is below.

….any thoughts?

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_MAX31865.h>

Adafruit_MAX31865 thermo = Adafruit_MAX31865(D0, D1 , D2, D3);//(16, 5 , 4, 0)
#define RREF      430.0
#define RNOMINAL  100.0
uint16_t rtd;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXX";

// Your WiFi credentials.
char ssid[] = "XXX";
char pass[] = "XXX";


BlynkTimer timer;

void myTimerEvent()
{
  Serial.print("RTD value: "); Serial.println(rtd);
  rtd = thermo.readRTD();
  Blynk.virtualWrite(V1, millis() / 1000);
  
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Also, I had tried to use the NODEMCU standard SPI pins (D5,D6,D7,D8) but it was not possible to upload code to the board over USB so I moved to the D0,D1,D2,D3

@Woody please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly. The characters you’ve used are not triple backticks.
Triple backticks look like this:
```

Pete.

Sorted, sorry …first post :slight_smile:

Why don’t you just put the code that’s in the first void loop (minus the delay) into your sendSensor function? That way you’ll get to see any fault code messages.

Pete.

Thanks @PeteKnight; I have tried this but no fault is flagged when I run the code. I just get a 0 rtd value.

I wonder if there are any Blynk reserved pins on the NodeMCU that are causing conflict? Still getting to grips with this board.

Your code is structured in a rather odd way in that you are printing the RTD result before youre taking the reading:

This means that first time around the result will always be zero, but as you’ve moved the declaration of rtd up to the top of you code, making it global, the result that is achieved after taking the initial reading will be printed next time that this function is executed. This means that the results printed in the serial monitor will lag by one second.
I assume that it’s the serial monitor where you are looking for these results,m as you’er not actually sending the result to the Blynk app.

No Blynk reserved pins, but there are pins that will cause issues if you don’t understand how to use them:

I’d always recommend against directly using the “D” numbers that are printed on the NodeMCU and instead use the correct GPIO numbers. You can add a comment next to the declaration that included the D number to assist with wiring if you wish. This makes your code more portable from one device to another, and I find that it makes it easier to remember which groups of pins are potentially problematic as they tend to be grouped together when looking at the list in GPIO order.

Does your original (non-Blynk) code work with your changed pins?
Do you have any other widgets that are connected to digital pins?

Pete.

@PeteKnight thanks for the comprehensive response. Thanks for pointing out the rtd printing error, I did cobble this together with the main focus on trying to get a bare set of code working with this sensor/board combo.

Good news I have got it working now. I have learnt that I cannot connect to D0 or D7/D8 as these are used for USB coms and D0 for sleep/reset. Looking at the link you sent it appears that there are only actually about 5 pins that can be used for interfacing with sensors/peripheries. Think I may run out of pins very quickly and this board may not be best choice.

Any thoughts on an alternative Wifi connected board with higher number of usable pins? I am hoping to use 3 temperature sensors + a servo.

You have two choices - one centralised board with multiple sensors attached, or multiple boards in different physical locations with a local sensor attached.

If the things/areas that you want to monitor the temperature of are in close physical proximity (maybe within 2 metres of each other) then a single board with more pins - such as the ESP32 may be a better choice.
Normally, you’d be able to daisy chain multiple devices on the same SPI bus, but it’s not clear if you can do this with Adafruit Max 31865 library; and I’m not sure that you could define multiple instances of the Adafruit_MAX31865 thermo object in a single sketch either.

If the things you’re monitoring aren’t physically close together then you don’t have much choice other than to have multiple devices - each with their own sensor attached and with a different Blynk auth code - to achieve the result you need.

I assume that very high accuracy temperature monitoring is essential for your project? If not then there are many better (simpler) sensors out there that the MAX31865.

If you go for the ESP32 then scroll down the link I provided earlier for a link to other similar topics about the ESP32.

Pete.

Thanks @PeteKnight, plenty for me to consider.