2

For the student project funbots(https://github.com/melvinma/funbots), we had some problems controlling a servo using PWM. We have limited tools to diagnose the issue and please kindly help.

Setup:

  • Raspberry Pi (one model 3B and one model 2B)
  • Motor (Hitech HS-422 and TowerPro SG92R )
  • Software: WiringPi (used commandline) and Python 3.5 RPi.GPIO
  • OS: latest Raspbian

Wiring is exactly following this. 4 batteries provide 7.2 Volts. Servo gets the correct power voltage in the two power lines.

We tried two ways to control the servos:

  1. commandline wiringpi utility (gpio) are as the following:
gpio -g mode 18 pwm
gpio pwm-ms
gpio pwmc 192
gpio pwmr 2000
gpio -g pwm 18 100 
gpio -g pwm 18 150 
gpio -g pwm 18 200
  1. python 3 code:

    pin=12

    try:
      GPIO.setmode(GPIO.BOARD)
      GPIO.setup([pin], GPIO.OUT)
      print("Setup Done !!!!! yay Woho")
    
      print("start pwm")
      pwm=GPIO.PWM(pin, 50)
    
      time.sleep(10)
    
      print("start 5 ...")
      pwm.start(5)
      time.sleep(10)
    
      print("7.5 ...")
      pwm.ChangeDutyCycle(7.5)
      time.sleep(10)
      print("10 ...")
      pwm.ChangeDutyCycle(10)
      time.sleep(10)
      print("6 ...")
      pwm.ChangeDutyCycle(6)
      time.sleep(10)
      print("0 ...")
      pwm.ChangeDutyCycle(0)
      time.sleep(10)
    
      print("stop ...")
      pwm.stop()
      time.sleep(10)
    
      print("HALT")
    
    except:
      print("ohhh nooooooooooooo", sys.exc_info()[0])
    finally:
      GPIO.cleanup()
    

Here is what we saw:

  1. When running either gpio commandline or python, the voltage of pin 18 relative to the ground kept changing (as measured in voltage from a digital multimeter) in the range of 0 - 0.8 Volts.
  2. however, neither servo moved accordingly.
  3. the servo seems to be working because sometimes, accidentally, while wiring, the servo does move.

Additional Information: Now I suspect that we previously broke the both servos by connecting the circuit wrong. I checked resistance of servos. Here is the result: SG92R ground/plus 4 Mega Ohms, ground/signal 13 kilo Ohms. HS-422 ground/plus 0.5 Kilo Ohms, ground/signal 3 Mega Ohms. Is any of the motor still actually good? Thanks

Please give us suggestions on what to do next. Thank you!

  • If the servo moves while wiring, check your wiring. Do a continuity test on your circuit, there may be a bad wire or poor soldering somewhere. – tlhIngan Feb 28 '17 at 7:19
  • If you use similar batteries to those shown they will only drive a similar servo for a minute or so. – joan Feb 28 '17 at 9:11
  • joan, I got a new servo and it worked. Now, the servo is LS-1006A (Analog, osepp.com/wp-content/uploads/2012/09/LS-1006A_datasheet.pdf, running current no load: 150mA @6V, stall current 1.2A @6V) . Let us assuming usage to be 600mA, 4 AA batteries should support 4*2500=10,000mAh. Therefore, the battery pack should support 17 hours of operation (instead of minutes). Please correct me if I am wrong. Thanks! – BSharer App - Share Books Mar 2 '17 at 17:26
1

There is very little to go wrong with servos.

If the servo is powered externally you must ensure the power supply ground, the servo ground, and the Pi ground are connected.

If the servo is powered from the Pi you must ensure the Pi ground and the servo ground are connected.

To generate servo pulses on any GPIO you may use the following commands.

The example is for GPIO18 (pin 12).

sudo pigpiod # start pigpio daemon

pigs s 18 1000 # counterclockwise
pigs s 18 1500 # centre
pigs s 18 2000 # clockwise

pigs s 18 0 # switch servo pulses off
  • This did not work for me. I now suspect that the servos are broken. Added resistance values. Are they still good? Thanks! – BSharer App - Share Books Mar 1 '17 at 17:45
  • @BSharerApp-ShareBooks If they don't work when properly connected and being sent the correct pulses that suggest they are terminally bust. – joan Mar 1 '17 at 18:03
1

joan gave a lot of good help. In the end, as joan suggested, the root cause was the servos I had were all bad (presumably because of our positive/negative wiring errors). I bought a new one and it worked like a charm.

0

I had exactly the same problem, including the motors moving randomly when wires were jiggled. I tried three servo motors, and they all behaved identically.

In my case, the problem was not that the motors were bad (they were all good), but that I did not have the battery ground connected to the raspberry Pi ground (and the servo ground), which was the first thing on joan's checklist. Make sure to check that, it is the fastest and easiest fix.

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.