Hello,
I'm pretty new to the forum so please correct me, if I'm doing something wrong But i've got a searious issue with my MPU6050 sensor in my ArduinoProMini5V16MHz-based qadcopter.Basicly the problem is that readings from sensor hangs up, whenever the motors start to run, and stays like that until I reset arduino. ``Motors are powered from Lipo battery, and arduino is sending PWM signals.
//calculations
//All the information for controlling the motor's is available.
     //The refresh rate is 250Hz. That means the esc's need there pulse every 4ms.
     while(micros() - loop_timer < 4000);               //We wait until 4000us are passed.
     loop_timer = micros();                      //Set the timer for the next loop.
   Â
     PORTD |= B11110000;                       //Set digital outputs 4,5,6 and 7 high.
     timer_channel_1 = esc_1 + loop_timer;              //Calculate the time of the faling edge of the esc-1 pulse.
     timer_channel_2 = esc_2 + loop_timer;              //Calculate the time of the faling edge of the esc-2 pulse.
     timer_channel_3 = esc_3 + loop_timer;              //Calculate the time of the faling edge of the esc-3 pulse.
     timer_channel_4 = esc_4 + loop_timer;              //Calculate the time of the faling edge of the esc-4 pulse.
    Â
     while(PORTD >= 16){                       //Stay in this loop until output 4,5,6 and 7 are low.
      esc_loop_timer = micros();                   //Read the current time.
      if(timer_channel_1 <= esc_loop_timer)PORTD &= B11101111;    //Set digital output 4 to low if the time is expired.
      if(timer_channel_2 <= esc_loop_timer)PORTD &= B11011111;    //Set digital output 5 to low if the time is expired.
      if(timer_channel_3 <= esc_loop_timer)PORTD &= B10111111;    //Set digital output 6 to low if the time is expired.
      if(timer_channel_4 <= esc_loop_timer)PORTD &= B01111111;    //Set digital output 7 to low if the time is expired.
     }
Also arduino is powered via raw pin and is giving constant Vcc - 5V.
It is worth to mention that I somehow fried A5 pin, sooo I have to use SoftI2Cmaster library and it's SoftWire.h to adapt to code from before frying A5.
void gyro_read(){
 Wire.beginTransmission(0x68);            //Start communication with the gyro
  Wire.write(0x43);                      //Start reading @ register 43h and auto increment with every read
  Wire.endTransmission();                   //End the transmission
  Wire.requestFrom(0x68,6);              //Request 6 bytes from the gyro
  while(Wire.available() < 6);                //Wait until the 6 bytes are received
  gyro_axis[1] = Wire.read()<<8|Wire.read();         //Read high and low part of the angular data
  gyro_axis[2] = Wire.read()<<8|Wire.read();         //Read high and low part of the angular data
  gyro_axis[3] = Wire.read()<<8|Wire.read();         //Read high and low part of the angular data
  Serial.print(gyro_axis[1]);
Â
 if(cal_int == 2000){
  gyro_axis[1] -= gyro_axis_cal[1];              //Only compensate after the calibration
  gyro_axis[2] -= gyro_axis_cal[2];              //Only compensate after the calibration
  gyro_axis[3] -= gyro_axis_cal[3];              //Only compensate after the calibration
 }
 gyro_roll = gyro_axis[1];
 gyro_pitch = gyro_axis[2];
 gyro_yaw = gyro_axis[3];
}
So now I'm using A4 --> SDA, A3 --> SCL.
Do you guys, have ANY idea what's going on?
Best regards
I'm posting schematics and output from serial monitor.
I know but, arduino's voltage regulator is powering the MPU so the noise is terminated and there's correction for voltage drop in the code(and voltage chceker connected to A6)
Ykob:
I know but, arduino's voltage regulator is powering the MPU so the noise is terminated and there's correction for voltage drop in the code(and voltage chceker connected to A6)
Ok, so what do you think is causing the problem?
Is it voltage dropping when starting motors?
I've checked Vcc pin with multimeter and it's holding 5V stabile when turning motors on.
But I've also noticed that voltage is RISING on A3 and A4 pins from ~3.3V to ~3.45V. I don't know if that is normal, or mayby that is caused by stopped communication or THIS is stopping communication.
EMI can introduce unwanted noise to any signal (including power). Idk, just thought I should mention it. Best to use shielding and twisted pair wiring when using high power electronics/motors/generators.
Nope, I've rewiried gyro and it doesn't change anything. I've also twisted the wires and move them from motor wires as far as possibble, still same results.
Thanks for your reply, I will defenetly try that out. I'm wondering one thing. My project is based on this one: YMFC-3D V2 - The easy Arduino quadcopter - official main page.
The wirings are pretty much the same and it works fine. I've just got smaller distances between motor cables and arduino cables. Could that be the point?
You do have all the gnds, especially the HI current gnds connected to the battery in star arrangement, and not daisy chaining the gnd from one point to the next.
Ok, so I made few tests, with second arduino attached - Arduino UNO
1.Wired MPU6050 to arduino UNO with voltage input from battery, and get it as close to running motor wires as possible - everything is working properly so that's not EMI
2. Supplied MPU with voltage from Pro Mini and attached SDA and SCL wires to arduino UNO with voltage input from battery - working properly on motors running
3. Supplied MPU with voltage from UNO with voltage input from battery, and attached SDA and SCL wires to Pro Mini - and here's data hangs up when i turn on the motors
You are testing things without any understanding of what you are doing. In the absence of any new data, from these tests I still conclude that it is lack of decoupling on the supplies.
However, are the optional I2C pull up resistors R1 & R3 fitted? If so what value are they?
Thanks I read this article and it's very usefull
But I don't get it, how should I attach the pull ups?
To the arduino 5V and SDA and SCL wire? (Like in atachment?)
" A simple formula for calculating the smallest pull-up resistor is Rp = (Vcc - 0.4)/3mA, which for a 5V system comes out to be about 1.5k ohms."
5V sytem is refered to Arduino 5V or should I use 3.3V from MPU6050?
eg: 1.5Kohm or 1Kohm
And should I disable the pullups in the code?
And author says: "while technically being specified as a 3.3V device in the datasheet, the MPU-6050 is more than happy to tolerate 5V signals and power without blowing up (or even getting damaged). Supply voltage can handle VDD = -0.5V to +6V and logic levels of -0.5V to VDD + 0.5V."
So maybe that's the point and i don't have to modify circuit that much and set it up as in my schemat?