This question is a follow up for this question. I have a classic servo motor (Vin, PWM, Ground), and a short program to work with it. The code is:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 100)
pwm.start(5)
def update(angle):
duty = float(angle) / 10.0 + 2.5
output = pwm.ChangeDutyCycle(duty)
print output
def loop():
update(170)
time.sleep(1)
update(20)
time.sleep(1)
def main():
i=0
while i<3:
loop()
i+=1
return 0
if name=="main":
main()
My goal is to detect if the servo motor is actually connected and working. The program works well disregarding the servo status (connected/disconnected). As the answer suggests - implementing the circuit to check if the signal is coming. There's an idea to implement the switch circuits (as stated in the answer to a previous question). However I was wondering if someone can provide another solution. The priority is cheap as possible.
I use the external power source for servo - 4 AAA batteries in sequence. I've tried connecting LED in sequence between Vout of battery and Vin of servo - LED lit, but servo didn't move. Same happened when I connected LED in between PWM GPIO and PWM of servo - LED blinked but servo didn't move.