Open JavitoLope opened 4 years ago
I'm not sure that P5 would have enough current to actually power active RCX sensors. But it should be possible to enable battery voltage on P1 similar to NXT. (For anyone else reading this, we use P3 on EV3 instead of P2 like NXT because on NXT P2 and P3 are both ground, but on EV3, P2 is not ground).
So the wiring would just look like this:
P1_______(+)
P3_______(-)
For a passive device, like a touch sensor. We can just force the port into nxt-analog
mode and measure the voltage on P1. echo nxt-analog > /sys/class/lego-port/portX/mode
. A generic NXT analog sensor will appear in /sys/class/lego-sensor/
that can be used to read 0-5V.
For an active device, we need to put the port into raw
mode. echo raw > /sys/class/lego-port/portX/mode
. Then there will be gpios available in /sys/class/gpio/gpioX/*
. Then we need to look at the CPU pinout to figure out which gpio is which. For example "Input Port 3 Pin 1 Out" is "GPIO8-9" which translates to 16*8+9 = gpio137.
The pseudo code looks fine to me other than replacing P5 with P1 (although it has been a while, I don't remember the timing off hand of how long the power is supposed to be turned on). There are direction
and value
attributes in the gpio sysfs that I mentioned above that will cover most of the functions.
Unfortunately, it looks like we forgot to allow changing the direction of the gpio on P1 so the direction
attribute is missing from that gpio in the current ev3dev kernels, but we can fix that.
Then to read the analog voltage, we us /sys/bus/iio/devices/iio:device0/
. See the wiki for more info.
Unfortunately, it looks like we forgot to allow changing the direction of the gpio on P1 so the
direction
attribute is missing from that gpio in the current ev3dev kernels, but we can fix that.
Actually, I take this back. The GPIO on pin 1 just turns the battery voltage on or off, so it is always output and never input, so just set it high or low using the value
attribute.
I'm using ev3dev-stretch-ev3-generic-2019-10-23 image
robot@ev3dev:~$ sudo bash -c 'echo 137 >/sys/class/gpio/export' bash: line 0: echo: write error: Device or resource busy
I'm waitting some connectors. I'll post the results. Thank you very much David.
Should I unload some driver? Thanks.
The gpio gets automatically exported when the input port is placed in raw
mode, so sudo bash -c 'echo 137 >/sys/class/gpio/export'
is not necessary.
Once the port is in raw
mode, ls /sys/class/gpio
should show several gpioX
nodes where X
is a number.
It works perfect, sorry I forgot the raw change before looking at gpio. Thank you so much.
I connected a light rcx sensor. I think I can not get timing right using shell script. Is there any library to access ev3 gpio from python in an efficient way?
Maybe pwm? I don't know what to do. It should be great to have a "rcx" mode in /sys/class/lego-port/portX/modes
I read this: "If someone wants design a new converter cable, we could make them work." in http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensors.html
I made this converter cable:
I'd like to unload ev3dev sensors driver with modprobe and compile this pseudocode program:
Any help with program?
Thanks for this great software.