0
Offline
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« on: November 16, 2012, 02:28:04 pm » |
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
Online
Brattain Member
Karma: 242
Posts: 16505
Available for Design & Build services
|
 |
« Reply #1 on: November 16, 2012, 04:09:52 pm » |
missing 4.7K pullup resistors? mixing 3.3V and 5V parts? bad addresses to the devices?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #2 on: November 16, 2012, 04:15:29 pm » |
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
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #3 on: November 16, 2012, 04:33:06 pm » |
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/1265I 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
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #4 on: November 17, 2012, 01:52:53 am » |
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
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #5 on: November 17, 2012, 10:34:20 am » |
I also noticed that my imu already have pullup resistors
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 275
Posts: 25482
Solder is electric glue
|
 |
« Reply #6 on: November 17, 2012, 05:33:51 pm » |
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. 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
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #7 on: November 18, 2012, 06:19:58 am » |
As requested: Uno connection:  Mega connection:  Main 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)
Offline
Brattain Member
Karma: 275
Posts: 25482
Solder is electric glue
|
 |
« Reply #8 on: November 18, 2012, 02:08:31 pm » |
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
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #9 on: November 18, 2012, 02:38:09 pm » |
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)
Offline
Brattain Member
Karma: 275
Posts: 25482
Solder is electric glue
|
 |
« Reply #10 on: November 18, 2012, 05:03:06 pm » |
Can it be something with ic atmega2560? I would not have thought so.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #11 on: November 19, 2012, 12:30:20 am » |
Can it be something with ic atmega2560? I would not have thought so. So, what is your diagnosis?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 275
Posts: 25482
Solder is electric glue
|
 |
« Reply #12 on: November 19, 2012, 03:34:49 am » |
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
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #13 on: November 19, 2012, 09:11:39 am » |
I don't have oscilloscope yet. 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 16
|
 |
« Reply #14 on: November 19, 2012, 07:55:48 pm » |
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
|
|
|
|
|
|