Reputation: 1
i am getting repeated invalid data when connect MLX90614 with Logicrom SPARK board.. I am using PlatformIO with logicromSDK framework. its either connection or another configuration i dont know.. will writing in EEPROM will work...anyone have changes to made ...will be great help.. code:
#define MLX90614_I2C_ADDR 0x5A<<1
// Function to read temperature from MLX90614
int read_mlx90614_temp(uint8_t command, float *temperature)
{
uint8_t rdbuf[3];
uint16_t temp_data;
int ret;
ret = i2c_hw_write(I2C_PORT_0, MLX90614_I2C_ADDR, &command, 1);
printf("ret_i2c_write: %d\n", ret);
if (ret != 1)
{
printf("Failed to write to MLX90614 sensor\n");
return -1;
}
usleep(50000); // Increase delay to ensure the sensor has time to process
ret = i2c_hw_read(I2C_PORT_0, MLX90614_I2C_ADDR, rdbuf, 3);
printf("ret_i2c_read: %d\n", ret);
if (ret != 3)
{
printf("Failed to read from MLX90614 sensor\n");
return -1;
}
// Check for invalid data
if ((rdbuf[0] == 0xFF && rdbuf[1] == 0xFF && rdbuf[2] == 0xFF) ||
(rdbuf[0] == 0x00 && rdbuf[1] == 0x00 && rdbuf[2] == 0x00))
{
printf("Raw data: 0x%02X 0x%02X 0x%02X\n", rdbuf[0], rdbuf[1], rdbuf[2]);
printf("Invalid data received from MLX90614 sensor\n");
return -1;
}
printf("Raw data: 0x%02X 0x%02X 0x%02X\n", rdbuf[0], rdbuf[1], rdbuf[2]);
temp_data = rdbuf[0] | (rdbuf[1] << 8);
// Convert raw data to temperature in Celsius
*temperature = (temp_data * 0.02) - 273.15; // Convert to Celsius
return 0;
}
in main we have call both temperature pins address
int main(int argc, char *argv[])
{
int ret;
float objectTemp, ambientTemp;
logicrom_init(STDIO_PORT, urc_callback);
printf("System Ready\n");
sleep(5);
ret = i2c_hw_init(I2C_PORT_0, 100);
printf("\nI2C init: %d [Initialized]\n", ret);
if (ret)
return -1;
while (1)
{
ret = read_mlx90614_temp(0x07, &objectTemp); // Read object temperature
printf("ret_obj: %d\n", ret);
if (ret == 0)
{
printf("Object Temperature: %.2f°C\n", objectTemp);
}
printf("---------\n");
ret = read_mlx90614_temp(0x06, &ambientTemp); // Read ambient temperature
printf("ret_amb: %d\n", ret);
if (ret == 0)
{
printf("Ambient Temperature: %.2f°C\n", ambientTemp);
}
printf("#################\n");
sleep(3);
}
}
output:
I2C init: 0 [Initialized]
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_obj: -1
---------
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_amb: -1
#################
NW: Data Activated
ret_i2c_write: 1
ret_i2c_read: -5
Failed to read from MLX90614 sensor
ret_obj: -1
---------
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_amb: -1
#################
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_obj: -1
---------
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_amb: -1
#################
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_obj: -1
---------
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_amb: -1
#################
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_obj: -1
---------
ret_i2c_write: 1
ret_i2c_read: 3
Raw data: 0xFF 0xFF 0xFF
Invalid data received from MLX90614 sensor
ret_amb: -1
Solution of Recurring ocurring values or configurations setting or proper address of pins
Upvotes: 0
Views: 20