Skip to content

Commit

Permalink
release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jarzebski committed Oct 20, 2014
1 parent f01536e commit 39503eb
Show file tree
Hide file tree
Showing 17 changed files with 1,140 additions and 50 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MPU6050 Arduino Library W.I.P.
MPU6050 Arduino Library 1.0.0 / 20.10.2014
======================================================================

* W.I.P.
* First release
146 changes: 142 additions & 4 deletions MPU6050.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MPU6050.cpp - Class file for the MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
Version: W.I.P.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
Expand Down Expand Up @@ -138,6 +138,14 @@ mpu6050_range_t MPU6050::getRange(void)
return (mpu6050_range_t)value;
}

void MPU6050::setDHPFMode(mpu6050_dhpf_t dhpf)
{
uint8_t value;
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
value &= 0b11111000;
value |= dhpf;
writeRegister8(MPU6050_REG_ACCEL_CONFIG, value);
}

void MPU6050::setClockSource(mpu6050_clockSource_t source)
{
Expand All @@ -156,7 +164,6 @@ mpu6050_clockSource_t MPU6050::getClockSource(void)
return (mpu6050_clockSource_t)value;
}


bool MPU6050::getSleepEnabled(void)
{
return readRegisterBit(MPU6050_REG_PWR_MGMT_1, 6);
Expand All @@ -167,6 +174,96 @@ void MPU6050::setSleepEnabled(bool state)
writeRegisterBit(MPU6050_REG_PWR_MGMT_1, 6, state);
}

bool MPU6050::getIntZeroMotionEnabled(void)
{
return readRegisterBit(MPU6050_REG_INT_ENABLE, 5);
}

void MPU6050::setIntZeroMotionEnabled(bool state)
{
writeRegisterBit(MPU6050_REG_INT_ENABLE, 5, state);
}

bool MPU6050::getIntMotionEnabled(void)
{
return readRegisterBit(MPU6050_REG_INT_ENABLE, 6);
}

void MPU6050::setIntMotionEnabled(bool state)
{
writeRegisterBit(MPU6050_REG_INT_ENABLE, 6, state);
}

bool MPU6050::getIntFreeFallEnabled(void)
{
return readRegisterBit(MPU6050_REG_INT_ENABLE, 7);
}

void MPU6050::setIntFreeFallEnabled(bool state)
{
writeRegisterBit(MPU6050_REG_INT_ENABLE, 7, state);
}

uint8_t MPU6050::getMotionDetectionThreshold(void)
{
return readRegister8(MPU6050_REG_MOT_THRESHOLD);
}

void MPU6050::setMotionDetectionThreshold(uint8_t threshold)
{
writeRegister8(MPU6050_REG_MOT_THRESHOLD, threshold);
}

uint8_t MPU6050::getMotionDetectionDuration(void)
{
return readRegister8(MPU6050_REG_MOT_DURATION);
}

void MPU6050::setMotionDetectionDuration(uint8_t duration)
{
writeRegister8(MPU6050_REG_MOT_DURATION, duration);
}

uint8_t MPU6050::getZeroMotionDetectionThreshold(void)
{
return readRegister8(MPU6050_REG_ZMOT_THRESHOLD);
}

void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold)
{
writeRegister8(MPU6050_REG_ZMOT_THRESHOLD, threshold);
}

uint8_t MPU6050::getZeroMotionDetectionDuration(void)
{
return readRegister8(MPU6050_REG_ZMOT_DURATION);
}

void MPU6050::setZeroMotionDetectionDuration(uint8_t duration)
{
writeRegister8(MPU6050_REG_ZMOT_DURATION, duration);
}

uint8_t MPU6050::getFreeFallDetectionThreshold(void)
{
return readRegister8(MPU6050_REG_FF_THRESHOLD);
}

void MPU6050::setFreeFallDetectionThreshold(uint8_t threshold)
{
writeRegister8(MPU6050_REG_FF_THRESHOLD, threshold);
}

uint8_t MPU6050::getFreeFallDetectionDuration(void)
{
return readRegister8(MPU6050_REG_FF_DURATION);
}

void MPU6050::setFreeFallDetectionDuration(uint8_t duration)
{
writeRegister8(MPU6050_REG_FF_DURATION, duration);
}

bool MPU6050::getI2CMasterModeEnabled(void)
{
return readRegisterBit(MPU6050_REG_USER_CTRL, 5);
Expand All @@ -182,9 +279,50 @@ bool MPU6050::getI2CBypassEnabled(void)
return readRegisterBit(MPU6050_REG_INT_PIN_CFG, 1);
}

void MPU6050::setI2CBypassEnabled(bool state)
void MPU6050::setAccelPowerOnDelay(mpu6050_onDelay_t delay)
{
uint8_t value;
value = readRegister8(MPU6050_REG_MOT_DETECT_CTRL);
value &= 0b11001111;
value |= (delay << 4);
writeRegister8(MPU6050_REG_MOT_DETECT_CTRL, value);
}

mpu6050_onDelay_t MPU6050::getAccelPowerOnDelay(void)
{
uint8_t value;
value = readRegister8(MPU6050_REG_MOT_DETECT_CTRL);
value &= 0b00110000;
return (mpu6050_onDelay_t)(value >> 4);
}

uint8_t MPU6050::getIntStatus(void)
{
writeRegisterBit(MPU6050_REG_INT_PIN_CFG, 1, state);
return readRegister8(MPU6050_REG_INT_STATUS);
}

Activites MPU6050::readActivites(void)
{
uint8_t data = readRegister8(MPU6050_REG_INT_STATUS);

a.isOverflow = ((data >> 4) & 1);
a.isFreeFall = ((data >> 7) & 1);
a.isInactivity = ((data >> 5) & 1);
a.isActivity = ((data >> 6) & 1);
a.isDataReady = ((data >> 0) & 1);

data = readRegister8(MPU6050_REG_MOT_DETECT_STATUS);

a.isNegActivityOnX = ((data >> 7) & 1);
a.isPosActivityOnX = ((data >> 6) & 1);

a.isNegActivityOnY = ((data >> 5) & 1);
a.isPosActivityOnY = ((data >> 4) & 1);

a.isNegActivityOnZ = ((data >> 3) & 1);
a.isPosActivityOnZ = ((data >> 2) & 1);

return a;
}

Vector MPU6050::readRawAccel(void)
Expand Down
142 changes: 107 additions & 35 deletions MPU6050.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MPU6050.h - Header file for the MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
Version: W.I.P
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
Expand All @@ -27,40 +27,50 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "WProgram.h"
#endif

#define MPU6050_ADDRESS (0x68) // 0x69 when AD0 pin to Vcc

#define MPU6050_REG_ACCEL_XOFFS_H (0x06)
#define MPU6050_REG_ACCEL_XOFFS_L (0x07)
#define MPU6050_REG_ACCEL_YOFFS_H (0x08)
#define MPU6050_REG_ACCEL_YOFFS_L (0x09)
#define MPU6050_REG_ACCEL_ZOFFS_H (0x0A)
#define MPU6050_REG_ACCEL_ZOFFS_L (0x0B)
#define MPU6050_REG_GYRO_XOFFS_H (0x13)
#define MPU6050_REG_GYRO_XOFFS_L (0x14)
#define MPU6050_REG_GYRO_YOFFS_H (0x15)
#define MPU6050_REG_GYRO_YOFFS_L (0x16)
#define MPU6050_REG_GYRO_ZOFFS_H (0x17)
#define MPU6050_REG_GYRO_ZOFFS_L (0x18)
#define MPU6050_REG_GYRO_CONFIG (0x1B) // Gyroscope Configuration
#define MPU6050_REG_ACCEL_CONFIG (0x1C) // Accelerometer Configuration
#define MPU6050_REG_INT_PIN_CFG (0x37) // INT Pin. Bypass Enable Configuration
#define MPU6050_REG_ACCEL_XOUT_H (0x3B)
#define MPU6050_REG_ACCEL_XOUT_L (0x3C)
#define MPU6050_REG_ACCEL_YOUT_H (0x3D)
#define MPU6050_REG_ACCEL_YOUT_L (0x3E)
#define MPU6050_REG_ACCEL_ZOUT_H (0x3F)
#define MPU6050_REG_ACCEL_ZOUT_L (0x40)
#define MPU6050_REG_TEMP_OUT_H (0x41)
#define MPU6050_REG_TEMP_OUT_L (0x42)
#define MPU6050_REG_GYRO_XOUT_H (0x43)
#define MPU6050_REG_GYRO_XOUT_L (0x44)
#define MPU6050_REG_GYRO_YOUT_H (0x45)
#define MPU6050_REG_GYRO_YOUT_L (0x46)
#define MPU6050_REG_GYRO_ZOUT_H (0x47)
#define MPU6050_REG_GYRO_ZOUT_L (0x48)
#define MPU6050_REG_USER_CTRL (0x6A) // User Control
#define MPU6050_REG_PWR_MGMT_1 (0x6B) // Power Management 1
#define MPU6050_REG_WHO_AM_I (0x75) // Who Am I
#define MPU6050_ADDRESS (0x68) // 0x69 when AD0 pin to Vcc

#define MPU6050_REG_ACCEL_XOFFS_H (0x06)
#define MPU6050_REG_ACCEL_XOFFS_L (0x07)
#define MPU6050_REG_ACCEL_YOFFS_H (0x08)
#define MPU6050_REG_ACCEL_YOFFS_L (0x09)
#define MPU6050_REG_ACCEL_ZOFFS_H (0x0A)
#define MPU6050_REG_ACCEL_ZOFFS_L (0x0B)
#define MPU6050_REG_GYRO_XOFFS_H (0x13)
#define MPU6050_REG_GYRO_XOFFS_L (0x14)
#define MPU6050_REG_GYRO_YOFFS_H (0x15)
#define MPU6050_REG_GYRO_YOFFS_L (0x16)
#define MPU6050_REG_GYRO_ZOFFS_H (0x17)
#define MPU6050_REG_GYRO_ZOFFS_L (0x18)
#define MPU6050_REG_GYRO_CONFIG (0x1B) // Gyroscope Configuration
#define MPU6050_REG_ACCEL_CONFIG (0x1C) // Accelerometer Configuration
#define MPU6050_REG_FF_THRESHOLD (0x1D)
#define MPU6050_REG_FF_DURATION (0x1E)
#define MPU6050_REG_MOT_THRESHOLD (0x1F)
#define MPU6050_REG_MOT_DURATION (0x20)
#define MPU6050_REG_ZMOT_THRESHOLD (0x21)
#define MPU6050_REG_ZMOT_DURATION (0x22)
#define MPU6050_REG_INT_PIN_CFG (0x37) // INT Pin. Bypass Enable Configuration
#define MPU6050_REG_INT_ENABLE (0x38) // INT Enable
#define MPU6050_REG_INT_STATUS (0x3A)
#define MPU6050_REG_ACCEL_XOUT_H (0x3B)
#define MPU6050_REG_ACCEL_XOUT_L (0x3C)
#define MPU6050_REG_ACCEL_YOUT_H (0x3D)
#define MPU6050_REG_ACCEL_YOUT_L (0x3E)
#define MPU6050_REG_ACCEL_ZOUT_H (0x3F)
#define MPU6050_REG_ACCEL_ZOUT_L (0x40)
#define MPU6050_REG_TEMP_OUT_H (0x41)
#define MPU6050_REG_TEMP_OUT_L (0x42)
#define MPU6050_REG_GYRO_XOUT_H (0x43)
#define MPU6050_REG_GYRO_XOUT_L (0x44)
#define MPU6050_REG_GYRO_YOUT_H (0x45)
#define MPU6050_REG_GYRO_YOUT_L (0x46)
#define MPU6050_REG_GYRO_ZOUT_H (0x47)
#define MPU6050_REG_GYRO_ZOUT_L (0x48)
#define MPU6050_REG_MOT_DETECT_STATUS (0x61)
#define MPU6050_REG_MOT_DETECT_CTRL (0x69)
#define MPU6050_REG_USER_CTRL (0x6A) // User Control
#define MPU6050_REG_PWR_MGMT_1 (0x6B) // Power Management 1
#define MPU6050_REG_WHO_AM_I (0x75) // Who Am I

#ifndef VECTOR_STRUCT_H
#define VECTOR_STRUCT_H
Expand All @@ -72,6 +82,21 @@ struct Vector
};
#endif

struct Activites
{
bool isOverflow;
bool isFreeFall;
bool isInactivity;
bool isActivity;
bool isPosActivityOnX;
bool isPosActivityOnY;
bool isPosActivityOnZ;
bool isNegActivityOnX;
bool isNegActivityOnY;
bool isNegActivityOnZ;
bool isDataReady;
};

typedef enum
{
MPU6050_CLOCK_KEEP_RESET = 0b111,
Expand Down Expand Up @@ -99,6 +124,24 @@ typedef enum
MPU6050_RANGE_2G = 0b00,
} mpu6050_range_t;

typedef enum
{
MPU6050_DELAY_3MS = 0b11,
MPU6050_DELAY_2MS = 0b10,
MPU6050_DELAY_1MS = 0b01,
MPU6050_NO_DELAY = 0b00,
} mpu6050_onDelay_t;

typedef enum
{
MPU6050_DHPF_HOLD = 0b111,
MPU6050_DHPF_0_63HZ = 0b100,
MPU6050_DHPF_1_25HZ = 0b011,
MPU6050_DHPF_2_5HZ = 0b010,
MPU6050_DHPF_5HZ = 0b001,
MPU6050_DHPF_RESET = 0b000,
} mpu6050_dhpf_t;

class MPU6050
{
public:
Expand All @@ -111,6 +154,33 @@ class MPU6050
mpu6050_clockSource_t getClockSource(void);
mpu6050_dps_t getScale(void);
mpu6050_range_t getRange(void);
void setDHPFMode(mpu6050_dhpf_t dhpf);
mpu6050_onDelay_t getAccelPowerOnDelay();
void setAccelPowerOnDelay(mpu6050_onDelay_t delay);

uint8_t getIntStatus(void);

bool getIntZeroMotionEnabled(void);
void setIntZeroMotionEnabled(bool state);
bool getIntMotionEnabled(void);
void setIntMotionEnabled(bool state);
bool getIntFreeFallEnabled(void);
void setIntFreeFallEnabled(bool state);

uint8_t getMotionDetectionThreshold(void);
void setMotionDetectionThreshold(uint8_t threshold);
uint8_t getMotionDetectionDuration(void);
void setMotionDetectionDuration(uint8_t duration);

uint8_t getZeroMotionDetectionThreshold(void);
void setZeroMotionDetectionThreshold(uint8_t threshold);
uint8_t getZeroMotionDetectionDuration(void);
void setZeroMotionDetectionDuration(uint8_t duration);

uint8_t getFreeFallDetectionThreshold(void);
void setFreeFallDetectionThreshold(uint8_t threshold);
uint8_t getFreeFallDetectionDuration(void);
void setFreeFallDetectionDuration(uint8_t duration);

bool getSleepEnabled(void);
void setSleepEnabled(bool state);
Expand All @@ -120,6 +190,7 @@ class MPU6050
void setI2CBypassEnabled(bool state);

float readTemperature(void);
Activites readActivites(void);

int16_t getGyroOffsetX(void);
void setGyroOffsetX(int16_t offset);
Expand Down Expand Up @@ -150,6 +221,7 @@ class MPU6050
Vector na, ng; // Normalized vectors
Vector tg, dg; // Threshold and Delta for Gyro
Vector th; // Threshold
Activites a; // Activities

float dpsPerDigit, rangePerDigit;
float actualThreshold;
Expand Down
2 changes: 1 addition & 1 deletion MPU6050_accel_pitch_roll/MPU6050_accel_pitch_roll.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MPU6050 Triple Axis Gyroscope & Accelerometer. Pitch & Roll Accelerometer Example.
Read more: TODO
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
GIT: https://github.com/jarzebski/Arduino-MPU6050
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
Expand Down
2 changes: 1 addition & 1 deletion MPU6050_accel_simple/MPU6050_accel_simple.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MPU6050 Triple Axis Gyroscope & Accelerometer. Simple Accelerometer Example.
Read more: TODO
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
GIT: https://github.com/jarzebski/Arduino-MPU6050
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
Expand Down
Loading

0 comments on commit 39503eb

Please sign in to comment.