IR Thermometer MLX90614

Hello guys,

i first tried to do this alone, but i didn't have that much succes. That's why I hope you can help me. I mostly worked with the following web page: http://bildr.org/2011/02/mlx90614-arduino/ which is also very well explained. I copied the I2C master in the library directory und I imported the wire library and the i2c library into my wiring environment. After that I uploaded the programm, which i have also taken from the page mentioned above but it always tells me:

MLX90614\twimaster.cpp.o: In function i2c_init()': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:31: multiple definition ofi2c_init()' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:31: first defined here MLX90614\twimaster.cpp.o: In function i2c_start(unsigned char)': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:41: multiple definition ofi2c_start(unsigned char)' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:41: first defined here MLX90614\twimaster.cpp.o: In function i2c_start_wait(unsigned char)': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:77: multiple definition ofi2c_start_wait(unsigned char)' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:77: first defined here MLX90614\twimaster.cpp.o: In function i2c_rep_start(unsigned char)': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:130: multiple definition ofi2c_rep_start(unsigned char)' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:130: first defined here MLX90614\twimaster.cpp.o: In function i2c_stop()': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:141: multiple definition ofi2c_stop()' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:141: first defined here MLX90614\twimaster.cpp.o: In function i2c_write(unsigned char)': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:161: multiple definition ofi2c_write(unsigned char)' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:161: first defined here MLX90614\twimaster.cpp.o: In function i2c_readAck()': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:182: multiple definition ofi2c_readAck()' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:182: first defined here MLX90614\twimaster.cpp.o: In function i2c_readNak()': C:\Users\Enrico\Desktop\Studium\3. Semester\E-technik\Semesterarbeit\arduino-0022\libraries\MLX90614/twimaster.cpp:197: multiple definition ofi2c_readNak()' twimaster.cpp.o:C:\Users\Enrico\AppData\Local\Temp\build8202608816710175734.tmp/twimaster.cpp:197: first defined here

I have no clue what i have to do in order to solve this problem. : ( Can someome assist me?

Many thanks in advance!

I copied the I2C master in the library directory und I imported the wire library and the i2c library into my wiring environment.

Why?

From the page you linked:

The standard wire library wasn’t working for people, so we will be using the i2cmaster library instead.

Does the word instead mean something different to you than it means to the rest of us?

Yeah you are absolutely right. I adjusted it as requested and i also get a signal from the sensor. However, the temperatur displayed right now is -273.15 degrees celsius and does not change. Do you have any idea what could be the possible reaon for this?

Do you have any idea what could be the possible reaon for this?

Could be a number of things. Could be that the sensor is not connected correctly. Could be that the sensors address is not what the code says it is. Could be the sensor is defective.

To complicate things even more, the i2cmaster wont run on the Arduino out of the box, some files need to be renamed and changed, and an extra txt file is needed to get it working. But… because it is open-sourced I can make those changes, and redistribute it. So that’s what I’m going to do, I’m just giving it to you here in its working version to save you some time and headache. You will need to drop the library into your Arduino library folder for it to work, but we will get there.

Did you do all of this?

Yeah I finally got it working. The mistake was due to a loose connection.

But I still have some questions concerning the program:

  1. What does this command do? I know that it enables the pull ups. Does this mean with this command I enable the resistors of port 4 and port 5? And why is this important for the SDA and SCL connection?
    PORTC = (1 << PORTC4) | (1 << PORTC5);

  2. Moreover, I have read that the following order sends an address and transfers a direction. But what does this exactly mean? The second parts means as much as write address 7, but i do not even use port 7?
    i2c_start_wait(dev+I2C_WRITE);
    i2c_write(0x07);

Many thanks for your patience :smiley:

What does this command do? I know that it enables the pull ups.

Then you know what it does.

Does this mean with this command I enable the resistors of port 4 and port 5?

It enables the pullup resistors for pins 4 and 5 of port C (which is the analog pin port).

Moreover, I have read that the following order sends an address and transfers a direction.

The first line sets and address AND and transfer direction, but doesn't send anything. The second line sends a value. What value to send depends on the hardware you are talking to.

The second parts means as much as write address 7, but i do not even use port 7?

No, it doesn't.

Thank you for your help : )

My sensor does just measure the object temperature. i2c_start_wait(dev+I2C_WRITE); i2c_write(0x07); i2c_rep_start(dev+I2C_READ); data_low = i2c_readAck(); data_high = i2c_readAck(); pec = i2c_readNak();

But it can also measure the ambient temperature. Do you know how i can measure this ambient temperature? Can i employ the same code as for the object temperature?

And is there a way to show the voltage in the serial monitor with the right temperature? I imagined it like this: int reading = analogRead(4); //since the data

// converting that reading to voltage, for 3.3v arduino use 3.3 float voltage = reading * 3.3; voltage /= 1024.0;

// print out the voltage Serial.print(voltage); Serial.println(" volts");

// now print out the temperature float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset //to degrees ((volatge - 500mV) times 100) Serial.print(temperatureC); Serial.println(" degrees C");

delay(1000); //waiting a second }

Thanks for your help!

But it can also measure the ambient temperature. Do you know how i can measure this ambient temperature? Can i employ the same code as for the object temperature?

Post a link to (the data sheet for) your device.

And is there a way to show the voltage in the serial monitor with the right temperature? I imagined it like this

Start hinting and pecking, and find out.

You can find the data sheet under the following link:

http://www1.futureelectronics.com/doc/MELEXIS/MLX90614ESF-ACC.pdf

Ok i figured out how to display the object and the ambient temperature:

#include <i2cmaster.h>

const int analogpin = 0; // Analog input pin
void setup(){
Serial.begin(9600);
Serial.println(“Herzlich willkommen. Zeig mir einen Gegenstand”) ;
Serial.println(“und ich zeig dir wie warm er ist : )”);
i2c_init(); //Initialise the i2c bus

PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}

void loop(){
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int data_low1 = 0;
int data_high1 = 0;
int pec = 0;
int pec1 = 0;

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);
i2c_rep_start(dev+I2C_READ);

data_low = i2c_readAck();

data_high = i2c_readAck();
pec = i2c_readNak();

i2c_stop();

float tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
float tempData = 0x0000; // zero out the data
int frac; // data past the decimal point
tempData = (((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;

float celcius = tempData - 273.15;

Serial.print("Celcius: ");
Serial.println(celcius);

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x06);
i2c_rep_start(dev+I2C_READ);

data_low1 = i2c_readAck();

data_high1 = i2c_readAck();
pec1 = i2c_readNak();

i2c_stop();

float tempFactor1 = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
float tempData1 = 0x0000; // zero out the data
int frac1; // data past the decimal point
tempData1 = (((data_high1 & 0x007F) << 8) + data_low1);
tempData1 = (tempData1 * tempFactor1)-0.01;

float celcius1 = tempData1 - 273.15;

Serial.print("Raumtemperatur: ");
Serial.println(celcius1);
delay(1000);
}

I added the follwoing commands to my program in order to measure the voltage:
int voltage=analogRead(analogpin);
voltage=voltage*3.3/1024;
Serial.print(voltage); Serial.println(" volts");

But i do not get the right values. it just keeps saying 1Volt. Can i measure the voltage via analogRead(analogpin) ??

int voltage=analogRead(analogpin);
voltage=voltage*3.3/1024;
Serial.print(voltage); Serial.println(" volts");

What does multiplying an int by 3.3 accomplish? The result is still an int, though the range of possible values is now from 0 to 3375.

Dividing that by 1024 drops the range to 0, 1, 2, or 3.

But i do not get the right values. it just keeps saying 1Volt.

Given the arithmetic you are performing, why do you thing that 1 is the wrong answer?

Yeah you are right. As soon as i define it as float it gives out a more likely value. What does this value really represent? I mean the sensor measures the ambient and the object temperature. The voltage depends on the temperatures, but on which does it depend? If the voltage changes does this mean the object temperature changes or the ambient temperature or even both?

Can i also manually measure the voltage? Then where do i have to measure the temperature - between the SDA and SCL or ground?