tino / pyFirmata

Python interface for the Firmata (http://firmata.org/) protocol. It is compliant with Firmata 2.1. Any help with updating to 2.2 is welcome. The Capability Query is implemented, but the Pin State Query feature not yet.
MIT License
575 stars 193 forks source link

How to get 20kg servo working in pyfirmata #116

Open glendell03 opened 2 years ago

glendell03 commented 2 years ago

Servo brand and specs: https://www.makerlab-electronics.com/product/digital-standard-servo-motor-20kg-mg958/

Hi, I need help to get the 20kg servo working

# main.py

from arduino.servo import Servo
from pyfirmata import Arduino

PORT = "/dev/ttyACM0"
board = Arduino(PORT)

servo = Servo(board, 9)

servo.angle(90)
# servo.py

from time import sleep

class Servo:
    def __init__(self, board, pin):
        self.board = board
        self.pin = pin
        self.servo = self.board.get_pin(f"d:{self.pin}:s")

    def angle(self, angle):
        self.servo.write(angle)
        sleep(0.015)

In SG90 servo (small) the code works but in big servo it doesn't


I tried creating a sweep like in arduino and it worked but the one I need is in the code above

from arduino.servo import Servo
from pyfirmata import Arduino

PORT = "/dev/ttyACM0"
board = Arduino(PORT)

servo = Servo(board, 9)

while True:
    for i in range(0, 180):
        print(i)
        servo.angle(i)
    for i in range(180, 1, -1):
        print(i)
        servo.angle(i)
nildude commented 1 year ago

Hi @glendell03

Since the servo physically need to respond to the requests, you might consider adding some delay into your code ( sleep(1) etc.). That will allow the servo to finish the hardware cycle before invoking the next hardware request.

I have not come across any other more refined ways to do this yet.

myselfgautham commented 4 months ago

Add A Small Delay Of Roughly .25 Seconds That Should Work Else Let Me Know