I2C question

This is my first time using arduino or I2C, if I want to connect some temp sensors to an I2C bus do I need an RTC?

Welcome in Arduino world :wink:

No you don't need an RTC, but such a device can be handy when you are going to write your measurements to a logfile - Data-Logger Shield for Arduino

Furthermore if you use I2C the following sketch is usefull - I2CScanner: Arduino as I2C bus scanner – todbot blog

What temperature sensor you want to use?

robtillaart,

Thanks for the response, I'll be using 7 IR Temp sensors (http://uk.rs-online.com/web/6843579.html).

In the second link you posted it says "Older devices have a fixed address, or a “choose one-of-four” approach. But newer I2C devices have fully programmable addresses, leading to cases of not knowing what address a device is at." I'm not sure which is the case for my sensors. Will I have trouble using 7 of these same sensors on this bus?

Here is the datasheet

Thanks again

Page 13 of the datasheet says "The MD has read access to the RAM and EEPROM and write access to 9 EEPROM cells (at addresses 0x20h, 0x21h, 0x22h, 0x23h, 0x24h, 0x25h*, 0x2Eh, 0x2Fh, 0x39h)". Does that mean I can potentially use 9 of these sensors on the same bus as slaves and be able to read values from each of them?

Also a few lines down it says "Special care must be taken not to put two MLX90614 devices with the same SD addresses on the same bus as MLX90614 does not support ARP"

I'm a little confused, any help would be appreciated

Page 30 of the datasheet: "The MLX90614 supports a 7-bit slave address in EEPROM, thus allowing up to 127 devices to be read via two common wires."

So, yes, you can connect multiple temperature sensors to the I2C bus. You will have to connect each one individually and program the EEPROM slave address to make them all different. You write the desired address to EEPROM byte 0x0E (SMBus Address).

You can set aside a range of addresses to use and keep track of which ones are in use. Occasonally (or maybe at startup) check to see if a temperature sensor is responding to the default address. If it is, program it for the first available address. That way if you have to replace a unit it will be re-addressed automatically.

Thanks johnwasser,

I don't plan on having to replace any units so I go with option #1 and program each slave address. 0x0E is the address of the slave device then? I don't understand how I would go about giving them all different addresses, can you give me some example code? I'm assuming I would have to

Wire.beginTransmission(0x0E);
Wire.send(some stuff);
Wire.endTransmission();

and do that for each sensor?

Ah, no.

0x0E is the address inside the EEPROM of the device. First you need to address the device. According to page 7 of the datasheet the default slave address is 0x5A.

So it would be more like:

Wire.beginTransmission(0x5A);  // default device address
Wire.send(some stuff);  // change slave address
Wire.endTransmission();

Skimming through the datasheet it looks like the "some stuff" would be something like:

EEPROM access (0b001x xxxx)

So without reading all 40 pages, it would be something along the lines of:

Wire.beginTransmission(0x5A);  // default device address
Wire.send (0b00100000 | 0x0E);  // write to EEPROM address 0x0E.
Wire.send (0x42);  // change device address to 0x42
Wire.endTransmission();

After that, presumably you the address the device with 0x42 rather than 0x5A.

jellybird:
and do that for each sensor?

Yes, change each one separately. Make sure one works before you do the lot.

Ok, I haven't gotten around to changing the addresses yet because I'm still having trouble communicating with the sensors at this point. What's wrong with this code? I can't get anything to print to Serial.

//I2C address
Wire.beginTransmission(0x5A);
//register for T(obj1)
Wire.send(0x07);
Wire.endTransmission();
Wire.requestFrom(0x5A, 1);
byte c = Wire.receive();
Serial.println(c);

I've also tried

while (Wire.available()){
byte c = Wire.receive();
Serial.print("temp");
}

but nothing inside the while loop prints either

What's going on?

See what result you get from Wire.endTransmission();.

eg.

int err = Wire.endTransmission();

Serial.print ("error was ");
Serial.println (err, DEC);

It should be zero. If not, you have a problem.

Thanks for your help Nick,

Wire.endTransmission() returns a 2 for me. Does this mean I have the wrong address? I dont understand how, you already pointed out the default slave address on page 7 of the datasheet. Any ideas what else could be the problem?

My connections: Pin 1 connected to SCL (Arduino Mega pin 21),
Pin 2 connected to SDA (Arduino Mega pin 20)
Pin 3 connected to +5V
Pin 4 connected to GND

The datasheet says Pin 2 on the sensor is PWM/SDA. Would I have to configure anything in the device to work with I2C?

I can't figure it out

Maybe you accidentally changed the device address. There have been I2C scanners written, I couldn't find one readily so I made my own, see here (near the bottom):

If you run that, you should see on your monitor window the address actually being used. If the address is really 0x5A it should display 90 (as the display is in decimal).

Nick

Thank you very much for you help. Your scanner is telling me I have 0 devices hooked up. I dont think I have it hooked up wrong, there are only 4 connections. Do you have any other suggestions?

Can you show your exact wiring please? I note that the device you quoted is a 3V device.

Here's my wiring, sorry for the poor resolution (taken with my cell phone)


On the left, the orange goes to power and the purple goes to ground
On the right, red is SDA from the Mega and black is SCL from the Mega

Where did you see that the device is 3V? On the pinout it says Vdd = 4.5V ... 5.5V. Here's a pic of the pinout


Either way, I've connected Vdd to +5 from the Mega and +3.3V from the Mega and I get nothing. I'm stumped.

jellybird:
robtillaart,

Thanks for the response, I'll be using 7 IR Temp sensors (http://uk.rs-online.com/web/6843579.html).

From that page:

RS Stock No. 684-3579
Manufacturer Melexis
Manufacturers Part No. MLX90614ESF-BAA

The "-BAA" part requires 3V. This explains what the "B" means:

(1) Supply Voltage/ Acccuracy
A -5V
B -3V
C - Reserved
D - 3V medical accuracy

Here's my wiring, sorry for the poor resolution (taken with my cell phone)

That doesn't help. I can't see where the wires go. Can't you sketch it or something?

On the left, the orange goes to power and the purple goes to ground

I was going to check whether it was 5V power or 3.3V power. But you said you tried both.

Are you using pull-up resistors between SDA and power, and SCL and power? 4.7K would be about right.

If you really have the 3V device I would run it from 3V and not 5V. Try to check the part number on the unit.

Thanks for your continued support Nick.

Are you using pull-up resistors between SDA and power, and SCL and power? 4.7K would be about right.

What do you mean between SDA and power and SCL and power? I added 4.7K resistors between SCL coming off the board and the SCL pin as well as SDA coming off the board and the SDA pin but still nothing.

Alright disregard that last post I think I had the resistor touching the base of the sensor, got your scanner to recognize it, thanks so much Nick. Now I'm working on readdressing them.

@jellybird

I am quite interested if you have those 7 up and running , when they measure the same object what are the values returned per sensor (according to the spec there is a max delta of 0.5 C . Could you post such information? Thanks in advance,

Rob

jellybird:
What do you mean between SDA and power and SCL and power? I added 4.7K resistors between SCL coming off the board and the SCL pin as well as SDA coming off the board and the SDA pin but still nothing.

That was what I meant. Actually I meant just the one resistor per line, two of them is getting close to 2.35K which might be a bit low.

Glad it works now.