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:
- 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
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:
- 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.
- however, neither servo moved accordingly.
- 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!