How to have motors hold power


I am writing a small program in Python that moves a motor 90 degrees, waits a few seconds, and then moves back to the original position as follows:

angle = 90
power = 100

The motors move as requested, however it seems that power to to the motor is disabled after the move finishes during the 5 seconds sleep. I want the power to remain on like it does on Lego NXT-G.

Any pointers?



Hey Jaime, what do you mean by “remain on”. The motors do indeed timeout if they haven’t been addressed (to prevent runaway robots).

What if, instead of a hard pause for 5 seconds, you set the motor power to 0, and reset it to 0 over the course of your pause?


Hi Jaime,
Can you please explain what do you mean by power remaining on?

Do you have some pressure on the motors and want them to remain in the same position for 5 seconds holding it?


I think (at least the old RCX motors) lego motors had four settings. Forward/Backwards, freewheel (unpowered) and hold - that shorted the motor so that it wouldn’t turn when powered down.



The Lego RCX motors (and the NXT and EV3 motors) have the internal motor connected directly to the connector (no internal control circuit). It’s up to the RCX/NXT/EV3/BrickPi to allow for forward, backward, float, and brake, by use of an H-Bridge configuration that permits these abilities.

Since the NXT and EV3 motors have encoders (position feedback), using the proper algorithms, it’s possible to set a position for a motor, and have the motor run to and hold that position (controlled actively by the BrickPi and RPi).

For a motor with an encoder, if you want it to brake and hold the current position, you can set the desired position to the position you want it to hold (i.e. the current position). This is called active braking.