So, I am currently attempting to read data from a MPU-6050 IMU chip. Since this is my first time with I2C and using hardware this advanced, I am following along with a code I found on this website. In this section of the code (which is found in the MPU6050 Arduino Code section of the website), it says that the '6' in the Wire.requestFrom function reads 6 registers.
void loop() {
// === Read acceleromter data === //
Wire.beginTransmission(MPU);
Wire.write(0x3B); // Start with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
//For a range of +-2g, we need to divide the raw values by 16384, according to the datasheet
AccX = (Wire.read() << 8 | Wire.read()) / 16384.0; // X-axis value
AccY = (Wire.read() << 8 | Wire.read()) / 16384.0; // Y-axis value
AccZ = (Wire.read() << 8 | Wire.read()) / 16384.0; // Z-axis value
This is where I get confused. From the Arduino documentation website, it states that the second argument, the quantity argument tells the number of bytes to return. So, I have two questions:
- Given that the
Wire.write(0x3B)line only says to write to one register (which only outputs 1 byte from my understanding of the MPU 6050 register datasheet), how does therequestFromreturn more than 1? - Hypothetically, if the '6' indicates the number of registers to read, why isn't the documentation clearer about this? Or is the Arduino definition clear for programmers to understand?
Excuse any ignorance or lack of clarity in my question; From the start, I've been pretty overwhelmed with the whole I2C communication process. But, I'm trying to learn it.
Thanks for any help.