wokoeck_ch aaa78c8a23 Menu updated; Magnetic sensor offsets groundwork & shell script for easy program start | 3 ani în urmă | |
---|---|---|
.. | ||
MPU9250 | 3 ani în urmă | |
examples | 3 ani în urmă | |
.piopm | 3 ani în urmă | |
LICENSE | 3 ani în urmă | |
MPU9250.h | 3 ani în urmă | |
README.md | 3 ani în urmă | |
library.json | 3 ani în urmă | |
library.properties | 3 ani în urmă |
Arduino library for MPU9250 Nine-Axis (Gyro + Accelerometer + Compass) MEMS MotionTracking™ Device
This library is based on the great work by kriswiner, and re-writen for the simple usage.
#include "MPU9250.h"
MPU9250 mpu;
// MPU9255 mpu; // You can also use MPU9255
void setup() {
Serial.begin(115200);
Wire.begin();
delay(2000);
mpu.setup(0x68); // change to your own address
}
void loop() {
if (mpu.update()) {
mpu.printRollPitchYaw();
}
}
round device around during mag calibration
#include "MPU9250.h"
MPU9250 mpu;
// MPU9255 mpu; // You can also use MPU9255
void setup() {
Serial.begin(115200);
Wire.begin();
delay(2000);
mpu.setup(0x68); // change to your own address
delay(5000);
// calibrate anytime you want to
mpu.calibrateAccelGyro();
mpu.calibrateMag();
mpu.printCalibration();
}
void loop() { }
You must set your own address based on A0, A1, A2 setting as:
mpu.setup(0x70);
You can use other I2C library e.g. SoftWire.
MPU9250_<SoftWire, MPU9250_WHOAMI_DEFAULT_VALUE> mpu;
SoftWire sw(SDA, SCL);
// in setup()
mpu.setup(0x70, sw);
Magnetic declination should be set depending on where you are to get accurate data. To set it, use this method.
mpu.setMagneticDeclination(value);
You can find magnetic declination in your city here.
For more details, see wiki.
enum class AFS { A2G, A4G, A8G, A16G };
enum class GFS { G250DPS, G500DPS, G1000DPS, G2000DPS };
`enum class MFS { M14BITS, M16BITS };
MPU9250 class is defined as follows.
template <
typename WireType,
AFS AFSSEL = AFS::A16G,
GFS GFSSEL = GFS::G2000DPS,
MFS MFSSEL = MFS::M16BITS
>
class MPU9250_;
So, please use like
class MPU9250_<TwoWire, AFS::A4G, GFS::G500DPS, MFS::M14BITS> mpu; // most of Arduino
class MPU9250_<i2c_t3, AFS::A4G, GFS::G500DPS, MFS::M14BITS> mpu; // Teensy
To use MPU9255 instead of MPU9250, just declare MPU9255.
MPU9255 mpu;
bool setup(const uint8_t addr, WireType& w = Wire);
void verbose(const bool b);
void calibrateAccelGyro();
void calibrateMag();
bool isConnectedMPU9250();
bool isConnectedAK8963();
bool available();
bool update();
float getRoll() const;
float getPitch() const;
float getYaw() const;
float getQuaternion(uint8_t i) const;
float getQuaternionX() const;
float getQuaternionY() const;
float getQuaternionZ() const;
float getQuaternionW() const;
float getAcc(const uint8_t i) const;
float getGyro(const uint8_t i) const;
float getMag(const uint8_t i) const;
float getAccX() const;
float getAccY() const;
float getAccZ() const;
float getGyroX() const;
float getGyroY() const;
float getGyroZ() const;
float getMagX() const;
float getMagY() const;
float getMagZ() const;
float getAccBias(const uint8_t i) const;
float getGyroBias(const uint8_t i) const;
float getMagBias(const uint8_t i) const;
float getMagScale(const uint8_t i) const;
float getAccBiasX() const;
float getAccBiasY() const;
float getAccBiasZ() const;
float getGyroBiasX() const;
float getGyroBiasY() const;
float getGyroBiasZ() const;
float getMagBiasX() const;
float getMagBiasY() const;
float getMagBiasZ() const;
float getMagScaleX() const;
float getMagScaleY() const;
float getMagScaleZ() const;
float getTemperature() const;
void setAccBias(const uint8_t i, const float v);
void setGyroBias(const uint8_t i, const float v);
void setMagBias(const uint8_t i, const float v);
void setMagScale(const uint8_t i, const float v);
void setAccBiasX(const float v);
void setAccBiasY(const float v);
void setAccBiasZ(const float v);
void setGyroBiasX(const float v);
void setGyroBiasY(const float v);
void setGyroBiasZ(const float v);
void setMagBiasX(const float v);
void setMagBiasY(const float v);
void setMagBiasZ(const float v);
void setMagScaleX(const float v);
void setMagScaleY(const float v);
void setMagScaleZ(const float v);
void setMagneticDeclination(const float d);
void print() const;
void printRawData() const;
void printRollPitchYaw() const;
void printCalibration() const;
MIT