This has been replaced by: User Space IO get more details on this thread.
Well, it's time to say goodbye to sysfs and hello to libgpiod! @zador.blood.stained pointed me in the right direction, but you need to do one little hack I'll explain below involving compiler_types.h. I tested this on a NanoPi Duo, but it should work on any mainline Armbian release (and other distros as well) as long as the kernel is >= 4.8. Try ls /dev/gpiochip* and see if anything is listed. If so, then proceed.
I'm continuing work on my Github site https://github.com/sgjava/libgpiod-extra, so please report any issues there. There is an Armbian install script that automates the steps below I generated the Python wrapper, but there's a lot of functions to test, so I'm not sure of the quality. I'm working on some simple Python tests.
Wire up LED (the normal way) and use Duo's IOG11 then to turn on and off:
sudo gpioset gpiochip0 203=0
sudo gpioset gpiochip0 203=1
Python code
import time
from libgpiod.libgpiod import*
chip = gpiod_chip_open("/dev/gpiochip0")
line = gpiod_chip_get_line(chip,203)# The will set line for output and set initial value (LED on)if gpiod_line_request_output(line,"test",0)==0:
time.sleep(3)# LED off
gpiod_line_set_value(line,1)
gpiod_line_release(line)
gpiod_chip_close(chip)
Question
sgjava
This has been replaced by: User Space IO get more details on this thread.
Well, it's time to say goodbye to sysfs and hello to libgpiod! @zador.blood.stained pointed me in the right direction, but you need to do one little hack I'll explain below involving compiler_types.h. I tested this on a NanoPi Duo, but it should work on any mainline Armbian release (and other distros as well) as long as the kernel is >= 4.8. Try ls /dev/gpiochip* and see if anything is listed. If so, then proceed.
I'm continuing work on my Github site https://github.com/sgjava/libgpiod-extra, so please report any issues there. There is an Armbian install script that automates the steps below
I generated the Python wrapper, but there's a lot of functions to test, so I'm not sure of the quality. I'm working on some simple Python tests.
Let's try some commands:
sudo gpiodetect
gpiochip0 [1c20800.pinctrl] (224 lines)
gpiochip1 [1f02c00.pinctrl] (32 lines)
sudo gpioinfo | grep "\[used\]"
line 10: unnamed "nanopi:blue:status" output active-high [used]
line 166: unnamed "cd" input active-high [used]
line 202: unnamed "interrupt" input active-high [used]
line 205: unnamed "reset" output active-low [used]
line 6: unnamed "?" output active-high [used]
line 7: unnamed "vcc-wifi" output active-high [used]
line 10: unnamed "nanopi:green:pwr" output active-high [used]
Notice how it found the Duo's built in LEDs
Now let's test the Duo's built in button (press and release 3 times):
sudo gpiomon --num-events=3 --rising-edge gpiochip1 3
event: RISING EDGE offset: 3 timestamp: [1516774143.944174870]
event: RISING EDGE offset: 3 timestamp: [1516774145.123474395]
event: RISING EDGE offset: 3 timestamp: [1516774145.987531088]
Wire up LED (the normal way) and use Duo's IOG11 then to turn on and off:
sudo gpioset gpiochip0 203=0
sudo gpioset gpiochip0 203=1
Python code
More reading at https://www.cnx-software.com/2017/11/03/learn-more-about-linuxs-new-gpio-user-space-subsystem-libgpiod and https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README. Maybe @Larry Bank will work on ArmbianIO II
It looks like in the old Github site there was a milestone to create Python and C++ wrappers https://github.com/brgl/libgpiod/milestone/3. Once I learn more about libgpiod I may just generate them like I did for ArmbianIO.
Edited by Tidoadded note for: User Space IO
Link to comment
Share on other sites
13 answers to this question
Recommended Posts