encoderMotorRun(3, -50) make motor go crazy


I’m having difficulties with one of my encoder motors, when I set it to reverse it drives in reverse at full speed and will not stop until power is cut. It’s only happening to one specific motor, I tested this by moving the motor to different ports and the problem follows it.

I suspect the problem is with the motor hardware, as the other 2 encoder motors don’t have an issue even when I move them to the same port.

Does anyone on this forum have any suggestions for debugging this motor?

I have the MegaPi on top of a Raspberry pi running Python3.8.3 and megapi library.
Here’s an example of the code I’m using

Python 3.8.3 (default, Jun  1 2020, 05:31:00)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from megapi import *

Version:3.8.3 (default, Jun  1 2020, 05:31:00)
[GCC 6.3.0 20170516]
>>> bot = MegaPi()
init MegaPi
>>> bot.start()
<megapi_python3.mSerial object at 0x769c1820>
>>> bot.encoderMotorRun(3, 0) <-- No movement, as expected
>>> bot.encoderMotorRun(3, 50) <-- Moves as expected at a slow pace
>>> bot.encoderMotorRun(3, -50) <-- Motor runs full speed in reverse
>>> bot.encoderMotorRun(3, 0)	<-- Motor continues to run at full speed


Sounds like a broken encoder on the motor or lead. The software will output a voltage to the motor then read back the encoder speed and if it to slow then it increases the voltage or if the speed is too high it then decreases the voltage in order then repeats this over and over in order to maintain correct speed. If it isn’t getting the expected signals back from the encoder the software thinks the motor is still so it keeps increasing voltage.

I would check lead by trying another lead


Thanks, OutoftheBOTS.
Tested a different cable on the problem motor, and it’s still persists. For my project I’m replacing the motor with a separate one, and will give the circuit on the motor a closer look to see if it’s an easy fix, if not then possibly try to exchange it for another.


Hi MangoTheCat,
Please connect the motor to the Megapi board and test it with mBlock5.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.