Max31855 thermocouple not working (Adafruit tutorial)

I am trying to get the max31855 thermocouple board from Adafruit working. I’ve copied the code from github and added a few cosmetic changes and server.log function but no change to the spi readblob line. But I am getting all 0’s returned from the thermocouple board.

I verified the thermocouple board is working and the thermocouple is connected correctly (via Arduino code and a different PID controller). The board is connected to the electric imp per the tutorial (http://learn.adafruit.com/connecting-the-max31855-thermocouple-amplifier-breakout-to-an-electric-imp/get-the-code)

clock=pin1
chip select=pin2
data=pin9

But when I run the dode I get the results:
2014-01-19 18:54:07 UTC-8: [Status] Device booting; 4.56% program storage used
2014-01-19 18:54:07 UTC-8: [Device] Device started as Thermocouple test
2014-01-19 18:54:07 UTC-8: [Device] 0000 0000 0000 0000
2014-01-19 18:54:07 UTC-8: [Device] 0°C
2014-01-19 18:54:07 UTC-8: [Device] 32°F

Here is my code for the device (no agent code):
`
// Read data from MAX31855 chip on Adafruit breakout boards
// Code developed by Electric Imp Forum members rivers,
// mjkuwp94, Brown, as well as Hugo, peter, and others.
// Modified for use by Joel Wehr.
// pins:
// imp 1 CLK
// imp 2 CS
// imp 5 UNASSIGNED
// imp 7 UNASSIGNED
// imp 8 UNASSIGNED
// imp 9 DO

//Configure Pins
spi <- hardware.spi189;
spi.configure(MSB_FIRST | CLOCK_IDLE_LOW , 1000);
chipSelPin <- hardware.pin2;
chipSelPin.configure(DIGITAL_OUT); //chip select

// define variables
farenheit <- 0;
celcius <- 0;

// print binary data (first 16 bits)
function logBin(temp32) {
local res=((temp32[0]&128).tostring()+(temp32[0]&64).tostring()+(temp32[0]&32).tostring()+(temp32[0]&16).tostring());
res+=(" “+(temp32[0]&8).tostring()+(temp32[0]&4).tostring()+(temp32[0]&2).tostring()+(temp32[0]&1).tostring());
res+=(” “+(temp32[1]&128).tostring()+(temp32[1]&64).tostring()+(temp32[1]&32).tostring()+(temp32[1]&16).tostring());
res+=(” "+(temp32[1]&8).tostring()+(temp32[1]&4).tostring()+(temp32[1]&2).tostring()+(temp32[1]&1).tostring());
server.log(res);
}

//Define functions
function readChip189(){
//Get SPI data
chipSelPin.write(0); //pull CS low to start the transmission of temp data
local temp32 = spi.readblob(4); //SPI read is totally completed here
chipSelPin.write(1); // pull CS high
logBin(temp32);

// Begin converting Binary data for chip 1
local tc = 0;
if ((temp32[1] & 1) ==1){
    //Error bit is set
    local errorcode = (temp32[3] & 7);// 7 is B00000111
	local TCErrCount = 0;
	if (errorcode>0){
		//One or more of the three error bits is set
		//B00000001 open circuit
		//B00000010 short to ground
		//B00000100 short to VCC
		switch (errorcode){            
        case 1:
            server.log("TC open circuit");
		    break;
		case 2:         
            server.log("TC short to ground");
		    break;           
        case 3:          
            server.log("TC open circuit and short to ground")
            break;
		case 4:         
            server.log("TC short to VCC");
		    break;
		default:           
            //Bad coding error if you get here
		    break;
		}
		TCErrCount+=1;
		//if there is a fault return this number, or another number of your choice
		 tc= 67108864; 
	}
    else
    {
         server.log("error in SPI read");
    }      
} 
else //No Error code raised
{
	local highbyte =(temp32[0]<<6); //move 8 bits to the left 6 places
	local lowbyte = (temp32[1]>>2);	//move to the right two places	
	tc = highbyte | lowbyte; //now have right-justifed 14 bits but the 14th digit is the sign    
	//Shifting the bits to make sure negative numbers are handled
    //Get the sign indicator into position 31 of the signed 32-bit integer
    //Then, scale the number back down, the right-shift operator of squirrel/impOS
    tc = ((tc<<18)>>18); 
    // Convert to Celcius
	    celcius = (1.0* tc/4.0);
    // Convert to Farenheit
    farenheit = (((celcius*9)/5)+32);
    server.log(celcius + "°C");
    server.log(farenheit + "°F");
    //agent.send("Xively", farenheit);
    imp.wakeup(10, readChip189); //Wakeup every 10 second and read data.
}

}

//Begin executing program
server.log(“Device started as Thermocouple test”);
chipSelPin.write(1); //Set the Chip Select pin to HIGH prior to SPI read
readChip189(); //Read SPI data
`

Have you tried running it with the unmodified code?

Yes, I get the same results when running the code copied directly from the library (attached).

Results:
2014-01-20 08:34:06 UTC-8: [Status] Downloading new code; 3.38% program storage used
2014-01-20 08:34:06 UTC-8: [Device] 32°F
2014-01-20 08:34:06 UTC-8: [Device] 0°C

If that is the case, I’d say the problem is the hardware. Do you have a multimeter that you can check that your chip select pin is driving high? You would need a digital signal analyzer or o-scope to see the SPI signal. I have purchased about 8 of these breakouts from Adafruit and haven’t had any trouble with them.

There is the known issue with Pin 1 and the Sparkfun boards, so that is a possibility to rule out. You could try using SPI_257 instead of the SPI_189 bus, to eliminate that as a possibility. Here is the Imp pin mux:

https://electricimp.com/docs/hardware/imp/pinmux/

Use pin 5 for clock and 2 for data.

I buy all of my April boards through Digikey as they have the best prices. It is nice that the Sparkfun boards don’t come with the jumper populated, as I often remove it and mount the board flush to a prototyping board.

That was the issue. I have a bad pin 1 on my April board :open_mouth:

Thanks for your help Joel, and thanks for the tutorial. I’m working on my internet-connected sous vide cooker.

@cliquot22

PID controller?

PID controller (http://www.auberins.com/?main_page=index&cPath=1)

I should add PID control to my dual probe temp monitor project, but you would need to use the Imp module for access to more pins. Someone needs to sell a module breakout, like the Amber or Aria. The Smartmaker breakout is fine for messing around on a breadboard, but not practical for much else. Maybe I should get on that. :slight_smile: