Go Down

Topic: MLX90614 contactless temprature sensor problems (Read 616 times) previous topic - next topic

dikshahere

Feb 08, 2017, 05:49 pm Last Edit: Feb 08, 2017, 06:04 pm by dikshahere
Here : I have connected 4 MLX90614 temp sensors which work on i2c protocol I have got the code worked out but, I am facing some weird problem the problem is:
Initially the program runs well but if I power off the arduino and repower it the data gets hanged and the results are:
Code: [Select]
[b]Setup...
> Read address
  MLX address: 0, Data: Setup...
> Read address
  MLX address: 0, Data: [/b]

It gets stuck here and doesnot proceed... BUT, I interchanged as follows:
A4--->SDA   A5--->SCL (initial connections)
changed to:
A4--->SCL  A5----->SDA resetted the controller and then back to:
A4--->SDA   A5--->SCL and  started to work back I tried it more than 5 times the same thing I needed to do.
Now how do I resolve this issue???
here is my code:
Code: [Select]

#include "i2cmaster.h"
float ReadTemp(byte);
void setup() {
  Serial.begin(9600);
  Serial.println("Setup...");/**/
  // Initialise the i2c bus, enable pullups and then wait
  i2c_init();
  PORTC = (1 << PORTC4) | (1 << PORTC5);
  delay(5000);
  // Read current address bytes
  ReadAddr(0);
  Serial.println("**---DONE---**");
}

void loop() {
 ReadTemp(0X0D);
  delay(2000);
   ReadTemp(0X0A);
delay(2000);
     ReadTemp(0X0C);
  delay(2000);
     ReadTemp(0X0B);
  delay(2000);
  }
float ReadTemp(byte address) {
  int data_low = 0;
  int data_high = 0;
  int pec = 0;
  byte MLXAddress = address<<1;

  Serial.print("> [ReadTemp] Read temperature ");
  if (MLXAddress == 0) {
    Serial.print("using MLX univeral address");
  } else {
    Serial.print("using MLX address ");
    Serial.print(address, HEX);
  };
  Serial.print(": ");

  i2c_start_wait(MLXAddress + I2C_WRITE);
  i2c_write(0x07);
  i2c_rep_start(MLXAddress + I2C_READ);
  data_low = i2c_readAck();
  data_high = i2c_readAck();
  pec = i2c_readNak();
  i2c_stop();

  float temp = 0x0000;                  
  temp = (float)(((data_high & 0x007F) << 8) + data_low);
  temp = (temp * 0.02) - 273.16;
  Serial.print(temp);
  Serial.println(" C");
  return temp;
}

void ReadAddr(byte Address) {
  Serial.println("> Read address");
  // Inform the user
  Serial.print("  MLX address: ");
  Serial.print(Address, HEX);
  Serial.print(", Data: ");

  // Send start condition and write bit
  i2c_start_wait(Address + I2C_WRITE);
  // Send command for device to return address
  i2c_write(0x2E);
  i2c_rep_start(Address + I2C_READ);

  // Read 1 byte and then send ack (x2)
  Serial.print(i2c_readAck(), HEX);
  Serial.print(", ");
  Serial.print(i2c_readAck(), HEX);
  Serial.print(", ");
  Serial.println(i2c_readNak(), HEX);
  i2c_stop();
}


the output I got was :
Code: [Select]

Setup...
> Read address
  MLX address: 0, Data: Setup...
> Read address
  MLX address: 0, Data: Setup...
> Read address
  MLX address: 0, Data: 8, 0, 80
**---DONE---**
> [ReadTemp] Read temperature using MLX address D: 30.46 C
> [ReadTemp] Read temperature using MLX address A: 26.98 C
> [ReadTemp] Read temperature using MLX address C: 26.02 C
> [ReadTemp] Read temperature using MLX address B: 26.10 C
> [ReadTemp] Read temperature using MLX address D: 27.40 C
> [ReadTemp] Read temperature using MLX address A: 27.10 C
> [ReadTemp] Read temperature using MLX address C: 26.02 C

jremington

A4 is SDA and A5 is SCL on a standard Arduino. It won't work if connected the other way around.

How are you powering the sensor?

Do you have the required 0.1 uF (100 nF) capacitor across the sensor power terminals?

el_supremo

Just to make sure, did you write the slave device addresses 0x0A, 0x0B, 0x0C and 0x0D individually into the sensors? (The factory default slave address is 0x5A).

Pete
Don't send me technical questions via Private Message.

dikshahere

Just to make sure, did you write the slave device addresses 0x0A, 0x0B, 0x0C and 0x0D individually into the sensors? (The factory default slave address is 0x5A).

Pete
I changed their addresses to the one I wanted to 0X0A,0X0B,0X0C,0X0D.



dikshahere

A4 is SDA and A5 is SCL on a standard Arduino. It won't work if connected the other way around.

How are you powering the sensor?

Do you have the required 0.1 uF (100 nF) capacitor across the sensor power terminals?

I did not connect any because I have such sensors (below):
http://www.haoyuelectronics.com/Attachment/GY-906/GY-906-1.jpg
 they come with all signal conditioning circuit right?


dikshahere

I figured out that in above code Its not proceeding after i2c_write(0X07);
Please give me some inputs..
Code: [Select]

float ReadTemp(byte address) {
  int data_low = 0;
  int data_high = 0;
  int pec = 0;
  byte MLXAddress = address<<1;

  Serial.print("> [ReadTemp] Read temperature ");
  if (MLXAddress == 0) {
    Serial.print("using MLX univeral address");
  } else {
    Serial.print("using MLX address ");
    Serial.print(address, HEX);
  };
  Serial.print(": ");

  i2c_start_wait(MLXAddress + I2C_WRITE);
  Serial.print("hi");
  i2c_write(0x07);

jremington


dikshahere

Try adding the capacitor.
I have tried adding capacitor,resistors(pullup )
everything...

Go Up