ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
431 stars 145 forks source link

Unable to find TouchSensor on PiStorms #643

Closed RobinMarchart closed 4 years ago

RobinMarchart commented 5 years ago

On PiStorms-v2 using ev3dev I Tried using TouchSensor and got this Error:

import ev3dev.pistorms as ev3
ev3.TouchSensor(ev3.INPUT_2).address
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 1664, in address
    self._address, value = self.get_attr_string(self._address, 'address')
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 226, in get_attr_string
    return self._get_attribute(attribute, name)
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 202, in _get_attribute
    raise Exception("%s is not connected" % self)
Exception: Sensor(pistorms:BAS2) is not connected

I looked inside the sys filesystem and figured out that (touch) sensors are only shown if the mode is set to ev3-analog in /sys/class/lego-port/port<n>/mode. after setting this value the sensor was shown in /sys/class/lego-sensor and the previous code worked.

This should propably be indicated in the docs or automatically be set. when setting not connected /sys/class/lego-port/port<n>/mode to ev3-analog it seems to be shown as not pressed sensor

dlech commented 5 years ago

Can you share your code?

Sensors are not automatically detected on PiStorms like they are on EV3, so you have to configure the mode of the port first.

dlech commented 5 years ago

@KWSmit might have some example code for PiStorms.

KWSmit commented 5 years ago

I think my tic-tac-toe is a good exemple, see repo https://github.com/KWSmit/KSmEV3TicTacToe--PiStorms-version-

dwalton76 commented 4 years ago

Please re-open with the requested info