Do you guys know what kind of serial.prints/writes changes I need to make in this sketch to make the output in this format?
Thanks!
send this out every second for the 15 temps.
ChannelNumber Description value value mappedvalue ChannelNumber Description value value mappedvalue
etc....for the 15 total
#include <SPI.h>
byte SSarray[] = {
10,7,6,5,4,21,20,19,18,17,16,15,14,29,28}; // slave select pins. See Bobuino pins_arduino.h & schematic
byte config_write = 0x80;
byte RTD_MSB_write = 0x81; // not valid
byte RTD_LSB_write = 0x82; // not valid
byte High_Fault_Threshold_MSB_write = 0x83;
byte High_Fault_Threshold_LSB_write = 0x84;
byte Low_Fault_Threshold_MSB_write = 0x85;
byte Low_Fault_Threshold_LSB_write = 0x86;
byte Fault_Status_write = 0x87; // not valid
byte config_read = 0x00;
byte RTD_MSB_read = 0x01;
byte RTD_LSB_read = 0x02;
byte High_Fault_Threshold_MSB_read = 0x03; // 83h FFh R/W
byte High_Fault_Threshold_LSB_read = 0x04; // 84h FFh R/W
byte Low_Fault_Threshold_MSB_read = 0x05; // 85h 00h R/
byte Low_Fault_Threshold_LSB_read = 0x06; // 86h 00h R/W
byte Fault_Status = 0x07; // read 07h R
int ADCcode;
byte convert;
float temperature;
byte Fault_Error;
byte x=0; // chip counter
byte y=0; // register counter
byte msb_rtd;
byte lsb_rtd;
byte incomingByte;
byte incomingByte1;
byte incomingByte2;
byte incomingByte3;
byte incomingByte4;
unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedMicros;
unsigned long interval = 100UL; // Set lo
byte regHi;
byte regLo;
byte regNo;
byte valueHi;
byte valueLo;
byte value;
byte command;
byte hiNib;
byte loNib;
byte channelCount = 14;
static float a = 0.00390830;
static float b = -0.0000005775;
static float c = -0.00000000000418301;
float Reference_Resistor = 4000.; //Reference Resistor installed on the board.
float RTD_Resistance = 1000.;
void setup(){
// set up output pins
for (x=0; x<15; x=x+1){
pinMode(SSarray[x], OUTPUT); // set Slave Select pins as outputs
digitalWrite (SSarray[x], HIGH); // set Slave Select pins high
}
Serial.begin(115200);
SPI.begin(); //
SPI.setDataMode(SPI_MODE1); // choices 0,1,2,3 - use 1,3 for MAX31865
SPI.setClockDivider(SPI_CLOCK_DIV128); // choices 2,4,8,16,32,64,128. 2 = 8 MHz, 4 = 4 MHz, 8 = 1 MHz, etc. 5 MHz max for MAX31865
x=0; // setup "chip pointer" x for use later, eventually loop thru 15 MAX31865 chips
} // end setup
void loop(){
// Alternate between looking for incoming message, read/send out a temperature
currentMicros = micros();
elapsedMicros = currentMicros - previousMicros;
if (elapsedMicros >=1000000UL){ // 1 second? take a reading
previousMicros = previousMicros + 1000000UL;
channelCount = channelCount +1;
if (channelCount ==15){
channelCount = 0; // reset
}
Serial.println("");
Serial.print ("Channel ");
Serial.print (channelCount+1);
Serial.print (" ");
// check fault register
// send read address, read the data
digitalWrite (SSarray[channelCount], LOW);
digitalWrite (SSarray[channelCount], LOW);
SPI.transfer(Fault_Status); // send out register #
delayMicroseconds(10);
Fault_Error = SPI.transfer(0); // read register contents back
digitalWrite(SSarray[channelCount], HIGH);
Serial.print ("Fault code ");
Serial.print (Fault_Error, HEX);
Serial.println(" ");
if (Fault_Error == 0){
// send write address, data to start a conversion
digitalWrite (SSarray[channelCount], LOW);
digitalWrite (SSarray[channelCount], LOW);
SPI.transfer(0x80); // send out register #
delayMicroseconds(10); // see if slight delay between write & read helps
SPI.transfer(0xA0); // send out data 0b10100000 or 0b110000?
digitalWrite(SSarray[channelCount], HIGH);
delay (55); // conversion time
digitalWrite (SSarray[channelCount], LOW);
digitalWrite (SSarray[channelCount], LOW);
SPI.transfer(RTD_MSB_read); // send out register #
delayMicroseconds(10);
msb_rtd = SPI.transfer(0); // read register contents back
digitalWrite(SSarray[channelCount], HIGH);
digitalWrite (SSarray[channelCount], LOW);
digitalWrite (SSarray[channelCount], LOW);
SPI.transfer(RTD_LSB_read); // send out register #
delayMicroseconds(10);
lsb_rtd = SPI.transfer(0); // read register contents back
digitalWrite(SSarray[channelCount], HIGH);
Serial.print ("ADCcode = ");
ADCcode = (msb_rtd<<8) + lsb_rtd;
Serial.println (ADCcode, HEX);
ADCcode = ADCcode >>1;
temperature = float((ADCcode/32.) - 256.);
Serial.print ("Linear Temperature Deg C ");
Serial.println (temperature, 1);
// Hani conversion
float RTD = ((msb_rtd << 7)+((lsb_rtd & 0xFE) >> 1)); //Combining RTD_MSB and RTD_LSB to protray decimal value. Removing MSB and LSB during shifting/Anding
float R = (RTD*Reference_Resistor)/32768; //Conversion of ADC RTD code to resistance
float Temp = -RTD_Resistance*a + sqrt(RTD_Resistance*RTD_Resistance*a*a - 4*RTD_Resistance*b*(RTD_Resistance-R)); //Conversion of RTD resistance to Temperature
Temp = Temp/(2*RTD_Resistance*b);
Serial.print("Hani Temperature: ");
Serial.println(Temp, 1 ); //Printing Temperature on console
Serial.println("");
byte fault_test = lsb_rtd&0x01;
if (fault_test == 0x01){
Serial.print ("Channel ");
Serial.print (channelCount+1);
Serial.print (" Error was detected. The RTD resistance measured is not within the range specified in the Threshold Registers.");
Serial.println(" ");
}
} // 1 channel/second test
}
else {
// fault detected
byte temp = 0; //temporary variable created: Purpose is to find out which error bit is set in the fault register
temp = Fault_Error & 0x80; //Logic Anding fault register contents with 0b10000000 to detect for D7 error bit
if(temp>0) {
Serial.println("Bit D7 is Set. Is the RTD device disconnected from RTD+ or RTD-? Please verify your connection and High Fault Threshold Value");
Serial.println("");
}
temp = Fault_Error & 0x40;
if(temp>0) {
Serial.println("Bit D6 is Set. It's Possible your RTD+ and RTD- is shorted. Please verify your connection and your Low Fault Threshold Value.");
Serial.println("");
}
temp = Fault_Error & 0x20;
if(temp>0){
Serial.println("Bit D5 is Set. Vref- is greater than 0.85 * Vbias");
Serial.println("");
}
temp = Fault_Error & 0x10;
if(temp>0){
Serial.println("Bit D4 is Set. Please refer to data sheet for more information");
Serial.println("");
}
temp = Fault_Error &0x08;
if(temp>0){
Serial.println("Bit D3 is Set. Please refer to data sheet for more information");
Serial.println("");
}
temp = Fault_Error &0x04;
if(temp>0){
Serial.println("Bit D2 is Set. Please refer to data sheet for more information");
Serial.println("");
}
// send write address to clear faults
digitalWrite (SSarray[channelCount], LOW);
digitalWrite (SSarray[channelCount], LOW);
SPI.transfer(0x80); // send out register #
delayMicroseconds(10); // see if slight delay between write & read helps
SPI.transfer(0b10000010); // send out data - Fault register isn't cleared automatically. Users are expected to clear it after every fault.
digitalWrite(SSarray[channelCount], HIGH);
delay (700);
// send write address to clear faults
digitalWrite (SSarray[channelCount], LOW);
digitalWrite (SSarray[channelCount], LOW);
SPI.transfer(0x80); // send out register #
delayMicroseconds(10); // see if slight delay between write & read helps
SPI.transfer(0b10100000); // send out data - Setting the device in autoconfiguration again. 0b10100000 or 0b11000000?
digitalWrite(SSarray[channelCount], HIGH);
delay (700);
}
}