In the original Adafruit_MAX31865 library, the library works well with a single MAX31865.
I am trying to read up to 10 MAX31865 using an Arduino Mega, however, at the setup thermo.begin(MAX31865_2WIRE); allows modification of the bool line only up to three, any modification after the third returns a null value for the MAX31865.
Have tried the multiple sensor code by @sylvanoMTL and others but there is still no reading after the third modification.
Can you provide a working library with example for reading multiple MAX31865 sensors of up to 10 with an arduino sketch.
It is my belief that the arduino.h code is limited somehow to just three instances preventing additional instances.
I have attached a sample code for 5 MAX31865 to aid troubleshooting.
Note: when thermo3.begin(MAX31865_2WIRE); and thermo4.begin(MAX31865_2WIRE); are commented out, I get stable readings from the MAX31865 for the first three, however when they are uncommented, only the first gives a reading, while the others is driven to the 5V HIGH.
I have commented out all others and was able to find that the problem is from the setup function and it has something to do with the bool begin function as explained above.
/***************************************************
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
Designed specifically to work with the Adafruit RTD Sensor
----> https://www.adafruit.com/products/3328
This sensor uses SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_MAX31865.h>
// Use software SPI: CS, DI, DO, CLK 54213
// for uno and nano SPI pins are 11(DI), 12(DO), 13(CLK)
// for mega the SPI pins are: 51(DI), 50(DO), 52(CLK)
/*Adafruit_MAX31865 thermo = Adafruit_MAX31865(46,51,50,52); // for 1st max31865
Adafruit_MAX31865 thermo1 = Adafruit_MAX31865(44,51,50,52); //for 2nd max31865, only CS is changing
Adafruit_MAX31865 thermo2 = Adafruit_MAX31865(42,51,50,52); //for 3rd max31865, only CS is changing
Adafruit_MAX31865 thermo3 = Adafruit_MAX31865(40,51,50,52); //for 4th max31865, only CS is changing
Adafruit_MAX31865 thermo4 = Adafruit_MAX31865(38,51,50,52); //for 5th max31865, only CS is changing
*/
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 thermo = Adafruit_MAX31865(46);
Adafruit_MAX31865 thermo1 = Adafruit_MAX31865(44);
Adafruit_MAX31865 thermo2 = Adafruit_MAX31865(42);
Adafruit_MAX31865 thermo3 = Adafruit_MAX31865(40);
Adafruit_MAX31865 thermo4 = Adafruit_MAX31865(38);
// 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
float ratio, ratio1, ratio2, ratio3, ratio4;
void setup() {
Serial.begin(115200);
Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
thermo.begin(MAX31865_2WIRE); //delay(50);// set to 2WIRE or 4WIRE as necessary
thermo1.begin(MAX31865_2WIRE); //delay(50); // set to 2WIRE or 4WIRE
thermo2.begin(MAX31865_2WIRE); //delay(150);// set to 2WIRE or 4WIRE
thermo3.begin(MAX31865_2WIRE); //delay(150);// set to 2WIRE or 4WIRE
thermo4.begin(MAX31865_2WIRE); //delay(150);
}
void loop() {
uint16_t rtd = thermo.readRTD(); //delay(50);
uint16_t rtd1 = thermo1.readRTD(); //delay (50);
uint16_t rtd2 = thermo2.readRTD(); //delay (50);
uint16_t rtd3 = thermo3.readRTD();
uint16_t rtd4 = thermo4.readRTD();
Serial.print("RTD value 1: "); Serial.println(rtd);
Serial.print("RTD value 2: "); Serial.println(rtd1);
Serial.print("RTD value 3: "); Serial.println(rtd2);
Serial.print("RTD value 4: "); Serial.println(rtd3);
Serial.print("RTD value 5: "); Serial.println(rtd4);
ratio = rtd;
ratio1 = rtd1;
ratio2 = rtd2;
ratio3 = rtd3;
ratio4 = rtd4;
ratio /= 32768;
ratio1 /= 32768;
ratio2 /= 32768;
ratio3 /= 32768;
ratio4 /= 32768;
Serial.print("Ratio 1 = "); Serial.println(ratio,8);
Serial.print("Resistance 1 = "); Serial.println(RREFratio,8);
Serial.print("Ratio 2 = "); Serial.println(ratio1,8);
Serial.print("Resistance 3 = "); Serial.println(RREFratio1,8);
Serial.print("Ratio 4 = "); Serial.println(ratio2,8);
Serial.print("Resistance 4 = "); Serial.println(RREFratio2,8);
Serial.print("Ratio 5 = "); Serial.println(ratio3,8);
Serial.print("Resistance 5 = "); Serial.println(RREFratio3,8);
Serial.print("Ratio 5 = "); Serial.println(ratio4,8);
Serial.print("Resistance 5 = "); Serial.println(RREF*ratio4,8);
Serial.print("Temperature 1 = "); Serial.println(thermo.temperature(RNOMINAL, RREF));
Serial.print("Temperature 2 = "); Serial.println(thermo1.temperature(RNOMINAL, RREF));
Serial.print("Temperature 3 = "); Serial.println(thermo2.temperature(RNOMINAL, RREF));
Serial.print("Temperature 4 = "); Serial.println(thermo3.temperature(RNOMINAL, RREF));
Serial.print("Temperature 5 = "); Serial.println(thermo4.temperature(RNOMINAL, RREF));
//*/
// Check and print any faults
uint8_t fault = thermo.readFault();
uint8_t fault1 = thermo1.readFault();
uint8_t fault2 = thermo2.readFault();
uint8_t fault3 = thermo3.readFault();
uint8_t fault4 = thermo4.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();
thermo1.clearFault();
thermo2.clearFault();
thermo3.clearFault();
thermo4.clearFault();
}
Serial.println();
delay(1000);
}