Mapping CS pin on MAX31865 with MuxShield II
Im trying to use a Adafruit MAX31865 (PT100 version, if that matters) with a Mayhew Labs MuxShield II. The end project would use multiple RTDs with other I/O, so the Multiplexer is required.
After a bunch of testing, I have found that I cannot get the RTD code to read where the CS pin is. The MuxShield library passes a "void" value to express where the pin is, and the Adafruit_MAX21865 library expects an "int" value. I've tried casting the void value into an integer, but that was like handing the keys of a battleship to a 7-year-old.
How do I get this to work? Am I missing something very obvious? My code is below:
#include <MuxShield.h> //Initialize the Mux Shield
#include <Adafruit_MAX31865.h> // Initialize the MAX31865
#define RREF 430.0 // The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RNOMINAL 100.0 // The 'nominal' 0-degrees-C resistance of the sensor (100.0 for PT100)
MuxShield muxShield; //start the muxsheild
int CSint;
int DIpin = 5;
int DOpin = 9;
int CLKpin = 13;
float tempNow;
const int setTemp = 30;
void setup() {
Serial.begin(115200);
Serial.println("Setup Started.");
muxShield.setMode(1,DIGITAL_OUT); //set I/O 1 as digital output
muxShield.setMode(2,DIGITAL_IN_PULLUP); //set I/O 2 as digital in with pullup (not used, from example code)
muxShield.setMode(3,ANALOG_IN); //set I/O 3 as analog input (not used, from example code)
Serial.println("Setup Complete");
delay(1000);
}
void loop() {
CSint = (int8_t)(muxShield.digitalWriteMS (1,0,HIGH)); //My attempt at casting a "void" to an "int", which fails completely
tempNow = (CurTemp(CSint, DIpin, DOpin, CLKpin)); //Calling the function below
Serial.println("T1 = ");
Serial.println(tempNow);
if ( (tempNow > (setTemp)) ) { //this part seems to work just fine, if the RTD is directly wired in to the arduino
// turn LED on:
muxShield.digitalWriteMS(1,15,HIGH);
Serial.println("LED on");
} else {
// turn LED off:
muxShield.digitalWriteMS(1,15,LOW);
Serial.println("LED Off");
}
Serial.println("\r\n");
delay(5000);
}
float CurTemp(int CS, int DI, int DO, int CLK){ //This function works when the RTD is wired into the Arduino directly.
Adafruit_MAX31865 thermo1 = Adafruit_MAX31865(CS, DI, DO, CLK);// Use software SPI: CS, DI, DO, CLK
thermo1.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
return thermo1.temperature(RNOMINAL, RREF); //returns a float
}
Apologies for the lack of proper terminology. I only know enough coding to get me trouble, and not enough to get me out of it.