As Bob mention, would it be possible to send through a link or datasheet to the servo you are using?
(And a bit more background as to what hardware you ended up going with for your project).
Your code looks good at a glance, adding a sleep in your while True loop will give it a chance to break out cleanly, without the consistent “setting it to mid” point.
Hi BellAmi
Without understanding Python I have looked a bit further into this.
In your screen shot of your text you declare your Min pulse to be 0.5mSec and Max to be 2.5mSec. Centre or neutral would be 1.5mSec
In that case your Duty cycle calc
would be valid.
But if the servo in question used the more “normal” range of Min 1.0mSec (5% DC) and Max 2mSec (10% DC) with centre 1.5mSec (7.5% DC) your calc is anything BUT valid. In this case the correct calc would be
“duty = 5 + (angle / 360.0) * 10” or “duty = 5 + (angle / 180.0) * 5” Both work. Please note the 90º, neutral or centre is the same for both scenarios (pulse width 1.5mSec or 7.5% due cycle).
What I am getting at is if you used the calc for a 2mSec pulse width variation and the servo is actually a 1mSec pulse width type you could be easily hitting the servo end stops and this could very well be the cause of the jittering or chattering you experience. If the servo is just holding position then as I said you need to keep the control pules going and this should not cause the jitter and should do no harm as this is normal operation (without the jitter).
Cheers Bob
There is some confusion (to me anyway) about which code are you actually using. Could you please post your actual code. Complete would be a help not bits of.
I’m looking at your screenshot from the other day and your loop just seems to be calling servo.mid() constantly. That’s not ‘ninety degrees’ so much as it is, return to centre position, according to the API docs for gpiozero:
Gpiozero doesn’t really have the option of specifying position, just servo.max() for forward, servo.min() for backwards, and servo.mid() for the 0 point.
You could combine servo.value() with the above directions to make some rough movement controls. Servo.value() would return a number between -1 and 1, with 0 being the middle point. If you put your code to servo.max() until registers a servo.value() return of 0.5 (not quite 45 degrees but close enough), then you could have it switch to servo.min() and turn around.
It would not be enough to physically halt it there, but it gives you some simple movement controls.