2

I have read several answers and approaches to controlling an SG-90 servo with a raspberry pi and I have tried the following approaches, with varying but never satisfactory results.

Wiring Setup:

  • Servo + to 5V external power
  • Servo - to external ground
  • External ground connected to R-PI ground
  • R-PI PIN 13 (BCM 27) to servo signal

First approach was to use RPi.GPIO with PIN set to output and GPIO.PWM(13, 50). None of the values used had any effect whatsoever on the servo, no movement at all.

Second approach was to use pi-blaster. I've used the default rates and did some echo "27=0.075" > /etc/pi-blaster and could get the motor to move. However lets say moving from -90 to +90 degrees would not be a continous movement, it was more like 3 intervals where it moved fast, halted a while, moved again until it reached the position. Otherwise it was fine, i.e. reliable movements, no jerking except the very large intervals.

Third approach was with some additional helper. I have used one of my Arduino motor shields that I have used on the arduino to successfully control that same servo and connected the external power to the shield, used pin 9 and ground of the shield to the R-PI and connected the servo to the second servo slot. I tried both pi-blaster and RPi.GPIO but neither of them had any effect on the motor.

What am I missing here? I saw many articles where people were pretty much hooking up an sg-90 to an external PSU (and connect grounds) and directly to the R-PI and then using pythons RPi.GPIO without any issues, but this wont even get the motor to move in my case.

  • You do not need external power. You should be able to supply the modest SG-90 requirements from the Pi. Seehttps://gpiozero.readthedocs.io/en/stable/api_output.html?highlight=servo#servo for a simple example. – Milliways Oct 18 at 23:00
  • You might find my answer to the following servo Q&A helpful. There is a fully debugged, copy and run Rpi4B demo test python program for toy servos (with an intro to PWM, and how to use Rpi/3/4 PWM pins): Run the program in the laptop and use the raspberry gpios, PWM to control servos - rpi se 2019jun06 raspberrypi.stackexchange.com/questions/99315/… servoing. Cheers. – tlfong01 Oct 19 at 1:40
2

Assuming you have correctly connected the servo to power and you have connected the control line to GPIO 27 (pin 13).

https://pinout.xyz/

Also assuming you have a recent Raspbian.

Test the servo with the following commands.

sudo pigpiod # start the pigpio daemon

pigs s 27 1500 # centre servo

pigs s 27 1000 # counterclockwise servo

pigs s 27 2000 # clockwise servo

If the servo does not move you have not made the proper connections and you will need to add clear photos of your connections to your question.

| improve this answer | |
  • This is actually quite similar to pi-blaster. The movements are really accurate in terms of where they end up but the movement to them is sometimes a bit odd. Sometimes going from 550 to 2250 and back works great and smooth, sometimes it stops at a random point for a fraction of second and then does the rest. Sometimes it does that 2 or 3 times. It feels a bit like a timing issue. – Yanick Salzmann Oct 19 at 3:29
  • You are testing the servo range. You may be stripping the end stops. – joan Oct 19 at 6:31
  • Yea, I tested the servo range to be 550 to 2250, thats the range it can move without hitting the end stops. The same thing is also true when using 1000 and 1900, sometimes it goes smoothly, sometimes there are short jerks at random points during the movement. Sometimes it also reaches the designated position and after very short brake does one single tiny jerk – Yanick Salzmann Oct 19 at 6:34
  • Are you sure you haven't stripped the end-stops? That occasionally jerky movement is characteristic. – joan Oct 19 at 7:09
  • What exactly does "stripped" mean in this context? I assumed hitting them because I try to go past the maximum range, but I think its not that. – Yanick Salzmann Oct 19 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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