Interface an inertial measurement unit (IMU) with raspberry pi

First things first, if you have not checked out my previous blog about how to interface an ultrasonic sensor and a camera with raspberry pi, then have a quick read this blog.

  1. 3-axis gyroscope (measures angular velocity along 3 separate axes)
  2. Temperature sensor (you know what it does ;p)
GY-512 MPU-6050
  1. GND — Ground.
  2. SCL — Serial Clock Line for IIC/I²C communication.
  3. SDA — Serial Data Line for IIC/I²C communication.
  1. GND — — — — — — — — — GND — — — — which is— — —- Pin 6
  2. SCL — — — — — — — — — GPIO 3- — — — which is — — — — Pin 5
  3. SDA — — — — — — — — — GPIO 2- — — — which is — — — Pin 3
IMU’s green light switches on.
sudo raspi-config
Raspberry pi configuration tool.
Select P15 for selecting I2C.
from mpu6050 import mpu6050
sensor = mpu6050(0x68)
while (1):
accelerometer_data = sensor.get_accel_data()
temp = sensor.get_temp()
gyro_data = sensor.get_gyro_data()
print("Acceleration")
print("-----------------")
print(accelerometer_data)
print("-----------------")
print("Temperatue")
print("-----------------")
print(temp)
print("-----------------")
print("Gyro data")
print("-----------------")
print(gyro_data)
print("-----------------")
Output in the terminal
Photo by Anna Louise on Unsplash

Autonomous Vehicles Algorithm Developer