S
I have been working on the mlx90614 for the last day and can communicate successfully with 6 on an I2C bus, but am am receiving an overwhelming number of errors. Right now it hovers around 25% of attempts to read the sensor. I believe it could be related to a timing issue of the I2C communication in micropython.
Some errors are the result of a bad read of the I2C data, which can be verified if you read the PEC byte after the data. The third byte should come back with a crc-8 value, but sometimes it comes back as 0xFF, as if the mlx90614 is one byte ahead of the lopy.
The other error is related to readfrom_mem function in i2c. This error produces an OSError exception about every one in four attempts. In other mlx90614 libraries the flow for reading bytes is slightly more complicated, for example
// send the slave address then the command and set any
// error status bits returned by the write
Wire.beginTransmission(_addr);
Wire.write(cmd);
_rwError |= (1 << Wire.endTransmission(false)) >> 1;
// experimentally determined delay to prevent read errors
// (manufacturer's data sheet has left something out)
delayMicroseconds(30);
// resend slave address then get the 3 returned bytes
Wire.requestFrom(_addr, (uint8_t)3);
// data is returned as 2 bytes little endian
val = Wire.read();
val |= Wire.read() << 8;
// read the PEC (CRC-8 of all bytes)
_pec = Wire.read();
return val;
Is there anyway to imitate this flow control? Using the above style code on an Arduino I receive no errors and do not have to do coding gymnastics to control errors.