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 Error - Melexis, 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:
/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