I2C no go on Mega 2560

I cannot get either of my two i2c devices to work on my mega 2560. One is a compass (HMC5883L), the other an lcd screen. Neither software to run them nor any of the three scanners I have tried produce any results. I have tried them with and without pull up resistors. I have tried 4.7K and higher value resistors. I have tried 3.3v and 5v Vcc sources, although both devices are supposed to be 5v compatible. I have looked at the output from SCL and SCA on an oscilloscope, and at least can verify that when running the scan programs there is output that goes from +5v down to zero in a square wave like form. Whether that form is perfect enough for the i2c devices, I cannot determine, other than to say neither device works, nor can I retrieve the i2c addresses using scanners.

Anyone have a tried and true formula that they are using on their mega 2560 for I2C device connection?

I really need to get a working compass on my project. I've had nothing but success with other devices interfaced with my mega 2560, but i2c just isn't flowing any data for me.

Are you sure you are using the correct pins for I2C on your mega board? Which pin numbers are you using?

I am using pin 21 as SCL and 20 as SDA. Man, would I love it to be something like that.

4.7K and 10K pull ups are a no go. Not sure if the secret lies in something to do with the onboard pull up resistors. Hoping someone has done this with a Mega 2560.

More reading on this subject online suggests others are experiencing problems with the mega 2560 and I2c as well. Apparently the onboard 10K pull up resistors are tied to +5v, and this can cause a problem with 3.3V circuits. The compass I am using is an hmc5883L which is a 3.3v chip. I see some compass boards using this chip have compensation for 3.3 vs 5 volts, and others do not.

Anyone running an I2C device on a Mega 2560 R3?

Northof49:
4.7K and 10K pull ups are a no go. Not sure if the secret lies in something to do with the onboard pull up resistors. Hoping someone has done this with a Mega 2560.

That's a function of the arduino software library use for I2C, so it does the same for a mega2560 as it does for a Uno board.
The most common problem beginners have with I2C with mega2560 is when using shield mounted I2C components that assume the two I2C clock and data pins are on pins A4 and A5 which is not the case for a mega2560 board. That is why on the newest Uno rev3 boards and mega2560 boards, arduino added new shield pins that were the two I2C pins so a shield using I2C would connect to the proper AVR signal pins no matter which board it was used for. However that of course doesn't help older shield designs that don't use the new defined pins..

Is there anything that needs to be done by me to the software on the mega to assign the data to the correct pins, 20 and 21, or is that automatic?

Northof49:
Is there anything that needs to be done by me to the software on the mega to assign the data to the correct pins, 20 and 21, or is that automatic?

No that is fixed wiring, no user control of where the I2C pins are.

Very frustrating then. I have a couple more I2c compasses on order. If those don't work either, it must be the mega board. I would sure like to hear from anyone who is successfully running I2C device(s) on a Mega 2560 R3, and what their wiring configuration is. Pull up resistors, etc.

There is certainly a 5v amplitude signal coming off both 20 and 21 pins. I can see it on my oscilloscope.

Looking for success stories. :slight_smile:

I don't know what you want, but I have a I2C bus working. Both ends are using 5V. Only difficulty was when I had to break 12bit data to 8 bit pieces. But that is C language.

I assume this means on a Mega 2560. Is it also an R3?

If so, are you using added pull up resistors, and if so, what value?

Any tweaks of any sort done to software or hardware?

I use a Mega 2560 with 6 I2C devices with no problem at all.

I dont use any pull-up resistors because Mega2560 have 10k PullUp resistors to 5V on I2C by default.
For that reason be careful if you ever try to connect a 3V i2c device on mega.

Do you run a compass by any chance? If so, what make?

Sorry no.

Try I2Cscanner. Your compass might be on the same address with another device.

I can't get any results from any of the three scanners I have tried. Only one device tested at a time. Both the lcd display and the compass come up blank.

I conclude this story with having replaced the Mega 2560 with another new one, and the I2C now works perfectly. Something wrong with the first mega I bought. Works fine otherwise.