I want to read the value of I2C register of MPU6050, and other registers like the scale range selected of a gyro.
The I2C address according to MPU6050 datasheet is 0x68.
I wrote this code:
#include <Wire.h>
const int register_to_use=0x68;
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println("Start Scanning");
}
void loop() {
int value;
Serial.println("Scanning..");
Wire.beginTransmission(register_to_use);
value = Wire.endTransmission();
Serial.println(value);
Wire.endTransmission();
delay(2000);
}
The value shown is 0
. Is it the error number returned or the actual value of the I2C register ?
I changed it to Wire.read()
:
#include <Wire.h>
const int register_to_use=0x68;
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println("Start Scanning");
}
void loop() {
int value;
Serial.println("Scanning..");
Wire.beginTransmission(register_to_use);
value = Wire.read();
Serial.println(value);
delay(2000);
}
The value displayed is now -1
.
Which one is the actual value of the I2C register and how to read the values of other registers and change them? Because the default range selected for accelerometer is 2g but I want to use the 8g.