MPU6050 6-DoF Accelerometer and Gyro Created by Bryan Siepert Last updated on 2019-12-04 09:47:04 PM UTC
Overview The MPU-6050 is a popular six DoF accelerometer and gyroscope (gyro) that has all the info you need on how things are shakin' and spinnin' . With six axes of sensing and 16-bit measurements, you'll have everything you need to give your robot friend a sense of balance, using the MPU-6050 as its inner ear. This combination of gyroscopes and accelerometers is commonly referred to as an Inertial Measurement Unit or IMU. Not so long ago IMUs were the size of a breadbox (https://adafru.
As with all Adafruit breakouts, we've done the work to make the MPU-6050 super easy to use. We've put it on a breakout board with the required support circuitry and connectors to make it easy to work with. And of course we've added SparkFun Qwiic (https://adafru.it/Fpw) compatible STEMMA QT (https://adafru.it/Ft4) JST SH connectors that allow you to get going without needing to solder. Just use a STEMMA QT adapter cable (https://adafru.
© Adafruit Industries https://learn.adafruit.
Pinouts Power Pins Vin - this is the power pin. Since the sensor chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V 3Vo - this is the 3.
Arduino Wiring Wiring the MPU-6050 to communicate with your microcontroller is straight forward thanks to the I2C interface. For these examples we can use the Metro or Arduino to take measurements. The instructions below show a Metro (https://adafru.it/METROXMETR), but the same applies to an Arduino Connect board VCC (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
Click the Manage Libraries ... menu item, search for Adafruit MPU6050, and select the Adafruit MPU6050 library and click Install: Then follow the same process for the Adafruit BusIO library. Lastly find and install the Adafruit Unified Sensor library Basic Reading Example Open up File -> Examples -> Adafruit MPU6050 -> basic_readings and upload to your Arduino wired up to the sensor. One you've uploaded the sketch to your board open up the Serial Monitor (Tools->Serial Monitor) at 115200 baud.
Give the sensor a wiggle or a spin and watch how the measurements change! Basic Readings Example Code // Basic demo for accelerometer readings from Adafruit MPU6050 #include #include #include Adafruit_MPU6050 mpu; void setup(void) { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("Adafruit MPU6050 test!"); // Try to initialize! if (!mpu.begin()) { Serial.
Serial.println("+- 2000 deg/s"); break; } mpu.setFilterBandwidth(MPU6050_BAND_21_HZ); Serial.print("Filter bandwidth set to: "); switch (mpu.getFilterBandwidth()) { case MPU6050_BAND_260_HZ: Serial.println("260 Hz"); break; case MPU6050_BAND_184_HZ: Serial.println("184 Hz"); break; case MPU6050_BAND_94_HZ: Serial.println("94 Hz"); break; case MPU6050_BAND_44_HZ: Serial.println("44 Hz"); break; case MPU6050_BAND_21_HZ: Serial.println("21 Hz"); break; case MPU6050_BAND_10_HZ: Serial.
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degC"); Serial.println(""); delay(500); } © Adafruit Industries https://learn.adafruit.
Arduino Docs Arduino Docs (https://adafru.it/GtD) © Adafruit Industries https://learn.adafruit.
Python and CircuitPython It's easy to use the MPU6050 sensor with CircuitPython and the Adafruit CircuitPython MPU6050 (https://adafru.it/GEt) library. This library allows you to easily write Python code that reads the acceleration and adjust the measurement settings. You can use this sensor with any CircuitPython microcontroller board or with a Linux single board computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library (https://adafru.it/BSN).
Pi 3V to sensor VCC (red wire) Pi GND to sensor GND (black wire) Pi SCL to sensor SCL (yellow wire) Pi SDA to sensor SDA (blue wire) CircuitPython Installation of MPU6050 Library You'll need to install the Adafruit CircuitPython MPU6050 (https://adafru.it/GEt) library on your CircuitPython board. First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/Amd) for your board.
require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready (https://adafru.it/BSN)! Once that's done, from your command line run the following command: sudo pip3 install adafruit-circuitpython-mpu6050 If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.
© Adafruit Industries https://learn.adafruit.
Python Docs Python Docs (https://adafru.it/GtE) © Adafruit Industries https://learn.adafruit.
Downloads Files MPU6050 Datasheet (https://adafru.it/GEu) MPU6050 Register Map (https://adafru.it/GEv) EagleCAD files on GitHub (https://adafru.it/GEw) Fritzing object in Adafruit Fritzing Library (https://adafru.it/Gud) Schematic Fab Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2019-12-04 09:47:04 PM UTC Page 20 of 20