Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 1 month ago.
Problems with MLX90615 infrared temperature sensor
I am trying to acquire temperature data with a MLX90615 infrared temperature sensor. I have connected Vdd to 3.3V, Vss to ground, SDA and SCL to PB9 and PB8 pulled up to 3.3V with 12 kOhm resistances. I am using a NUCLEO L152RE board with the online MBED compiler. What I get is, for both ambient and object temperature, always the maximum value (255 for both the least significant byte and most significant byte). Following is the code I have created.
- include "mbed.h"
- define TO_REG_ADRS (0x27) Object temperature address
- define TA_REG_ADRS (0x26) Ambient temperature address
- define SENSOR_ADDR (0x00) IR sensor address write
- define SENSOR_ADDR_RD (0x01) IR sensor address read
I2C i2c(PB_9, PB_8); Serial pc(PA_2, PA_3);
char d1, d2, d3; char my_char, ch_test; float to, ta;
int main() { pc.printf("USART TEST OK\n\r"); i2c.frequency(20000); wait(0.1);
while (1) { if (pc.readable()) { my_char = pc.getc(); if (my_char == 'a') { do { do { do { i2c.stop(); wait(0.2); i2c.start(); ch_test = i2c.write(SENSOR_ADDR); } while (ch_test == 0);
ch_test = i2c.write(TO_REG_ADRS); } while (ch_test == 0);
i2c.start(); ch_test = i2c.write(SENSOR_ADDR_RD); } while (ch_test == 0);
d1 = i2c.read(1); d2 = i2c.read(1); d3 = i2c.read(1); i2c.stop(); wait(0.1); pc.printf("%d %d\n\r", d1, d2); to = d1 + 256*d2; to = to*0.02;
do { do { do { i2c.stop(); wait(0.2); i2c.start(); ch_test = i2c.write(SENSOR_ADDR); } while (ch_test == 0);
ch_test = i2c.write(TA_REG_ADRS); } while (ch_test == 0);
i2c.start(); ch_test = i2c.write(SENSOR_ADDR_RD); } while (ch_test == 0);
d1 = i2c.read(1); d2 = i2c.read(1); d3 = i2c.read(1); i2c.stop(); wait(0.1); pc.printf("%d %d\n\r", d1, d2); ta = d1 + 256*d2; ta = ta*0.02;
pc.printf("OBJECT TEMPERATURE = %f \n\r", to); pc.printf("AMBIENT TEMPERATURE = %f \n\r", ta); pc.printf("\n\r"); } else if (my_char == 's') { pc.printf("USART TEST OK\n\r"); } } }
}