Two thermocouple input question

I am working on bringing in the temperature of two thermocouple breakout boards. I knocked this together to see if I could at least get the temperature of both at the sequentially. This is my first attempt and I don’t yet have the breakout boards. Would this code at least log both temperatures? (yes the code is heavily borrowed :slight_smile: )

`// assign hardware.pin5 to a global variable
therm1 <- hardware.pin5;
// configure pin5 to be an ANALOG_IN
therm1.configure(ANALOG_IN);

// assign hardware.pin6 to a global variable
therm2 <- hardware.pin6;
// configure pin6 to be an ANALOG_IN
therm2.configure(ANALOG_IN);

// these constants are particular to the thermistor we’re using
// check your datasheet for what values you should be using
const b_therm = 3977.0;
const t0_therm = 298.15;

// the resistor in the circuit (10KΩ)
const R2 = 10000.0;

function GetTemp_F() {
local Vin = hardware.voltage();

local Vout = Vin * therm.read() / 65535.0;
local R_Therm1 = (R2*Vin / Vout) - R2;

local ln_therm1 = math.log(10000.0 / R_Therm);
local temp_K = (t0_therm * b_therm) / (b_therm - t0_therm*ln_therm);

local temp_C = temp_K - 273.15;
local temp_F = temp_C * 9.0 / 5.0 + 32.0;

return temp_F;
}

function GetTemp_F2() {
local Vin = hardware.voltage();

local Vout = Vin * therm.read() / 65535.0;
local R_Therm2 = (R2*Vin / Vout) - R2;

local ln_therm2 = math.log(10000.0 / R_Therm);
local temp_K = (t0_therm * b_therm) / (b_therm - t0_therm*ln_therm);

local temp_C = temp_K - 273.15;
local temp_F = temp_C * 9.0 / 5.0 + 32.0;

return temp_F2;
}

function poll() {
// Get and log Fahrenheit temperature 1
local temp = GetTemp_F();
server.log(temp2 + " F");

// Get and log Fahrenheit temperature 2
local temp2 = GetTemp_F2();
server.log(temp2 + " F");

// wakeup in 5 seconds and read the value again:
imp.wakeup(5.0, poll);

}

poll()`

thermistor or thermocouple?

Not sure at this point, I believe the boards are a thermocouple amplification breakout.

Oh wait, LOL they are coming from Joel so I believe thermocouple.

I am seeing I need to go through the adafruit tutorial to use a thermocouple breakout. kk… heaving reading to do in the morning :slight_smile:

The Adafruit tutorial has all the info that you need to program an Imp for the MAX31855 breakout board. The code is available from the GitHub page listed.

OK so a couple of questions. To add a second MAX31855 would I wire pin 9 of the second board into pin 8 of the first to daisy chain two thermocouples?

Then I would add change the device portion to read:

//Configure Pins hardware.spi189.configure(MSB_FIRST | CLOCK_IDLE_LOW , 1000); hardware.pin2.configure(DIGITAL_OUT); //chip select hardware.pin3.configure(DIGITAL_OUT); //chip select

After that, I would initiate the read by selecting pin 3 instead of two in order to read the second thermocouple board?

Yes, you can read as many chips as you like through SPI as long as you have chip select pins. Pick one of the SPI busses, 257 or 189 and connect the data and clock pins to each board. You want MISO on the Imp connected to DO on the breakout. You can reconfigure the MOSI pin to be chip select if you like, or use any of the other pins.

I’ve been working on a two probe tutorial for a while, and it would be complete if I didn’t keep changing the design. I’ll post code that you can use today with a link to GitHub.

Take a look at this code. It is what I currently use for my impTherm X2 temperature monitor. It has code for a number of handy features. Let me know if you have any questions.

I see you are sending the data to Xively. Is this a requirement or more of an IoT feature? The reason I ask is that I am going to have events trigger depending on the temperature readings and am wondering if it would be best to have that stored locally or on the net.

Not a requirement… just a fun feature. Nothing in the agent is really required if you just want to use the Imp to read temperatures, just examples of interesting things you can do.