3

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?

  • 2
    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 Mar 26 '20 at 06:16
  • 3
    Perhaps look at a wiki to understand how servos are controlled. Nothing to do with the Pi. – joan Mar 26 '20 at 06:32
  • 1
    @tlfong01 Can the direction be switched upon command? I've read about a hardware solution but my project requires automatic control. – frc_contributor Mar 26 '20 at 06:32
  • 1
    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: https://www.adafruit.com/product/815. Good luck and cheers. – tlfong01 Mar 26 '20 at 07:01
  • 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: https://en.wikipedia.org/wiki/PID_controller. – tlfong01 Mar 26 '20 at 07:13
  • 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: https://raspberrypi.stackexchange.com/questions/108873/rpi-python-using-l298-motor-driver-and-pca9685-servo-controller-to-change-speed. Have a great auto control project. Cheers. – tlfong01 Mar 26 '20 at 07:24
  • 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: https://raspberrypi.stackexchange.com/questions/108880/how-can-rpi-python-3-uses-pca9685-pwm-controller-to-change-direction-and-positio. Cheers. – tlfong01 Mar 26 '20 at 07:31
  • 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": https://www.youtube.com/watch?time_continue=4&v=xHDT4CwjUQE&feature=emb_logo. Happy python programming. Cheers. – tlfong01 Mar 26 '20 at 09:02
  • 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 Mar 26 '20 at 09:09
  • 1
    Thank you so much! I will look into all of these :) – frc_contributor Mar 26 '20 at 19:48
  • Hi @frc_contributor, you are welcome. Be humble and go slow.It took me a couple of hobbyist months to learn the basic tricks of servos, step motors, PWM, L298N, and PCA9685 etc. Happy learning. Cheers. – tlfong01 Mar 27 '20 at 09:26

0 Answers0