Currently working on a project to collect temperature data from thermocouples and transmit that data over the BLE. I have managed to get the MAX31856 to communicate by SPI with an arduino uno however when connecting the pins to the Nano the communication seems to fail. The values reported are all zero instead of the actual temperatures. The error does not seem to trigger any of the error detection in the code, but when connected with the Nano I am able to remove the MISO wire with no error. leading me to believe the MAX31856 isn't properly pulling the MISO line on the nano but is on the uno. I have seen other posts regarding SPI com issues with the Nano any help would be appreciated. Note: the spi.h is not orange in my code like normal when adding a library.
#include <ArduinoBLE.h>
#include "PlayingWithFusion_MAX31856.h"
#include "PlayingWithFusion_MAX31856_STRUCT.h"
#include <SPI.h>
uint8_t TC0_CS = 10;
uint8_t TC1_CS = 9;
PWF_MAX31856 thermocouple0(TC0_CS);
PWF_MAX31856 thermocouple1(TC1_CS);
const int BLE_LED_PIN = LED_BUILTIN;
BLEService testService("1853");
BLEFloatCharacteristic ThermoCh0("1999-00", BLERead | BLENotify);
BLEFloatCharacteristic ThermoCh1("1999-01", BLERead | BLENotify);
void setup() {
// put your setup code here, to run once:
SPI.begin(); // begin SPI
SPI.beginTransaction(SPISettings(1000000,MSBFIRST, SPI_MODE1));
thermocouple0.MAX31856_config(J_TYPE, CUTOFF_60HZ, AVG_SEL_4SAMP, CMODE_AUTO);
thermocouple1.MAX31856_config(J_TYPE, CUTOFF_60HZ, AVG_SEL_4SAMP, CMODE_AUTO);
pinMode( BLE_LED_PIN, OUTPUT );
if( setupBleMode() )
{
digitalWrite( BLE_LED_PIN, HIGH );
}
}
void loop() {
// put your main code here, to run repeatedly:
BLEDevice central = BLE.central();
delay(1000); // 500ms delay... can be as fast as ~100ms in continuous mode, 1 samp avg
static struct var_max31856 TC_CH0, TC_CH1;
double tmp;
struct var_max31856 *tc_ptr;
// Read CH 0
tc_ptr = &TC_CH0; // set pointer
thermocouple0.MAX31856_update(tc_ptr); // Update MAX31856 channel 0
// Read CH 1
tc_ptr = &TC_CH1; // set pointer
thermocouple1.MAX31856_update(tc_ptr); // Update MAX31856 channel 1
// ##### Print information to serial port ####
// Thermocouple channel 0
Serial.print("Thermocouple 0: "); // Print TC0 header
if(TC_CH0.status)
{
// lots of faults possible at once, technically... handle all 8 of them
// Faults detected can be masked, please refer to library file to enable faults you want represented
Serial.println("fault(s) detected");
Serial.print("Fault List: ");
if(0x01 & TC_CH0.status){Serial.print("OPEN ");}
if(0x02 & TC_CH0.status){Serial.print("Overvolt/Undervolt ");}
if(0x04 & TC_CH0.status){Serial.print("TC Low ");}
if(0x08 & TC_CH0.status){Serial.print("TC High ");}
if(0x10 & TC_CH0.status){Serial.print("CJ Low ");}
if(0x20 & TC_CH0.status){Serial.print("CJ High ");}
if(0x40 & TC_CH0.status){Serial.print("TC Range ");}
if(0x80 & TC_CH0.status){Serial.print("CJ Range ");}
Serial.println(" ");
}
else // no fault, print temperature data
{
Serial.println("no faults detected");
// MAX31856 Internal Temp
tmp = (double)TC_CH0.ref_jcn_temp * 0.015625; // convert fixed pt # to double
Serial.print("Tint = "); // print internal temp heading
if((-100 > tmp) || (150 < tmp)){Serial.println("unknown fault");}
else{Serial.println(tmp);}
// MAX31856 External (thermocouple) Temp
tmp = (double)TC_CH0.lin_tc_temp * 0.0078125; // convert fixed pt # to double
Serial.print("TC Temp = "); // print TC temp heading
Serial.println(tmp);
ThermoCh0.writeValue(tmp);
}
// Thermocouple channel 1
Serial.print("Thermocouple 1: "); // Print TC0 header
if(TC_CH1.status)
{
// lots of faults possible at once, technically... handle all 8 of them
// Faults detected can be masked, please refer to library file to enable faults you want represented
Serial.println("fault(s) detected");
Serial.print("Fault List: ");
if(0x01 & TC_CH1.status){Serial.print("OPEN ");}
if(0x02 & TC_CH1.status){Serial.print("Overvolt/Undervolt ");}
if(0x04 & TC_CH1.status){Serial.print("TC Low ");}
if(0x08 & TC_CH1.status){Serial.print("TC High ");}
if(0x10 & TC_CH1.status){Serial.print("CJ Low ");}
if(0x20 & TC_CH1.status){Serial.print("CJ High ");}
if(0x40 & TC_CH1.status){Serial.print("TC Range ");}
if(0x80 & TC_CH1.status){Serial.print("CJ Range ");}
Serial.println(" ");
}
else // no fault, print temperature data
{
Serial.println("no faults detected");
// MAX31856 Internal Temp
tmp = (double)TC_CH1.ref_jcn_temp * 0.015625; // convert fixed pt # to double
Serial.print("Tint = "); // print internal temp heading
if((-100 > tmp) || (150 < tmp)){Serial.println("unknown fault");}
else{Serial.println(tmp);}
// MAX31856 External (thermocouple) Temp
tmp = (double)TC_CH1.lin_tc_temp * 0.0078125; // convert fixed pt # to double
Serial.print("TC Temp = "); // print TC temp heading
Serial.println(tmp);
ThermoCh1.writeValue(tmp);
}
}
bool setupBleMode()
{
if ( !BLE.begin() )
{
return false;
}
// set advertised local name and service UUID:
BLE.setDeviceName( "Arduino Nano 33 BLE" );
BLE.setLocalName( "Arduino Nano 33 BLE" );
BLE.setAdvertisedService( testService );
testService.addCharacteristic(ThermoCh0);
testService.addCharacteristic(ThermoCh1);
BLE.addService( testService );
// start advertising
BLE.advertise();
return true;
}
capstonetest.ino (5.13 KB)
