1

I'm using a Fitec FS90R continuous servo with my Raspberry Pi Zero, and trying to make it turn slowly in either direction (it's controlling a small turntable with a display on it).

My test script is below and it works exactly how I want for counter-clockwise, but not in a clockwise direction. No matter what values I try I can't get it to run the same speed in the other direction, and I don't understand why. Am I trying to make it do something it's not meant to?

All help gratefully received.

from datetime import datetime, time, timedelta
from output import *
from time import sleep

import requests
import RPi.GPIO as GPIO
pin = 17

GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)

for i in range(0, 300):
    GPIO.output(pin, GPIO.HIGH)
    sleep(0.019) 
    GPIO.output(pin, GPIO.LOW)
    sleep(.001)


GPIO.cleanup()
print("Ended")

In response to comments:

I have tried using pigs to find the 'neutral' point where my servo is stopped, and then higher and lower values to go CW and CCW at increasing speeds (I used a loop to steadily go thru every possible value). Close to the middlepoint, the servo is either too fast and juddering, or switching direction back and forth. It was never the slow smooth rotation that I got with the test script included in my question above.

This is confusing to me because I've read so many articles which give this advice (about finding the middlepoint). That's why I started wondering whether this only applies to non-continous servos. It's not alway clear whether advice given only applies to one or both types of servo. It seems like it should be really easy but it's driving me nuts!

Also, the test script above was an example given one of the many articles I read about using servos - and it does work, resulting in the rotation speed I'm looking for, but only in a CCW direction.

My understanding of servos is that they work in the way described on Controlling Servos Using Raspberry Pi & Python - Ray's Blog. Most articles describe it this way. Is this not correct?

@milliways you say GPIO does not support hard PWM, but then why is this so very often the example given? What is the better way to control a server?

7
  • Use the pigs servo command.
    – joan
    Nov 4, 2023 at 12:43
  • write code for controlling regular servo ... setting the servo angle to 80 degrees should make your servo run in one direction ... setting to 100 degrees should run in the opposite direction ... 90 degrees should be stop ... 91 degrees should be slow ... 180 degrees should be very fast
    – jsotola
    Nov 4, 2023 at 17:38
  • RPi.GPIO does not support hardware PWM so shudder is inevitable if you try to use it. DO NOT put details in Comments; edit your Question. What is a "RP nano"?
    – Milliways
    Nov 4, 2023 at 21:58
  • The script you gave does not help. What do you think it should do? I'm not convinced you understand how servos are controlled (normal or continuous).
    – joan
    Nov 4, 2023 at 23:20
  • "you say GPIO does not support hard PMW, but then why is this so very often the example given?" Anyone can post a "tutorial" on the web and frankly most are rubbish. I never mentioned "hard PMW" but hardware PWM - the RPI.GPIO documentation states "Note that the current release does not support SPI, I2C, hardware PWM or serial functionality on the RPi yet." Joan has already posted a link that works which I recommend, she is probably the best source for servos. (If you search you will find a few hardware PWM implementations - I have posted my own)
    – Milliways
    Nov 5, 2023 at 5:42

1 Answer 1

0

First check if your power supply is correct. Try experimenting with the pulse width values in your code. You can adjust the sleep times in your code to achieve this. For example, increase the sleep time after GPIO.LOW to make the pulse longer and see if the servo responds better in the clockwise direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.