Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: MPU-6050, RTC DS3231 and Reset button Problem

  1. #1
    Junior Member
    Join Date
    Dec 2016
    Posts
    17

    MPU-6050, RTC DS3231 and Reset button Problem

    Hello all,

    I have a problem using a RTC DS3231, a MPU-6050 and a T3.5. I'm using the example MPU6050_raw from MPU6050.h library. When I upload the sketch I get some values from the Accelerometer and the Gyro (I had changed the address from 0x68 to 0x69 in the library MPU6050.h because I want to use a RTC too).
    Click image for larger version. 

Name:	Values.PNG 
Views:	38 
Size:	14.7 KB 
ID:	10960

    When I press RESET button I get any values.
    Click image for larger version. 

Name:	Values_0.PNG 
Views:	33 
Size:	8.1 KB 
ID:	10961

    Click image for larger version. 

Name:	MPU and RTC.PNG 
Views:	142 
Size:	550.2 KB 
ID:	10962


    Code:
    #include "Wire.h"
    #include "I2Cdev.h"
    #include "MPU6050.h"
    
    MPU6050 accelgyro;
    
    int16_t ax, ay, az;
    int16_t gx, gy, gz;
    
    #define LED_PIN 13
    bool blinkState = false;
    
    void setup() {
        // join I2C bus (I2Cdev library doesn't do this automatically)
        Wire.begin();
    
        // initialize serial communication
        // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
        // it's really up to you depending on your project)
        Serial.begin(38400);
    
        // initialize device
        Serial.println("Initializing I2C devices...");
        accelgyro.initialize();
    
        // verify connection
        Serial.println("Testing device connections...");
        Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
    
        // configure Arduino LED for
        pinMode(LED_PIN, OUTPUT);
    }
    
    void loop() {
        // read raw accel/gyro measurements from device
        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    
        // these methods (and a few others) are also available
        //accelgyro.getAcceleration(&ax, &ay, &az);
        //accelgyro.getRotation(&gx, &gy, &gz);
    
        // display tab-separated accel/gyro x/y/z values
        Serial.print("a/g:\t");
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
    
        // blink LED to indicate activity
        blinkState = !blinkState;
        digitalWrite(LED_PIN, blinkState);
    }
    Any ideas?

    Thank you so much!

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,572
    Is your Gyro supposed to be running on 3.3V or 5V? You possibly also have duplicate pullups on the i2C bus, removing one set may be closer to best practise.

    In terms of getting reset to work if I understand the question right, things work if you plug the device in, and let it go but reseting without cycling power is a problem? This would suggest that the gyro unit gets confused if it was configured and left to run and then the MCU goes away and doesn't re-init it properly.

    This may be fixable with a delay before you init the gyro to give it time to settle, otherwise you need to look into the gyro library and see if there is a reset command you can send to restore default configuration ready to re-init.

  3. #3
    I've experience similar behavior to this using jrowberg's mpu-6050 library. It was one of multiple issues I was having with the library, and I ended up switching to use Kris Winer's library for my project. You might want to give that test ride and see if it works any better.

    Something to consider: the reset button when you're connected to your computer doesn't exactly do what you might expect. There's more information on the teensy troubleshooting page about that.

    I'm presenting a project using a similar hardware set up this Thursday through Sunday. If I can get a minute after that, I can try running your code to see if anything else comes to mind, but I am travelling the following week so it'll be a tight window. Is what you posted the entire code?

  4. #4
    Junior Member
    Join Date
    Jan 2018
    Posts
    3
    The krisWiner's library is not working for me, iam still getting false reading from the gyro, please can you illustrate how to use it ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •