Search code examples
pythonarduinopyserialservofirmata

Delays between servo movements in pyfirmata don't work


I'm writing a program in python where moving servos at specific times is a crucial part of the project. To achive this, I am using the pyfirmata library.

I've tried two methods of delays, but none of them seem to work. When I run the code, the servo turns the first time, but after the delay, it doesn't turn and the program just stops, instead of moving the servo to 0 degrees and then stopping.

This is the one with the board.pass_time() built in to the pyfirmata library:

from pyfirmata import Arduino, util
import time
board = Arduino('COM3')
servo = board.get_pin('d:9:s')

servo.write(180)        #This works and turns the servo
time.sleep(1)
servo.write(0)          #This time the servo does not turn, then the program ends

And here's the one with time.sleep():

from pyfirmata import Arduino, util
board = Arduino('COM3')
servo = board.get_pin('d:9:s')

servo.write(180)        #This works and turns the servo
board.pass_time(1)
servo.write(0)          #This time the servo does not turn, then the program ends

I would highly appreciate if someone could help.

Thank you, David


Solution

  • I found the answer! There might be a better answer, but if I write board.get_pin('d:9:s') as board.get_pin('d:9:'), like this, I need to control it with a value from 0 to 5 instead of 0 to 360, but the delays work