thank you for the information of the new return value from "Wire.end".
Do you know why the second part in "MLX90640_I2CWrite" worked?
int MLX90640_I2CWrite(uint8_t _deviceAddress, unsigned int writeAddress, uint16_t data)
Wire.write(writeAddress >> 8); //MSB
Wire.write(writeAddress & 0xFF); //LSB
Wire.write(data >> 8); //MSB
Wire.write(data & 0xFF); //LSB
if (Wire.endTransmission() != 0)
//Sensor did not ACK
Serial.println("Error: Sensor did not ack");
I changed "MLX90640_I2CRead" to:
int MLX90640_I2CRead(uint8_t _deviceAddress, unsigned int startAddress, unsigned int nWordsRead, uint16_t *data)
//Caller passes number of 'unsigned ints to read', increase this to 'bytes to read'
uint16_t bytesRemaining = nWordsRead * 2;
//It doesn't look like sequential read works. Do we need to re-issue the address command each time?
uint16_t dataSpot = 0; //Start at beginning of array
//Setup a series of chunked I2C_BUFFER_LENGTH byte reads
while (bytesRemaining > 0)
Wire.write(startAddress >> 8); //MSB
Wire.write(startAddress & 0xFF); //LSB
if (Wire.endTransmission(false) != 7) //Do not release bus
Serial.println("No ack read");
return (0); //Sensor did not ACK
uint16_t numberOfBytesToRead = bytesRemaining;