Git Product home page Git Product logo

mpu9250_asukiaaa's Introduction

MPU9250_asukiaaa

A library to read value of MPU9250.

Installation

You can install to Arduino IDE with using library manager.

  1. Select [Sketch -> Include Library -> Manage Libraries] to open library manager.
  2. Search MPU9250 in library manager.
  3. Select and install this project.

Connection

For uno, nano and so on.

Arduino MPU9250
3.3 VCC
A4(SDA) SDA
A5(SCL) SCL
GND GND

For other boards, please check i2c pin assign.

Usage

You can see all function on example project.

Accelerometer

#include <MPU9250_asukiaaa.h>
MPU9250 mySensor;
float aX, aY, aZ, aSqrt;

void setup() {
  Wire.begin();
  mySensor.setWire(&Wire);
  mySensor.beginAccel();
}

void loop() {
  mySensor.accelUpdate();
  aX = mySensor.accelX();
  aY = mySensor.accelY();
  aZ = mySensor.accelZ();
  aSqrt = mySensor.accelSqrt();
  // Do what you want
}

Gyrometer

#include <MPU9250_asukiaaa.h>
MPU9250 mySensor;
float gX, gY, gZ;

void setup() {
  Wire.begin();
  mySensor.setWire(&Wire);
  mySensor.beginGyro();
}

void loop() {
  mySensor.gyroUpdate();
  gX = mySensor.gyroX();
  gY = mySensor.gyroY();
  gZ = mySensor.gyroZ();
  // Do what you want
}

Magnetometer

#include <MPU9250_asukiaaa.h>
MPU9250 mySensor;
float mDirection;
uint16_t mX, mY, mZ;

void setup() {
  Wire.begin();
  mySensor.setWire(&Wire);
  mySensor.beginMag();
}

void loop() {
  Serial.begin(115200);
  mySensor.magUpdate();
  mX = mySensor.magX();
  mY = mySensor.magY();
  mZ = mySensor.magZ();
  mDirection = mySensor.magHorizDirection();
  // Do what you want
}

If you get values of sensor like this..

Name Max Min
magX 70 -30
maxY 110 10

You can calcurate offset values like this.

maxXOffset = - (magXMax + magXMin) / 2
           = - (70 - 30) / 2
           = - 40 / 2
           = -20
magYOffset = - (magYMax + magYMin) / 2
           = - (110 + 10) / 2
           = - 120 / 2
           = -60

Then set the offset values like this.

void setup() {
  mySensor.magXOffset = -20;
  mySensor.magYOffset = -60;
}

Then you can get like this.

Name Max Min
magX 50 -50
maxY 50 -50

After setting offset value, you can get magHorizDirection as you expected.

Warning: Offset value changes by temperature or some reason. If you want to get high accuracy value, you should recheck the offset value.

With customizable Wire

For ESP8266, ESP32 and so on.

void setup() {
  Wire.begin(26, 25); //sda, scl
  mySensor.setWire(&Wire);
}

License

MIT

References

mpu9250_asukiaaa's People

Contributors

asukiaaa avatar

Watchers

Dan Romescu avatar James Cloos 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.