I have a question about "Wire.read()".

Hello, guys.
I use MPU-6050 to collect both gyro data and accel.
This is my code.

Wire.beginTransmission(mpu_addr);
Wire.write(0x43);
Wire.endTransmission(false);
Wire.requestFrom(mpu_addr, 6, true);
gy_x = Wire.read() << 8 | Wire.read();
gy_y = Wire.read() << 8 | Wire.read();
gy_z = Wire.read() << 8 | Wire.read();

By using Wire.requestFrom(), I can get 6 byte data from mpu_addr.
but, I don’t understand the above things.

gy_x = Wire.read() << 8 | Wire.read();
gy_y = Wire.read() << 8 | Wire.read();
gy_z = Wire.read() << 8 | Wire.read();

The 6 byte data can input gy_x, gy_y, gy_z sequentially?
Thank you for your help! :slight_smile:

It appears the code is reassembling 6 bytes into 3 integers. It does a read, then shifts the byte left 8 bits, putting that byte into the high byte of the integer, then reads the low byte and puts it into the low byte of the integer. Repeats 2 more times.

It really helpful.
I understand that problem.
Thank you for your help :slight_smile: