Motors / Output Devices

The EV3 has four output ports for connecting motors and other devices (like LEDs). If you are trying to use something that plugs into one of the output ports, then you are in the right place. If you are working with a motor that connects to a motor controller which plugs into an input port, you will find information on the motor controller on the [sensors] page.

This page lists well-known devices, however any device that is rated for 9VDC, requires 500mA or less and can handle pulse width modulation is safe to connect directly to the output ports on the EV3.

Supported Motors

Part Number Name Driver Type Auto-detect
Actuonix
L12-EV3-100 L12 EV3 100mm act-l12-ev3-100 ev3 N [1]
L12-EV3-50 L12 EV3 50mm act-l12-ev3-50 ev3 N [1]
LEGO
43362 Motor 9V Mini-motor, newer lighter weight lego-43362 rcx N
45502 EV3 Large Servo Motor lego-ev3-l-motor ev3 Y [1]
45503 EV3 Medium Servo Motor lego-ev3-m-motor ev3 Y [1]
47154 Technic Motor 9V Geared lego-47154 rcx N
70823 Motor 9V Micromotor lego-70823 rcx N
71427 Motor 9V Mini-motor, older heavier weight lego-71427 rcx N
74569 Technic Motor 9V lego-74569 rcx N
88002 Power Functions Train Motor lego-88002 rcx N
88003 Power Functions L-Motor lego-88003 rcx N
88004 Power Functions Servo Motor lego-88004 rcx N
8882 Power Functions XL-Motor lego-8882 rcx N
8883 Power Functions M-Motor lego-8883 rcx N
9670 Power Functions E-Motor lego-9670 rcx N
9842 NXT (Interactive Servo) Motor lego-nxt-motor ev3 Y [1]
[1](1, 2, 3, 4, 5) Motors are only automatically detected on the LEGO MINDSTORMS EV3 platform. LEGO NXT Motors are detected as LEGO EV3 Large motors. 3rd party motors will not be correctly detected and must be manually specified.

Types of Motors

There are currently three basic types of classes of devices that are supported in ev3dev. Tacho motors, DC motors and LEDs.

Tacho Motors

Tacho motors get their name from the LMS2012 (official LEGO) source code. Tacho is short for tachometer. This is probably a bit of a misnomer because the motor itself does not have a tachometer. Instead, the EV3 brick acts as the tachometer. Technically speaking the motors have a incremental rotary encoder (also called quadrature encoder) that is used by the EV3 to determine the speed and direction of rotation.

DC Motors

DC motors are just “plain” motors. They do not have a quadrature encoder for feedback.

LEDs

Any 9VDC rated (i.e. it has an appropriately sized resistor) LED can be used.

Using Motors and LEDs

Currently, only NXT and EV3 motors can be automatically detected. To use other devices, see the [EV3 Output Port Driver] for information on how to set the mode of the output port.

RCX compatible (aka 9V) motors and LEDs can be connected to the EV3 using a LEGO 8528 cable.

Power Functions motors and LEDs can be connected using a LEGO 8528 cable plus a LEGO 8886 cable or LEGO 8871 cable.

tacho-motor Subsystem

The tacho-motor class provides a uniform interface for using motors with positional and directional feedback such as the EV3 and NXT motors. This feedback allows for precise control of the motors.

Sysfs

Tacho motors can be found at /sys/class/tacho-motor/motor<N>, where <N> is incremented each time a motor is loaded.

Note

The number <N> is not related to the port the motor is plugged in to.

sysfs attributes
Attribute Access Description
address read-only Returns the name of the port that the motor is connected to.
command write-only

Sends a command to the motor controller. Possible values are:

  • run-forever: Causes the motor to run until another command is sent.
  • run-to-abs-pos: Runs the motor to an absolute position specified by``position_sp`` and then stops the motor using the command specified in stop_action.
  • run-to-rel-pos: Runs the motor to a position relative to the current position value. The new position will be current position + position_sp. When the new position is reached, the motor will stop using the command specified by stop_action.
  • run-timed: Run the motor for the amount of time specified in time_sp and then stops the motor using the command specified by stop_action.
  • run-direct: Runs the motor using the duty cycle specified by duty_cycle_sp. Unlike other run commands, changing duty_cycle_sp while running will take effect immediately.
  • stop: Stop any of the run commands before they are complete using the command specified by stop_action.
  • reset: Resets all of the motor parameter attributes to their default values. This will also have the effect of stopping the motor.

Not all commands may be supported. Read the commands attribute to get the list of commands supported by a particular driver.

commands read-only Returns a space separated list of commands that are supported by the motor controller.
count_per_rot read-only Returns the number of tacho counts in one rotation of the motor. Tacho counts are used by the position and speed attributes, so you can use this value to convert from rotations or degrees to tacho counts. (rotation motors only)
count_per_m read-only Returns the number of tacho counts in one meter of travel of the motor. Tacho counts are used by the position and speed attributes, so you can use this value to convert from distance to tacho counts. (linear motors only)
full_travel_count read-only Returns the number of tacho counts in the full travel of the motor. When combined with the count_per_m atribute, you can use this value to calculate the maximum travel distance of the motor. (linear motors only)
driver_name read-only Returns the name of the driver that provides this tacho motor device.
duty_cycle read-only Returns the current duty cycle of the motor. Units are percent. Values are -100 to 100.
duty_cycle_sp read/write Writing sets the duty cycle setpoint. Reading returns the current value. Units are in percent. Valid values are -100 to 100. A negative value causes the motor to rotate in reverse.
polarity read/write

Sets the polarity of the motor. Valid values are:

  • normal: A positive duty cycle will cause the motor to rotate clockwise.
  • inversed: A positive duty cycle will cause the motor to rotate counter-clockwise.
position read/write Returns the current position of the motor in pulses of the rotary encoder. When the motor rotates clockwise, the position will increase. Likewise, rotating counter-clockwise causes the position to decrease. Writing will set the position to that value. The range is -2,147,483,648 and +2,147,483,647 tachometer counts (32-bit signed integer).
hold_pid/Kd read/write The derivative constant for the position PID.
hold_pid/Ki read/write The integral constant for the position PID.
hold_pid/Kp read/write The proportional constant for the position PID.
max_speed read Returns the maximum value that is accepted by the speed_sp attribute. This value is the speed of the motor at 9V with no load. Note: The actual maximum obtainable speed will be less than this and will depend on battery voltage and mechanical load on the motor.
position_sp read/write Writing specifies the target position for the run-to-abs-pos and run-to-rel-pos commands. Reading returns the current value. Units are in tacho counts. You can use the value returned by counts_per_rot to convert tacho counts to/from rotations or degrees. The range is -2,147,483,648 and +2,147,483,647 tachometer counts (32-bit signed integer).
speed read-only Returns the current motor speed in tacho counts per second. Note, this is not necessarily degrees (although it is for LEGO motors). Use the count_per_rot attribute to convert this value to RPM or deg/sec.
speed_sp read/write Writing sets the target speed in tacho counts per second used for all run-* commands except run-direct. Reading returns the current value. A negative value causes the motor to rotate in reverse with the exception of run-to-*-pos commands where the sign is ignored. Use the count_per_rot attribute to convert RPM or deg/sec to tacho counts per second. Use the count_per_m attribute to convert m/s to tacho counts per second.
ramp_up_sp read/write Writing sets the ramp up setpoint. Reading returns the current value. Units are in milliseconds and must be positive. When set to a non-zero value, the motor speed will increase from 0 to 100% of max_speed over the span of this setpoint. The actual ramp time is the ratio of the difference between the speed_sp and the current speed and max_speed multiplied by ramp_up_sp. Values must not be negative.
ramp_down_sp read/write Writing sets the ramp down setpoint. Reading returns the current value. Units are in milliseconds and must be positive. When set to a non-zero value, the motor speed will decrease from 0 to 100% of max_speed over the span of this setpoint. The actual ramp time is the ratio of the difference between the speed_sp and the current speed and max_speed multiplied by ramp_down_sp. Values must not be negative.
speed_pid/Kd read/write The derivative constant for the speed regulation PID.
speed_pid/Ki read/write The integral constant for the speed regulation PID.
speed_pid/Kp read/write The proportional constant for the speed regulation PID.
state read-only

Reading returns a space separated list of state flags. Possible flags are:

  • running: Power is being sent to the motor.
  • ramping: The motor is ramping up or down and has not yet reached a constant output level.
  • holding: The motor is not turning, but rather attempting to hold a fixed position.
  • overloaded: The motor is turning as fast as possible, but cannot reach its speed_sp.
  • stalled: The motor is trying to run but is not turning at all.
stop_action read/write

Reading returns the current stop action. Writing sets the stop action. The value determines the motors behavior when command is set to stop. Possible values are:

  • coast: Removes power from the motor. The motor will freely coast to a stop.
  • brake: Removes power from the motor and creates a passive electrical load. This is usually done by shorting the motor terminals together. This load will absorb the energy from the rotation of the motors and cause the motor to stop more quickly than coasting.
  • hold: Causes the motor to actively try to hold the current position. If an external force tries to turn the motor, the motor will “push back” to maintain its position.

Not all actions may be supported. Read stop_actions to get the actions available for a particular driver.

stop_actions read-only Returns a space-separated list of stop actions supported by the motor controller.
time_sp read/write Writing specifies the amount of time the motor will run when using the run-timed command. Reading returns the current value. Units are in milliseconds. Values must not be negative.

dc-motor Subsystem

The dc-motor class provides a uniform interface for using regular DC motors with no fancy controls or feedback. This includes LEGO MINDSTORMS RCX motors and LEGO Power Functions motors.

Sysfs

DC motors can be found at /sys/class/dc-motor/motor<N>, where <N> is incremented each time a motor is loaded.

Note

The number <N> is not related to the port address.

Sysfs Attributes
Attribute Access Description
address read-only Returns the name of the port that the motor is connected to.
command write-only

Sets the command for the motor. Possible values are:

  • run-forever: Causes the motor to run until another command is sent.
  • run-timed: Runs the motor for the amount of time specified in time_sp and then stops the motor using the command specified by stop_action.
  • run-direct: Runs the motor at the duty cycle specified by duty_cycle_sp. Unlike other run commands, changing duty_cycle_sp while running will take effect immediately.
  • stop: Stops any of the run commands before they are complete using the command specified by stop_action.

Not all commands may be supported. Read commands to find out which commands are supported for a particular driver.

commands read-only Returns a space separated list of commands supported by the motor controller.
driver_name read-only Returns the name of the motor driver that loaded this device. See the list of supported motors for a list of drivers.
duty_cycle read-only Shows the current duty cycle of the PWM signal sent to the motor. Values are -100 to 100 (-100% to 100%).
duty_cycle_sp read/write Writing sets the duty cycle setpoint of the PWM signal sent to the motor. Valid values are -100 to 100 (-100% to 100%). Reading returns the current setpoint.
polarity read/write

Sets the polarity of the motor. Valid values are:

  • normal: Causes the motor to turn in the direction indicated by the sign (+/-) of the duty_cycle_sp.
  • inversed: Causes the motor to turn in the opposite direction of the sign (+/-) of the duty_cycle_sp.
state read-only

Gets a space separated list of flags indicating the motor status. Possible flags are:

  • running: Indicates that the motor is powered.
  • ramping: Indicates that the motor has not yet reached the duty_cycle_sp.
stop_action write-only

Sets the stop action that will be used when the motor stops. Possible values are:

  • coast: Causes the motor to coast to a stop by floating the outputs.
  • brake: Causes the motor to stop more quickly by shorting the outputs.

Not all values may be supported. Read stop_actions to find out which actions are supported for a particular driver.

stop_actions read-only Gets a space separated list of supported stop actions.
ramp_down_sp read/write Sets the time in milliseconds that it take the motor to ramp down from 100% to 0%. Valid values are 0 to 10000 (10 seconds). Default is 0.
ramp_up_sp read/write Sets the time in milliseconds that it take the motor to up ramp from 0% to 100%. Valid values are 0 to 10000 (10 seconds). Default is 0.
time_sp read/write Sets the time setpoint used with the run-timed command. Units are in milliseconds. Values must not be negative.

servo-motor Subsystem

The servo-motor class provides a uniform interface for using hobby type servo motors.

Note

LEGO calls the NXT and EV3 motors, “servo” motors on their website. Technically, that is a correct name for them because they provide position feedback. However, the servo-motor class is only used for a very specific type of servo motor that uses a 50MHz control signal.

It is not used by any LEGO brand motors.

Sysfs

Servo motors can be found at /sys/class/servo-motor/motor<N>, where <N> is incremented each time a servo is loaded.

Note

The number <N> is not related to the port the motor is plugged in to.

sysfs attributes
Attribute Access Description
address read-only Returns the name of the port that the motor is connected to.
command write-only

Sets the command for the servo. Possible values are:

  • run: Causes the servo to be driven to the position set in the position_sp attribute.
  • float: Removes power from the motor.
driver_name read-only Returns the name of the motor driver that loaded this device.
max_pulse_sp read/write Used to set the pulse size in milliseconds for the signal that tells the servo to drive to the maximum (clockwise) position_sp. Default value is 2500. Valid values are 2000 to 3000. You must write to the position_sp attribute for changes to this attribute to take effect. Values must not be negative.
mid_pulse_sp read/write Used to set the pulse size in milliseconds for the signal that tells the servo to drive to the mid position_sp. Default value is 1500. Valid values are 1000 to 2000. For example, on a 180 degree servo, this would be 90 degrees. On continuous rotation servo, this is the “neutral” position where the motor does not turn. You must write to the position_sp attribute for changes to this attribute to take effect. Values must not be negative.
min_pulse_sp read/write Used to set the pulse size in milliseconds for the signal that tells the servo to drive to the minimum (counter-clockwise) position. Default value is 500. Valid values are 0 to 1000. You must write to the position_sp attribute for changes to this attribute to take effect. Values must not be negative.
polarity read/write

Sets the polarity of the servo. Valid values are:

  • normal: Causes the position_sp attribute to act in the usual manner.
  • inversed: Causes the position_sp value to be inverted. i.e -100 will correspond to max_pulse_sp, and 100 will correspond to min_pulse_sp.
position_sp read/write Reading returns the current position_sp of the servo. Writing instructs the servo to move to the specified position_sp. Units are percent. Valid values are -100 to 100 (-100% to 100%) where -100 corresponds to min_pulse_sp, 0 corresponds to mid_pulse_sp and 100 corresponds to max_pulse_sp.
rate_sp read/write Sets the rate_sp at which the servo travels from 0 to 100.0% (half of the full range of the servo). Units are in milliseconds. Example: Setting rate_sp to 1000 means that it will take a 180 degree servo 2 seconds to move from 0 to 180 degrees. Note: Some servo controllers may not support this in which case reading and writing will fail with -EOPNOTSUPP. In continuous rotation servos, this value will affect the rate at which the speed ramps up or down. Values must not be negative.
state read-only

Returns a space separated list of flags indicating the state of the servo. Possible flag is:

  • running: Indicates that the motor is powered.

Motor Modules

EV3/EVB Motors

The legoev3-motor module is used on devices like the EV3 where motors are connected directly to the CPU rather than an external controller.

Generic DC Motors

The rcx-motor module provides a dc-motor Subsystem interface for RCX motors, Power Functions motors or any other 9V rated DC motor connected to an output port. You can find the devices bound to this driver in the directory /sys/bus/lego/drivers/rcx-motor.

Generic LEDs

The rcx-led module provides a leds interface for RCX motors, Power Functions motors or any other 9V rated LED connected to an output port.