Servo - Motor & Pot Control

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
Posts: 454
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall

Servo - Motor & Pot Control

Post by devnull » Sat Sep 14, 2019 11:56 am

To save me reinventing the wheel, has anyone done anything with motor / pot servos (not R/C) servos ?

The motor drives a gearbox and the output shaft rotates a 10K servo pot.

I want to be able to rotate the motor to specific positions using upython.

I am guessing that the servo pot will be read as ADC value, any code snippets or suggestions welcome :-)

User avatar
Posts: 1837
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Servo - Motor & Pot Control

Post by jimmo » Sat Sep 14, 2019 12:26 pm

What you're describing is actually exactly what's inside an RC servo. They have a tiny pot and a simple circuit that drives the motor based on the difference between the analog pot value and the incoming PWM duty cycle. Because servo motors move (relatively) slowly, their control logic can be very simple, they're on/off controllers (not even P).

So you could do that in MicroPython in a couple of lines of code. Like you say, you'd read the pot using one of the ADC pins.

Depending on your motor and load, that might be sufficient. But from there you have a wide range of control system options, starting with a P controller, then PID, etc. Real servo motors (like ones that are used in place of steppers in mechatronic applications), e.g. from companies like ClearPath use much more sophisticated algorithms. And instead of pots, they use more accurate position encoders (e.g. optical or magnetic).

Not MicroPython, but you might find some inspiration from this project. (I have some of these, they run a MicroPython compatible microcontroller, if I had more hours in the day I would totally try and write some MicroPython firmware for them :) )

Post Reply