Skip to content

Hello, I'm newbie with EV3DEV and I'm trying to make my absolute sensor working on my ev3. #774

Description

@dlech

Hello, I'm newbie with EV3DEV and I'm trying to make my absolute sensor working on my ev3.
The sensor is recognized by the brick but i have a problem with loading the "sensor.lego" module.
Here is the error message in vscode :

Traceback (most recent call last):
File "/home/robot/vscode-hello-python-master/test mindstorm.py", line 5, in
from sensor.lego import Sensor
ImportError: No module named 'sensor'

Kernel 4.14.117-ev3dev-2.3.5-ev3

Can you help me please ?

Originally posted by @gaminoi in #650 (comment)

Activity

  1. dlech commented on Aug 30, 2021

    @dlech
    MemberAuthor

    Can you share the full program?

  2. gaminoi commented on Aug 31, 2021

    @gaminoi

    Yes :

    #!/usr/bin/env python3
    
    import time
    from sensor.lego import Sensor
    from ev3dev2.port import LegoPort
    
    def main():
    
        absport = LegoPort(address='ev3-ports:in2')
        absport.mode = 'nxt-i2c'
        abs = Sensor('ev3-ports:in2:i2c17')
        abs.mode = "TILT"
        print(abs.value(0))
        
        time.sleep(5)
    
    if __name__ == '__main__':
        main()
  3. dlech commented on Aug 31, 2021

    @dlech
    MemberAuthor

    The docs say that the Sensor class is in the ev3dev2.sensor module, not sensor.lego.

  4. gaminoi commented on Aug 31, 2021

    @gaminoi

    Your the best dlech ! It works fine if I remove the LegoPort configuration.
    Here is the final code :

    #!/usr/bin/env python3
    import time
    import os
    from ev3dev2.sensor import Sensor
    
    def main():
    
        print('\x1Bc', end='') #RAZ écran
        os.system('setfont ' + 'Lat15-Terminus24x12') #Police
    
        abs = Sensor('ev3-ports:in2:i2c17')
        abs.mode = "TILT"
        for i in range(20):
            print(abs.value(0))
            time.sleep(0.1)
    
    if __name__ == '__main__':
        main()`

    Thank you !!

  5. WesleyJ-128 commented on Sep 8, 2021

    @WesleyJ-128

    It sounds like you have solved the problem. Please close this issue if that is the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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