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

How to create a new sensor class

GongYi edited this page Jul 20, 2014 · 5 revisions

Create a new sensor class

Introduction

Python-ev3 is built on ev3dev system. So please first read the Using Sensors
There are two types of sensor in the ev3dev

  • MSENSOR
  • I2CS

MSENSOR

Msensor can be recognized by ev3dev automatically. Ev3dev creates a new node at /sys/class/msensor when msensor attached to ev3. To create a new msensor class, inherit from ev3dev.Msensor and give a type_id.
For example the ColorSensor

class ColorSensor(Msensor):

    def __init__(self):
        Msensor.__init__(self, type_id=29)

You may also give some shortcut of the meaningful sensor property. For example

    @property
    def rgb(self):
        self.mode = 'RGB-RAW'
        return self.value0, self.value1, self.value2

I2CS

A lot of 3rd party i2c sensors can't be recognized by ev3dev automatically. They are I2CS sensor. Ev3dev creates node at /dev/i2c-in*. Please reference Using I2C Sensors To create a new I2CS class, inherit from ev3dev.I2CS

Clone this wiki locally