MAX31856 Example for Particle

Hello Community!

I have been a lurker for a few years now, and have run into an area where I have hit a wall. I have used a lot of DS18B20 Thermocouples for kegerator and space heater projects and was hoping to start using some K-Type thermocouples for a coffee roasting project and some beer brewing upgrades, but I cannot for the life of me get the Adafruit MAX31856 to work with a Photon. There is a Particle library ‘MAX31856TC’ for this board but no example and I am struggling to create code to work with it. I have tried porting the Adafruit library (which looks much different than the current Particle library), example code and using modified MAX31855 libraries to no avail.

I was hoping there was some example code out there to pull temperatures from this board using Particle. Hopefully this will also help out many others in the future, as there aren’t any Particle examples I could dig up for the updated board.

Thank you so much in advance and Cheers!

Since the interface for the MAX3856TC library is very simple I’d think a simple measuring sample would be rather straight forward to implement.

But as it turns out, when visiting the GitHub repo for the library there is a sample after all
https://github.com/jcalcote/MAX31856/blob/master/firmware/examples/MAX31856TC/MAX31856TC.ino

Thank you ScruffR, I appreciate the reply. The code referenced above and MAX31856TC library only appear to switch between two MAX31856 boards using the CS control pins. When the sample code is run it does not find the boards, sending the NO_MAX31856 case. I do not see why the SCK, SDO and SDI pins are not used, like the Adafruit Library. Based off the documentation, aren’t they also needed to control the board?

Here is the Adafruit product page and library:

I guess because HW SPI is used which is hardwired to A3~A5

Look here

MAX31856TC::MAX31856TC(int cs)
{
    _cs = cs;

    // Initialize SPI firmware API
    // SPI mode 1 or 3 required - chip can detect polarity and
    // can work either way but SPI must read on the rising edge
    SPI.begin(_cs);
    SPI.setDataMode(SPI_MODE1);
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockSpeed(10, MHZ);

    // Add input pull up to MISO to detect MAX fault
    pinMode(MISO, INPUT_PULLUP);

    // Manage cs line separately
    pinMode(_cs, OUTPUT);

    // Default cs pin state
    digitalWrite(_cs, HIGH);

    // Set up the shadow registers with the default values
    byte reg[NUM_REGISTERS] = {0x00,0x03,0xff,0x7f,0xc0,0x7f,0xff,0x80,0,0,0,0};
    for (int i = 0; i < NUM_REGISTERS; i++)
        _registers[i] = reg[i];
}

BTW, the Adafruit page you linked to does also talk about HW SPI

Oh, it works! I wasn’t aware that the SPI function specifically called out hardwired pins. I now see other posts of yours referring to the A3-A5. I appreciate the help on this, thank you!

2 Likes