Hi again,
I’ve just hit a bit of a problem with my project:
I was in a hurry to wire-up my other Imp and “fried” the MLX90614 on Imp_2 i2c12.
Not so much of a problem I thought but as it turns out, this causes the code to simply stop executing the first time it is asked to check the value of i2c12.
I guess I was supposed to put in some better kind of error handling, would anyone mind helping to educate me around this kind of thing?
Here’s the code that calls i2c12:
`/*
I blew a sensor up, so gotta comment this out until I get a new one
really need to get some error handling in here to stop
the Imp locking up if a peripheral device doesn’t report in
*/
/*
local bytes_12=hardware.i2c12.read(0xb4, “\x07”, 3);
if (typeof(bytes_12)!= “string”) {
server.log("i2c12 read error: "+bytes_12);
return;
}
local data_low_12 = bytes_12[0];
local data_high_12 = bytes_12[1];
server.log("data_low_12 is: "+data_low_12);
server.log("data_high_12 is: "+data_high_12);
// The conversions below are taken straight from a bildr Arduio project
// http://bildr.org/2011/02/mlx90614-arduino/
//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
local tempFactor_12 = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
local tempData_12 = 0x0000; // zero out the data
//frac; // data past the decimal point
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData_12 = (((data_high_12 & 0x007F) << 8) + data_low_12);
tempData_12 = (tempData_12 * tempFactor_12)-0.01;
celcius_12 = tempData_12 - 280.15;
*/
// wakeup every 5 seconds and read temperature
imp.wakeup(5, read_c);
server.log("The temperature on i2c89 sensor is " +celcius_89 +"C");
/*
I blew a sensor up, so gotta comment it out until I get a new one
really need to get some error handling in here to stop
the Imp locking up if a peripheral device doesn’t report in
*/
// server.log("The temperature on i2c12 sensor is " +celcius_12 +“C”);
/*
To send both i2c89 and i2c12 readings to Xively on different channels:
create a table called "thermotemps"
which hold the variables "thermo1temp" and "thermo2temp"
assign the value of variable "celcius_89" to "thermo1temp"
assign the value of variable "celcius_12" to "thermo2temp"
*/
local thermotemps = {"thermo1temp" : celcius_89, "thermo2temp" : celcius_12};
// pass the above created table "thermotemps" to the "Xively" AGENT
agent.send("Xively", thermotemps);`
I just hard-coded the value of i2c12 to be “0” so that the pass to the agent would still have something to pass along.
Many thanks in advance,
duBe