Input / Output Ports

This page is about the kind of ports that you plug sensors and motors into. Ports that have more than one connection type will have drivers that let you control the port itself. The input and output ports on the EV3 itself and some sensor multiplexers fall into this category (see list below). Simple multiplexers that only support one connection type will not have a separate driver for the port.

Input Port 5 on the BrickPi is physically wired to the I2C pins on the RaspberryPi. See BrickPi Input Port 5 for the details.

Port drivers use the lego-port-class to provide a common interface for interacting with individual ports. Follow the link for more information.

List of port drivers

This is a list of port drivers that are currently available in the ev3dev kernel.

Name Description Connection Types Module
pistorms-out-port mindsensors.com PiStorms Output Port tacho-motor pistorms
ms-nxtmmx-out-port mindsensors.com NXTMMX Output Port tacho-motor ms-nxtmmx
brickpi-out-port Dexter Industries BrickPi Output Port tacho-motor, dc-motor, led brickpi
brickpi-in-port Dexter Industries BrickPi Input Port NXT/Analog, NXT/I2C, EV3/Analog, EV3/UART brickpi
legoev3-input-port EV3 Input Port NXT/Analog, NXT/I2C, Other/I2C, EV3/Analog, EV3/UART, Other/UART legoev3_ports
legoev3-output-port EV3 Output Port tacho-motor, dc-motor, led legoev3_ports
ht-nxt-smux-port HiTechnic NXT Sensor Multiplexer Input Port NXT/I2C, NXT/Analog ht-nxt-smux
evb-output-port EV3 Output Port tacho-motor, dc-motor, led evb_ports
brickpi3-in-port Dexter Industries BrickPi3 Input Port NXT/Analog, NXT/I2C, EV3/Analog, EV3/UART brickpi3
brickpi3-out-port Dexter Industries BrickPi3 Output Port tacho-motor, dc-motor, led brickpi3
evb-input-port EV3 Input Port NXT/Analog, NXT/I2C, Other/I2C, EV3/Analog, EV3/UART, Other/UART evb_ports
ms-ev3-smux-port mindsensors.com EV3 Sensor Multiplexer Input Port EV3/UART, EV3/Analog ms-ev3-smux
wedo-port LEGO WeDo Port WeDo/Analog, dc-motor, led wedo
pistorms-in-port mindsensors.com PiStorms Input Port NXT/Analog, NXT/Color, NXT/I2C, Other/I2C, EV3/Analog, EV3/UART pistorms

The lego-port Subsystem

The lego-port class provides an interface for working with input and output ports that are compatible with LEGO MINDSTORMS RCX/NXT/EV3, LEGO WeDo and LEGO Power Functions sensors and motors. Supported devices include the LEGO MINDSTORMS EV3 Intelligent Brick, the LEGO WeDo USB hub and various sensor multiplexers from 3rd party manufacturers.

Some types of ports may have multiple modes of operation. For example, the input ports on the EV3 brick can communicate with sensors using UART, I2C or analog validate signals - but not all at the same time. Therefore there are multiple modes available to connect to the different types of sensors.

In most cases, ports are able to automatically detect what type of sensor or motor is connected. In some cases though, this must be manually specified using the mode and set_device attributes. The mode attribute affects how the port communicates with the connected device. For example the input ports on the EV3 brick can communicate using UART, I2C or analog but not all at the same time, so the mode must be set to the one that is voltages, appropriate for the connected sensor. The set_device attribute is used to specify the exact type of sensor that is connected. Note: the mode must be correctly set before setting the sensor type.

Sysfs

Ports can be found at /sys/class/lego-port/port<N> where <N> is incremented each time a new port is registered.

Note

The number <N> is not related to the actual port at all - use the address attribute to find a specific port.

Sysfs Attributes
Attribute Access Description
address read-only Returns the name of the port. See individual driver documentation for the name that will be returned.
driver_name read-only Returns the name of the driver that loaded this device. You can find the complete list of drivers in the list of port drivers.
modes read-only Returns a space separated list of the available modes of the port.
mode read/write Reading returns the currently selected mode. Writing sets the mode. Generally speaking when the mode changes any sensor or motor devices associated with the port will be removed new ones loaded, however this will depend on the individual driver implementing this class.
set_device write-only For modes that support it, writing the name of a driver will cause a new device to be registered for that driver and attached to this port. For example, since the exact type of an NXT/Analog sensor cannot be automatically detected, you must use this attribute to load the correct driver. For I2C sensors, you must write the I2C address in addition to the driver name. Returns -EOPNOTSUPP if setting a device is not supported for the current mode of the port.
status read-only In most cases, reading status will return the same value as mode. In cases where there is an auto mode additional values may be returned, such as no-device or error. See individual port driver documentation for the full list of possible values.

Events

In addition to the usual add and remove events, the kernel change event is emitted when mode or status changes.