EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: NameToRemember on June 02, 2020, 04:05:53 pm

Title: PI - Servo stops turning after a few turns? Do I need to power it separately?
Post by: NameToRemember on June 02, 2020, 04:05:53 pm
I am trying to get a servo motor to work with my raspberry pi for the first time. I have successfully got it to turn when I run a simple python script but was just wondering if this problem is because the servo motor needs to be powered externally by itself? I read online that the current being drawn to move the servo can sometimes be too much for the PI to handle powering from just the board. I also understand that the PWM needs to be setup right according to your servo. I have tried about 5 different scripts and all of them have the same outcome. I followed along a youtube tutorial where they are using the exact same pi and servo motor.

If I do need to power the servo separately can I do so using some AA alkaline batteries in series? I know there are better ways to power the servo using separate 5v power supply boards but would like to know this is the problem before i buy them.

servo: SG90 9g

Video of the servo stopping in a while True continuous loop:
https://www.youtube.com/watch?v=XCAj4k8lu40 (https://www.youtube.com/watch?v=XCAj4k8lu40)


My python script running on the Pi:

Code: [Select]
from gpiozero import Servo
from time import sleep

myGPIO=4

servo = Servo(myGPIO)
print("Rassberry Pi Servo");
while True:
    servo.min()
    sleep(0.5)
    servo.mid()
    sleep(1)
    servo.max()
    sleep(1)
Title: Re: PI - Servo stops turning after a few turns? Do I need to power it separately?
Post by: Benta on June 02, 2020, 04:30:36 pm
What do you means with "stops after a few turns? It's only supposed to turn +/- 90 degrees.
But yes, you should power it separately. DC motors and low power circuitry don't mix well.

Title: Re: PI - Servo stops turning after a few turns? Do I need to power it separately?
Post by: NameToRemember on June 02, 2020, 04:44:29 pm
What do you means with "stops after a few turns? It's only supposed to turn +/- 90 degrees.
But yes, you should power it separately. DC motors and low power circuitry don't mix well.

the script that is running is a While True: keep moving the servo motor so in theory the servo should never stop but it does after a few turns. By turns i mean from -90 to 0 to 90 degrees and then back to -90 in a loop.
Title: Re: PI - Servo stops turning after a few turns? Do I need to power it separately?
Post by: wizard69 on June 02, 2020, 05:23:39 pm
Start debugging!

First increase the delays between moves to see if there is an impact there.

By the way make sure the app isn't crashing or other wise halted.

Ad a few print line debug strings.   This can be helpful as it shows you that the program is still executing.   If it stops executing you may be able to determine where it stops.

A separate power supply for the servos is always a good idea.   Will it help here I have no idea.

Get rid of the min and max commands and replace them with commands that go 75% of the way there.

Ask yourself what you you do to get the unit to run again.