1
\$\begingroup\$

I need to work with Temperature MLX90614 on Arduino, when i used it's default library code, in bread board sometimes i get correct answer, so i used the soldered circuit for it like this:

enter image description here

in this situation i get correct answer and i used I2C Scanner with randomly, with firstly it found unreal devices on I2C buss i don't get correct answer, the code is show here:

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not known.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();
  //Wire.setClock(100000);
  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 80; address < 127; address++ ) 
//if(1) 
  {
//    address=0x5A;
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    Serial.print("error:");Serial.print(error);Serial.println("   ");

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknow error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

And the output is :


I2C Scanner
Scanning...
error:2   
error:4   
Unknow error at address 0x51
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:0   
I2C device found at address 0x58  !
error:2   
error:2   
error:2   
error:2   
error:4   
Unknow error at address 0x5D
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:2   
error:0   
I2C device found at address 0x6A  !
error:2   
error:2   
error:2   
error:2   
error:4   
Unknow error at address 0x6F
error:2   
error:2   
error:2   
error:2   
error:2   
error:4   
Unknow error at address 0x75
error:2   
error:2   
error:2   
error:2   
error:0   
I2C device found at address 0x7A  !
error:2   
error:2   
error:2   
error:2   
done

A you can see it found many devices on unreal I2C Address.(error 2 means no answer from Those I2C Adress). now the MLX90614 example get this output:

Adafruit MLX90614 test
Ambient = 1037.55*C Object = 1037.55*C
Ambient = 1899.59*F Object = 1899.59*F

That example code is :


/*************************************************** 
  This is a library example for the MLX90614 Temp Sensor
  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1747 3V version
  ----> https://www.adafruit.com/products/1748 5V version
  These sensors use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!
  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin();  
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}

but when i use this code for I2CScanning Shown below:

/**
 * I2CScanner.ino -- I2C bus scanner for Arduino
 *
 * 2009,2014, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
                void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, 0);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,DEC);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 8;       // lower addresses are reserved to prevent conflicts with other protocols
byte end_address = 119;       // higher addresses unlock other modes, like 10-bit addressing

// standard Arduino setup()
void setup()
{
    Wire.begin();

    Serial.begin(9600);                   // Changed from 19200 to 9600 which seems to be default for Arduino serial monitor
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,DEC);
    Serial.print(" to ");
    Serial.print(end_address,DEC);
    Serial.println("...");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");

    // Set pin mode so the loop code works ( Not required for the functionality)
    pinMode(13, OUTPUT);
}

// standard Arduino loop()
void loop() 
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}

It could found on the correct MlX90614 I2C Adress (0x5A or 90 in decimal) like this:

I2CScanner ready!
starting scanning of I2C bus from 8 to 119...
addr: 8 found!
addr: 9         addr: 10        addr: 11        addr: 12       
addr: 13        addr: 14        addr: 15        addr: 16       
addr: 17        addr: 18        addr: 19        addr: 20       
addr: 21        addr: 22        addr: 23        addr: 24       
addr: 25        addr: 26        addr: 27        addr: 28       
addr: 29        addr: 30        addr: 31        addr: 32       
addr: 33        addr: 34        addr: 35        addr: 36       
addr: 37        addr: 38        addr: 39        addr: 40       
addr: 41        addr: 42        addr: 43        addr: 44       
addr: 45        addr: 46        addr: 47        addr: 48       
addr: 49        addr: 50        addr: 51        addr: 52       
addr: 53        addr: 54        addr: 55        addr: 56       
addr: 57        addr: 58        addr: 59        addr: 60       
addr: 61        addr: 62        addr: 63        addr: 64       
addr: 65        addr: 66        addr: 67        addr: 68       
addr: 69        addr: 70        addr: 71        addr: 72       
addr: 73        addr: 74        addr: 75        addr: 76       
addr: 77        addr: 78        addr: 79        addr: 80       
addr: 81        addr: 82        addr: 83        addr: 84       
addr: 85        addr: 86        addr: 87        addr: 88       
addr: 89        addr: 90 found! addr: 91        addr: 92       
addr: 93        addr: 94        addr: 95        addr: 96       
addr: 97        addr: 98        addr: 99        addr: 100       
addr: 101           addr: 102           addr: 103           addr: 104       
addr: 105           addr: 106           addr: 107           addr: 108       
addr: 109           addr: 110           addr: 111           addr: 112       
addr: 113           addr: 114           addr: 115           addr: 116       
addr: 117           addr: 118           addr: 119           
done

After Uploading the main example for MLX90614 into Arduino and with previous circuit it gives the correct answer like this:

Ambi = 25.69*C  Object = 25.29*C
Ambient = 78.24*F   Object = 77.52*F

Adafruit MLX90614 test
Ambient = 25.69*C   Object = 25.25*C
Ambient = 78.24*F   Object = 77.45*F

I have two MLX90614 Sensors So i firstly I2C Scanner code and for one of them and other second I2C Scanner code (historical reach to correct answer), so the reading code was uploaded to another Arduino and based of those I2C Scanned codes as guessed second Mlx90614 worked and first don't worked !!!

When i disconnect Arduino from my PC again the mlx90614 don't show correct temp and it needs to run the second I2C Scanner uploaded to Arduino and after that reading codes uploaded to Arduino to reach the correct answer from mlx90614!!!!

So how uploading one I2CScanner program into my Arduino Could reach to Correct sensor reading ?

I have bought my mlx90614 from this site: enter image description here

which have this laser mark on it ;B90453X12E like this

in it's datasheet said about laser mark:

16.7. Part marking The MLX90614 is laser marked with 10 symbols. First 3 letters define device version (AAA, BCC, etc), and the last 7 are the lot number. Example: “ACC9307308” – MLX90614ACC from lot 9307308.

but this laser mark is started with B90 and not means any more based of this instruction.Could it be fake sensor?

My guess is there is some historical effect on the sensor!!! Why?

\$\endgroup\$
  • \$\begingroup\$ first few lines of your post say that the sensor worked sometimes when you were using a breadboard ... go back to that setup and run the I2C scanner ... it makes no sense to do anything else \$\endgroup\$ – jsotola Sep 3 at 19:26
  • \$\begingroup\$ The soldered board is more reliable,doesn't is? \$\endgroup\$ – moha_alpha-web.net Sep 3 at 19:30
  • \$\begingroup\$ Did you know that Nick Gammon, the author of the first script, is a very active user on the Arduino SE? Perhaps if you get a hold of him, he might tell you what's going on in his script. \$\endgroup\$ – KingDuken Sep 3 at 19:31
  • \$\begingroup\$ if i understand your post correctly, your device stopped working when you soldered the circuit ... that means that something is not as it should be .... you need to go back to the last known working configuration \$\endgroup\$ – jsotola Sep 3 at 19:41
  • \$\begingroup\$ Excuses me my device sometimes randomly worked with both of soldered board and bread board ( I have edited the question). So in soldered board it worked when i used the second I2C Scanner codes before reading the sensor !!! \$\endgroup\$ – moha_alpha-web.net Sep 3 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.