Gyroscope and accelerometer in one
I give the Gyroscope and accelerometer in one a rating of 5 stars!
Mihir Joshi
/products/{handle}.md)
and JSON
(/products.json, /products/{handle}.json).
Little Bird
This compact MPU-6050 module combines a MEMS accelerometer and MEMS gyroscope in a single chip for detecting movement, tilt and rotation across the X, Y and ...
This compact MPU-6050 module combines a MEMS accelerometer and MEMS gyroscope in a single chip for detecting movement, tilt and rotation across the X, Y and Z axes.
Each channel is captured with 16-bit analogue-to-digital conversion, allowing the module to read the accelerometer and gyro axes at the same time. It communicates using the standard IIC protocol and has 2.54mm pin spacing for straightforward connection in maker projects.
Specifications:
Typical applications include motion sensing games, augmented reality, electronic image stabilisation (EIS), optical image stabilisation (OIS), zero-touch gesture user interfaces, pedestrian navigation and gesture shortcuts.
Plain-language definitions for the technical terms used above.
Find this product in
Sensors & Input
Sample code to get started with this product
Read all six axes over I2C with the Wire library (defaults: +/-2 g, +/-250 deg/s) and print to the Serial Monitor.
#include <Wire.h>
const int MPU = 0x68; // MPU-6050 I2C address (AD0 tied low)
void setup() {
Serial.begin(115200);
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // wake the sensor (clear the sleep bit)
Wire.endTransmission(true);
}
void loop() {
Wire.beginTransmission(MPU);
Wire.write(0x3B); // start at ACCEL_XOUT_H
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true); // 6 accel + 2 temp + 6 gyro bytes
int16_t ax = Wire.read() << 8 | Wire.read();
int16_t ay = Wire.read() << 8 | Wire.read();
int16_t az = Wire.read() << 8 | Wire.read();
Wire.read(); Wire.read(); // skip temperature
int16_t gx = Wire.read() << 8 | Wire.read();
int16_t gy = Wire.read() << 8 | Wire.read();
int16_t gz = Wire.read() << 8 | Wire.read();
// Defaults: accel +/-2 g (16384 LSB/g), gyro +/-250 deg/s (131 LSB/(deg/s))
Serial.print("accel g: ");
Serial.print(ax / 16384.0); Serial.print(", ");
Serial.print(ay / 16384.0); Serial.print(", ");
Serial.println(az / 16384.0);
Serial.print("gyro deg/s: ");
Serial.print(gx / 131.0); Serial.print(", ");
Serial.print(gy / 131.0); Serial.print(", ");
Serial.println(gz / 131.0);
delay(500);
}
Read the MPU-6050 over I2C using machine.I2C, with signed 16-bit conversion.
from machine import I2C, Pin
import time
MPU = 0x68 # I2C address (AD0 tied low)
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
# Wake the MPU-6050: clear the sleep bit in PWR_MGMT_1 (0x6B)
i2c.writeto_mem(MPU, 0x6B, b"\x00")
def read_word(reg):
hi, lo = i2c.readfrom_mem(MPU, reg, 2)
val = (hi << 8) | lo
return val - 65536 if val > 32767 else val # signed 16-bit
while True:
ax = read_word(0x3B) / 16384.0
ay = read_word(0x3D) / 16384.0
az = read_word(0x3F) / 16384.0
gx = read_word(0x43) / 131.0
gy = read_word(0x45) / 131.0
gz = read_word(0x47) / 131.0
print("accel g:", ax, ay, az)
print("gyro deg/s:", gx, gy, gz)
time.sleep(0.5)
Read the MPU-6050 over the Pi's I2C bus (enable I2C via raspi-config) using smbus2.
import smbus2
import time
MPU = 0x68 # I2C address (AD0 tied low)
bus = smbus2.SMBus(1) # I2C bus 1 on the 40-pin header
# Wake the MPU-6050: clear the sleep bit in PWR_MGMT_1 (0x6B)
bus.write_byte_data(MPU, 0x6B, 0)
def read_word(reg):
hi = bus.read_byte_data(MPU, reg)
lo = bus.read_byte_data(MPU, reg + 1)
val = (hi << 8) | lo
return val - 65536 if val > 32767 else val # signed 16-bit
while True:
ax = read_word(0x3B) / 16384.0
ay = read_word(0x3D) / 16384.0
az = read_word(0x3F) / 16384.0
gx = read_word(0x43) / 131.0
gy = read_word(0x45) / 131.0
gz = read_word(0x47) / 131.0
print("accel g: %.2f, %.2f, %.2f" % (ax, ay, az))
print("gyro deg/s: %.2f, %.2f, %.2f" % (gx, gy, gz))
time.sleep(0.5)
Hi, I'm Maddy. My team and I are ready to help with your order or any questions.