Go Down

Topic: Mistery: I2C not working, blink working (Read 2373 times) previous topic - next topic

Spin7ion

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.

Yes I connected right: 21-SCL;20-SDA.

What it can be?

CrossRoads

missing 4.7K pullup resistors?
mixing 3.3V and 5V parts?
bad addresses to the devices?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

dhenry

Quote
What it can be?


We can safely rule out your code.

We can probably rule out your set-up / connection.

Everything else is on the table, however.

Spin7ion

#3
Nov 16, 2012, 10:33 pm Last Edit: Nov 16, 2012, 10:40 pm by Spin7ion Reason: 1
Ok, code is from examples for L3G, it works on uno, but don't work on mega. Don't think it need to be checked.
Addresses are default, that proved by uno run.
Using this imu: http://www.pololu.com/catalog/product/1265

I don't use any resistors. Tried to use 3.3V and 5V, imu board uses vin voltage for I2C voltage.

Spin7ion

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).

Spin7ion

I also noticed that my imu already have pullup resistors

Grumpy_Mike

Quote
Ok, code is from examples for L3G, it works on uno, but don't work on mega. Don't think it need to be checked.

You would be wrong their.

Quote
And how can be explained that same circuit and same code works on arduino with 328p and hangs on arduino with 2560?

Code or how you wire it up.
There can be no other explanation. You are not helping us much because you are providing virtually no information.

Links to the code, photographs of your working setup with the Uno and non working setup with the Mega.

Spin7ion

As requested:
Uno connection:


Mega connection:


Main code:
Code: [Select]

#include <Wire.h>
#include <L3G.h>

L3G gyro;

void setup() {
  Serial.begin(9600);
  Wire.begin();
 
  if (!gyro.init())
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }

  gyro.enableDefault();
}

void loop() {
  gyro.read();

  Serial.print("G ");
  Serial.print("X: ");
  Serial.print((int)gyro.g.x);
  Serial.print(" Y: ");
  Serial.print((int)gyro.g.y);
  Serial.print(" Z: ");
  Serial.println((int)gyro.g.z);

  delay(100);
}


Library: https://github.com/pololu/L3G

Grumpy_Mike

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.

Spin7ion

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?

Grumpy_Mike

Quote
Can it be something with ic atmega2560?

I would not have thought so.

Spin7ion


Quote
Can it be something with ic atmega2560?

I would not have thought so.


So, what is your diagnosis?

Grumpy_Mike

Well from my experience when this sort of thing happens, it always turns out to be the thing that is obviously right and dosn't need checking.

Use a scope to determin if the mega is sending out any I2C signals.

Spin7ion


Duckie58

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.

Go Up