Hello, I have strange trouble with my arduino mega.
I'm trying to connect I2C gyroscope and I2C IMU to it, but wire.transmit() hangs. I connected same gyro to my arduino uno and run same programm and gyro worked.
And how can be explained that same circuit and same code works on arduino with 328p and hangs on arduino with 2560?
As I said before, I used different pins on uno and mega. And different voltages too.
L3G library uses wire library.
I wonder if mega I2C circuit is different to uno circuit(except I2C pins placement).
Thanks for that.
Unfortunately (for you) everything looks fine with that to me.
You could have the two lines swapped over on the Mega but I can't see one way or the other from the photograph.
Have you done anything else with the I2C on the Mega? It could be that those pins are damaged.
Try blinking an LED on them.
Blink working on each pin. Swaping is not helpful, but i admit that circuit is right. I used this mega for i2c month ago. Can it be something with ic atmega2560?
It may sound too simple, but how are you powering the setup? I have had I2C issues like this when trying to run from the USB power. Switch to a real power source and see if it changes your result.
As I understand I2C is digital protocol, but why we can use ony 2 pins for it?
Because the AVR chip uses special internal hardware to support the I2C function and it only wires that function to those two specific pins. Just like the hardware serial function on a standard Uno is only available on pins 0 and 1, same thing going on there. analogWrite (pwm outputs) only works on specific pins because it uses internal chip hardware timers that only wire up to specific pins. All I/O pins can be used as simple digital input or output pins, but most of the special functions of the chip are only supported by specific pins. The AVR datasheet is the best source of information on this topic.
As I understand I2C is digital protocol, but why we can use ony 2 pins for it?
Because the AVR chip uses special internal hardware to support the I2C function and it only wires that function to those two specific pins. Just like the hardware serial function on a standard Uno is only available on pins 0 and 1, same thing going on there. analogWrite (pwm outputs) only works on specific pins because it uses internal chip hardware timers that only wire up to specific pins. All I/O pins can be used as simple digital input or output pins, but most of the special functions of the chip are only supported by specific pins. The AVR datasheet is the best source of information on this topic.