• Stars
    star
    716
  • Rank 63,241 (Top 2 %)
  • Language
    C++
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Basic MPU6050 Arduino sketch of sensor function

MPU-6050

Basic MPU-6050 Arduino sketch of sensor function

For a discussion of performance on various microcontroller platforms, uses and limitations of the MPU-6050 see here.

I have written a report from the June 11-12, 2014 Invensense Developers Conference.

This sketch demonstrates MPU-6050 basic functionality including initialization, accelerometer and gyro calibration, sleep mode functionality as well as parameterizing the register addresses. Added display functions to allow display to on-breadboard monitor. No DMP use. We just want to get out the accelerations, temperature, and gyro readings.

Runs on 3.3V 8 MHz Pro Mini and Teensy 3.1.

Added quaternion filter based on Madgwick's open-source sensor fusion algorithms. The MPU-6050 lacks a magnetic vector for absolute orientation estimation as is possible with the MPU-9150 or LSM9DS0. This algorithm allows estimation of quaternions and relative orientation, allowing output of Yaw, Pitch, and Roll which is subject to Yaw drift due to gyro bias drift. Despite the inclusion of a gyro bias drift correction component to the sensor fusion algorithm, Yaw drift is about half a degree per minute or less, which is not too bad. In principle, Yaw should not be possible to estimate with only a single absolute reference (gravity down), yet this algorithm does a good job of estimating relative Yaw with good stability over short time scales.

I have added code compiled with the mbed compiler to run 6-axis sensor fusion using the STM32MF401 ARM processor and the MPU-6050. Why would this be necessary or desirable?

The filter runs at a 200 Hz update rate on a 3.3 V 8 MHz Pro Mini AVR (Arduino) microcontroller.

The filter runs at a 3200 Hz update rate on a 3.3 V 96 MHz Teensy 3.1 ARM microcontroller.

The filter runs at a 5500 Hz update rate on a 3.3 V 84 MHz STM32F401 ARM microcontroller.

One doesn't need more that about 1000 Hz sensor fusion filter update rate to get optimal performance from 6- and 9-axis motion sensors, but the power consumption is proportional to the microcontroller clock speed. If that 1000 Hz rate can be achieved at a lower clock speed, then lower power consumption can be achieved. This is a critical consideration for portable (wearable) motion sensing and motion control devices.

Let's assume the sensor fusion filter update rate is linearly proportional to the clock speed (a pretty good assumption). Then to get 1000 Hz update rates for the Teensy only requires 96/3.2 = 30 MHz clock speed. In fact, at 24 MHz clock speed the update rate with the Teensy 3.1 is 1365 Hz. For the STM32F401, the clock speed needs to be only 84/5.5 = 16 MHz to reach a sensor fusion filter update rate of 1000 Hz. In practice, the clock speeds are not arbitrary but must meet certain constraints; it might not be possible to run the STM32F401 at such a low speed. So far, I have only run it at 84 and 42 MHz; at 42 MHz I got sensor fusion filter update rates of ~4400 Hz. It appears that the STM32F401 would require less than half the power compared to the Teensy 3.1 to achieve the same level of sensor fusion performance. Meaning that all else being equal (it never is!), a wearable device using the STM32F401 as the microcontroller could last twice as long before battery change or charging is required. This is a major commercial advantage and why the STM32 M4 Cortex family of processors is so interesting.

More Repositories

1

MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
C++
1,025
star
2

ESP32

Arduino sketches for the ESP32
C++
163
star
3

EM7180_SENtral_sensor_hub

(Affordable) Ultimate Sensor Fusion Solution
C++
96
star
4

CMWX1ZZABZ

Collection of sketches using the Arduino core for Murata's CMWX1ZZABZ (STM32L082 and SX1276)
C++
94
star
5

MPU9150

Arduino sketch for MPU9150 9DoF with AHRS sensor fusion
Arduino
75
star
6

ESP8285

ESP8285 Development Board
C++
55
star
7

BNO055

Teensiduino sketch for 9-axis BNO055 motion sensor + MS5637 pressure sensor
Arduino
54
star
8

LSM9DS1

ST's new smaller, lower-power 9-axis motion sensor
C++
40
star
9

LSM9DS0

LSM9DS0 9DOF sensor AHRS sketch
Arduino
39
star
10

ICM42688

Collection of Arduino sketches for TDK's combo accel/gyro motion sensor
C++
32
star
11

MPU6050HMC5883AHRS

9 DoF sensor fusion with AHRS output for MPU-6050 gyro/accel + HMC5883 magnetometer sensor
Arduino
28
star
12

ESP8266_Flight_Controller

Arduino
26
star
13

BMX-055

Arduino
22
star
14

VL53L5CX

Some sketches for the VL53L5CX ranging camera for use with the Arduino IDE
C++
22
star
15

IIS3DWB

Arduino sketches for ST's IIS3DWB vibration analyzer accelerometer
C++
21
star
16

Dragonfly

Arduino sketches for use with the Dragonfly (STM32L4)
C++
21
star
17

BME680

Arduino
21
star
18

ICM42605

C++ Arduino sketch with quaternion output
C++
21
star
19

AS7265X

18-channel, 40-nm FWHM spectrometer
C++
19
star
20

HT16K33_Display_Driver

Simple demo of driving four seven segment bubble displays with one HT16K33 display driver
Arduino
16
star
21

LSM6DSO

Sketches demonstrating utility of the LSM6DSO for motion sensing
C++
15
star
22

nRF52832DevBoard

C++
15
star
23

DS3231RTC

Basic sketch for the DS3231 Real Time Clock
Arduino
14
star
24

Butterfly

C++
13
star
25

nRF51822_IoT_Breakout

C++
12
star
26

VL6180X

Proximity sensor using ir laser range finding
C++
12
star
27

Katydid_STM32WB55

Arduino sketches for the STM32WB-based Katydid (aka Connected Motion Sense) wearable IoT platform
C++
12
star
28

VL53L0X

Arduino
11
star
29

CCS811

Arduino sketch for the BME280_CCS811 Air Quality Sensor Breakout
C++
11
star
30

PAA3905

Optical flow X-Y velocity sensor plus 35 x 35 pixel 15 Hz video camera
C++
10
star
31

GY-80

10DoF sensor fusion with AHRS
Arduino
10
star
32

MAX21100

MAX21100 6 DoF motion sensor with hardware 9 DoF sensor fusion
Arduino
10
star
33

STHS34PF80

ST IR temperature sensor with embedded presence and motion detection
C++
10
star
34

Teensy_Prop_Shield

Arduino
9
star
35

STM32F401

STM32F401 Nucleo 6- and 9-axis sensor fusion examples
C++
9
star
36

MMC5983MA

Arduino sketch for 10 DoF AHRS using the MMC5983MA magnetometer
C++
9
star
37

Ladybug

C++
9
star
38

SensorTile

Sensor Tile-eyes and ears
Arduino
9
star
39

LIS2DW12

Arduino sketches demonstrating operation of ST's LIS2DW12 low-power accelerometer
C++
9
star
40

LC709204F

OnSemi low-power LiPo battery fuel gauge
C++
8
star
41

IS31FL3246

36-channel led driver from Lumissil
C++
8
star
42

CaliPile

Arduino sketch for Excelitas' CaliPile TPiS 1S 1385 Thermoipile I2C sensor
C++
8
star
43

AS7331

Sample sketches for the AS7331 UVA/B/C light sensor by AMS
C++
8
star
44

LSM6DSM_LIS2MDL_LPS22HB

C++
8
star
45

BMA280

C++
7
star
46

LP5036

TI 12x rgb led driver
C++
7
star
47

ESP8266

Arduino
6
star
48

MMA8452Q

Sketch for the MMA8452Q Accelerometer
Arduino
6
star
49

FRDM-FXS-MULT

Freescale sensor evaluation board
Arduino
6
star
50

IS31FL3194

C++
5
star
51

AMG8833

Arduino
5
star
52

ILPS22QS

High-accuracy barometer and QVAR (touch) sensor
C++
5
star
53

APDS9500

Arduino
5
star
54

Rodan

Multi-sensor data logger with BLE programmable via USB using the Arduino IDE
C++
4
star
55

MC3635

mCube's ultra-low-power wake-on-motion 3-axis accelerometer
C++
4
star
56

PAW3902

Optical flow sensor with three light levels
C
4
star
57

SPIFlash

C++
4
star
58

LSM6DSV_GestureEngine

High-accuracy accel/gyro and barometer configured as gesture engine
C++
4
star
59

H3LIS331D

ST Microelectronics' Hi-g accelerometer
Arduino
4
star
60

BMP-180

Bosch's newest low-power, small-footprint, high-precision pressure sensor/altimeter
Arduino
4
star
61

VEML6075

Arduino
3
star
62

PAF9701

Arduino sketches for PixArt Imaging's 8 x 8 pixel IR thermal imaging camera
C++
3
star
63

PMW3901

C++
3
star
64

AssetTracker

C++
3
star
65

VEML6070

VEML6070 UV Sensor
Arduino
3
star
66

LSM6DSM_master_LIS2MDL_slave

Arduino sketches for two or more LSM6DSM on an I2C bus
C++
3
star
67

IS31FL3236A

Led ring of 36 white leds driven by the IS31FL3236A led driver
C++
3
star
68

APDS9253

Arduino sketch for the APDS9253 I2C RGBiR light sensor with threshold interrupt
C++
2
star
69

DRV8837

Arduino
2
star
70

TM915_RFID_Reader

Arduino
2
star
71

BME280

C++
2
star
72

M24M02_EEPROM

Arduino
2
star
73

HDC2010

Low-Power Digital Temperature and Humidity Sensor
C++
2
star
74

A1454-Hall-Sensor

Arduino sketch for A1454 I2C Hall Effect Sensor
C++
2
star
75

LP55231_LED_Driver

Arduino
2
star
76

Firefly

C++
1
star
77

BMA400

Arduino class for the BMA400 accelerometer
C++
1
star
78

TMP007

TI's IR thermopile temperature sensor in a small breakout board
Arduino
1
star
79

IQS624

C++
1
star
80

BM1422AGM

Arduino sketch to test BM1422AGM against LIS2MDL magnetometer
C++
1
star
81

AK9753

C++
1
star
82

VEML6040

Teensiduino sketch for Vishay's VEML6040 RGBW color sensor
C++
1
star
83

MLX90621

Arduino
1
star
84

BMA222E

Arduino
1
star
85

Teensy_Flight_Controller

Teensy Flight Control board test programs
C++
1
star
86

ITG3701_LSM303D_MS5637

Arduino
1
star
87

LSM303AGR

ST's combo accel/magnetometer (e-compass), sketch for Arduino
C++
1
star
88

KTD2061

Demo sketch for 36-channel KTD2058/KTD2061 rgb led driver family
C++
1
star