line 118 of wire.cpp checks if i2c_read(...) returns zero, and discards the data if it does not.
i2c_read(...) in Dev2C.h, does not return zero on a successful read. It will return the result of read(...) in AZ3166WiFiUdp.cpp, which returns the result of recvfrom(...) in UDPSocket.h, which returns the number of bytes sent from the buffer.
Modifying Wire.cpp so that it reads in the data regardless of what i2c_read returns removes the issue, though some sort of replacement error handling should probably be added.
END EDIT
I'm using an IoT devkit to read temperature from an MLX90614 sensor, using the kitronik edge connector to link the two. Pins 19 and 20 on the kitronik are being used as SCL and SDA, and I'm using the Adafruit MLX90614 library to read from the sensor. I've been using a Saleae logic analizer to examine the signals being sent between the two.
When I try to read it, the devkit sends the correct signals to the sensor, which sends back replies that correctly represent the current temperature. However, the devkit reports that the signals it is receiving are always 0xff, regardless of what the sensor is sending. So when it reads in two bites representing the temperature, it always reads 0xffff, which on the sensor in question corresponds to 1037.55 degrees celcius. The actual values that the saleae reports from the sensor, (e.g. 0xA7, 0x3A), when processed, convert to an accurate temperature of 27.15, so the sensor appears to be working correctly.
I've checked this with a backup MLX90614 sensor and received the same result. I've also checked it with and without using a pair of 10kOhm resistors to pull up the sda and scl lines by connecting them to the 3v rail of a breadboard, and received the same results.
edit: I thought there was an issue with the voltage, it looks like I was just reading it incorrectly, the voltage appears to be fine.
When I checked the voltage reaching the sensor, it appears to only be 2.1 volts, below the sensor's required minimum of 2.6 volts, despite being hooked up to the 3v VDD pin. The devkit is being powered by a USB connection to a macbook pro. I was initially powering an Atlas serial port expander as well, but the behavior and low voltage persists even when the MLX90614 sensor is the only device being powered.
The original code I used to check the input from the sensor:
include
include
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
//this emulates the function of the Adafruit_MLX90614 "readAmbientTempC()" function, but displays the bytes received from the sensor.
float read16() {
uint16_t ret;
Wire.beginTransmission(0x5A); // start transmission to device
Wire.write(0x07); // sends register address to read from
Wire.endTransmission(false); // end transmission
Wire.requestFrom(0x5A, (uint8_t)3);// send data n-bytes read
ret = Wire.read(); // receive DATA
ret |= Wire.read() << 8; // receive DATA
uint8_t pec = Wire.read(); //crc check, not used
Serial.println(ret, HEX); //prints the two bytes the arduino recieves
float processed = (ret * 0.02) - 273.15; //converts recieved data into celcius
return processed;
}
EDIT: PROBLEM FOUND
line 118 of wire.cpp checks if i2c_read(...) returns zero, and discards the data if it does not.
i2c_read(...) in Dev2C.h, does not return zero on a successful read. It will return the result of read(...) in AZ3166WiFiUdp.cpp, which returns the result of recvfrom(...) in UDPSocket.h, which returns the number of bytes sent from the buffer.
Modifying Wire.cpp so that it reads in the data regardless of what i2c_read returns removes the issue, though some sort of replacement error handling should probably be added.
END EDIT
I'm using an IoT devkit to read temperature from an MLX90614 sensor, using the kitronik edge connector to link the two. Pins 19 and 20 on the kitronik are being used as SCL and SDA, and I'm using the Adafruit MLX90614 library to read from the sensor. I've been using a Saleae logic analizer to examine the signals being sent between the two. When I try to read it, the devkit sends the correct signals to the sensor, which sends back replies that correctly represent the current temperature. However, the devkit reports that the signals it is receiving are always 0xff, regardless of what the sensor is sending. So when it reads in two bites representing the temperature, it always reads 0xffff, which on the sensor in question corresponds to 1037.55 degrees celcius. The actual values that the saleae reports from the sensor, (e.g. 0xA7, 0x3A), when processed, convert to an accurate temperature of 27.15, so the sensor appears to be working correctly.![screen shot 2018-09-18 at 6 17 07 pm](https://user-images.githubusercontent.com/43284367/45725345-506ec200-bb6f-11e8-97bc-9413a663e85e.png)
I've checked this with a backup MLX90614 sensor and received the same result. I've also checked it with and without using a pair of 10kOhm resistors to pull up the sda and scl lines by connecting them to the 3v rail of a breadboard, and received the same results.
edit: I thought there was an issue with the voltage, it looks like I was just reading it incorrectly, the voltage appears to be fine.
When I checked the voltage reaching the sensor, it appears to only be 2.1 volts, below the sensor's required minimum of 2.6 volts, despite being hooked up to the 3v VDD pin. The devkit is being powered by a USB connection to a macbook pro. I was initially powering an Atlas serial port expander as well, but the behavior and low voltage persists even when the MLX90614 sensor is the only device being powered.
edit: I'm testing out code in this repository: https://github.com/douglas-johnston/testing-i2c-on-AZ3166
The original code I used to check the input from the sensor:
include
include
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
//this emulates the function of the Adafruit_MLX90614 "readAmbientTempC()" function, but displays the bytes received from the sensor.
float read16() { uint16_t ret;
Wire.beginTransmission(0x5A); // start transmission to device Wire.write(0x07); // sends register address to read from Wire.endTransmission(false); // end transmission
Wire.requestFrom(0x5A, (uint8_t)3);// send data n-bytes read ret = Wire.read(); // receive DATA ret |= Wire.read() << 8; // receive DATA uint8_t pec = Wire.read(); //crc check, not used Serial.println(ret, HEX); //prints the two bytes the arduino recieves float processed = (ret * 0.02) - 273.15; //converts recieved data into celcius return processed; }
void setup() { Serial.begin(115200); mlx.begin();
Serial.println(read16()); Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); Serial.print("C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("C"); }
void loop() {
}