Thank you for your reply. I do have pullups on SCL and SDA. I have checked the pinout and even verified that I can read i2C using a melexis IR (and its corresponding addresses)
I modified the code as follows. I have also tried with base address 0x01…
`const SENSITIVITY_EPROM = “\x10”;
const OFFSET_EPROM = “\x12”;
const BASE_ADDRESS = 0x81; //Datasheet says 01. Everybody says 81
fout<-count <- hardware.pin1;
fout.configure(PULSE_COUNTER, 1);
// Imp Pins
// Pin 8 = SCL
// Pin 9 = SDA
// set the i2c clock speed.
hardware.i2c89.configure(CLOCK_SPEED_10_KHZ);
const IMP_INT = 2 //every half second
//=========================================================================================
//=========================================================================================
function read_c() {
local bytes =0;
bytes=hardware.i2c89.read(BASE_ADDRESS, SENSITIVITY_EPROM, 2);
if (typeof bytes == "string") server.log(format("%02x %02x", bytes[0], bytes[1]));
else server.log("i2c error: "+bytes);
bytes=hardware.i2c89.read(BASE_ADDRESS, OFFSET_EPROM, 2);
if (typeof bytes == "string") server.log(format("%02x %02x", bytes[0], bytes[1]));
else server.log("i2c error: "+bytes);
}
//=========================================================================================
function GetFrequency() {
local numPulses = fout.read();
return numPulses;
}
//=========================================================================================
function intIR ()
{
imp.sleep(1);
server.log (“Humidity Sensor Started”);
read_c();
}
//=========================================================================================
function hum ()
{
local freq = GetFrequency();
server.log (freq);
imp.wakeup(IMP_INT, hum);
}
//=========================================================================================
intIR();
hum();`
The output is as follows. I can also affect the fout readout (using a steamer) correctly. I just can seem to read the store i2c values so I can apply the formula.
2014-05-07 08:16:32 UTC-7: [Status] Downloading new code; 3.34% program storage used
2014-05-07 08:16:33 UTC-7: [Device] Humidity Sensor Started
2014-05-07 08:16:33 UTC-7: [Device] i2c error: (null : 0x0)
2014-05-07 08:16:33 UTC-7: [Device] i2c error: (null : 0x0)
2014-05-07 08:16:34 UTC-7: [Device] 7229
2014-05-07 08:16:37 UTC-7: [Device] 7165
2014-05-07 08:16:40 UTC-7: [Device] 7170
2014-05-07 08:16:43 UTC-7: [Device] 7187
2014-05-07 08:16:46 UTC-7: [Device] 7202
2014-05-07 08:00:41 UTC-7: [Device] 7253