Giter Site home page Giter Site logo

mpu9250_spi_rpi's Introduction

mpu-spi-lib

This python package interfaces the MPU9250 (9-Axis (Gyro + Accelerometer + Compass) MEMS MotionTracking Device) with the Raspberry Pi using the SPI interface. Package includes functions for data extraction from sensors (Accelerometer, Gyroscope, Temperature), calibration, range setting for sensors and inbuilt Low Pass Filters. This repository will be updated constantly with more functions, better functionalities, test results etc. This is an experimental and learning project for me.

In this README:

Features

Version: v1

  • Extraction of raw data directly from registers, sensors values in standard units and calibrated sensor values.
  • Set multiple data ranges on the sensors for each application it is used.
  • Apply various inbuilt LPFs on the sensors for filtering out noise and getting cleaner data.

Wiring

MPU9250 is interfaced to the Raspberry Pi using the SPI interface. This can be acheived by using the following wiring scheme:

RPi MPU9250
Pin 1 Vcc
Pin 6 GND
Pin 23 SCL
Pin 19 SDA
Pin 21 AD0
Pin 24 NCS
Pin 6 FSYNC

Software Setup

  1. Ensure that SPI has been enabled in your Raspberry Pi. Follow this link to setup SPI in your RPi.
  2. Install spidev
    sudo pip install spidev
  3. Install spidev
    sudo pip install numpy

Functions

Get raw accelerometer value

Gets the raw accelerometer data in the unsigned int16 format.

getRawAccValues()

Get raw gyroscope value

Gets the raw gyroscope data in the unsigned int16 format.

 getRawGyrValues()

Get G values

Gets the accelerometer values in 'g'. Run the calibration function before this function to get the adjusted g values.

getGValues()

Get gyroscope values

Gets the gyroscope values in angular velocity. Run the calibration function before this function to get the adjusted gyroscope values.

getGyrValues()

Get Temperature

Gets the temperature readings from the sensor in degree celsius.

getTemperature()

Set accelerometer range

Sets the following ranges in the accelerometer.

setAccRange(accelRange)
"""
accelRange : str
	The supported ranges are as following:
	2g: AccelRangeSelect2G
	4g: AccelRangeSelect4G
	8g: AccelRangeSelect8G
	16g: AccelRangeSelect16G
"""

Set gyroscope range

setGyroRange(accelRange)
"""
gyroRange : str
	The supported ranges are as following ->
	250DPS: GyroRangeSelect250DPS
	500DPS: GyroRangeSelect500DPS
	1000DPS: GyroRangeSelect1000DPS
	2000DPS: GyroRangeSelect2000DPS
"""

Set Digital Low Pass Filter

Set digital lowpass filters from 8 levels on the accelerometer and gyroscope. Check the FFT outputs for each of the DLPF levels.

# Accelerometer DLPF
enableAccDLPF()
setAccDLPF(level)

# Gyroscope DLPF
enableGyrDLPF()	
setGyrDLPF(level)
"""
Select from the 8 levels of Low Pass Filters
	1 > MPU9250_DLPF_0
	2 > MPU9250_DLPF_1
	3 > MPU9250_DLPF_2
	4 > MPU9250_DLPF_3
	5 > MPU9250_DLPF_4
	6 > MPU9250_DLPF_5
	7 > MPU9250_DLPF_6
	8 > MPU9250_DLPF_7
	
Check the Register map for more details. 
"""

Calibration

Calibrates accelerometer and gyroscope. sample_count is used to set the number of calibration samples used.

calibrate(sample_count)

Clear calibration offsets

Clears the offset values of the calibration.

clear_offsets()

mpu9250_spi_rpi's People

Contributors

farishr avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.