Go Down

Topic: Using mpu6050.h what exactly does 'initialize' do? (Read 111 times) previous topic - next topic

DryRun

Hello,

I am using the MPU-6050 sensor with the MPU6050.h Arduino library on my Arduino UNO R3. I am using the following code but i am having trouble understanding exactly why and what's happening behind those commands:
Code: [Select]
#include <MPU6050.h>

MPU6050 mpu6050;

void setup()
{
  Wire.begin();     
  Serial.begin(9600);       
  delay(1500); 
  mpu6050.initialize(); 
  delay(2);
}

I have the following questions:
1. Why is there a delay of 1500ms after the Serial.begin()? Is that necessary? What could be its purpose? I've seen similar delays added in many example codes of Serial.begin on various sites.
2. What is exactly happening with this mpu6050.initialize() function? I mean, what is it really doing under-the-hood? I have tried to do some digging but i can't get a full list of commands that this library is actually doing with the MPU6050 hardware.
3. Why is there another delay of only 2ms after mpu6050.initialize()? I'm thinking that maybe it's to wait for the MPU6050 to actually get out of sleep mode and start accumulating data that can then be retrieved? Am i correct in my assumptions?

jremington

#1
Jul 20, 2019, 03:36 am Last Edit: Jul 20, 2019, 04:30 am by jremington
1. The delay is completely pointless. That line in itself indicates that the code or tutorial is not worth copying or trying to understand.

2. You have the source code for the library, read it to determine what it does.

3. See (1).

Go Up