Pages: [1] 2   Go Down
Author Topic: Mistery: I2C not working, blink working  (Read 2078 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27353
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

missing 4.7K pullup resistors?
mixing 3.3V and 5V parts?
bad addresses to the devices?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 16, 2012, 04:40:04 pm by Spin7ion » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I also noticed that my imu already have pullup resistors
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34521
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As requested:
Uno connection:


Mega connection:


Main code:
Code:
#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
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34521
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34521
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can it be something with ic atmega2560?
I would not have thought so.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can it be something with ic atmega2560?
I would not have thought so.

So, what is your diagnosis?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34521
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have oscilloscope yet.  smiley-confuse
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2   Go Up
Jump to: