Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

Using Sensors

GongYi edited this page Jul 26, 2014 · 3 revisions

Overview

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

Msensor

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

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

List of python-ev3 supported Sensors

Manufacturer Mfg. P/N Name Connection Type Auto-
detected
Driver (Module)
CODATEX Codatex RFID Sensor
Dexter Industries
HiTechnic NAA1030 NXT Angle Sensor I2C/M Y ht‑naa1030 (nxt‑i2c‑sensor)
NAC1040 NXT Acceleration / Tilt Sensor I2C/M Y ht‑nac1040 (nxt‑i2c‑sensor)
NBR1036 NXT Barometric Sensor I2C/M Y ht‑nbr1036 (nxt‑i2c‑sensor)
NCO1038 NXT Color Sensor V2 I2C/M Y ht‑nco1038 (nxt‑i2c‑sensor)
NEO1048 NXT EOPD Analog/NXT Y* (nxt‑analog‑sensor)
NFS1074 NXT Force Sensor Analog/NXT Y* (nxt‑analog‑sensor)
NGY1044 NXT Gyro Sensor Analog/NXT Y* (nxt‑analog‑sensor)
NIL1046 NXT IRLink Sensor I2C/M Y ht‑nil1046 (nxt‑i2c‑sensor)
NIS1070 NXT PIR Sensor I2C/M Y ht‑nis1070 (nxt‑i2c‑sensor)
NIR1032 NXT IRReceiver Sensor I2C/M Y ht‑nir1032 (nxt‑i2c‑sensor)
NMC1034 NXT Compass Sensor I2C/M Y ht‑nmc1034 (nxt‑i2c‑sensor)
NMS1035 NXT Magnetic Sensor Analog/NXT Y* (nxt‑analog‑sensor)
NSK1042 NXT IRSeeker V2 I2C/M Y ht‑nsk1042 (nxt‑i2c‑sensor)
NSX2020 NXT Sensor Multiplexer I2C/M Y ht‑nsx2020 (nxt‑i2c‑sensor)
NTX1060 NXT Touch Sensor Multiplexer Analog/NXT Y*
SPR2010 NXT SuperPro Prototype Board I2C/M Y ht‑spr2010 (nxt‑i2c‑sensor)
??? NXT Color Sensor (v1) I2C/M Y ht‑nco (nxt‑i2c‑sensor)
LEGO / LEGO Education 9668 Energy Display I2C/M Y lego‑9668 (nxt‑i2c‑sensor)
9694 NXT Color Sensor Special Y nxt‑color‑sensor
9749 NXT Temperature Sensor I2C/S N tmp275 (lm75)
9843 NXT Touch Sensor Analog/NXT Y nxt‑analog‑sensor (touch‑sensor)
9844 NXT Light Sensor Analog/NXT Y nxt‑analog‑sensor (nxt‑light‑sensor)
9845 NXT Sound Sensor Analog/NXT Y* (nxt‑analog‑sensor)
9846 NXT Ultrasonic Sensor I2C/M Y lego‑9846 (nxt‑i2c‑sensor)
45504 EV3 Ultrasonic Sensor UART Y
45505 EV3 Gyro Sensor UART Y
45506 EV3 Color Sensor UART Y
45507 EV3 Touch Sensor Analog/EV3 Y ev3‑analog‑sensor (touch‑sensor)
45509 EV3 Infrared Sensor UART Y
LogIT NXT Sensor Adapter
mindsensors.com LightSensorArray Light Sensor Array I2C/M Y ms‑light‑array (nxt‑i2c‑sensor)
MagicWand Magic Wand Kit I2C/S N pcf8574 (gpio‑pcf857x)
PCF8574-Nx Sensor building kit for NXT with PCF8574 IC I2C/S N pcf8574 (gpio‑pcf857x)
PCF8591-Nx Sensor building kit for NXT with PCF8591 IC I2C/S N pcf8591 (pcf8591)
RTC-Nx-v3 Realtime Clock for NXT I2C/S N ds1307 (rtc‑ds1307)
Vernier NXT Sensor Adapter

Clone this wiki locally