Skip to content

Commit

Permalink
apply I2C Read fix (Issue tockn#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Starkov committed Aug 29, 2019
1 parent 31c05b9 commit 89ffd68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/MPU6050_tockn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ void MPU6050::calcGyroOffsets(bool console, uint16_t delayBefore, uint16_t delay
}
wire->beginTransmission(MPU6050_ADDR);
wire->write(0x43);
wire->endTransmission(false);
byte rxStatus = wire->endTransmission(true);
if (rxStatus != 0 && console) Serial.println("MPU6050::update EC: " + String(rxStatus));

wire->requestFrom((int)MPU6050_ADDR, 6);

rx = wire->read() << 8 | wire->read();
Expand All @@ -94,10 +96,12 @@ void MPU6050::calcGyroOffsets(bool console, uint16_t delayBefore, uint16_t delay
}
}

void MPU6050::update(){
void MPU6050::update(bool console){
wire->beginTransmission(MPU6050_ADDR);
wire->write(0x3B);
wire->endTransmission(false);
byte rxStatus = wire->endTransmission(true);
if (rxStatus != 0 && console) Serial.println("MPU6050::update EC: " + String(rxStatus));

wire->requestFrom((int)MPU6050_ADDR, 14);

rawAccX = wire->read() << 8 | wire->read();
Expand Down
2 changes: 1 addition & 1 deletion src/MPU6050_tockn.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MPU6050{
float getGyroYoffset(){ return gyroYoffset; };
float getGyroZoffset(){ return gyroZoffset; };

void update();
void update(bool console = false);

float getAccAngleX(){ return angleAccX; };
float getAccAngleY(){ return angleAccY; };
Expand Down

0 comments on commit 89ffd68

Please sign in to comment.