RE: Breakout Board GY-521

Hi Gang

I recently purchased a Breakout Board GY-521 which has a MPU-6050 (accelerometer/gyroscope) chip. I found the following YouTube video and sample code very helpful.

Ep. 57 Arduino Accelerometer & Gyroscope Tutorial MPU-6050 6DOF Module

MPU6050_Implementation.ino

I am curious as to why the raw data is stored in a 'long' given that it's only 16-bit?

long accelX, accelY, accelZ;

Gyroscope ADC Word Length 16

My hunch is that when the raw data is processed it's combined with a float (both 32-bit)?

gForceX = accelX / 16384.0;

I'd love it if someone could shed some light on this mystery?

Cheers

Jase :slight_smile:

I am curious as to why the raw data is stored in a 'long' given that it's only 16-bit?

You need to ask the author of the library that question.

Hi PaulS

As per your suggestion I've posted a question on his YouTube video. There is no library used here aside from the Wire library. It's interesting though that any code you dig up on communicating with this board does exactly the same thing. Either everyone is copying one another or there is a specific reason for the use of 'long'.

Cheers

Jase :slight_smile:

ilovetoflyfpv:
Hi PaulS

As per your suggestion I've posted a question on his YouTube video. There is no library used here aside from the Wire library. It's interesting though that any code you dig up on communicating with this board does exactly the same thing. Either everyone is copying one another or there is a specific reason for the use of 'long'.

Cheers

Jase :slight_smile:

It looks like they are being safe using 2 extra bytes that are not needed. Change it to int and you should be fine.
From a library specifically designed to access all the mpu6050 values only 16bit int's are returned

       // ACCEL_*OUT_* registers
        void getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz);
        void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
        void getAcceleration(int16_t* x, int16_t* y, int16_t* z);
        int16_t getAccelerationX();
        int16_t getAccelerationY();
        int16_t getAccelerationZ();
        // TEMP_OUT_* registers
        int16_t getTemperature();
        // GYRO_*OUT_* registers
        void getRotation(int16_t* x, int16_t* y, int16_t* z);
        int16_t getRotationX();
        int16_t getRotationY();
        int16_t getRotationZ();

Z

Hi zhomeslice

Sorry for the late reply. I'll give it a go.

Cheers

Jase :slight_smile: