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 )
`// 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()`