arduinompu

Powering MPU-6050 with Arduino digital pins


I have been trying to use MPU-6050 (specifically GY-521) with an Arduino Nano v3.0 but am not getting any readings when I try to power the MPU-6050 with the VCC and GND hooked up to digital pins on the Arduino.

When I have VCC and GND hooked to the 5V or 3V3 and GND on the Arduino, I am able to get readings from the gyro/accelerometer. When I hook them up to digital pins, I get readings but they are all zeros and even when the sensor is shaken the values stay at zero. The code I use in the settings for the digital pins is as follows:

pinMode(powerpin, OUTPUT);
pinMode(groundpin, OUTPUT);
digitalWrite(powerpin, HIGH);
digitalWrite(groundpin, LOW);

When I power an accelerometer, ADXL377, with the same pins, I get readings without a problem. Is this a problem with the amount of current that can be passed through the digital pins? Seems that the digital pins on the Nano can spit out at max 40mA and the MPU-6050 only needs like 3mA, so I am supposing the current is not a problem. Any help would be great.


Solution

  • I had the same problem, here is why it was a problem. First of all connecting LOW to GND is a good idea. Another thing: when you set up your pin HIGH by:

    pinMode(powerpin, OUTPUT);
    digitalWrite(powerpin, HIGH);
    

    it will go high after a while, so you should put some delay between:

    pinMode(powerpin, OUTPUT);
    digitalWrite(powerpin, HIGH);
    
    delay(10);
    
    Wire.begin();
    Wire.beginTransmission(0x68);
    Wire.write(0x6B);  // PWR_MGMT_1 register
    Wire.write(0);     // set to zero (wakes up the MPU-6050)
    Wire.endTransmission(true);
    

    So you need to get power and then wake up device. Ab. 10ms is a good value.

    After that you can read as normal (and good idea is to sleep device if you don't read from it too often).