-
Notifications
You must be signed in to change notification settings - Fork 73
Using Sensors
We try to make python-ev3 to support as many sensors as possible. If you have a sensor that does not work, let us know about it.
Python-ev3 align with ev3dev sensor capability. According ev3dev, python-ev3 implements sensor in two classes: Msensor and I2CS
These are the sensors which can be recognized by ev3dev and has node at /sys/class/msensor/
. To communicate with these sensors, python-ev3 use the regular python file api to read/write values.
ev3.Msensor
maps its property to each file at /sys/class/msensor/
. For example
from ev3.ev3dev import Msensor
d = Msensor(port=1)
print (d.type_id) #read type_id file
print (d.value1) #read value1 file
Also python-ev3 converts the raw value0 to value7 to int date type.
python-ev3 also provides a lot of concrete sensor classes. Theses classes have meaningful property instead of the generic value0 to value7.
When use a concrete sensor class, you can ignore the port number if there's only one sensor of each type attached to the brick. Python-ev3 uses the type_id to detect the right msensor
node path.
d = ColorSensor() #ignore the port number
I2CS sensors are sensors that communicate with the intelligent brick via the I2C protocol and can NOT auto-detected by ev3dev.
Ev3dev creates /dev/i2c-in* nodes when I2CS sensor attached to the brick. To communicate with these sensors, the smbus python need to be installed.
For python 2.7, you may install from the debian source
apt-get install python-smbus
For python 3.4, you need to download from python-ev3 release page and install by dpkg -i <the_python3.4_smbus.deb>
Since the I2CS devices has not generic property, you have to create your own class for a specially sensor. See How to create a new sensor class
</tr>
<tr>
<td rowspan="5">
<a href="http://lego.com">LEGO</a> / <a href="http://education.lego.com">LEGO Education</a>
</td>
<td>
45504
</td>
<td>
[[EV3 Ultrasonic Sensor|LEGO EV3 Ultrasonic Sensor (45504)]]
</td>
<td>
Msensor
</td>
</tr>
<tr>
<td>
45505
</td>
<td>
[[EV3 Gyro Sensor|LEGO EV3 Gyro Sensor (45505)]]
</td>
<td>
Msensor
</td>
</tr>
<tr>
<td>
45506
</td>
<td>
[[EV3 Color Sensor|LEGO EV3 Color Sensor (45506)]]
</td>
<td>
Msensor
</td>
</tr>
<tr>
<td>
45507
</td>
<td>
[[EV3 Touch Sensor|LEGO EV3 Touch Sensor (45507)]]
</td>
<td>
Msensor
</td>
</tr>
<tr>
<td>
45509
</td>
<td>
[[EV3 Infrared Sensor|LEGO EV3 Infrared Sensor (45509)]]
</td>
<td>
Msensor
</td>
</tr>
<tr>
<td rowspan="2">
<a href="http://www.mindsensors.com">mindsensors.com</a>
</td>
<td>
AbsoluteIMU
</td>
<td>
[[AbsoluteIMU|mindsensors.com AbsoluteIMU]]
</td>
<td>
I2CS
</td>
</tr>
<tr>
<td>
PSP-Nx-v4-REF
</td>
<td>
[[PSP-Nx-v4-REF]]
</td>
<td>
I2CS
</td>
</tr>
Manufacturer | Mfg. P/N | Name | Sensor Type |
---|