Sensors / Input Devices

The EV3 has four input ports for connecting sensors and other devices (like sensor multiplexers or motor controllers). If you are trying to use something that plugs into one of those ports, you are in the right place.

Supported Sensors

This is a list of sensors that currently have drivers available in the ev3dev kernel. The Part Number column links to the vendor website. The Name column links to the sensor’s entry in Appendix A.

Part Number Name Driver Type Auto-detect
  Generic EV3 Analog Sensor ev3-analog-XX EV3/Analog Y
  Generic NXT Analog Sensor nxt-analog NXT/Analog Y
Charmed Labs
Pixy LEGO Pixy (CMUcam5) for LEGO pixy-lego NXT/I2C Y
Dexter Industries
dFlex Flexible Sensor for Mindstorms NXT di-dflex NXT/Analog N [5]
Fatcatlab
9DOF Sensor 9DOF Sensor fcl-9dof EV3/UART Y
ADC Adapter ADC Adapter fcl-adc EV3/UART Y
Altitude Sensor Altitude Sensor fcl-altitude EV3/UART Y
Gesture Sensor Gesture Sensor fcl-gesture EV3/UART Y
Humidity Sensor Humidity Sensor fcl-humidity EV3/UART Y
IR Receiver IR Receiver fcl-ir EV3/UART Y
Light Sensor Light Sensor fcl-light EV3/UART Y
HiTechnic
  NXT Color Sensor ht-nxt-color NXT/I2C Y
NAA1030 NXT Angle Sensor ht-nxt-angle NXT/I2C Y
NAC1040 NXT Acceleration / Tilt Sensor ht-nxt-accel NXT/I2C Y
NBR1036 NXT Barometric Sensor ht-nxt-barometric NXT/I2C Y
NCO1038 NXT Color Sensor V2 ht-nxt-color-v2 NXT/I2C Y
NEO1048 NXT EOPD ht-nxt-eopd NXT/Analog N [2]
NFS1074 NXT Force Sensor ht-nxt-force NXT/Analog N [2]
NGY1044 NXT Gyro Sensor ht-nxt-gyro NXT/Analog N [2]
NIL1046 NXT IRLink Sensor ht-nxt-ir-link NXT/I2C Y
NIR1032 NXT IRReceiver Sensor ht-nxt-ir-receiver NXT/I2C Y
NIS1070 NXT PIR Sensor ht-nxt-pir NXT/I2C Y
NMC1034 NXT Compass Sensor ht-nxt-compass NXT/I2C Y
NMS1035 NXT Magnetic Sensor ht-nxt-mag NXT/Analog N [2]
NSK1042 NXT IRSeeker V2 ht-nxt-ir-seek-v2 NXT/I2C Y
NSX2020 NXT Sensor Multiplexer ht-nxt-smux NXT/I2C Y
SPR2010 NXT SuperPro Prototype Board ht-super-pro NXT/I2C Y
LEGO
45504 EV3 Ultrasonic Sensor lego-ev3-us EV3/UART Y
45505 EV3 Gyro Sensor lego-ev3-gyro EV3/UART Y
45506 EV3 Color Sensor lego-ev3-color EV3/UART Y
45507 EV3 Touch Sensor lego-ev3-touch EV3/Analog Y
45509 EV3 Infrared Sensor lego-ev3-ir EV3/UART Y
9581 WeDo USB Hub wedo-hub USB Y
9583 WeDo Motion Sensor wedo-motion Wedo/Analog Y
9584 WeDo Tilt Sensor wedo-tilt Wedo/Analog Y
9668 Energy Display lego-power-storage NXT/I2C Y
9749 NXT Temperature Sensor lego-nxt-temp NXT/I2C Y
9843 NXT Touch Sensor lego-nxt-touch NXT/Analog Y [1]
9844 NXT Light Sensor lego-nxt-light NXT/Analog Y
9845 NXT Sound Sensor lego-nxt-sound NXT/Analog N [2]
9846 NXT Ultrasonic Sensor lego-nxt-us NXT/I2C Y
Microinfinity
CruizCore XG 1300L Digital Gyroscope And Accelerometer mi-xg1300l NXT/I2C N [4]
mindsensors.com
AbsoluteIMU(-A/C/G) Gyro, MultiSensitivity Accelerometer and Compass ms-absolute-imu NXT/I2C Y
AngleSensor GlideWheel-AS ms-angle NXT/I2C Y
EV3SensorMUX EV3 Sensor Multiplexer ms-ev3-smux NXT/I2C Y
LightSensorArray Light Sensor Array ms-light-array NXT/I2C Y
LineLeader Line Follower Sensor ms-line-leader NXT/I2C Y
NXTCam-v4 Vision Subsystem v4 for NXT or EV3 ms-nxtcam NXT/I2C Y
NXTCam-v5 Vision Subsystem v5 for NXT or EV3 (with fixed lens) ms-nxtcam5 NXT/I2C Y
NXTMMX-v2 Multiplexer for NXT/EV3 Motors ms-nxtmmx NXT/I2C Y
NxtServo 8-channel Servo Controller ms-8ch-servo NXT/I2C Y
PCF8574-Nx Sensor building kit for NXT with PCF8574 IC pcf8574 Other/I2C N [3]
PCF8591-Nx Sensor building kit for NXT with PCF8591 IC pcf8591 Other/I2C N [3]
PPS58-Nx Digital Pneumatic Pressure Sensor ms-pps58-nx NXT/I2C Y
PixyAdapter Pixy Adapter for MINDSTORMS EV3 or NXT ms-pixy-adapter NXT/I2C Y
RTC-Nx-v3 Realtime Clock for NXT ds1307 Other/I2C N [3]
TouchMux Touch Sensor Multiplexer for NXT & EV3 ms-nxt-touch-mux NXT/Analog N [2]
[1]Only touch sensors that shipped with the NXT 2.0 set can be automatically detected. Older touch sensors that shipped with the original NXT sets are missing an electrical connection (pin 2 is not internally connected to pin 3) and cannot be automatically detected.
[2](1, 2, 3, 4, 5, 6) The automatic detection algorithm detects this sensor as an NXT/Analog type sensor but it cannot determine the exact sensor type. The generic analog driver (nxt-analog) will be loaded by default for this sensor. See the The lego-port Subsystem for information on how to manually load the correct driver.
[3](1, 2, 3) The automatic detection algorithm detects this sensor as an I2C sensor and the port is automatically put into I2C mode. However, the sensor does not follow the LEGO MINDSTORMS convention for I2C sensors, so the exact type of sensor cannot be determined. See Appendix C: I2C Devices for information on how to manually load the correct driver.
[4]The automatic detection algorithm detects this sensor as an I2C sensor and the port is automatically put into I2C mode. However, this sensor only partially follows the LEGO MINDSTORMS convention for I2C sensors, so the driver must be loaded manually. See the sensor’s page for more information.
[5]The Dexter Industries dFlex sensor cannot be automatically detected (because pin 2 is not connected to pin 3). In order to use this sensor, you must manually set the port to nxt-analog mode and then set the driver to di-dflex.

Unsupported Sensors

One of the goals of ev3dev is to support as many sensors as possible. In fact, even if a manufacturer’s documentation says that a device does not work with the EV3, chances are it will work with ev3dev.

If you have a sensor that is not supported yet, let us know about it by opening an issue on GitHub. For many sensors adding a driver is trivial - even if you are not a “kernel hacker” or a “c programmer”. For the non-trivial sensors, see the contributing page for information on how to write a driver or how to donate hardware to someone who will.

Using Sensors

Automatic Detection

The EV3 has “smart” sensor ports that can identify most sensors. Beware! Full automatic detection works on EV3 only. And even on EV3, some sensors cannot be automatically detected. See notes below in the table of supported sensors.

For sensors that cannot be automatically detected, you can manually control the input port mode. Read more about it on Input / Output Ports page.

On FatcatLab’s EVB, EV3/Analog and EV3/UART sensors can be automatically detected. For NXT/Analog sensors, you must manually set the mode. Most NXT/I2C sensors should be automatically detected.

On BrickPi, BrickPi+ and BrickPi3, sensors cannot be automatically detected at all. You must manually configure the input ports for all sensors.

On PiStorms, detection of EV3/UART, EV3/Analog and NXT/I2C sensors is semi-automatic. If you put the input port into ev3-uart, ev3-analog, or i2c-thru mode, the specific type of sensor will be automatically detected (assuming it is a LEGO compatible sensor). So you usually don’t have to write to the set_device attribute of the port for these sensors.

MINDSTORMS Compatible Sensors

Most of the supported sensors are designed to work with LEGO MINDSTORMS. These sensors use the LEGO sensor class. You can find these in sysfs at /sys/class/lego-sensor/. The sensors have modes that select what type of data is read from the sensor. Generally, you will select a mode and then read the data value from the sensor. Follow the link above for more details.

Other Sensors and Advanced Usage

Many sensors that were not specifically designed for LEGO MINDSTORMS can be used with ev3dev too. You can read more about the “Other” sensor types below. Also, some MINDSTORMS compatible sensor may have advanced features that are not accessible using the lego-sensor class.

When using sensors this way, often automatic detection will not work correctly, therefore it is usually best to manually select the mode of input port (e.g. other-i2c or other-uart).

For more information on using I2C sensors, check out Appendix C: I2C Devices.

Types of Sensors

When dealing with sensors in ev3dev, it is useful to know how it communicates with the EV3 brick. There are three basic kinds of communication that the input ports can use to get information from the sensor, Analog Sensors, I2C Sensors and UART Sensors, plus one special type for LEGO NXT Color Sensors.

Analog Sensors

These are the simplest type of sensor. The measured value is converted to a voltage (0-5VDC) that is read by the EV3.

EV3/Analog Sensors

These are sensors that were designed specifically for the EV3 and will not work on the NXT because the pinout is different. They contain an ID resistor so that the EV3 can tell different types of sensors apart. The actual analog value is measured on pin6.

NXT/Analog Sensors

These sensors are designed for the NXT, but also work on the EV3. The EV3 cannot differentiate between most of these sensors though, so you have to tell it which one your have or just use the generic driver.

RCX/Analog Sensors

RCX sensors also fall into this category, but do not work with the EV3 - at least not with the converter cable described in the NXT Hardware Developers kit. This is due to a difference in the input port pins between the EV3 and the NXT. If someone wants design a new converter cable, we could make them work.

WeDo/Analog Sensors

WeDo sensors are also analog sensors. They are actually electrically similar to EV3/Analog sensors (require 5V power and have ID resistor). Currently, we only support WeDo sensors attached to a WeDo hub, but if someone would like to design a cable and modify the wedo-sensor and lego-ports drivers, we could easily make them work with the input ports on the EV3.

LEGO NXT Color Sensors

The LEGO NXT Color Sensor is in a class of its own. It uses a hybrid of analog and (non-standard) digital communications. The NXT Color Sensor is not usable at this point in time. We can detect it with the auto-detect, but we don’t have a driver for it yet.

I2C Sensors

I2C sensors are sensors that communicate with the intelligent brick via the I2C protocol. In the NXT documentation, they are referred to a “digital” sensors. These sensors can be sorted into two categories.

NXT/I2C Sensors

These are sensors designed using LEGO’s guidelines for NXT digital sensors. NXT/I2C sensors can be automatically detected because they contain vendor and product IDs at specific I2C registers.

Other/I2C Sensors

These can be any off-the-shelf I2C device or 3rd party sensors that are designed for LEGO MINDSTORMS, but do not follow the guidelines of NXT/I2C sensors.

UART Sensors

The EV3 has a UART transceiver connected to each input port that can be used to communicate with many devices using this widely used standard.

EV3/UART Sensors

These is a new type of sensor that is designed specifically for the EV3 (they don’t work with the NXT). These sensors are a bit “smarter” in that in addition to sending the data of what they measure, they also send information about their capabilities. This means that any new EV3/UART sensors should “just work” without us having to write new drivers.

Other/UART Sensors

In addition to sensors designed to work with EV3, any UART device can be connected. But, be careful of voltage levels. The EV3 uses 3.3V I/O. It is safe to connect other devices that use 3.3V or 5V I/O. But, don’t connect anything with higher voltage!

The lego-sensor Subsytem

The lego-sensor class provides a uniform interface for using most of the sensors available for the EV3. The various underlying device drivers will create a lego-sensor device for interacting with the sensors.

Sensors are primarily controlled by setting the mode and monitored by reading the value<N> attributes. Values can be converted to floating point if needed by value<N> / 10.0 ^ decimals.

Identifying sensors

Since the name of the sensor<N> device node does not correspond to the port that a sensor is plugged in to, you must look at the address attribute if you need to know which port a sensor is plugged in to. However, if you don’t have more than one sensor of each type, you can just look for a matching driver_name. Then it will not matter which port a sensor is plugged in to - your program will still work.

Sysfs

Sensors can be found at /sys/class/lego-sensor/sensor<N>, where <N> is incremented each time a sensor 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 sensor is connected to, e.g. in1. I2C sensors also include the I2C address (decimal), e.g. in1:i2c8.
bin_data read-only Reading the file will give the unscaled raw values in the value<N> attributes. Use bin_data_format, num_values and the individual sensor documentation to determine how to interpret the data.
bin_data_format read-only

Returns the format of the values in bin_data for the current mode. Possible values are:

  • u8: Unsigned 8-bit integer (byte)
  • s8: Signed 8-bit integer (sbyte)
  • u16: Unsigned 16-bit integer (ushort)
  • s16: Signed 16-bit integer (short)
  • s16_be: Signed 16-bit integer, big endian
  • s32: Signed 32-bit integer (int)
  • s32_be: Signed 32-bit integer, big endian
  • float: IEEE 754 32-bit floating point (float)
command write-only Sends a command to the sensor. See the individual sensor documentation for possible commands. Sensors that do not support commands will return -EOPNOTSUPP when writing to this attribute.
commands read-only Returns a space separated list of the valid commands for the sensor. Returns -EOPNOTSUPP if no commands are supported.
direct read/write Allows direct communication with the sensor for using advanced features that are not otherwise available through the lego-sensor class. Returns -EOPNOTSUPP if the sensor does not support this. Currently this only works with I2C sensors. For I2C sensors, use :c:func:`seek()` to set the register to read or write from, then read or write the number of bytes required.
decimals read-only Returns the number of decimal places for the values in the value<N> attributes of the current mode.
driver_name read-only Returns the name of the sensor device/driver. See the list of supported sensors for a complete list of drivers.
fw_version read-only Returns the firmware version of the sensor if available. Currently only NXT/I2C sensors support this.
mode read/write Returns the current mode. Writing one of the values returned by modes sets the sensor to that mode. See the individual sensor documentation for a description of the modes available for each type of sensor.
modes read-only Returns a space separated list of the valid modes for the sensor.
num_values read-only Returns the number of value<N> attributes that will return a valid value for the current mode.
poll_ms read/write Returns the polling period of the sensor in milliseconds. Writing sets the polling period. Setting to 0 disables polling. Returns -EOPNOTSUPP if changing polling is not supported. Note: Setting poll_ms too high can cause the input port autodetection to fail. If this happens, use the mode attribute of the port to force the port to nxt-i2c mode. Values must not be negative.
units read-only Returns the units of the measured value for the current mode. May return empty string if units are unknown.
value<N> read-only Returns the value or values measured by the sensor. Check num_values to see how many values there are. Values with N >= num_values will return an error. The values are fixed point numbers, so check decimals to see if you need to divide to get the actual value.
text_value read-only Returns a space delimited string representing sensor-specific text values. Returns -EOPNOTSUPP if a sensor does not support text values.

Events

In addition to the usual add and remove events, the kernel change event is emitted when mode or poll_ms is changed. The value<N> attributes change too rapidly to be handled this way and therefore do not trigger any uevents.

Sensor Modules

The sensor drivers are implemented in the following modules:

EV3/Analog

The ev3-analog-sensor module provides all of the drivers for EV3/Analog sensors.

You can a list of the the devices implemented by this module by reading the driver_names attribute in the /sys/bus/lego/drivers/ev3-analog-sensor/.

EV3/UART

The ev3-uart-sensor-ld module is a tty line discipline that runs on top of a tty. It listens for the information data that is sent from EV3/UART sensors. When it receives valid data, it negotiates with the sensor, telling the sensor to enter data sending mode.

This line discipline has been assigned the number 29. To attach this line discipline to a tty, run ldattach 29 /dev/tty<N> where <N> is the name of the tty you want to connect to.

Note

This driver works with any tty, which means the sensor does not necessarily have to be plugged into one of the input ports on the EV3.

EV3/UART sensors do not require individual driver implementations like other types of sensors. Instead, all of the needed info to sent from the sensor in a common format. As a result, the name returned by the driver_name attribute may not be a real driver name. For well-known sensors (the LEGO EV3 sensors and FatcatLab sensors) it will return a name like lego-ev3-color. For unknown sensors it returns ev3-uart-<N>, where <N> is the type id of the sensor.

The ev3-uart-sensor module provides all of the drivers for EV3/UART sensors. This module is only used on devices that can’t use the line discipline.

You can a list of the the devices implemented by this module by reading the driver_names attribute in the /sys/bus/lego/drivers/ev3-uart-sensor/.

NXT/Analog

The nxt-analog-sensor module provides all of the drivers for NXT/Analog sensors. These drivers scale the analog voltage read from the sensor to a useful value.

You can a list of the the devices implemented by this module by reading the driver_names attribute in the /sys/bus/lego/drivers/nxt-analog-sensor/.

NXT/I2C

The nxt-i2c-sensor module provides all of the drivers for NXT/I2C sensors.

Module Parameters
allow_autodetect Setting to N disables probing of sensors. Default is Y.
default_poll_ms This provides the default value for the poll_ms attribute. A value of 0 will disable polling by default. Changes only affect sensors plugged in after the change was made. Default is 100 msec. Values must not be negative.

Note

These parameters can be changed at runtime by writing to /sys/module/nxt_i2c_sensor/parameters/<parameter>.

You can a list of the the devices implemented by this module by reading the driver_names attribute in the /sys/bus/lego/drivers/nxt-i2c-sensor/.