Controlling two digital servo motors with MPU6050 and Arduino uno

i did check the code and connection of wire, it is working with 9kg micro servo motor. It rotated for pitch and roll axis which is followed by Gyroscope moving for that two axis. But when i switch to one of DC 5535 digital motor it is keep continuously rotating. The wired thing is another on of 5535 digital motor is working as 9kg micro servo motor. So i guess that it is wrong default setting inside of that digital motor. Can someone help me to figure out it? thanks.

        

#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <Servo.h>   

Servo servo1;    
Servo servo2;       

//int servo_pin1 = 6;
//int servo_pin2 = 4;

MPU6050 sensor ;

int16_t ax, ay, az ;

int16_t gx, gy, gz ;

void setup ( )

{ 


Wire.begin ( );

Serial.begin  (115200); 

Serial.println  ( "Initializing the sensor" ); 

sensor.initialize ( ); 

Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed"); 
//
//delay (10); 
//
//Serial.println ( "Taking Values from the sensor" );

servo1.attach (3);
servo2.attach (9);




}




void loop ( ) 

{ 

sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);

ax = map (ax, -17000, 17000, 0, 180);
servo1.write(ax);
Serial.println(ax);
delay(15);
sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
ay = map (ay, -17000, 17000, 0, 180);
servo2.write(ay);
Serial.println(ay);
delay(15);
}

1 Like

Hi Torres
If you look at the text here

This seems to have a different positioning pulse from others I have come across, 0.5mSec to 2.5mSec for 0 to 180º instead of 1.5mSec to 2mSec for “normal” servos. Also it indicates only 1 pulse is required for positioning and holding instead of a series of pulses at 20mSec intervals.

Maybe this has something to do with it and the “<servo.h>” library may not work with this model. I am not sure and I don’t have one to experiment with. So you may have to “roll your own” when driving this unit.
Cheers Bob

3 Likes

Hi Bob,
i see, but my meaning is one micro motor for pitch and one digital motor (i bought two DC5535 digital motors) for roll, it is working. When i switched to another one digital motor(they are same one DC5535 from core electronics) for roll, it keeps rotating. i used same code and connection for two digital motors, why one is working another one is not, should be get same result because they are totally same digital motors.

Hi Torres
The first thing I would do is swap the two “digital” (I don’t quite understand this term) motors and see if the problem goes with the motor or stays in the same place in the scheme of things.
Cheers Bob

Hi Bob,
like one Micro motor and one digital motor is a group and then u swap to another digital motor n the scheme of things.and keep micro motor in the same place for second group. The first one is working good and digital motor of second group is keep rotating, it is not good should rotate follow with Gyroscope. So that is weird thing.
If the code is not working, should be for both digital motors right not for one? i am stuck in it.

Hi Torres
I still don’t get the term “Digital motor” But:
It appears the problem is following the “motor”. Conclusion…Suspect faulty motor.
Cheers Bob

Hi Bob,
that is DC5535 digital servo motor which is bought from core electronics. Yeah i agree with that.

Cheers Torres

Hi Torres,

Given your two identical servos are behaving differently when they are swapped I’d agree this is likely a hardware fault. I’ve just sent you an email regarding the replacement of the servo.

Thanks for your assistance with methodical troubleshooting and isolating the fault @Robert93820

1 Like