A problem with a servo motor

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Chemist
Posts: 20
Joined: Wed Mar 04, 2015 5:25 pm

A problem with a servo motor

Post by Chemist » Mon Mar 09, 2015 4:16 pm

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.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: A problem with a servo motor

Post by blmorris » Mon Mar 09, 2015 4:54 pm

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

Chemist
Posts: 20
Joined: Wed Mar 04, 2015 5:25 pm

Re: A problem with a servo motor

Post by Chemist » Mon Mar 09, 2015 5:09 pm

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

Post Reply