I2C initialisation problem with MLX90614

Posted on
  • Currently I'm developing an Espruino module for MLX90614 - an infra red thermometer I2C sensor.
    https://learn.adafruit.com/using-melexis­-mlx90614-non-contact-sensors/overview
    It's nearly complete but I have strange problems with the initialisation. I figured out that the sensor always works when the power supply will be switched on after I2C1.setup(..)-call. So I have connected Vin of the sensor with B3 to simulate switching on/off programmatically.
    The following code works without any problems:

    I2C1.setup( { scl: B6, sda: B7 } );
    digitalWrite( B3, 1 ); // Power on after I2C1.setup(..)
    
    function start() {
      I2C1.writeTo( { address: 0x5a, stop: false }, 0x06 ); // repeated start I2C requests
      var d = I2C1.readFrom( 0x5a, 3 );
    
      var temp = ((d[1] << 8) + d[0]) * 0.02 - 273.15; // formula from datasheet
      console.log( "Temperature = " + temp + "°C" );
    }
    
    setTimeout( start, 250 ); // Sensor available 1/4 sec after POR
    

    But now strange things happen. The following code works only one or two times after connecting the USB cable and then never again.

    digitalWrite( B3, 1 ); // Power on before I2C1.setup(..)
    I2C1.setup( { scl: B6, sda: B7 } );
    
    function start() {
      I2C1.writeTo( { address: 0x5a, stop: false }, 0x06 );
      var d = I2C1.readFrom( 0x5a, 3 );
    
      var temp = ((d[1] << 8) + d[0]) * 0.02 - 273.15; // formula from datasheet
      console.log( "Temperature = " + temp + "°C" );
    }
    
    setTimeout( start, 250 ); // Sensor available 1/4 sec after POR
    

    Instead of Temperature = 22.37°C an exception is thrown:

    Uncaught InternalError: Timeout on I2C Write BUSY
     at line 14 col 51
    i2c.writeTo( { address: 0x5a, stop: false }, 0x06 );
                                                      ^
    in function called from system
    

    I have no ideas anymore how to find the cause. I don't have a memory oscilloscope and can't say what happens during "I2C1.setup(..)".
    Does anybody have an idea how I could continue...?

  • Can you confirm which version of espruino you're using on which board?
    What is the value of the pull-up resistors you have connected to the two i2c lines?

  • The pull-ups for SDA and SCL have 2.2k.
    I tried with two different pico boards (1v84) - same result. Next I will check the original board.

  • Ooh, it works with the original Espruino board:

    I2C1.setup( { scl: B6, sda: B7 } );
    function start() {
      I2C1.writeTo( { address: 0x5a, stop: false }, 0x06 );
      var d = I2C1.readFrom( 0x5a, 3 );
      var temp = ((d[1] << 8) + d[0]) * 0.02 - 273.15; // formula from datasheet
       console.log( "Temperature = " + temp + "°C" );
    }
    setTimeout( start, 250 ); // Sensor available 1/4 sec after POR
    

    Are the boards different related to the power supply or the i2c setup?

  • Wow, that looks like a very cool sensor!

    That's odd - the boards should be the same. You're using up to date firmware on both? The default I2C clock speed is 50000 (but it could be different on earlier firmwares) - it could be something that trips up the module.

    One thing that will get you is that on the Pico, B6 and B7 are used for the Serial console when USB isn't connected - so on initialisation they are set up as a Serial port. I guess they might end up getting pulled low at times and that could confuse the module?

    Maybe try something else - B4 and A8 on I2C3, and see if you have any more luck?

  • Yay, it works with I2C3.setup( { scl: A8, sda: B4 } ); on the pico. Thank you!!

    I've checked the other I2C-pins too:

    1. I2C1.setup( { scl: B6, sda: B7 } ); // not working
      2. I2C1.setup( { scl: B8, sda: B9 } ); // not working
      3. I2C2.setup( { scl: B10, sda: B3 } ); // working
      4. I2C3.setup( { scl: A8, sda: B4 } ); // working

      But USB is always connected. Is there really no difference between I2C1 and the I2C2 or I2C3?
  • Strange... but it does work intermittently? There are minor differences in the hardware, but Espruino tries quite hard to avoid them. I've definitely used I2C1 - in fact just earlier this week with a display - and it worked fine.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

I2C initialisation problem with MLX90614

Posted by Avatar for luwar @luwar

Actions