B4R Question [SOLVED] MG996R servo help needed

giggetto71

Active Member
Licensed User
Longtime User
Hi,
for a project I need to use the MG966R servo. I have tried to use the servo library which I have successfully used with the KY66 micro servo and the PC9685 pwm board.
in the below example I have on channel 0 e 1 two functional KY66 following a potentiometer input and the MG966R on the channel #2.
I am assuming (and maybe that is the mistake that I can use the same MIN and MAX pulse width and frequency for the MG966R..
Does anyone have experience with this servo?
thanks!


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public servo1 As Servo
    Public pinservo As Pin
    Public Timer1 As Timer
   
    Public potentiometer As Pin
    Public driver As Adafruit_PWMServoDriver
   
    Public const MIN_PULSE_WIDTH As Long = 80
    Public const MAX_PULSE_WIDTH As Long = 620
    Public const FREQUENCY As Long = 50
   
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    potentiometer.Initialize(potentiometer.A0,potentiometer.AnalogRead)
   
       
    driver.Initialize(0x40)
    driver.SetPWMFreq(FREQUENCY)
   
    AddLooper("IntPot")
End Sub


Sub IntPot
    Dim ServoPos As Int
    ServoPos = MapRange(potentiometer.AnalogRead,0,1023,0,179)

    driver.SetPWM(0,0,convert2angle(ServoPos)) ' KY66 working
    driver.SetPWM(1,0,convert2angle(ServoPos)) 'KY66 working'
    driver.SetPWM(2,0,convert2angle(ServoPos)) 'MG966R NOT working
   
    Log("pot:",potentiometer.AnalogRead)
    Log("ServoCmd:",ServoPos)
   
End Sub
Sub convert2angle (myang As Int) As Int
    Dim pulse As Int
    pulse =MapRange(myang,0,180,MIN_PULSE_WIDTH,MAX_PULSE_WIDTH)
    Return pulse
End Sub
 

giggetto71

Active Member
Licensed User
Longtime User
found it...I was using a 0.5A power supply...the MG966R is a bigger servo and simply draws more current. I tried with a smartphone 2A power supply and it works as expected.
 
Upvote 0

Marc DANIEL

Well-Known Member
Licensed User
Voir aussi et ce threed
ServoMoteur.jpg
 
Upvote 0
Top