SG90 servo notes

Viewed 11 times

I have been working on controlling servos in one direction with PWM control via GPIO ports on my RPi 3. I’ve worked with motor controllers that use PWM before and it seems that I should be able to provide negative PWM values to indicate the opposite direction, but GPIO seems not to allow that. For my current project, I do need to be able to control one servo in both directions. (Precise positional control would not be necessary, I just need to be able to control direction)

I have found an alternative solution where I can create a jank analog device by hooking up a resistor and capacitor in parallel. If I were to try to achieve positional control of the servo, could I potentially use analog information from this strategy to do so?

 New contributor
  • But you can adjust PWM duty cycle to turn servo motor CW or CCW, normally within a range of about 180 degrees.. PWM duty cycle is defined from 0% to +100%. Negative PWM duty cycle is unthinkable. – tlfong01 2 hours ago
  • 1
    Perhaps look at a wiki to understand how servos are controlled. Nothing to do with the Pi. – joan 2 hours ago
  • 1
    @tlfong01 Can the direction be switched upon command? I’ve read about a hardware solution but my project requires automatic control. – frc_contributor 2 hours ago
  • Yes, I would suggest three methods: (1) using GPIO pin in PWM mode, (2) using L298N DC motor/servo driver, also using GPIO pins in PWM mode. (3) Using PCA9685 PWM Controller. You can search this forum using key words “servo”, “PWM”, “L298N”, PCA9685″ to find more details. Lady Ada’s tutorial is a good start: adafruit.com/product/815. Good luck and cheers. – tlfong01 2 hours ago
  • And if your project is on Rpi auto control of motor/servo, then you should try PCA9685 with Rpi PID control using hardware or software. Wiki is a good place to start to explore: en.wikipedia.org/wiki/PID_controller. – tlfong01 1 hour ago
  • This USD80 smart robot card project uses IR sensor (line tracing), supersonic sensor (object detection and distance measurement), and Rpi camera (object recognition), to do feedback control of servo/DC motors using Rpi GPIO PWM pins, L298N and PCA9685 controller: raspberrypi.stackexchange.com/questions/108873/…. Have a great auto control project. Cheers. – tlfong01 1 hour ago
  • And the web link below explains, with a couple of references (see comments), the PWM principle and how Rpi uses L298N, GPIO pins in PWM mode, and also PCA9685 PWM controller to to do auto/feeback control of speed/direction of smart 4WD with DC motors and servos: raspberrypi.stackexchange.com/questions/108880/…. Cheers. – tlfong01 1 hour ago
  • Now I have given you a big picture of Rpi based automatic control of servos, introducing you the basic idea of PWM. But I do NOT recommend you to start with L298N or PCA9685. And do NOT jump start with AdaFruit’s very expensive US$99 smart car with ultrasonic sensor or Rpi camera. I highly recommend you to start humble, with the little cheap servo SG90. A very good newbie tutorial on Rpi + python + PWM + SG90 is the following YouTube: “Raspberry Pi Servo Motor Control 2020jan12”: youtube.com/…. Happy python programming. Cheers. – tlfong01 7 mins ago
  • PS – I am a huge fan of the funny YouTube guy Christopher Barnett. I enjoy watching his videos and learning a lot from him. I hope you also enjoy his videos. Cheers. – tlfong01 38 secs ago   Edit

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: