Looking for some help with a hanging I2C program.

I have another thread more in line with my project in general, but I wanted to make one for this specific problem. I am trying to connect an magnetometer to my arduino Mega 2560. I have everything all nice and wired up (had the circuit double checked by a coupe different people). It is based off a diagram that another user and I agreed should work.

components: Arduino Mega 2560, LSM303C mag sensor, and level shifter

I am just trying out the I2C scanner sketch to check if everything is at least wired properly. http://playground.arduino.cc/Main/I2cScanner

The code hangs in the first pass through the for loop once it reaches

error= wire.endTransmission();

I disconnected the circuit from the arduino and the scanner sketch ran fine, but the problem arose when I reconnected everything. I have seen a couple threads with similar issues but details were never explained well enough for me to follow.

my sensor data sheet: http://www.st.com/web/en/resource/technical/document/datasheet/DM00089896.pdf

I have a circuit diagram available to post if the need arises. Any suggestions on where to start with an issue like this?

I think I already told you ;) If SDA and SCL are shortcut to each other or if one of them is shortcut to GND (perhaps also when shortcut to 5V or 3.3V), the endTransmission() is never completed.

But I loooooooked. Of course I may be an idiot and just did not spot the issue. Besides I have that multimeter you requested.

I can take pictures of the actual circuit I built to give a best visual aid to how I built the darn thing.

I uh....I got it working........

Between the line from SDA to the 3.3V rail I added in a 4.7k resistor. Repeated it for SCL.

The 7 bit address of my sensor is 0x1E....I2C scanner returns device at 0x1E!!!!!!!

Though one weird thing is it is also saying I have a device at 0x1D. But that only shows up on the iteration 2+ in the for loop.

Hi,

How you will come to know that you have to put 4.7K resistor.

If I put 10K resistor what will happen? please let me know.

Regards, Harish

harishg92:
How you will come to know that you have to put 4.7K resistor.

If I put 10K resistor what will happen? please let me know.

Dead topic revived.
Best to start a new one of your own if you have problems.
You can still have a link to this post if it’s related to your problems.

I2C devices have open drain (or collector) outputs (switches to ground).
That’s why many devices are able to co-exist on a single bus.
That also means there must be some pull up system (e.g. resistors).

Resistor value needed depends on the number of devices and the total capacitance (length/type) of the wiring.
Some devices/boards already have 4k7 or 10k pull up resistors. A Mega has 10k resistors, the Uno has none.
Make sure, if you use many devices, that total pull up current is <=3mA (for default I2C).
Leo…

Hi

Thanks for the update..! I will go through.

Thanks a lot, for ur suggestion..!! I will take care from next time.

Regards, Harish