clk
Posts: 2
Joined: Wed Jul 17, 2019 11:47 pm

MG92B servo trouble

Thu Jul 18, 2019 12:20 am

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

pcmanbob
Posts: 6646
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: MG92B servo trouble

Thu Jul 18, 2019 5:39 am

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
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
neilgl
Posts: 781
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: MG92B servo trouble

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”

pcmanbob
Posts: 6646
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: MG92B servo trouble

Fri Jul 19, 2019 6:58 am

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.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

clk
Posts: 2
Joined: Wed Jul 17, 2019 11:47 pm

Re: MG92B servo trouble

Mon Jul 22, 2019 11:49 pm

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?

User avatar
joan
Posts: 14193
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: MG92B servo trouble

Tue Jul 23, 2019 4:33 am

See if pigpio has the same problem.

sudo pigpiod

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

DavidArbogast
Posts: 2
Joined: Wed Jul 24, 2019 10:01 am

Re: MG92B servo trouble

Wed Jul 24, 2019 10:11 am

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

pcmanbob
Posts: 6646
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: MG92B servo trouble

Wed Jul 24, 2019 4:41 pm

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.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Beginners”