Sony's Developer World forum

    • Home
    • Forum guidelines

    MPU6050 and Sony Spresense

    Spresense
    2
    6
    35
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tamer_ae last edited by

      I have an IMU sensor (MPU6050) that works fine on an Arduino mega, but gets me some odd values when I use it with my spresense board. Quite often, I get failed I2C connection error as well. Does it have to do with different clocking frequencies, or is the mpu6050 just not compatible with the spresense board?

      J 1 Reply Last reply Reply Quote
      • J
        jens6151 0 1 1 @tamer_ae last edited by

        @tamer_ae Can you please post the code you use and how you connect it?
        Do you have an extension board? Do you directly connect to the Spresense Main board?
        Spresense SDK? Arduino Library?

        A guess would be the level shifters? Noise?
        Please provide more information. Otherwise it would be just guessing around.

        This project uses the same sensor as you. Have a look at his Github. This is the configuration.

        CONFIG_SENSORS_MPU60X0=y
        # CONFIG_MPU60X0_SPI is not set
        CONFIG_MPU60X0_I2C=y
        CONFIG_MPU60X0_I2C_FREQ=400000
        
        J T 2 Replies Last reply Reply Quote
        • J
          jens6151 0 1 1 @jens6151 0 1 1 last edited by

          @jens6151-0-1-1 https://www.hackster.io/dyad/10n2-smart-student-driver-assistant-88787b

          T 1 Reply Last reply Reply Quote
          • T
            tamer_ae @jens6151 0 1 1 last edited by tamer_ae

            @jens6151-0-1-1 Thank you for your reply
            this is the code I am using:

            #include <Wire.h>
            const int MPU = 0x68; // MPU6050 I2C address
            float AccX[2], AccY[2], AccZ[2];
            float VelX[2], VelY[2], VelZ[2];
            float PosX[2], PosY[2], PosZ[2];
            float AccErrorX, AccErrorY, AccErrorZ;
            
            void setup() {
              Serial.begin(115200);
              Wire.begin();                      // Initialize comunication
              Wire.beginTransmission(MPU);       // Start communication with MPU6050 // MPU=0x68
              Wire.write(0x6B);                  // Talk to the register 6B
              Wire.write(0x00);                  // Make reset - place a 0 into the 6B register
              Wire.endTransmission(true);        //end the transmission
              
              // Configure Accelerometer Sensitivity - Full Scale Range (default +/- 2g)
              Wire.beginTransmission(MPU);
              Wire.write(0x1C);                  //Talk to the ACCEL_CONFIG register (1C hex)
              Wire.write(0x10);                  //Set the register bits as 00010000 (+/- 8g full scale range)
              Wire.endTransmission(true);
              // Configure Gyro Sensitivity - Full Scale Range (default +/- 250deg/s)
              Wire.beginTransmission(MPU);
              Wire.write(0x1B);                   // Talk to the GYRO_CONFIG register (1B hex)
              Wire.write(0x10);                   // Set the register bits as 00010000 (1000deg/s full scale)
              Wire.endTransmission(true);
              delay(20);
            
              // Call this function if you need to get the IMU error values for your module
              //initialise all to zero
              for (int i = 0; i <2; i++){ 
                AccX[i] = 0;
                AccY[i] = 0;
                AccZ[i] = 0;
                VelX[i] = 0;
                VelY[i] = 0;
                VelZ[i] = 0;
                PosX[i] = 0;
                PosY[i] = 0;
                PosZ[i] = 0;
              }
              calculate_IMU_error();
            
              delay(20);
            }
            void loop() {
              // === Read acceleromter data === //
              //take rolling average to act as a low pass filter
                Wire.beginTransmission(MPU);
                Wire.write(0x3B);
                Wire.endTransmission(false);
                Wire.requestFrom(MPU, 6, true);
                AccX[1] = ((Wire.read() << 8 | Wire.read()) / 16384.0) ;
                AccY[1] = ((Wire.read() << 8 | Wire.read()) / 16384.0) ;
                AccZ[1] = ((Wire.read() << 8 | Wire.read()) / 16384.0) ;
            
                AccX[1] = (AccX[1]) - AccErrorX;
                AccY[1] = (AccY[1]) - AccErrorY;
                AccZ[1] = (AccZ[1]) - AccErrorZ;
            
            
                
                // Print the values on the serial monitor
                Serial.print(AccX[1]);
                Serial.print(",");
                Serial.print(AccY[1]);
                Serial.print(",");
                Serial.println(AccZ[1]);
            }
            

            I am not currently using any library other than the wire.h

            Many thanks

            1 Reply Last reply Reply Quote
            • T
              tamer_ae @jens6151 0 1 1 last edited by

              @jens6151-0-1-1 said in MPU6050 and Sony Spresense:

              CONFIG_MPU60X0_I2C_FREQ=400000

              I cannot seam to find the configuration bit on github. was this also from the project link you provided?

              J 1 Reply Last reply Reply Quote
              • J
                jens6151 0 1 1 @tamer_ae last edited by

                @tamer_ae
                This is the direct link
                https://github.com/ds-dyad/10n2-app/blob/master/sdk.config

                This is not my project, so I cannot give details.

                I do not know if the speed plays an important role here. I added it to my code. (I interface LSM303)

                Wire.setClock(400000);  // 400KHz
                

                On the first glance the code looks good.

                I would try out one of the Arduino libraries like this https://github.com/adafruit/Adafruit_MPU6050. Just the given example to check if the hardware connections are good before writing own code.

                1 Reply Last reply Reply Quote
                • First post
                  Last post
                Developer World
                Copyright © 2021 Sony Group Corporation. All rights reserved.
                • Contact us
                • Legal