All Projects → natanaeljr → Esp32 Mpu Driver

natanaeljr / Esp32 Mpu Driver

Licence: mit
ESP32 full library for all MPU6000 MPU6050 MPU6500 MPU9150 MPU9250 with SPI and I2C support and more.

Projects that are alternatives of or similar to Esp32 Mpu Driver

Ofxgpio
Library C++ for raspberrypi and orangepi, GPIO interfaces compatible with openframeworks.
Stars: ✭ 155 (+39.64%)
Mutual labels:  spi, i2c, library
gfx demo
GFX Demo for Arduino and the ESP-IDF
Stars: ✭ 63 (-43.24%)
Mutual labels:  i2c, esp32, spi
Nf Interpreter
⚙️ nanoFramework Interpreter, CLR, HAL, PAL and reference target boards
Stars: ✭ 168 (+51.35%)
Mutual labels:  esp32, spi, i2c
Esp8266 Oled Ssd1306
Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
Stars: ✭ 1,590 (+1332.43%)
Mutual labels:  esp32, spi, i2c
BME680
Arduino Library to access the Bosch BME680 - temperature, pressure, humidity and gas sensor
Stars: ✭ 30 (-72.97%)
Mutual labels:  i2c, sensor, spi
Ssd1306
Driver for SSD1306, SSD1331, SSD1351, IL9163, ILI9341, ST7735, PCD8544, Nokia 5110 displays running on Arduino/ESP32/Linux (Rasperry) platforms
Stars: ✭ 303 (+172.97%)
Mutual labels:  esp32, spi, i2c
Rppal
A Rust library that provides access to the Raspberry Pi's GPIO, I2C, PWM, SPI and UART peripherals.
Stars: ✭ 463 (+317.12%)
Mutual labels:  spi, i2c
Esp Dash
A blazing fast library to create a functional dashboard for ESP8266 and ESP32
Stars: ✭ 548 (+393.69%)
Mutual labels:  esp32, library
Adafruit sensor
Common sensor library
Stars: ✭ 757 (+581.98%)
Mutual labels:  sensor, library
Tinygo
Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
Stars: ✭ 9,068 (+8069.37%)
Mutual labels:  spi, i2c
Esp At
AT application for ESP32 ESP-IDF & ESP32S2 ESP-IDF & ESP8266 ESP8266_RTOS_SDK
Stars: ✭ 319 (+187.39%)
Mutual labels:  esp32, spi
Bmp085
A node.js module for reading a BMP085 barometer sensor.
Stars: ✭ 11 (-90.09%)
Mutual labels:  sensor, i2c
Rt U8g2
U8g2 for rt-thread - a monochrome graphics library
Stars: ✭ 56 (-49.55%)
Mutual labels:  spi, i2c
Esp32 tft library
Full featured TFT library for ESP32 with demo application
Stars: ✭ 383 (+245.05%)
Mutual labels:  esp32, library
Buck50
STM32F103 logic analyzer and more
Stars: ✭ 358 (+222.52%)
Mutual labels:  spi, i2c
Luma.oled
Python module to drive a SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106 OLED
Stars: ✭ 560 (+404.5%)
Mutual labels:  spi, i2c
Elixir ale
Interact with hardware in Elixir - GPIOs, I2C and SPI
Stars: ✭ 336 (+202.7%)
Mutual labels:  spi, i2c
Raspberrysharp
A .NET/Mono IO Library for Raspberry Pi This library is a complete refactoring of Raspberry-Sharp libraries, merged into one library and updated to RB3, CM3 and RB3+
Stars: ✭ 41 (-63.06%)
Mutual labels:  spi, i2c
Swiftygpio
A Swift library for hardware projects on Linux/ARM boards with support for GPIOs/SPI/I2C/PWM/UART/1Wire.
Stars: ✭ 1,188 (+970.27%)
Mutual labels:  spi, i2c
Esp32 I2c Ssd1306 Oled
A library for esp32 i2c oled ssd1306
Stars: ✭ 68 (-38.74%)
Mutual labels:  esp32, i2c

Documentation Build Status License: MIT

MPU Driver

A library for Invensense MPU chips. It is written in C++ and designed for working with ESP32 microcontroller esp-idf framework. Supports both SPI and I2C protocols interchangeably, selectable bus port, and even multiple connected MPUs.

Models

part sensors protocol
MPU6000 Gyro/Accel I2C, SPI
MPU6050 Gyro/Accel I2C
MPU6500 Gyro/Accel I2C, SPI
MPU6555 Gyro/Accel I2C, SPI
MPU9150 Gyro/Accel/Compass I2C
MPU9250 Gyro/Accel/Compass I2C, SPI
MPU9255 Gyro/Accel/Compass I2C, SPI

Features

  • [x] Support to SPI and I2C protocol (with selectable port)
  • [x] Basic configurations (sample rate (4Hz~32KHz), clock source, full-scale, standby mode, offsets, interrupts, DLPF, etc..)
  • [x] Burst reading for all sensors
  • [x] Low Power Accelerometer mode (various rates, e.g. 8.4μA at 0.98Hz)
  • [x] Low Power Wake-on-motion mode (with motion detection interrupt)
  • [x] FIFO buffer access for all internal and external sensors
  • [x] Complete Auxiliary I2C support for external sensors (up to 4)
  • [x] External Frame Synchronization (FSYNC) pass-through interrupt
  • [x] Motion, Zero-motion and Free-Fall detection (as motion detection interrupt)
  • [x] Total access to the Magnetometer (even when MPU connected by SPI protocol)
  • [x] Calibration for Gyro and Accel
  • [x] Self-Test (true implementation from MotionApps)

DMP

  • [ ] Quaternion (3-axis Gyroscope)
  • [ ] Quaternion (6-axis Gyroscope and Accelerometer)
  • [ ] Screen Orientation (Android's screen rotation algorithm)
  • [ ] Tap Detection
  • [ ] Pedometer
  • [ ] Gyroscope calibrated data

Getting Started

Prerequisites

MPU driver depends on the following protocol libraries to communicate with the chip with ease: [ I2Cbus | SPIbus ].
You must download the one according to the protocol you'll use and place within your components directory as well.

I2Cbus:  git clone https://github.com/natanaeljr/esp32-I2Cbus.git I2Cbus
SPIbus:  git clone https://github.com/natanaeljr/esp32-SPIbus.git SPIbus

Note: At least one of these libraries must be installed as components for the MPU library to work. It won't work otherwise.

Installation

Download the repository here, or clone it right into your project components directory with the following command.

git clone https://github.com/natanaeljr/esp32-MPU-driver.git MPUdriver

This way you can easily update the library with git pull whenever a update is available.

Usage

First of all, make sure MPU Driver is a component in you project, then run make menuconfig, select your chip model and communication protocol you'll use browsing through to Component config -> MPU Driver.

Menuconfig

Now, in your source code, include the mpu main header MPU.hpp, the communication library I2Cbus.hpp or SPIbus.hpp and any other mpu headers that you'll use. Then get the bus ready as shown below.

#include "MPU.hpp"        // main file, provides the class itself
#include "mpu/math.hpp"   // math helper for dealing with MPU data
#include "mpu/types.hpp"  // MPU data types and definitions
#include "I2Cbus.hpp"
// ...
i2c0.begin(SDA, SCL, CLOCK);  // initialize the I2C bus

And for SPI:

#include "MPU.hpp"        // main file, provides the class itself
#include "mpu/math.hpp"   // math helper for dealing with MPU data
#include "mpu/types.hpp"  // MPU data types and definitions
#include "SPIbus.hpp"
// ...
hspi.begin(MOSI, MISO, SCLK);  // initialize the SPI bus
spi_device_handle_t mpu_spi_handle;
hspi.addDevice(SPIMODE, CLOCK, CS_PIN, &mpu_spi_handle);

Note: You can initialize/configure the bus through the esp-idf API normally, it should work just fine too.

Create a MPU object, setup and initialize it.

MPU_t MPU;         // create an object
MPU.setBus(i2c0);  // set communication bus, for SPI -> pass 'hspi'
MPU.setAddr(mpud::MPU_I2CADDRESS_AD0_LOW);  // set address or handle, for SPI -> pass 'mpu_spi_handle'
MPU.testConnection()  // test connection with the chip, return is a error code
MPU.initialize();  // this will initialize the chip and set default configurations

Call set functions to configure the chip as needed.

MPU.setSampleRate(250);  // in (Hz)
MPU.setAccelFullScale(mpud::ACCEL_FS_4G);
MPU.setGyroFullScale(mpud::GYRO_FS_500DPS);
MPU.setDigitalLowPassFilter(mpud::DLPF_42HZ);  // smoother data
MPU.setInterruptEnabled(mpud::INT_EN_RAWDATA_READY);  // enable INT pin

Read sensor data:

mpud::raw_axes_t accelRaw;     // holds x, y, z axes as int16
mpud::raw_axes_t gyroRaw;      // holds x, y, z axes as int16
MPU.acceleration(&accelRaw);  // fetch raw data from the registers
MPU.rotation(&gyroRaw);       // fetch raw data from the registers
printf("accel: %+d %+d %+d\n", accelRaw.x, accelRaw.y, accelRaw.z);
printf("gyro: %+d %+d %+d\n", gyroRaw[0], gyroRaw[1], gyroRaw[2]);

Convert to more readable formats.

mpud::float_axes_t accelG = mpud::accelGravity(accelRaw, mpud::ACCEL_FS_4G);  // raw data to gravity
mpud::float_axes_t gyroDPS = mpud::gyroDecPerSec(gyroRaw, mpud::GYRO_FS_500DPS);  // raw data to º/s
printf("accel: %+.2f %+.2f %+.2f\n", accelG[0], accelG[1], accelG[2]);
printf("gyro: %+.2f %+.2f %+.2f\n", gyroDPS.x, gyroDPS.y, gyroDPS.z);

The API provides many other functions to manage and operate the sensor in its full potencial. See API Reference .

Tests

See MPU Unit Test for more information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright © 2017-2018, Natanael Josue Rabello [[email protected]]


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].