Control a Maestro with Python 3

Hi Pololu Maestro fans and experts,

I have Pololu Maestor 6 Channel that I’ve been trying to program using Python 3, which deals with bytes conversion in a more complex way than Python 2.

I have a very similar situation with 8-bit mode where I can send servos to typical 0, 90, 180 agles which correspond with min (720), mid (1360), and max (2000) positions set up on the Control Centre.

However, problem occured as I try it in an incremental loop, such as below:

for degree in range(0,180):
   setAngle(0, degree)

I sweeped through all angles 0 and 90 sweetly, but as soon as it reaches 91 it goes back to 89 and then go back up, then down, then stuck, then up again erracticly. What could be the problem?

I know this is topic was raised 6 years ago, but I couldn’t find the solution anywhere else. The only solution I can think of is to abandon 8-bit command or Python 3 altogether.

Has anyone gone far with Python 3 pyserial commands for the Maestro?


I moved your post to a new topic. Please do not post onto the end of unrelated topics. If you cannot find a topic that is relevant to your issue, you can create a new topic.

I noticed that you posted a very similar question on another thread on our forum. It looks like you are using the “RPi Android HTML5 Realtime Servo Control” example. Unfortunately, we do not have any Python example code for the Maestro. However, if you want help debugging your program, I recommend that you simplify your code to the simplest possible program that should work but does not and post the entire code here. When you post your code, please use [code ] and [/code ] tags (without the spaces) to make your code readable.

For your bytes conversion issue (that you mentioned in your other thread), you might try something like this:


For more information about bytes type, you can look at it in the Python documentation.

- Amanda

That is awesome. I have modified the Python driver and posted it on Linux Circle website.

The erratic behaviour of the servo is because the range specified in Pololu Maestro Control Centre is higher than the min or max limit. So to be save, please set the mid point to be between 1350μs and 1400μs, and the range should be around +/- 800μs. So that will give you 600uμs min and 2200μs max. The setAngle function will map 90 degree to the corresponding neutral value.

Please check out the full Python 3 code listing of Pololu Maestro device driver for everyone to use: