Page 1 of 1

A problem with a servo motor

Posted: Mon Mar 09, 2015 4:16 pm
by Chemist
Hello All,

I have a very strange situation. My detector consist of several components: a light sensor, a servo motor and and an led (PWM). Here is wiring:

light sensor - X1, VIN, GND
servo motor - X2, VIN, GND
led(pwm) - X3, GND

When I test the servo motor via picocom, everything works great but when I wire all components and run python3 pyboard.py detector.py - servo doesn't work (other parts work well). If I run python3 pyboard.py servo_test.py :

Code: Select all

# servo_test.py
import pyb
import time

servo = pyb.Servo(2)
for i in range(3):
    servo.angle(45)
    time.sleep(1)
    servo.angle(-45)
    time.sleep(1)
the servo works without any problems. So, my questions is : is there any compatibility problems between the pins? Maybe some of them cannot work together? Or I do something wrong? Please let me know if you need to see the code in detector.py

Thank you.

Re: A problem with a servo motor

Posted: Mon Mar 09, 2015 4:54 pm
by blmorris
According to the docs (haven't checked the code recently) the Servo class uses Timer 5 to generate the PWM servo control signal. If your script uses Timer 5 for the LED or the light sensor then this will prevent the Servo from working.

-Bryan

Re: A problem with a servo motor

Posted: Mon Mar 09, 2015 5:09 pm
by Chemist
Bryan,

Thank you! Indeed, I use Timer 5 for my led. So I just need to change the Timer from 5 to 2. Hopefully, the led will be working.

Best,
Vitali