local temperature = reply[4];
temperature *= 256;
temperature += reply[5];
temperature /= 10.0;
temperature *= (9.0/5.0);
temperature += 32.0
server.log(format("temperature=%.02f F, humidity=%.02f %%R.H.", temperature, humidity))
server.show(format("%.02f F, %.02f %%R.H.", temperature, humidity))
}
else {
server.log(“bad reply from i2c:” +phex(reply))
}
imp.wakeup(15, bigLoop); // sleep for 5 min.
} bigLoop();`
Hope this helps. btw, you must add pull-up resistors to SDA and SCL. Also the device seems to work better if you use Vin
I am planning going to power my April board with 5VDC by way of the VIN and GND terminals. I’m also planning on pulling the SCL and SDA lines to the 3.3v terminal on the April board with 10K resistors. Am I correct in doing so?
I’ve been using your code successfully for the past 24 hours and all of a sudden, I started getting the following errors one after another:
2014-01-10 23:05:05 UTC-5: [Status] Device booting; 3.18% program storage used
2014-01-10 23:05:05 UTC-5: [Device] ERROR: the index ‘0’ does not exist
2014-01-10 23:05:05 UTC-5: [Device] ERROR: at bigLoop:23
2014-01-10 23:05:05 UTC-5: [Device] ERROR: from main:49
line 23 is:
if ( reply[0] == 0x03 && reply[1] == 0x04) {
It would seem that reply is not an array any more. That would figure if the i2c read failed due to there being a problem with the sensor or the wiring to it?
I opened the AM2315, found the conductors from the cable twisted what I thought was a bit excessively, straightened them out and voila! It started working, again. I’ve used one of the sensors in the field for a couple of months with a Ruggeduino and it’s been rock solid. I’m hoping the issue here was simply a bad connection due to the wires being twisted. I really enjoy working with the imp, so I’m hoping this problem is behind me. The good news is that I cleaned up some of my sloppy code and learned quite a bit in the process. Resolving problems is always a great learning opportunity if you’re persistent!
Any feedback on why the i2c address is coded as “local i2c = 0x5c<<1;” instead of “local i2c = 0xB8” when they’re the same, the official address in the documentation is “0xBC” and the two are equivalent?