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.
9 years, 5 months ago.
F401RE and Infrared Thermometer MLX90614
Hi all,
I'm trying connect the MLX90614 with i2c on a F401RE, but I can't get it to work. I followed this guide http://bildr.org/2011/02/mlx90614-arduino/ and it works correctly on arduino; then I connected it to the F401RE on PB_8, PB_9, 3.3V and GND but I have a write error every time I try to send or read any data. The address is 0x5A, but I tried 0xB4 (0x5A<<1) too
Here is my code
MLX90614
#include "mbed.h" #define MLX90614_REG_TEMP (0x07) // Temperature Register #define MLX90614_ADDR (0xB4) // MLX90614 address I2C i2c(I2C_SDA, I2C_SCL); DigitalOut myled(LED1); Serial pc(SERIAL_TX, SERIAL_RX); int main() { char data_write[2]; char data_read[2]; // scan i2c addresses for (int address=0; address<256; address+=2) { if (!i2c.write(address, NULL, 0)) pc.printf("I2C address 0x%02X: FOUND!\n", address); else pc.printf("I2C address 0x%02X\n", address); } while (1) { data_write[0] = MLX90614_REG_TEMP; int status = i2c.write(MLX90614_ADDR, data_write, 1); if(status != 0) pc.printf("Write failed\n"); status = i2c.read(MLX90614_ADDR, data_read, 2); if(status != 0) pc.printf("Read failed\n"); pc.printf("%d-", (int)data_read[1]); pc.printf("%d\n", (int)data_read[0]); myled = !myled; wait(1.0); } }
Anyone know where am I doing wrong?
Thanks in advance
Regards, Dario
2 Answers
6 years, 11 months ago.
unfortunately the data sheet says you need a repeated start (and not a stop) between the write and the read calls. And unfortunately again I am not able to get a repeated start from mbedOS... notwithstanding the last parameter of the write member function is exactly designed for a repeated start (if true)... still trying to solve the problem...
9 years, 5 months ago.
You can set the slave address of this sensor to any value by using a specific command. Do you get any response to the "scan i2c addresses" part? If so at which address.
Are the wires for SDA, SCL connected correctly, are the pull-ups installed.
I assume the sensor is suitable for 3V3. There also seem to be versions of the sensor that only work on 5V.
I don't get any response to the scan part.
I think i connected correctly, i followed this guide for the connection (http://bildr.org/2011/02/mlx90614-arduino/) then I connected the green wire to PB_8 (SCL) and the blue one to PB_9 (SDA).
Do you think I could try to connect it to the 5V instead of the 3V3?
posted by 20 Jul 2015I assume that "I don't get any response to the scan part." means that you only see "I2C address 0x%02X\n", and never see the "I2C address 0x%02X: FOUND!\n". That is strange. You should see a response to the sensor slave address and also to the 0x00 general call address. I think there probably is a wiring problem.
Did you measure the connections and supply voltage on the sensor pins. Note that the PB_9 and PB_8 pins are NOT on the A4/A5 arduino connector of the nucleo but on D14/D15
Check the full device typenumber, when it says MLX90614ESF-Bxx then it is a 3V device. When it says MLX90614ESF-Axx then it is a 5V device Since it works on 3V3 with the Arduino I expect that you have a 3V device.
I dont have the MLX90614 but tested the code above with a PCF8570 I2C RAM device and it works as expected.
posted by 20 Jul 2015I did some tests, this is the situation
- my device is an MLX90614ESF-Bxx, a 3V device I think;
- it works correctly on Arduino on 3V3 at the expected address;
- running the scan code on a Nucleo with the device on 3V3 it doesn't finds it on any address;
- running the scan code with the device on 5V it finds it on 0x00;
- tried another I2C device, the scan code founds it at the correct address;
sorry for the late response, didn't see the alert on my notifications.
Thank you so much for your help.
posted by 29 Jul 2015