Skip to content

Latest commit

 

History

History
151 lines (94 loc) · 7.86 KB

README.md

File metadata and controls

151 lines (94 loc) · 7.86 KB

TABLE OF CONTENTS

MPU6050

  • It is a 6-axis motion tracking device
  • The MPU-6050 is a commonly used chip that combines a MEMS gyroscope and a MEMS accelerometer and uses a standard I2C bus for data transmission
  • The system processor is an I2C master to the MPU6050 (default address is 0x68 but can be changed to 0x69)
  • The MPU6050 can also act as an I2C master and directly accept inputs from an external compass
  • This is 3.3V device and hence is safe to connect to ESP32 pins directly.

Inertial Measurement Unit

  • These are small devices indicating changing orientation in smartphones, video game remotes, quadcopters, etc.
  • The IMU has both a gyroscope which measures angular rate and an accelerometer which measures linear acceleration, and/or compasses (magnetometers)
  • The number of sensor inputs in an IMU are referred to as ‘DoF’ (Degrees of Freedom), so a chip with a 3-axis gyroscope and a 3-axis accelerometer would be a 6-DOF IMU.

Initialising MPU6050

  • A sample wiring of the device to ESP32 looks as follows:

  • When power up, MPU6050 will start in SLEEP mode. To use it, we need to first disable this SLEEP mode

  • To use the I2C protocol, we send the value 0 to register PWR_MGMT_1 (0x6b)

  • The procedure to do so is as follows :

    1. Send a start sequence
    2. Send the I2C address (0x68) of the MPU6050 with the R/W bit high
    3. Send the internal register number you want to write to (0x6b : PWR_MGMT_1)
    4. Send the data byte (0x00) - This will power on the device
    5. Send the stop sequence

The data byte 0x00 sets all the bits of register 107 to 0, thus disabling SLEEP mode and CYCLE mode, and powering on the MPU-6050

There are various terms related with the Pulse Width Modulation:-

  • Off-Time :- Duration of time period when the signal is low.
  • ON-Time :- Duration of time period when the signal is high.
  • Duty cycle :- It is the percentage of the time period when the signal remains ON during the period of the pulse width modulation signal.
  • Period :- It is the sum of off-time and on-time of pulse width modulation signal.

Accelerometer

  • An accelerometer is a sensor that measures the force of linear acceleration.
  • It's output is in the form of m/s^2 of g-forces on a body. It is highly sensitive to movement in any direction.
  • The MPU6050 uses a MEMS accelerometer, which consists of stationary and movable electrodes acting as capacitor plates
  • Acceleration produces change in g-forces on the moving device, which causes displacement of the movable capacitor plates
  • This causes a change in capacitance across the plates, which is detected internally by change in Voltage
  • We then calculate the displacement from the in Capacitance, which helps us infer the value of acceleration

Reading Accelerometer Data

  • The acceleration of the three axes, X,Y and Z, are stored in 3 pairs of registers on the MPU6050
  • Each register on the MPU6050 is an 8-bit register
  • In each of these pairs, one register stores the MSB (most significant bit) and the other stores the LSB (least significant bit)
  • These 6 registers are burst-read and the 8-bit MSB and LSB bytes for each axis are combined to give a single 16-bit float

Accelerometer Euler Angles

  • The roll and pitch angles are calculated from the accelerometer using the formula below :

Gyroscope

  • A gyroscope is a sensor that measures the change in velocity (if at all) of a device rotating around its own axis.
  • A gyroscope measures changes in angular velocity.
  • The MPU6050 uses a MEMS gyroscope, which uses Coriolis effect

Reading Gyroscope Data

  • The acceleration of the three axes, X,Y and Z, are stored in 3 pairs of registers on the MPU6050
  • Each register on the MPU6050 is an 8-bit register
  • In each of these pairs, one register stores the MSB (most significant bit) and the other stores the LSB (least significant bit)
  • These 6 registers are burst-read and the 8-bit MSB and LSB bytes for each axis are combined to give a single 16-bit float
  • The gyroscope has a sensitivity factor of about 131, i.e. 1 degree of rotation gives a reading of 131 units
  • Therefore, the degrees of rotation are obtained by dividing the raw readings by 131
  • Euler angles are calculated by integrating raw readings of each axis over time

Complementary Filter

  • Since gyroscopic drift accumulates over time, it is necessary to reset the rate readings from the gyroscope at frequent intervals, so the drift can be minimised
  • To do this, we combine both the gyroscope and accelerometer readings in a weighted average
  • The value of alpha is determined experimentally

Reading Register Data

  • To read/receive data from a slave, the master has to first send a START condition addressing the MPU6050
  • Then the master must WRITE the requested register from which the data is to be read
  • After this, instead of sending a STOP condition to stop the WRITE operation and then sending a consecutive START condition to start the READ operation, the I2C bus provides the repeated start functionality, wherein instead of sending a STOP-START condition, we send only a START condition and read the specified number of bytes from the register.
  • The procedure to do so is as follows :
    1. Send a start sequence
    2. Send the I2C address (0x68) of the MPU6050 with the R/W bit low - This writes to the device
    3. Send the Internal register address you want to read from
    4. Send a start sequence again (repeated start)
    5. Send the I2C address of the device with the R/W bit high - This reads from the device
    6. Read the number of the requested data bytes from the registers
    7. Send the stop sequence.
    8. All write and read operations (except the last read) are answered with a ACK if successful.