lego-sensor class provides a uniform interface for using most of the
sensors available for the EV3. The various underlying device drivers will
lego-sensor device for interacting with the sensors.
Sensors are primarily controlled by setting the
mode and monitored by
value<N> attributes. Values can be converted to floating point
if needed by
value<N> / 10.0 ^
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.
Sensors can be found at
incremented each time a sensor is loaded (it is not related to which port
the sensor is plugged in to).
in1. I2C sensors also include the I2C address (decimal), e.g.
num_valuesand the individual sensor documentation to determine how to interpret the data.
bin_datafor 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)
-EOPNOTSUPPwhen writing to this attribute.
-EOPNOTSUPPif no commands are supported.
-EOPNOTSUPPif the sensor does not support this. Currently this only works with I2C sensors. For I2C sensors, use
seekto set the register to read or write from, then read or write the number of bytes required.
value<N>attributes of the current mode.
modessets the sensor to that mode. See the individual sensor documentation for a description of the modes available for each type of sensor.
value<N>attributes that will return a valid value for the current mode.
-EOPNOTSUPPif changing polling is not supported. Note: Setting
poll_mstoo high can cause the input port autodetection to fail. If this happens, use the
modeattribute of the port to force the port to nxt-i2c mode.
num_valuesto see how many values there are. Values with N >= num_values will return an error. The values are fixed point numbers, so check
decimalsto see if you need to divide to get the actual value.
-EOPNOTSUPPif a sensor does not support text values.
In addition to the usual “add” and “remove” events, the kernel “change”
event is emitted when
poll_ms is changed. The
attributes change too rapidly to be handled this way and therefore do not
trigger any uevents.