Page 1 of 1

MG92B servo trouble

Posted: Thu Jul 18, 2019 12:20 am
by clk
Need some help, I cant seem to figure out what i'm doing wrong, having trouble finding decent tutorials online. my servo isn't moving, not sure if my code is off or if my servo is shot, i have it connected to a 6v battery pack the wiring is correct and i know i have it connected to the right gpio pin. Any help would be appreciated

Code: Select all

Import RPi.GPIO as GPIO
Import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50)
p.start (7.5)
try:
    while True:
    p.ChangeDutyCycle(7.5)
    time.sleep(1)
    p.ChangeDutyCycle(2.5)
    time.sleep(1)
    p.ChangeDutyCycle(12.5)
    time.sleep(1)
except KeyboardInterrupt:
    p.stop()
    GPIO.cleanup()
Image

where i bought the servo
https://www.adafruit.com/product/2307

Re: MG92B servo trouble

Posted: Thu Jul 18, 2019 5:39 am
by pcmanbob
Hi.

So first your posted code does not match you pictured code so I hope its just a typo, you should also give your servo time to move 1 second is not very long try increasing it.

Code: Select all

Import RPi.GPIO as GPIO
Import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50)
p.start (7.5)
try:
    while True:
        p.ChangeDutyCycle(7.5)
        time.sleep(3)
        p.ChangeDutyCycle(2.5)
        time.sleep(3)
        p.ChangeDutyCycle(12.5)
        time.sleep(3)
        
except KeyboardInterrupt:
    p.stop()
    GPIO.cleanup()
    
and your servo/battery needs to be connected up like this

Image

Re: MG92B servo trouble

Posted: Thu Jul 18, 2019 10:13 pm
by neilgl
On reading the spec sheet it says you need 5V logic but pi gpio is 3V3.
“ this servo requires 5V signals, check that your driver/microcontroller is supplying 5V logic as well as 5V power”

Re: MG92B servo trouble

Posted: Fri Jul 19, 2019 6:58 am
by pcmanbob
neilgl wrote:
Thu Jul 18, 2019 10:13 pm
On reading the spec sheet it says you need 5V logic but pi gpio is 3V3.
“ this servo requires 5V signals, check that your driver/microcontroller is supplying 5V logic as well as 5V power”
Most servo's say they require 5v logic in the spec sheet but the pi gpio should be seen as a high even at 3.3v, in 5v logic any value over about 2.5v is seen as a high.

I suspect what the OP forgot was to connect the ground of the pi to the ground of the battery.

Re: MG92B servo trouble

Posted: Mon Jul 22, 2019 11:49 pm
by clk
Thanks for all your help guys, it was definitely my wiring that was wrong. The servo is working now but it jitters when i move my computer mouse in the program or when the servo is in position, i thought these where decent quality servos. Is there something that can make this smoother. a specific piece of hardware hookup i need, different code, or are these just cheap servos?

Re: MG92B servo trouble

Posted: Tue Jul 23, 2019 4:33 am
by joan
See if pigpio has the same problem.

sudo pigpiod

pigs s 18 1000 # left
pigs s 18 1500 # centre
pigs s 18 2000 # right

Re: MG92B servo trouble

Posted: Wed Jul 24, 2019 10:11 am
by DavidArbogast
Hi.

So first your posted code does not match you pictured code so I hope its just a typo, you should also give your servo time to move 1 second is not very long try increasing it.

Code: Select all

Import RPi.GPIO as GPIO
Import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50)
p.start (7.5)
try:
    while True:
        p.ChangeDutyCycle(7.5)
        time.sleep(3)
        p.ChangeDutyCycle(2.5)
        time.sleep(3)
        p.ChangeDutyCycle(12.5)
        time.sleep(3)
        
except KeyboardInterrupt:
    p.stop()
    GPIO.cleanup()
    
and your servo/battery needs to be connected up like this

Image
Please, explain it more detailed

Re: MG92B servo trouble

Posted: Wed Jul 24, 2019 4:41 pm
by pcmanbob
DavidArbogast wrote:
Wed Jul 24, 2019 10:11 am
Please, explain it more detailed
What is it you don't understand , the code if copied will drive the servo if it's connected as shown in the diagram.