Hi,
Before anything, thanks to everyone for reading. I've been strugling with this problem for the past 4 days and now I come here so hopefully someone could help me.
I am trying to read information from a PT100 using the MAX31865 breakout board from adafruit (Arduino Code | Adafruit MAX31865 RTD PT100 or PT1000 Amplifier | Adafruit Learning System) and an SDCard Module.
The problem is that I have no idea of how to connect the 2 devices as I only have one MOSI MISO CLK input in my arduino UNO but I do need 2 of them, or somehow, connect one interface SPI to another.
I looked in the forum and try to follow some pictures I found in google about the wiring, but still it is not working.
Could someone please explain how to connect and interact with the 2 devices? I've read about setting the CS pin to LOW when I wanna use it or HIGH when I don't need it, but also, I took a quick look at the libraries, and they are doing it for me.
Im currently using the MAX31865 library from adafruit (you can see it in the link) and the Arduino default SD Card library.
I would apreciate some help,
Just in case I attach my code
#include <SD.h>
#include <Wire.h>
#include <pt100rtd.h>
#include <SPI.h>
#include <Adafruit_MAX31865.h>
#define CS_SD 4
#define CS_SONDA 10
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 max = Adafruit_MAX31865(10);
File root;
#define RREF 430.0
#define C2F(c) ((9 * c / 5) + 32)
pt100rtd PT100 = pt100rtd() ;
void setup() {
Serial.begin(115200);
Wire.begin();
SPI.begin();
}
//------------------------------------------------------------
void loop() {
readSD();
//delay(2000);
readSonda();
}
void readSonda() {
// digitalWrite(4, HIGH);
//digitalWrite(9, LOW); //Enciendo CS 10
max.begin(MAX31865_2WIRE); // set to 2WIRE or 4WIRE as necessary
measurePT100();
// digitalWrite(9, HIGH);
// digitalWrite(4, HIGH);
}
void readSD() {
digitalWrite(CS_SONDA, HIGH);
digitalWrite(CS_SD, LOW);
Serial.print("Initializing SD card...");
if (!SD.begin(CS_SD)) {
Serial.print("Error");
}
digitalWrite(CS_SONDA, HIGH);
digitalWrite(CS_SD, HIGH);
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
void measurePT100() {
uint16_t rtd, ohmsx100 ;
uint32_t dummy ;
float ohms, Tlut ;
float Tcvd, Tcube, Tpoly, Trpoly ;
rtd = max.readRTD();
// fast integer math:
// fits in 32 bits as long as (100 * RREF) <= 2^16,
// i.e., RREF must not exceed 655.35 ohms (heh).
// Use uint16_t (ohms * 100) since it matches data type in lookup table.
dummy = ((uint32_t)(rtd << 1)) * 100 * ((uint32_t) floor(RREF)) ;
dummy >>= 16 ;
ohmsx100 = (uint16_t) (dummy & 0xFFFF) ;
// or use exact ohms floating point value.
ohms = (float)(ohmsx100 / 100) + ((float)(ohmsx100 % 100) / 100.0) ;
Serial.print("rtd: 0x") ; Serial.print(rtd, HEX) ;
Serial.print(", ohms: ") ; Serial.println(ohms, 2) ;
// compare lookup table and common computational methods
Tlut = PT100.celsius(ohmsx100) ; // NoobNote: LUT== LookUp Table
Tcvd = PT100.celsius_cvd(ohms) ; // Callendar-Van Dusen calc
Tcube = PT100.celsius_cubic(ohms) ; // Cubic eqn calc
Tpoly = PT100.celsius_polynomial(ohms) ; // 5th order polynomial
Trpoly = PT100.celsius_rationalpolynomial(ohms) ; // ugly rational polynomial quotient
Serial.print("Tlut = ") ; Serial.print(Tlut , 2) ; Serial.println(" C (exact)") ;
Serial.print("Tcvd = ") ; Serial.print(Tcvd , 2) ; Serial.println(" C") ;
Serial.print("Tcube = ") ; Serial.print(Tcube , 2) ; Serial.println(" C") ;
Serial.print("Tpoly = ") ; Serial.print(Tpoly , 2) ; Serial.println(" C") ;
Serial.print("Trpoly = ") ; Serial.print(Trpoly, 2) ; Serial.println(" C") ;
Serial.println();
delay(2000);
}