Ceiling module | Gyroscope and acceleration sensor GY-521 (MPU6050)

grafik.png grafik.png grafik.png

MPU6050 pin configuration

Pin number

Pin name

Description

1

Vcc

Provides power for the module, can be +3V to +5V. Typically +5V is used

2

Ground

Connected to Ground of system

3

Serial Clock (SCL)

Used for providing clock pulse for I2C Communication

4

Serial Data (SDA)

Used for transferring Data through I2C communication

5

Auxiliary Serial Data (XDA)

Can be used to interface other I2C modules with MPU6050. It is optional

6

Auxiliary Serial Clock (XCL)

Can be used to interface other I2C modules with MPU6050. It is optional

7

AD0

If more than one MPU6050 is used a single MCU, then this pin can be used to vary the address

8

Interrupt (INT)

Interrupt pin to indicate that data is available for MCU to read.

MPU6050 features

Key words

Enable I2C on Raspberry Pi

vim /boot/config.txt
dtparam=i2c_arm=on
vim /etc/modules
i2c-bcm2708
i2c-dev

Finde installierte I2C Module.

i2cdetect -y 1 #returns 0x68

By default, each MPU 6050 has the same address with bit 0x68. An enable signal can be sent via pin "AD0", which redirects the sensor to 0x69. Pin AD0 got a fixed solderding to give the secondary address 0x69.

grafik.png

i2cdetect -y 1 #now returns 0x69

 

Debugging

Sometimes the gyros do not properly work when connected. While working within Trikarus project, multiple errors occured. There were errors thrown like "OSError: [Errno 121] Remote I/O error - has occurred". Especially making DMP work was a horror trip because it threw a lot of errors while with regular raw values this was not the big deal. It seems to be a problem with long wire, unstable clock frequency and pullup resistors.

There are multiple solutions to fix the situation.

Monitoring → MPU 6050 (GY-521) Gyro + Accelerometer monitoring

C++ script to read the data (quickly show the output to console)

At https://github.com/richardghirst/PiBits there's a good example to use MPU6050 with raw data or filterered by DMP.

Configure and build

apt install libgtkmm-3.0-dev
git clone https://github.com/richardghirst/PiBits.git
cd MPU6050-Pi-Demo/
 
#adjust I2C basics
vim I2Cdev.cpp #change all "/dev/i2c-0" to "/dev/i2c-1"
 
#to change I2C 0x69 or 0x69 change MPU6050 accelgyro; to MPU6050 accelgyro(MPU6050_ADDRESS_AD0_HIGH);
vim demo_raw.cpp
 
#to change I2C 0x69 or 0x69 change MPU6050 mpu; to MPU6050 mpu(MPU6050_ADDRESS_AD0_HIGH);
vim demo_dmp.cpp
 
make

Run

#raw mode
./demo_raw
 
 
#DMP mode
./demo_dmp
#this will sometimes fail with
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
DMP Initialization failed (code 1)
 
#You can also run gdb to debug:
gdb ./demo_dmp
#then enter "run"

 


Version #1
Erstellt: 2026-06-07 23:40:06 CEST von Mario Voigt
Zuletzt aktualisiert: 2026-06-07 23:43:45 CEST von Mario Voigt