Hi all,
firstly, let me apologise for my complete lack of anything electronic &/or software.
This is my first foray into this area & I don’t have anyone in my circle of friends who can help me.
.
I want to get 2 x MLX90614 IR Thermometers to talk with the Electric Imp via the i2c12 & i2c89 ports (at least that’s what I think is possible).
.
For my first test, I followed Joel Wehr’s excellent tutorial on the Adafruit site regarding connecting a MAX31855 Thermocouple to the Electric Imp & have it communicate out via Xively & Twitter.
.
To my amazement; despite no understanding of how it works, not any previous knowledge of what Xively & Twitter were, I was able to get it going in a matter of minutes.
.
Buoyed by that success, I tried to adapt Joel Wehr’s project to the reference document I found on the Electric Imp main website regarding getting a “112 Temp Sensor” to talk to the i2c89 port.
.
I used another project on the bildr website to get a handle on the wiring of the MLX90614 for i2c.
.
Now that’s where my particular level of understanding ends.
.
I’ve uploaded the following DEVICE code:
.
`
// I’m trying to adapt the code from Joel Wehr
// regarding the MAX31855 thermocouple that posts to Xively & Twitter
// to work with a MLX90614 Infrared Thermometer
//
// To do that, I’m trying to adapt the
// Electric Imp Resources code
// regarding the i2c 112Temp Sensor
//
// Unfortunately, I’ve got no idea what I’m doing
// Hope I don’t fry anything
//Imp Pins for MLX90614 using i2c89
//
// imp 1 uassigned
// imp 2 unassigned
// imp 5 unassigned
// imp 7 unassigned
// imp 8 SCL
// imp 9 SDA
const TMP112 = 0x92;
const TEMP = 0x00;
const DEG_PER_COUNT = 0.0625;
// we need this for when we read a value
function twos_comp(value, mask) {
value = ~(value & mask) + 1;
return value & mask;
}
function read_c(i2c) {
local result = i2c.read(TMP112, format("%c", TEMP), 2);
local temp = (result[0] << 8) + result[1];
local mask = 0x0FFF;
local sign_mask = 0x0800;
local offset = 4;
temp = (temp >> offset) & mask;
if (temp & sign_mask) {
temp = -1.0 * (twos_comp(temp, mask));
}
return temp * DEG_PER_COUNT;
}
tmp112 <- hardware.i2c89;
tmp112.configure(CLOCK_SPEED_50_KHZ);
server.log(read_c(tmp112));
// Send reading to Xively
agent.send(“Xively”, tmp112);
// Configure with the server
imp.configure(“MLX_90614_IR_Thermometer”, [], []);
. This is what I see in the log: <i>.2013-11-20 21:04:40 UTC+11: [Status] Device booting 2013-11-20 21:04:40 UTC+11: [Device] ERROR: the index '0' does not exist 2013-11-20 21:04:40 UTC+11: [Device] ERROR: at read_c:33 2013-11-20 21:04:40 UTC+11: [Device] ERROR: from main:49 2013-11-20 21:04:45 UTC+11: [Power State] Power state: online=>offline 2013-11-20 21:04:51 UTC+11: [Power State] Power state: offline=>online 2013-11-20 21:04:51 UTC+11: [Status] Device booting</i> . This is the code that I think the error is referring to (I've inserted from line 31 to 49 below here) .
function read_c(i2c) {
local result = i2c.read(TMP112, format("%c", TEMP), 2);
local temp = (result[0] << 8) + result[1];
local mask = 0x0FFF;
local sign_mask = 0x0800;
local offset = 4;
temp = (temp >> offset) & mask;
if (temp & sign_mask) {
temp = -1.0 * (twos_comp(temp, mask));
}
return temp * DEG_PER_COUNT;
}
tmp112 <- hardware.i2c89;
tmp112.configure(CLOCK_SPEED_50_KHZ);
server.log(read_c(tmp112));
`
.
I really don’t know what the error refers to, nor how to fix it.
I was hoping that some kind person on here may be able to help me understand what the error is & how to rectify it.
.
Many thanks in advance,
duBe