Pages: [1]   Go Down
Author Topic: Problem with Reading/Writing to the EEPROM of a MLX90614  (Read 2900 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 2
Posts: 80
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello together,
I am stuck with the following problem and really need help from the community:
I have connected a Melexis MLX90614 Infrared Sensor to the Arduino to get temperature data.
Now i want to reduce the response time of the sensor by changing some values in the EEPROM.
According to this document http://www.melexis.com/Assets/Understanding-MLX90614-on-chip-digital-signal-filters-5272.aspx, I have to change bits 0-2 and 8-10 from a 16 bit column in the EEPROM ConfigRegister1. The other bits should not be changed, so the programm should read the register, make the alterations, then write the register value back, preserving the value in bits 3-7.

I found this sketch that modifies the emission rate of the MLX90614, i think this is very close to what I need:

Code:
/Simple program to read/write to the EEPROM (or read RAM) of the MLX90614 IR Sensor (in my case
//the MLX90614ESF-AAA). Example below erases the emissivity coefficient and then writes E = 1.
//Written be a total beginner, probably includes errors, and can definitely be
//improved on in many ways... /Lo-fi, 2011.

#include <i2cmaster.h>

void setup()
{
Serial.begin(9600);
Serial.println("----------Let's begin!----------");
i2c_init();                             //Initialise i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);  //enable pullups
}

void loop()
{
int dev = 0x00; // I use the general address. If I specify the address
                //(0x05<<1), the code doesn't work, don't know why... yet.
unsigned int data_l = 0;
unsigned int data_h = 0;
int pec = 0;

float data_t = 0;
float emissivity = 0;

//READ EEPROM/RAM

Serial.println("*1: Read EEPROM address:");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24);  //0x004 and 0x04 etc reads the same address in the RAM,
                  //add 2(0) for EEPROM, eg. 0x24 (emissivity correction
                  //coefficient in EEPROM).

i2c_rep_start(dev+I2C_READ);
data_l = i2c_readAck(); //Read 1 byte and then send ack
data_h = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

Serial.print("Data Low: ");
Serial.println(data_l);

Serial.print("Data High: ");
Serial.println(data_h);

Serial.print("Data combined: ");
data_t = (((data_h) << 8) + data_l);
Serial.println(data_t);

Serial.print("Emissivity: ");
emissivity = ((data_t) / 65535);
Serial.println(emissivity);

delay(5000);

//WRITE TO EEPROM, FIRST: ERASE OLD STUFF

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); //Register Address to write to

i2c_write(0x00); //Erase low byte (write 0)
i2c_write(0x00); //Erase high byte (write 0)
i2c_write(0xE8); //Send PEC
i2c_stop();

Serial.println("*2: Erasing old emissivity factor (writing 0).");
delay(5000);

//CHECK IF THE EEPROM VALUE HAS BEEN ERASED

Serial.println("*3: Check if the old emissivity coefficient was erased:");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24);  //See above comment.

i2c_rep_start(dev+I2C_READ);
data_l = i2c_readAck(); //Read 1 byte and then send ack
data_h = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

Serial.print("Data Low: ");
Serial.println(data_l);

Serial.print("Data High: ");
Serial.println(data_h);

Serial.print("Data combined: ");
data_t = (((data_h) << 8) + data_l);
Serial.println(data_t);

Serial.print("Emissivity: ");
emissivity = ((data_t) / 65535);
Serial.println(emissivity);
delay(5000);

//WRITE TO EEPROM, THE NEW STUFF!

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); //Register Address to write to

i2c_write(0xFF); //New emissivity factor, Ef=1
i2c_write(0xFF); //New emissivity factor, Ef=1
i2c_write(0xCC); //Send PEC
i2c_stop();

Serial.println("*4: Write new E to EEPROM (E = 1.0).");
delay(5000);
Serial.println("----------The process starts over again----------");
delay(5000);
}

The only thing i know so far is that I have to change i2c_write(0x24);  to i2c_write(0x25); and that I need to send the following 16 Bits to this register:
1;0;0;R;R;R;R;R;1;0;0;R;R;R;R;R
R stands for read, so that the sketch first reads whats the existing value and then uses it.

Can anybody please help me with the adaption of the code ? Thanks a lot in advantage  smiley
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use 'bitwise AND" and "bitwise OR" operators to clear the fields you want to set and set the values.

Code:
/Simple program to read/write to the EEPROM (or read RAM) of the MLX90614 IR Sensor (in my case
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); 
i2c_rep_start(dev+I2C_READ);
unsigned int register = i2c_readAck(); //Read low byte and then send ack
register |= i2c_readAck() << 8; //Read high byte and then send ack
pec = i2c_readNak();
i2c_stop();

// Set the register to: 0b100xxxxx100xxxxx  (where 'x' means 'do not modify)
register &= 0b0001111100011111;  // Clear all bits in the fields to be modified.
register |= 0b1000000010000000;  //Set bits in those fields to 1 where needed


//WRITE TO EEPROM, THE NEW STUFF!

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); //Register Address to write to
i2c_write(register);
i2c_write(register >> 8);
i2c_write(0xCC); //Send PEC
i2c_stop();

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Jr. Member
**
Karma: 2
Posts: 80
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use 'bitwise AND" and "bitwise OR" operators to clear the fields you want to set and set the values.

Code:
/Simple program to read/write to the EEPROM (or read RAM) of the MLX90614 IR Sensor (in my case
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); 
i2c_rep_start(dev+I2C_READ);
unsigned int register = i2c_readAck(); //Read low byte and then send ack
register |= i2c_readAck() << 8; //Read high byte and then send ack
pec = i2c_readNak();
i2c_stop();

// Set the register to: 0b100xxxxx100xxxxx  (where 'x' means 'do not modify)
register &= 0b0001111100011111;  // Clear all bits in the fields to be modified.
register |= 0b1000000010000000;  //Set bits in those fields to 1 where needed


//WRITE TO EEPROM, THE NEW STUFF!

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); //Register Address to write to
i2c_write(register);
i2c_write(register >> 8);
i2c_write(0xCC); //Send PEC
i2c_stop();


Thanks a lot for your work ! Unfortunately, it's not working correctly but I don't know whats the reason...
Heres the full code:
Code:
#include <i2cmaster.h>

void setup()
{
Serial.begin(9600);
i2c_init();                             //Initialise i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);  //enable pullups

int dev = 0x5A<<1; // I use the general address. If I specify the address
                //(0x05<<1), the code doesn't work, don't know why... yet.
unsigned int value = 0;
int pec = 0;
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x25); 
i2c_rep_start(dev+I2C_READ);
value = i2c_readAck(); //Read low byte and then send ack
value |= i2c_readAck() << 8; //Read high byte and then send ack
pec = i2c_readNak();
i2c_stop();
// Set the register to: 0b100xxxxx100xxxxx  (where 'x' means 'do not modify)
wert &= 0b0001111100011111;  // Clear all bits in the fields to be modified.
wert |= 0b1000000010000000;  //Set bits in those fields to 1 where needed


//WRITE TO EEPROM, THE NEW STUFF!

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x25); //Register Address to write to
i2c_write(value);
i2c_write(value >> 8);
i2c_write(0xCC); //Send PEC
i2c_stop();
}

void loop()
{
}

Anybody finds a mistake ?
Logged

0
Offline Offline
Jr. Member
**
Karma: 2
Posts: 80
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I still haven't managed it to get the sketch above working :-(
can anybody pls help me ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm trying to build similar scanning IR-camera as your camera. I'm wondering if you have tried reading the chip also with PWM, to test if it would be faster ? As I read from the data-sheets, default output is PWM on the range of -20 - 120 C. As I don't yet have actual chip, I can't verify the code above. But as I get the chip (MLX90614ESF-BCF from Future Electronics), I'll try to reproduce the project and test the response time.

Another speedup would be to highlight the "interesting areas" from the web-cam picture before taking actual temperature-measurements. That way the area that needs to be scanned with the sensor would be much smaller - at least if there are only few interesting areas in the whole picture. That would be useful when scanning for wiring, connectors, IC-chips etc. Lot's of background that could be scanned only with limited resolution / faster and then focus on the most important areas in the picture.

But this all is still theory until they deliver my chip - hopefully soon.

With best regards from Finland,

Henkka
« Last Edit: April 24, 2011, 10:17:19 am by oh6kft » Logged

0
Offline Offline
Jr. Member
**
Karma: 2
Posts: 80
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally solved the problem, now everything is working:

Code:
#include <i2cmaster.h>

void setup()
{
Serial.begin(9600);
Serial.println("This program will change the EEPROM settings of");
Serial.println("your MLX90614-DCI sensor to work best with the");
Serial.println("Cheap-Thermocam. PRESS ANY KEY TO CONTINUE.");
Serial.println("");
Serial.println("Created by Max Ritter - www.cheap-thermocam.tk");
Serial.println("");
while (Serial.available() == 0) {
}
Serial.println("----------Let's begin!----------");
Serial.println("");
i2c_init();
PORTC = (1 << PORTC4) | (1 << PORTC5);

int dev = 0x00;
unsigned int data_l = 0;
unsigned int data_h = 0;
int pec = 0;
float data_t = 0;
float emissivity = 0;

//WRITE TO EEPROM, FIRST: ERASE OLD STUFF
Serial.println("*1: Erasing old EEPROM settings");
Serial.println("");
Serial.println("Erasing filter settings..");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x25);
i2c_write(0x00); //Erase low byte (write 0)
i2c_write(0x00); //Erase high byte (write 0)
i2c_write(0x83); //Send PEC
//For PEC Calculation have a look at : http://smbus.org/faq/crc8Applet.htm
//In this case the PEC calculates from 250000 (=0x83)
i2c_stop();
delay(5000);

Serial.println("Erasing maximum temperature setting..");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x20);
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x43);
i2c_stop();
delay(5000);

Serial.println("Erasing minimum temperature setting..");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x21);
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x28);
i2c_stop();
delay(5000);

//WRITE TO EEPROM, THE NEW STUFF!
Serial.println("");
Serial.println("*2: Write new settings to EEPROM");
Serial.println("");
Serial.println("Writing new filter settings..");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x25); //Register Address to write to
i2c_write(0x74); //New filter settings (B374)
i2c_write(0xB3);
i2c_write(0x65); //Send PEC
i2c_stop();
delay(5000);

Serial.println("Writing new maximum temperature setting..");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x20);
i2c_write(0xFF);
i2c_write(0xFF);
i2c_write(0x67);
i2c_stop();
delay(5000);

Serial.println("Writing new minimum temperature setting..");
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x21);
i2c_write(0x5B);
i2c_write(0x4F);
i2c_write(0x59);
i2c_stop();

Serial.println("");
Serial.println("----------Finish!----------");
}
void loop()
{
}


The code changes the filter settings of the MLX90614-DCI to the minimum value of 49ms (100% FIR) and extends the standard temperature range from -20 - 120 degree to -70 - 370 °.

@ Henkka:
Great that you also try to build a IR camera. Limiting the scanning range to ínteressting areas will be a possible soon. I will build a portable version of this cheap-thermocam which can be used standalone without any computer and in this step I will include the function. The latest information are always at www.cheap-thermocam.tk  smiley-wink
Logged

Pages: [1]   Go Up
Jump to: