Skip to content

How can I use a generic I2C sensor? #782

@IanLewis42

Description

@IanLewis42
  • ev3dev version: 1.0.19(0.48/3/2)
  • ev3dev-lang-python version:
    ||/ Name Version Architecture Description
    +++-==============-============-============-=================================
    ii micropython-ev 2.1.0 all Python language bindings for ev3d
    ii python3-ev3dev 1.2.0 all Python language bindings for ev3d
    ii python3-ev3dev 2.1.0 all Python language bindings for ev3d

I'm trying to use a generic I2C sensor with my EV3, specifically, a Nintendo Wii Motion Plus (https://en.wikipedia.org/wiki/Wii_MotionPlus) I used this sensor with my NXT a couple of years ago, so I think my hardware interface should be OK.

What is the best way to do 'raw' i2c writes and reads?

I tried using the Sensor class, but it can't seem to find my sensor.

Code:

#!/usr/bin/env python3
from ev3dev2.sensor import Sensor

def main():

    wmp = Sensor('ev3-ports:in4:i2c83') #I2C address is 0xA6, unshifted is 0x53 = decimal 83
    wmp.command(0xFE, 0x04)

if __name__ == '__main__':
    main()

Output:

Starting: brickrun --directory="/home/robot/vscode-hello-python-master" "/home/robot/vscode-hello-python-master/wmp.py"
----------
Traceback (most recent call last):
  File "/home/robot/vscode-hello-python-master/wmp.py", line 10, in <module>
    main()
  File "/home/robot/vscode-hello-python-master/wmp.py", line 6, in main
    wmp = Sensor('ev3-ports:in4:i2c83') #I2C address is 0xA6, unshifted is 0x53 = decimal 83
  File "/usr/lib/python3/dist-packages/ev3dev2/sensor/__init__.py", line 78, in __init__
    super(Sensor, self).__init__(self.SYSTEM_CLASS_NAME, name_pattern, name_exact, **kwargs)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 223, in __init__
    chain_exception(DeviceNotFound("%s is not connected." % self), None)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 54, in chain_exception
    raise exception from cause
ev3dev2.DeviceNotFound: Sensor(ev3-ports:in4:i2c83) is not connected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions