Skip to content

Commit

Permalink
Wasting less i2c commands
Browse files Browse the repository at this point in the history
requested 2 bytes then discarded 1
requested 14 bytes then discarded 8 (also shifted some for no reason?)
  • Loading branch information
rune-scape committed Sep 19, 2018
1 parent f957b4f commit dd36f2a
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/MPU6050_tockn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ byte MPU6050::readMPU6050(byte reg) {
wire->beginTransmission(MPU6050_ADDR);
wire->write(reg);
wire->endTransmission(true);
wire->requestFrom((uint8_t)MPU6050_ADDR, (size_t)2/*length*/);
wire->requestFrom(MPU6050_ADDR, 1);
byte data = wire->read();
wire->read();
return data;
}

Expand All @@ -66,14 +65,10 @@ void MPU6050::calcGyroOffsets(bool console){
Serial.print(".");
}
wire->beginTransmission(MPU6050_ADDR);
wire->write(0x3B);
wire->write(0x43);
wire->endTransmission(false);
wire->requestFrom((int)MPU6050_ADDR, 14, (int)true);
wire->requestFrom((int)MPU6050_ADDR, 6, (int)true);

wire->read() << 8 | wire->read();
wire->read() << 8 | wire->read();
wire->read() << 8 | wire->read();
wire->read() << 8 | wire->read();
rx = wire->read() << 8 | wire->read();
ry = wire->read() << 8 | wire->read();
rz = wire->read() << 8 | wire->read();
Expand Down

0 comments on commit dd36f2a

Please sign in to comment.