MPU6050 Pinout: A Micro-Electro-Mechanical System for 6D Motion Tracking

Posted by

What is the MPU6050?

The MPU6050 is a compact, low-power, and highly accurate motion tracking device manufactured by InvenSense (now part of TDK). It features a 3-axis gyroscope and a 3-axis accelerometer, allowing it to measure angular velocity and linear acceleration in three dimensions. The sensor also includes an on-chip Digital Motion Processor (DMP) that can perform complex calculations and data fusion algorithms, offloading these tasks from the main microcontroller.

Key features of the MPU6050 include:
– 3-axis gyroscope with programmable full-scale range of ±250, ±500, ±1000, and ±2000°/sec
– 3-axis accelerometer with programmable full-scale range of ±2g, ±4g, ±8g, and ±16g
– Integrated Digital Motion Processor (DMP)
– I²C (Inter-Integrated Circuit) digital output interface
– VDD power supply range: 2.375V to 3.46V
– Low power consumption: 3.6mA when all 6 motion sensing axes are enabled

MPU6050 Pinout Diagram

To effectively use the MPU6050 in your projects, it is essential to understand its pinout. The following table and diagram provide a detailed overview of the MPU6050’s pins and their functions:

Pin Number Pin Name Description
1 VCC Power supply (2.375V to 3.46V)
2 GND Ground
3 SCL I²C serial clock
4 SDA I²C serial data
5 XDA I²C master serial data (for auxiliary I²C)
6 XCL I²C master serial clock (for auxiliary I²C)
7 AD0 I²C slave address LSB
8 INT Interrupt digital output

VCC and GND Pins

The VCC pin (Pin 1) is used to provide power to the MPU6050. The sensor requires a supply voltage between 2.375V and 3.46V. It is recommended to use a clean and stable power source to ensure optimal performance and minimize noise in the sensor readings.

The GND pin (Pin 2) is the ground connection for the MPU6050. It should be connected to the common ground of your system.

I²C Communication Pins (SCL and SDA)

The MPU6050 communicates with a microcontroller or other devices using the I²C protocol. The SCL pin (Pin 3) is the serial clock line, while the SDA pin (Pin 4) is the serial data line. These pins are used for bidirectional communication between the MPU6050 and the master device (e.g., a microcontroller).

The I²C bus requires pull-up resistors on both the SCL and SDA lines. The value of these resistors depends on the bus capacitance and the desired clock frequency. Typically, 4.7kΩ or 10kΩ resistors are used for most applications.

Auxiliary I²C Pins (XDA and XCL)

The MPU6050 features an auxiliary I²C bus that allows it to communicate with external sensors, such as magnetometers or pressure sensors. The XDA pin (Pin 5) is the master serial data line, and the XCL pin (Pin 6) is the master serial clock line for this auxiliary I²C bus.

When using the auxiliary I²C bus, the MPU6050 acts as the master device, controlling the communication with the external sensor. This feature enables the creation of more advanced motion tracking systems by combining data from multiple sensors.

I²C Slave Address Pin (AD0)

The AD0 pin (Pin 7) is used to set the least significant bit (LSB) of the MPU6050’s I²C slave address. By default, the MPU6050’s I²C address is 0x68 when AD0 is connected to GND, and 0x69 when AD0 is connected to VCC.

In situations where multiple MPU6050 sensors are used on the same I²C bus, the AD0 pin allows you to configure each sensor with a unique address, preventing communication conflicts.

Interrupt Pin (INT)

The INT pin (Pin 8) is a digital output pin that can be configured to generate interrupts based on various events, such as new data being available, motion detection, or FIFO buffer overflow. By using interrupts, your microcontroller can be notified when specific events occur, enabling more efficient data processing and power management.

The interrupt pin is active-high and open-drain, meaning that it requires an external pull-up resistor (typically 10kΩ) to function properly.

Connecting the MPU6050 to a Microcontroller

To integrate the MPU6050 into your project, you’ll need to connect it to a microcontroller or development board that supports I²C communication. In this example, we’ll demonstrate how to connect the MPU6050 to an Arduino Uno board.

Connection Diagram

Wiring Instructions

  1. Connect the VCC pin of the MPU6050 to the 3.3V pin on the Arduino Uno.
  2. Connect the GND pin of the MPU6050 to one of the GND pins on the Arduino Uno.
  3. Connect the SCL pin of the MPU6050 to the SCL pin (A5) on the Arduino Uno.
  4. Connect the SDA pin of the MPU6050 to the SDA pin (A4) on the Arduino Uno.
  5. (Optional) If you plan to use interrupts, connect the INT pin of the MPU6050 to a digital input pin on the Arduino Uno (e.g., pin 2). Remember to use an external pull-up resistor.

After connecting the MPU6050 to your Arduino Uno, you can use the Arduino IDE and the Wire library to communicate with the sensor and retrieve motion data.

Configuring the MPU6050

Before using the MPU6050, you need to configure its settings to suit your application’s requirements. The sensor has several registers that control its behavior, such as sample rate, gyroscope and accelerometer full-scale ranges, and interrupt settings.

Setting the Sample Rate

The sample rate determines how frequently the MPU6050 measures the gyroscope and accelerometer data. To set the sample rate, you need to write the desired value to the SMPLRT_DIV register (0x19). The sample rate is calculated using the following formula:

Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)

The gyroscope output rate is typically 8kHz, but it can be reduced to 1kHz for low-power applications. For example, to set the sample rate to 100Hz with an 8kHz gyroscope output rate, you would set SMPLRT_DIV to 79:

SMPLRT_DIV = (Gyroscope Output Rate / Desired Sample Rate) – 1
SMPLRT_DIV = (8000 Hz / 100 Hz) – 1 = 79

Configuring the Gyroscope and Accelerometer

The MPU6050’s gyroscope and accelerometer have programmable full-scale ranges that determine the sensor’s sensitivity and measurement range. You can set these ranges by writing to the GYRO_CONFIG (0x1B) and ACCEL_CONFIG (0x1C) registers, respectively.

The available full-scale ranges for the gyroscope are:
– ±250°/s (0x00)
– ±500°/s (0x08)
– ±1000°/s (0x10)
– ±2000°/s (0x18)

The available full-scale ranges for the accelerometer are:
– ±2g (0x00)
– ±4g (0x08)
– ±8g (0x10)
– ±16g (0x18)

To set the desired full-scale range, write the corresponding value to the appropriate register. For example, to set the gyroscope full-scale range to ±1000°/s and the accelerometer full-scale range to ±8g:

  1. Write 0x10 to the GYRO_CONFIG register (0x1B)
  2. Write 0x10 to the ACCEL_CONFIG register (0x1C)

Enabling Interrupts

The MPU6050 can generate interrupts based on various events, such as new data being available or motion detection. To enable interrupts, you need to configure the INT_ENABLE register (0x38) and the INT_PIN_CFG register (0x37).

The INT_ENABLE register allows you to select which events will generate an interrupt. For example, to enable interrupts for new data and motion detection:

  1. Write 0x01 to the INT_ENABLE register to enable data ready interrupt
  2. Write 0x40 to the INT_ENABLE register to enable motion detection interrupt

The INT_PIN_CFG register controls the behavior of the interrupt pin. You can configure the pin to be active-high or active-low, open-drain or push-pull, and you can also enable a latch mode that keeps the interrupt pin active until the interrupt status is cleared.

For example, to set the interrupt pin to active-high and open-drain:

  1. Write 0x50 to the INT_PIN_CFG register

After enabling interrupts and configuring the interrupt pin, you can use the INT pin to detect when an interrupt occurs and take appropriate action in your microcontroller’s code.

Reading Data from the MPU6050

Once you have connected and configured the MPU6050, you can start reading motion data from the sensor. The MPU6050 provides raw gyroscope and accelerometer data through a set of registers, which you can access using I²C communication.

Reading Gyroscope Data

The gyroscope data is stored in six registers, representing the angular velocity in the X, Y, and Z axes. Each axis has a high and a low byte register:

  • GYRO_XOUT_H (0x43) and GYRO_XOUT_L (0x44) for the X-axis
  • GYRO_YOUT_H (0x45) and GYRO_YOUT_L (0x46) for the Y-axis
  • GYRO_ZOUT_H (0x47) and GYRO_ZOUT_L (0x48) for the Z-axis

To read the gyroscope data, perform the following steps:

  1. Send a start condition and the MPU6050’s I²C address with the write bit set
  2. Send the address of the first register you want to read (e.g., GYRO_XOUT_H)
  3. Send a restart condition and the MPU6050’s I²C address with the read bit set
  4. Read the high and low bytes for each axis
  5. Combine the high and low bytes to obtain the 16-bit raw gyroscope data
  6. Convert the raw data to angular velocity using the selected full-scale range

Here’s an example of how to read the gyroscope data using the Arduino Wire library:

// Read gyroscope data
Wire.beginTransmission(0x68);
Wire.write(0x43); // Start with the GYRO_XOUT_H register
Wire.endTransmission(false);
Wire.requestFrom(0x68, 6, true); // Read 6 bytes (3 axes, 2 bytes each)

int16_t gyroX = (Wire.read() << 8) | Wire.read();
int16_t gyroY = (Wire.read() << 8) | Wire.read();
int16_t gyroZ = (Wire.read() << 8) | Wire.read();

// Convert raw gyroscope data to angular velocity (degrees per second)
float gyroXdps = gyroX / 131.0;
float gyroYdps = gyroY / 131.0;
float gyroZdps = gyroZ / 131.0;

Note that the conversion factor (131.0 in this example) depends on the selected full-scale range. For the other ranges, use:
– ±250°/s: 131.0
– ±500°/s: 65.5
– ±1000°/s: 32.8
– ±2000°/s: 16.4

Reading Accelerometer Data

Reading accelerometer data is similar to reading gyroscope data. The accelerometer data is stored in six registers, representing the linear acceleration in the X, Y, and Z axes. Each axis has a high and a low byte register:

  • ACCEL_XOUT_H (0x3B) and ACCEL_XOUT_L (0x3C) for the X-axis
  • ACCEL_YOUT_H (0x3D) and ACCEL_YOUT_L (0x3E) for the Y-axis
  • ACCEL_ZOUT_H (0x3F) and ACCEL_ZOUT_L (0x40) for the Z-axis

To read the accelerometer data, follow the same steps as for the gyroscope data, but use the accelerometer register addresses instead. Here’s an example using the Arduino Wire library:

// Read accelerometer data
Wire.beginTransmission(0x68);
Wire.write(0x3B); // Start with the ACCEL_XOUT_H register
Wire.endTransmission(false);
Wire.requestFrom(0x68, 6, true); // Read 6 bytes (3 axes, 2 bytes each)

int16_t accelX = (Wire.read() << 8) | Wire.read();
int16_t accelY = (Wire.read() << 8) | Wire.read();
int16_t accelZ = (Wire.read() << 8) | Wire.read();

// Convert raw accelerometer data to acceleration (g)
float accelXg = accelX / 16384.0;
float accelYg = accelY / 16384.0;
float accelZg = accelZ / 16384.0;

The conversion factor (16384.0 in this example) depends on the selected full-scale range. For the other ranges, use:
– ±2g: 16384.0
– ±4g: 8192.0
– ±8g: 4096.0
– ±16g: 2048.0

By regularly reading the gyroscope and accelerometer data, you can track the motion and orientation of your device in real-time.

Using the Digital Motion Processor (DMP)

The MPU6050 features an on-chip Digital Motion Processor (DMP) that can perform advanced motion processing tasks, such as sensor fusion, quaternion calculations, and gesture recognition. Using the DMP can offload these computationally intensive tasks from your main microcontroller, reducing processing overhead and power consumption.

To use the DMP, you’ll need to load firmware onto the MPU6050 and configure the DMP’s settings. This process is more complex than reading raw sensor data and requires a deeper understanding of the MPU6050’s internal workings.

Several libraries, such as the MPU6050_6Axis_MotionApps20 library for Arduino, provide high-level functions for initializing and using the DMP. These libraries abstract the complexity of working with the DMP, making it easier to integrate advanced motion processing features into your projects.

Here’s a simple example of how to use the MPU6050_6Axis_MotionApps20 library to read quaternion data from the DMP:

“`cpp

include

MPU6050 mpu;

// Quaternion data
Quaternion q;

void setup() {
// Initialize the MPU6050 and DMP
mpu.initialize();
mpu.dmpInitialize();

// Enable the DMP
mpu.setDMPEnabled(true);
}

void loop() {
// Check if DMP data is available

Leave a Reply

Your email address will not be published. Required fields are marked *