MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
wgrin
 
Posts: 4
Joined: Tue Mar 03, 2015 11:21 pm

MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post by wgrin »

Good evening,

A while back, I purchased two MLX90614 5V sensors for a home project. I can use the code provided by adafruit for one, but how do I get two I2C protocol connections to work with just the two SDL and SDA??

https://learn.adafruit.com/using-melexi ... g-and-test

What revisions to the adafruit code need to be made? From what I understand, you can use one chip to manage multiple I2C devices.

Thank you very much for your time!

Regards.

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post by Franklin97355 »


User avatar
wgrin
 
Posts: 4
Joined: Tue Mar 03, 2015 11:21 pm

Re: MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post by wgrin »

Thanks for the reply Franklin.

I already have the cutsheet, but I have no idea what information I need to use from the cutsheet, or how to integrate it into the code.

This is what I am stuck on!

Thanks again!!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post by adafruit_support_mike »

The MLX90614's I2C address is stored in EEPROM, so it's technically possible to set it by programming the chip outside the final circuit.

It's complicated though, because the chip wants an error-checking value called a Cyclic Redundancy Check for the sequence of bytes that you send.

This code will do that with an Arduino, and is tested with the byte sequences on page 17 of the datasheet:

Code: Select all

#define    CRC_GEN    0x07

void setup () {
	int d1[] = { 0xb4, 0x07, 0xb5, 0xd2, 0x3a };
	Serial.print( "crc = %02x\n", getCRC( d1, 5 ) );

	int d2[] = { 0xb4, 0x22, 0x07, 0xc8 };
	Serial.print( "crc = %02x\n", getCRC( d2, 4 ) );
	
	int d3[] = { 0xb4, 0x2e, 0x5b, 0x00 };
	Serial.print( "crc = %02x\n", getCRC( d3, 4 ) );
}

void loop () {
}

int getCRC ( int* data, int size ) {
	int result = 0;
	
	for ( int i=0 ; i < size ; i++ ) {
		result = calculateCRC8( data[ i ], result );
	}
	
	return( result );
}

int calculateCRC8 ( int data, int seed ) {
	int result = seed;
	
	for ( int i=7 ; i >= 0 ; i-- ) {
		result <<= 1;
		if ((( result >> 8 ) & 1 ) ^ (( data >> i ) & 1 )) {
			result ^= CRC_GEN;
		}
		result &= 0xff;
	}
	return( result );
}
The last line does the calculation for a command sequence that will change the device address to 0x5B.

User avatar
wgrin
 
Posts: 4
Joined: Tue Mar 03, 2015 11:21 pm

Re: MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post by wgrin »

Alright - So this will allow me to assign 1 address for each device?

Meaning I can have sensor one in address 0x5B and sensor two with a different address?

Thanks

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: MLX90614 - 2 x I2C Sensors for 1 Arduino Nano

Post by adafruit_support_mike »

It should. You'll probably need to do some testing and debugging though.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”