2021-06-10 03:02 PM
Hello, I have a question.
What are some ways to control GPIO from python?
I want to do that with a starter package.
Best Regards!
2021-06-10 04:49 PM
Does this Linux expose GPIOs in sysfs? /sys/class/... ?
Is this an interview question? :)
2021-06-11 06:26 AM
On the RPi I use this, I'd imagine ST has something similar for a GPIO library
https://pypi.org/project/RPi.GPIO/
2021-06-14 02:42 AM
Hi @KNaka.6 ,
OpenSTLinux is not supporting "/sys/class/gpio" but only the /dev/gpiochip* devices together with libgpiod.
See https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_userspace
Then for Python, interfacing with libgpiod command might be straightforward, or eventually using python3-gpiod.
Olivier
2021-06-14 05:49 AM
Thank you for your reply. I'm a Linux beginner and I'm sorry I couldn't explain it well. I'm using OpenStLinux-5.10-dunfell
I have tried the following but I get a permission error. I don't know how to resolve. Or is this the wrong way?
root@stm32mp1:/dev# sudo apt install python3-libgpiod
>>> import gpiod
>>> chip=gpiod.chip('gpiochip0')
>>> prt=chip.get_lines([14])
>>> prt.set_values([1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/root/.local/lib/python3.8/site-packages/gpiod/libgpiodcxx/__init__.py", line 1083, in set_values
self._m_bulk[i].set_value(values[i])
File "/home/root/.local/lib/python3.8/site-packages/gpiod/libgpiodcxx/__init__.py", line 629, in set_value
raise OSError(
PermissionError: [Errno 1] Operation not permitted: 'error setting GPIO line value'
Best Regards!
K-Naka
2021-06-14 06:54 AM
Hi @KNaka.6 ,
Please confirm first that playing with libgpiod works as explained in wiki :
Board $>gpioset gpiochip0 14=0 -->to set GPIO PA14 low // green led on
Board $>gpioset gpiochip0 14=1 -->to set GPIO PA14 high // green led off
Then @PatrickF just tell me he successfully tested this on DK2 out of the box ( and connected to network) :
python3 -m pip install -U --user pip gpiod
python3 -m gpiod.test.button gpiochip0 14 both
-> button user1 is ok
python3 -m gpiod.test.blink gpiochip0 14
-> led blink ok
Hope it help,
Olivier