Python code for position control of DC motor with encoder

I’m looking to automate the opening and closing a door weighing about 3Kg. I have tried using a 25Kg.cm servo but find that slowing the servo by moving in increments results in a jerky motor response. It seems that a 1:500 geared DC motor with an encoder might be more suitable. I have not been able to find suitable python code to control the position of such a motor.
Can somebody please refer me to some python code that could be adapted to rotate motor with encoder say 100 degrees when a signal is sent to a RPi pin, and then reverse when receiving another signal?
Thanks, Richard

1 Like

Thanks Mark, I’ll try adapting your code which is out of my league.

2 Likes

Hi Richard,

To get your servo working you might be able to use a bendy or stretchy linkage to smooth it out a little or add a reduction either through changing the length of the linking arm or a gear system.

Mark has some great code there and if you need a hand adapting it I’d try some AI tools or post back here and we can take a look!

Liam

Thanks Liam for these ideas. I’ll try these and let you know if I get an acceptable result.
Richard

1 Like