I am trying to connect a gyroscope MPU6050 to arduino ATmega2560 and read its raw values from its 6DOF (gyro and acc).
I found the following code:
//Activate the MPU-6050 Wire.beginTransmission(0x68); //Start communicating with the MPU-6050 Wire.write(0x6B); //Send the requested starting register Wire.write(0x00); //Set the requested starting register Wire.endTransmission(); //End the transmission //Configure the accelerometer (+/-8g) Wire.beginTransmission(0x68); //Start communicating with the MPU-6050 Wire.write(0x1C); //Send the requested starting register Wire.write(0x10); //Set the requested starting register Wire.endTransmission(); //End the transmission //Configure the gyro (500dps full scale) Wire.beginTransmission(0x68); //Start communicating with the MPU-6050 Wire.write(0x1B); //Send the requested starting register Wire.write(0x08); //Set the requested starting register Wire.endTransmission(); //End the transmission
I am trying to break it line by line, to understand what is going on during the setup of the gyroscope.
According to MPU6050 datasheet, the I2C is at the register
0x68. The I2C helps us to access all registers and communicate with the master connected to. Which gives the following 3 lines:
Wire.beginTransmission(0x68); Wire.write(0x6B); Wire.write(0x00);
According the the sheet, the
0x6B is the register designed to enable and disable the gyroscope:
This register allows the user to configure the power mode and clock source. It also provides a bit for resetting the entire device, and a bit for disabling the temperature sensor. By setting SLEEP to 1, the MPU-60X0 can be put into low power sleep mode. When CYCLE is set to 1 while SLEEP is disabled, the MPU-60X0 will be put into Cycle Mode. In Cycle Mode, the device cycles between sleep mode and waking up to take a single sample of data from accelerometer at a rate determined by LP_WAKE_CTRL (register 108). To configure the wake frequency, use LP_WAKE_CTRL within the Power Management 2 register (Register 108). An internal 8MHz oscillator, gyroscope based clock, or external sources can be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator or an external source is chosen as the clock source, the MPU-60X0 can operate in low power modes with the gyroscopes disabled. Upon power up, the MPU-60X0 clock source defaults to the internal oscillator. However, it is highly recommended that the device be configured to use one of the gyroscopes (or an external clock source) as the clock reference for improved stability. The clock source can be selected according to the following table.
So why we set its value to
And the same for setting up the gyroscope at register
0x1B where datasheets specify the full scale ranges as:
The code is setting the range of
500 dps, so why the coder set the register to
0x08 and not
0x01 where the
FS_SEL[1:0] should contain decimals from 0 to 3 right ?