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

[![grafik.png](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/scaled-1680-/pe3tw8HBlBUNWatM-grafik.png)](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/pe3tw8HBlBUNWatM-grafik.png) [![grafik.png](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/scaled-1680-/eqQxF2Ex4WN2JuHw-grafik.png)](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/eqQxF2Ex4WN2JuHw-grafik.png) [![grafik.png](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/scaled-1680-/P3W3z6SxflVfS7r5-grafik.png)](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/P3W3z6SxflVfS7r5-grafik.png)

<iframe height="450vh" id="bkmrk--2" src="https://wiki.stadtfabrikanten.org/pdfjs/web/viewer.html?file=https://wiki.stadtfabrikanten.org/attachments/149" title="PDF viwer" width="100%"></iframe>

<iframe height="450vh" id="bkmrk--3" src="https://wiki.stadtfabrikanten.org/pdfjs/web/viewer.html?file=https://wiki.stadtfabrikanten.org/attachments/150" title="PDF viwer" width="100%"></iframe>

<iframe height="450vh" id="bkmrk--4" src="https://wiki.stadtfabrikanten.org/pdfjs/web/viewer.html?file=https://wiki.stadtfabrikanten.org/attachments/151" title="PDF viwer" width="100%"></iframe>

## MPU6050 pin configuration

<div class="table-wrap" id="bkmrk-pin-number-pin-name-"><table><colgroup><col></col><col></col><col></col></colgroup><thead><tr><td>**Pin number**

</td><td>**Pin name**

</td><td>**Description**

</td></tr></thead><tbody><tr><td>1

</td><td>Vcc

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

</td></tr><tr><td>2

</td><td>Ground

</td><td>Connected to Ground of system

</td></tr><tr><td>3

</td><td>Serial Clock (SCL)

</td><td>Used for providing clock pulse for I2C Communication

</td></tr><tr><td>4

</td><td>Serial Data (SDA)

</td><td>Used for transferring Data through I2C communication

</td></tr><tr><td>5

</td><td>Auxiliary Serial Data (XDA)

</td><td>Can be used to interface other I2C modules with MPU6050. It is optional

</td></tr><tr><td>6

</td><td>Auxiliary Serial Clock (XCL)

</td><td>Can be used to interface other I2C modules with MPU6050. It is optional

</td></tr><tr><td>7

</td><td>AD0

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

</td></tr><tr><td>8

</td><td>Interrupt (INT)

</td><td>Interrupt pin to indicate that data is available for MCU to read.

</td></tr></tbody></table>

</div>## MPU6050 features

- MEMS 3-aixs accelerometer and 3-axis gyroscope values combined
- Power Supply: 3-5V
- Communication : I2C protocol
- Built-in 16-bit ADC provides high accuracy
- Built-in DMP provides high computational power (Digital Motion Processor) - reduces the load for the microcontroller (like the Arduino)
- Can be used to interface with other IIC devices like magnetometer
- Configurable IIC Address
- In-built Temperature sensor

## Key words

- <span class="placeholder-inline-tasks">gyro</span>
- <span class="placeholder-inline-tasks">Inclinometer</span>
- <span class="placeholder-inline-tasks">Beschleunigungssensor</span>
- <span class="placeholder-inline-tasks">Neigungssensor</span>
- <span class="placeholder-inline-tasks">gyroscope</span>
- <span class="placeholder-inline-tasks">accelerometer</span>
- <span class="placeholder-inline-tasks">tilt sensor</span>

## Enable I2C on Raspberry Pi

```bash
vim /boot/config.txt
```

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--5" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--6"></div></div></div></div><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--7" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--8"></div></div></div></div>```bash
dtparam=i2c_arm=on
```

```bash
vim /etc/modules
```

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--9" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--10"></div></div></div></div><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--11" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--12"></div></div></div></div><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--13" style="border-width: 1px;"><div class="syntaxhighlighter sh-django  bash"></div></div>```bash
i2c-bcm2708
i2c-dev
```

Finde installierte I2C Module.

```bash
i2cdetect -y 1 #returns 0x68
```

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--14" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--15"></div></div></div></div><span lang="en">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.</span>

[![grafik.png](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/scaled-1680-/rYLN1tdKEE3rLEju-grafik.png)](https://wiki.stadtfabrikanten.org/uploads/images/gallery/2026-06/rYLN1tdKEE3rLEju-grafik.png)

```
i2cdetect -y 1 #now returns 0x69
```

## Debugging

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk--17" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--18"></div></div></div></div>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.

- check wiring quality and wire length/isolation
- check the supply voltage vor MPU 6050. It requires nominally 3.3 V  
    
    - VDD → 2.375 V - 3.46 V
    - VLOGIC → 1.71 V to VDD
- check / adjust the I²C bus frequency of Raspberry Pi (have a look at [<span>https://github.com/fivdi/i2c-bus/blob/master/doc/raspberry-pi-i2c.md</span>)](https://github.com/fivdi/i2c-bus/blob/master/doc/raspberry-pi-i2c.md))
    
    
    - ```bash
         show recent baudrate
        cat /sys/module/i2c_bcm2708/parameters/baudrate
         
        # adjust baudrate temporarily - set it to 10.000
        modprobe i2c_bcm2708 baudrate=10000
        cat /sys/module/i2c_bcm2708/parameters/baudrate
         
        # if you want to edit it permanently edit boot config by your needs - maximum baudrate is 400.000, default is 100.000
        vim /boot/config.txt
        dtparam=i2c_arm=on
        i2c_arm_baudrate=400000
        ```
- check I²C communication by i2c dumping
    
    
    - ```bash
        while i2cdump -y -r 0-7 1 0x68 c; do sleep 1; done
        while i2cdump -y -r 0-7 1 0x69 c; do sleep 1; done
        ```
- maybe add some delay after setting smbus.SMBus(1) to settle. A lot of people set some wait time, e.g. 1 second
- if there is a second MPU 6050 connected please check if there are problems while addressing them. Check if AD0 is set to 1 accordingly and if AD0 is grounded correctly. Check the devices separetely by disconnecting one of both to ensure that they work in single mode correctly.

## Monitoring → [MPU 6050 (GY-521) Gyro + Accelerometer monitoring](https://old.stadtfabrikanten.org/pages/viewpage.action?pageId=65405374)

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

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

## Configure and build

```bash
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
```

<div class="rwui_steps conf-macro output-block" data-hasbody="true" data-macro-name="ui-steps" id="bkmrk--19"><div class="rwui_step conf-macro output-block" data-hasbody="true" data-macro-name="ui-step"><div class="rwui_item_content"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--20"></div></div></div></div></div></div><div class="rwui_step conf-macro output-block" data-hasbody="true" data-macro-name="ui-step"></div></div>## Run

```bash
#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"
```

<div class="rwui_steps conf-macro output-block" data-hasbody="true" data-macro-name="ui-steps" id="bkmrk--21"><div class="rwui_step conf-macro output-block" data-hasbody="true" data-macro-name="ui-step"><div class="rwui_item_content"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" style="border-width: 1px;"><div class="codeContent panelContent pdl"><div><div class="syntaxhighlighter sh-django  bash" id="bkmrk--22"></div></div></div></div></div></div></div>