10 years, 10 months ago.

Problem getting the lib to work

First, thanks for this library ! I wrote a similar one for the Arduino (http://forum.arduino.cc/index.php?topic=126244.0). To get a bether performance, I moved to the mbed FRDM KL25Z. The first thing I did on this plattform was getting the temp of a MLX90614, which worked fine. Now I connected my MLX90620-BAD to the mbed and compiled your library. I used the example code out of the header file and put it into a main.cpp, included the missing libs and changed the I2C Ports to PTE0 (sda) and PTE1 (scl) as they are defined on the KL25Z.

However, I can not read out any values from the MLX90620. Not the EEPROM, the temp values, nothing. Any ideas ? I attached the files I use:

/media/uploads/maxbot/mlx90620.h /media/uploads/maxbot/mlx90620.cpp /media/uploads/maxbot/main.cpp

/media/uploads/maxbot/output_mlx90620.png

Question relating to:

4 Answers

Max Ritter
poster
10 years, 10 months ago.

Maybe I forgot to add how I wired up the MLX90620 to the mbed: P3V3 -> Diode -> VDD (to get a voltage drop to 2.6V) ; PTE0 -> SDA ; PTE1 -> SCL ; GND -> VSS ; 4.7k Pullup Resistor between SDA <-> VDD and SCL <-> VDD

10 years, 10 months ago.

There are some problems with KL25Z I2C (in the hardware of the microcontroller), so that might be a problem. However it should still output on a serial window. I assume you used the example program given by that library? If yes, do you have your terminal program on the correct baudrate? 921600? Otherwise try it a bit lower, like 115200.

Hmm, hardware problems would be bad.. Not sure about that. Yes, I used the example code. I also tried the second I2C on the KL25Z and I also set the baudrate down to 115200. When I send a char over the serial window, it outputs the following: * manual i2c write error GetConfig0

IR Array Capture * manual i2c write error GetRAM0 * manual i2c write error StartMeas0 Pix 0 Temp nan Pix 1 Temp nan Pix 2 Temp nan Pix 3 Temp nan Pix 4 Temp nan Pix 5 Temp nan Pix 6 Temp nan Pix 7 Temp nan Pix 8 Temp nan Pix 9 Temp nan Pix 10 Temp nan Pix 11 Temp nan Pix 12 Temp nan Pix 13 Temp nan Pix 14 Temp nan Pix 15 Temp nan Pix 16 Temp nan Pix 17 Temp nan Pix 18 Temp nan Pix 19 Temp nan Pix 20 Temp nan Pix 21 Temp nan Pix 22 Temp nan Pix 23 Temp nan Pix 24 Temp nan Pix 25 Temp nan Pix 26 Temp nan Pix 27 Temp nan Pix 28 Temp nan Pix 29 Temp nan Pix 30 Temp nan Pix 31 Temp nan Pix 32 Temp nan Pix 33 Temp nan Pix 34 Temp nan Pix 35 Temp nan Pix 36 Temp nan Pix 37 Temp nan Pix 38 Temp nan Pix 39 Temp nan Pix 40 Temp nan Pix 41 Temp nan Pix 42 Temp nan Pix 43 Temp nan Pix 44 Temp nan Pix 45 Temp nan Pix 46 Temp nan Pix 47 Temp nan Pix 48 Temp nan Pix 49 Temp nan Pix 50 Temp nan Pix 51 Temp nan Pix 52 Temp nan Pix 53 Temp nan Pix 54 Temp nan Pix 55 Temp nan Pix 56 Temp nan Pix 57 Temp nan Pix 58 Temp nan Pix 59 Temp nan Pix 60 Temp nan Pix 61 Temp nan Pix 62 Temp nan Pix 63 Temp nan

Any ideas ?

posted by Max Ritter 09 Jul 2013

That hardware problem is afaik related to I2C repeated start conditions, while those don't use repeated start. They happen when the KL25Z sends an I2C command and does not get an ACK back. Often caused by either wrong I2C address, or wrong wiring.

posted by Erik - 09 Jul 2013
10 years, 10 months ago.

When the hardware is OK you probably have the wrong I2C slave address. Note that Arduino libs use a 7 bit slaveaddress where mbed libs use an 8 bit address. Shift the Arduino MLX90620 slaveaddress 1 bit left to get a proper mbed I2C slave address.

Played around with it for several hours now, it does not work at all. MLX90614 works fine, on the MLX90620 i can't even read out the EEPROM register... Also tried to shift the adress by one bit left, no difference. By the way, the adresses inside this MLX90620 mbed lib and those I used for the Arduino are equal.

posted by Max Ritter 09 Jul 2013

Can you post the mbed code that you are using. It is not clear where your error messages could come from (eg * manual i2c write error GetConfig0..).

The original arduino code seems to use the byte wise I2C calls rather than the blockwrites or reads. Both methods should work but there are some differences.

The EEPROM read seems to use repeated starts. Note that some problems have been reported with repeated starts on the I2C bus when there is too much delay. This bug has been fixed but may not yet have ended up in the mbed library version that you are using.

posted by Wim Huiskamp 09 Jul 2013

I attached the files I use. Mbed Lib is updated. /media/uploads/maxbot/main.cpp /media/uploads/maxbot/mlx90620.cpp /media/uploads/maxbot/mlx90620.h

posted by Max Ritter 09 Jul 2013

The code shows that you dont properly set the initial memory location for the EEPROM. The number of bytes you write is 0. That should be 1 to write EEBuf[0] which is the address of the first EEPROM location that you wish to read.

int MLX90620::GetEEPROM() {
    //clear out buffer first
    for(int i = 0; i < 256; i++) {
        EEbuf[i] = 0;
    }
    //load the entire EEPROM
    EEbuf[0] = 0;
    if(!i2c->write(0xA0, EEbuf, 0)) {                      //0 returned is ok
        i2c->read(0xA0, EEbuf, 256);                       //load contents of EEPROM
    } else {
        pc.printf("*** MLX90620 dump failed!!!\n");
       
        return(0);
    }    
    return(1);
}

should be:

int MLX90620::GetEEPROM() {
    //clear out buffer first
//Not really needed, you are going to overwrite it anyhow...
    for(int i = 0; i < 256; i++) {
        EEbuf[i] = 0;
    }
    //load the entire EEPROM
    EEbuf[0] = 0; // Init to 0 to select the first location in EEPROM

    if(!i2c->write(0xA0, EEbuf, 1)) {                      //0 returned is ok, make sure you write 1 byte, ie the initial EEPROM memory location
        i2c->read(0xA0, EEbuf, 256);                       //now load contents of EEPROM
    } else {
        pc.printf("*** MLX90620 dump failed!!!\n");
       
        return(0);
    }    
    return(1);
}

You should always get a '0' returned (ie acknowledge) to something like this

   i2c->write(0xA0, EEbuf, 1) ;  

In case that fails and assuming that the device is (still) functioning then there must be a wiring or powersupply problem. Probably best also to make sure you set the bitrate for the I2C bus to something like 100000.

posted by Wim Huiskamp 09 Jul 2013

Thanks a lot Wim for your time, but unfortunately this didn't help either.. Just tried the MLX90614 with the arduino to check up I haven't messed up anything, works smooth. So the problem must be somewhere on the software side, but I have no idea where.. Seems like this is not my day :(

/media/uploads/maxbot/output_mlx90620.png

posted by Max Ritter 09 Jul 2013

You print the 'v' values and the error seems to occur for the second byte write. eg ..GetConfig1

You should always get a '0' returned (ie acknowledge) to something like this

   i2c->write(0xA0, EEbuf, 1) ;  

In case that fails and assuming that the device is (still) functioning then there must be a wiring or powersupply problem. Probably best also to make sure you set the bitrate for the I2C bus to something like 100000.

posted by Wim Huiskamp 09 Jul 2013

Yes the v values are 1, but when I try to output the EEPROM values, they are all empty. I also set the I2C frequency to 100000, no result. Device is functional and the wiring also works. Power supply could not be the problem I think, the device does not consume that much current and the voltage behind the diode is 2.6V. I have absolutely no idea whats wrong.. By the way, I want to integrate this into the third version of my Cheap-Thermocam (www.cheap-thermocam.net), so it is really important for me to get it to work.

posted by Max Ritter 09 Jul 2013

Can you run something like the following code:

#include "mbed.h"

I2C i2c(your i2c pins);

int main() {
  char a = 0;
  char ret;
  for (int i = 0; i<256; i = i + 2) {
    ret = i2c.write(i, &a, 1); //or (i, NULL, 0)
    printf("Ret value at %02X = %d\n\r", i, a);
    wait(0.1);
  }
  while(1);
}

If I haven't made typos that should allow you to see if a device is listening at an address.

posted by Erik - 10 Jul 2013

When I scan for I2C devices, I find the following adresses:

/media/uploads/maxbot/i2c.png

The Lib uses A0 and C0 so this should be okay

posted by Max Ritter 10 Jul 2013
10 years, 10 months ago.

Hello,

This is Kevin, the author of the MLX90620 driver. I stumbled on your thread accidentally. If the thread mentioned the 90620 in the title, I would have seen this sooner.

I originally wrote this for the mbed1768. I have recently purchased a -KL25Z and can look into the failure. However, I am half a world away from home and it will be a couple of weeks before I can look into this.

From what I remember, the EEPROM is a standard 24Cxx part and it uses standard I2C code. The sensor array is a different animal, it is not fully I2C compliant. I had to use lower level I2C commands to get the sensor array to work.

I also use the sensor array in an array-dump mode that has since been removed from the datasheet. Melexis told me that they stopped supporting that mode because it created slight errors in the temperature readings. Maybe in newer 90620 devices, that mode has been disabled, but I do not know. Just a heads up.

Important note: Careful when writing commands to the EEPROM. During code development, I accidentally erased some of the cells in the EEPROM, causing some sensors' cell data to become corrupt. I had to buy another MLX90620 as a result. I have since made routines that save the EEPROM data to a file, just in case that happens again. Too bad the EEPROM isn't write protected.

...kevin braun

Hello Kevin, thanks for your long answer ! I still have even problems to read out the EEPROM, I think my wiring circuit does cause the problems. How did you wire up your MLX90620 to the mbed controller ? Which value did you use for the pullup resistors ? Thanks in advantage for your answer and have a good time wherever you are in the world at the moment ;)

posted by Max Ritter 11 Jul 2013

Yes Max,

I used something like 2.2k resistors on SDA and SCL. I even have a 3 foot shielded cable between the 90620 and mbed - running at 400KHz.

I also used a 2.6V LDO chip to supply the 90620 power. Diodes have too much slop for an accurate 2.6V output level. They vary greatly part-to-part and with temperature. I wouldn't recommend the use of diodes. BTW: have you used decoupling caps on you 2.6V supply?

...kevin

posted by Kevin Braun 12 Jul 2013

Hi Max,

I took a look at the MLX90620 code on the KL25Z. I can read the contents of the EEPROM ok and the data looks correct. However, the driver freezes on the first access to the sensor array. I am using i2c pins PTE0 and PTE1.

I believe that I saw on another mbed thread that the KL25Z has a bug in executing i2c re-start sequences. I do a lot re-starts when accessing the sensor array. I will look into this more in the next couple of days.

...kevin

posted by Kevin Braun 24 Jul 2013

Max,

I think I've narrowed down the problem. Today, when I updated my mbed.lbr from v62 to v64, i2c broke. When I went back to v62, it work as expected. I have a question in to the group to see what changed between v62 and v63/v64 that broke i2c in the KL25Z for my MLX driver. In the mean time, you can download my program KL25Z_MLX90620. It will contain the v62 of mbed.lbr and work properly.

...kevin

posted by Kevin Braun 06 Aug 2013