GY-521 MPU6050 MEGA 2560 Returning Zero(0) WHO_AM_I

I have tried two different boards and keep getting the same result a zero when returning the data.

Code used to get WHO_AM_I

#include <Wire.h>

uint8_t data[14];

void setup()
{
  Serial.begin(9600);
  int devAddr = 0x68;
  int regAddr = 0x75;
  Wire.begin();
  Wire.begin(devAddr);
  Serial.print("Started\n");
  Wire.beginTransmission(devAddr);
  Wire.write(regAddr);
  Wire.endTransmission(false);
  Wire.beginTransmission(devAddr);
  uint8_t noread = Wire.requestFrom(devAddr, 1, true);
  Serial.print("#Read:");
  Serial.print(noread);
  Serial.print("\n");
  
  uint8_t count = 0;
  
  while(Wire.available())
  {
    data[count] = Wire.read();
    Serial.print(data[count], HEX);
    Serial.print("\n");
    count++;
  }
  
  Serial.print(data[0], HEX);
  Serial.print("\n");
  Serial.print("Finished\n");
}

void loop()
{
}
Output is
Started
#Read:1
0
0
Finished

Connections on 2560
VCC >> 3.3V or 5V
GND >> GND
SCL >> SCL 21
SDA >> SDA 20

Any help appreciated

Hi mobile

Do you have pullup resistors between SCL and 5V and between SDA and 5V? EDIT - looks like the GY-521 has onboard pullup resistors.

What results do you get if you run the I2C scanner?

http://playground.arduino.cc/Main/I2cScanner

Regards

Ray

Your code

  Wire.begin();
  Wire.begin(devAddr);                           <<<   this line is incorrect,  remove it
  Serial.print("Started\n");
  Wire.beginTransmission(devAddr);
  Wire.write(regAddr);
  Wire.endTransmission(false);

has a line in it which is wrong. I don’t know if it causes your problem.

Hackscribble, thanks for the response, I did read posts that suggested to use 10K resistors as the on board were too low when connecting to the 3.3V, have tried that and made no difference. Also tried both voltages.

The scanner reports back that it can find a device on either 68 or 69 respective if the ADO line is high or low.

Hackscribble: Hi mobile

Do you have pullup resistors between SCL and 5V and between SDA and 5V? EDIT - looks like the GY-521 has onboard pullup resistors.

What results do you get if you run the I2C scanner?

http://playground.arduino.cc/Main/I2cScanner

Regards

Ray

michinyon, thanks for your reply.

I was under the impression when reading the wire notes that the first call Wire.begin() was to establish that the Arduino was the master and the second call, Wire.begin(devAddr) was to establish a slave call to the Gyro board.

michinyon:
Your code

  Wire.begin();

Wire.begin(devAddr);                           <<<   this line is incorrect,  remove it
  Serial.print(“Started\n”);
  Wire.beginTransmission(devAddr);
  Wire.write(regAddr);
  Wire.endTransmission(false);




has a line in it which is wrong. I don't know if it causes your problem.

The call there which I labelled was wrong, would only be used if the arduino was the slave device ( with some other device as master ). In this case, your arduino is not the slave device, your arduino is the master.

Furthermore, you are effectively trying to say that your arduino has device devaddr, and the mpu6050 you are trying to connect to, is also devaddr, which would not make sense, two devices with same address,

michinyon, thanks for adding some more, Quoted from arduino reference Wire.begin() Wire.begin(address)

Description Initiate the Wire library and join the I2C bus as a master or slave. This should normally be called only once. Parameters address: the 7-bit slave address (optional); if not specified, join the bus as a master.

So I take it that this is wrong?

Mobile

michinyon: The call there which I labelled was wrong, would only be used if the arduino was the slave device ( with some other device as master ). In this case, your arduino is not the slave device, your arduino is the master.

Furthermore, you are effectively trying to say that your arduino has device devaddr, and the mpu6050 you are trying to connect to, is also devaddr, which would not make sense, two devices with same address,

Hackscribble, after digging some more I have found that the device that is actually on the board is the ITG-3205 not the MPU6050, they have the same pin configuration but have a completely different registers, I can get the address of the unit using ox00 instead of the 0x75. I only discovered the label error when I stuck that device under a microscope to look that the printing as it had worn down.

It looks as if the board can have either chip on it.

Hopefully this helps me move forward.

Thanks again for your assistance

mobile: Hackscribble, thanks for the response, I did read posts that suggested to use 10K resistors as the on board were too low when connecting to the 3.3V, have tried that and made no difference. Also tried both voltages.

The scanner reports back that it can find a device on either 68 or 69 respective if the ADO line is high or low.

Hackscribble: Hi mobile

Do you have pullup resistors between SCL and 5V and between SDA and 5V? EDIT - looks like the GY-521 has onboard pullup resistors.

What results do you get if you run the I2C scanner?

http://playground.arduino.cc/Main/I2cScanner

Regards

Ray

Description
Initiate the Wire library and join the I2C bus as a master or slave. This should normally be called only once.
Parameters
address: the 7-bit slave address (optional); if not specified, join the bus as a master.

So I take it that this is wrong?

No, it is correct. But you have interpreted it completely wrongly.

You want the arduino to be the master device, not a slave. The master device does not have an I2C address. If you want to initialize the I2C with the arduino as master, then don’t specify a slave address. Call Wire.begin( ) with no slave address.

You specify the address of the I2C slave device in each communication sequence that you initiate. You can contact multiple slave devices from the one sketch ( but one at a time ). You specifiy the slave address each and every time your sketch contacts the slave devices. That’s why the beginTransmission, requestFrom(), functions etc have the slave device address in them.

You only call Wire.begin( ) once.