Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 15 additions & 36 deletions MPU6050.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version: 1.0.3
(c) 2014-2015 Korneliusz Jarzebski
www.jarzebski.pl

Modified by el-NASA (Daniel Alejandro Rodriguez) 2019

This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
Expand Down Expand Up @@ -49,7 +51,7 @@ bool MPU6050::begin(mpu6050_dps_t scale, mpu6050_range_t range, int mpua)
actualThreshold = 0;

// Check MPU6050 Who Am I Register
if (fastRegister8(MPU6050_REG_WHO_AM_I) != 0x68)
if (readRegister8(MPU6050_REG_WHO_AM_I) != 0x68)
{
return false;
}
Expand Down Expand Up @@ -352,10 +354,10 @@ Vector MPU6050::readRawAccel(void)
#endif
Wire.endTransmission();

Wire.beginTransmission(mpuAddress);
//Wire.beginTransmission(mpuAddress);
Wire.requestFrom(mpuAddress, 6);

while (Wire.available() < 6);
//while (Wire.available() < 6);

#if ARDUINO >= 100
uint8_t xha = Wire.read();
Expand Down Expand Up @@ -413,10 +415,10 @@ Vector MPU6050::readRawGyro(void)
#endif
Wire.endTransmission();

Wire.beginTransmission(mpuAddress);
//Wire.beginTransmission(mpuAddress);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove redundant comments?

Wire.requestFrom(mpuAddress, 6);

while (Wire.available() < 6);
//while (Wire.available() < 6);

#if ARDUINO >= 100
uint8_t xha = Wire.read();
Expand Down Expand Up @@ -612,31 +614,8 @@ void MPU6050::setThreshold(uint8_t multiple)
// Remember old threshold value
actualThreshold = multiple;
}

// Fast read 8-bit from register
uint8_t MPU6050::fastRegister8(uint8_t reg)
{
uint8_t value;

Wire.beginTransmission(mpuAddress);
#if ARDUINO >= 100
Wire.write(reg);
#else
Wire.send(reg);
#endif
Wire.endTransmission();

Wire.beginTransmission(mpuAddress);
Wire.requestFrom(mpuAddress, 1);
#if ARDUINO >= 100
value = Wire.read();
#else
value = Wire.receive();
#endif;
Wire.endTransmission();

return value;
}
//There preveiw code has the function "fastRegister8", but it has the same code as "readRegister8", making it unnecesary
//This correction was possible thanks to an issue posted by koepel in my project POA

// Read 8-bit from register
uint8_t MPU6050::readRegister8(uint8_t reg)
Expand All @@ -651,15 +630,15 @@ uint8_t MPU6050::readRegister8(uint8_t reg)
#endif
Wire.endTransmission();

Wire.beginTransmission(mpuAddress);
//Wire.beginTransmission(mpuAddress);
Wire.requestFrom(mpuAddress, 1);
while(!Wire.available()) {};
//while(!Wire.available()) {};
#if ARDUINO >= 100
value = Wire.read();
#else
value = Wire.receive();
#endif;
Wire.endTransmission();
//Wire.endTransmission();

return value;
}
Expand Down Expand Up @@ -690,17 +669,17 @@ int16_t MPU6050::readRegister16(uint8_t reg)
#endif
Wire.endTransmission();

Wire.beginTransmission(mpuAddress);
//Wire.beginTransmission(mpuAddress);
Wire.requestFrom(mpuAddress, 2);
while(!Wire.available()) {};
//while(!Wire.available()) {};
#if ARDUINO >= 100
uint8_t vha = Wire.read();
uint8_t vla = Wire.read();
#else
uint8_t vha = Wire.receive();
uint8_t vla = Wire.receive();
#endif;
Wire.endTransmission();
//Wire.endTransmission();

value = vha << 8 | vla;

Expand Down