How to code to control GPIO from python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 3: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!
- Labels:
-
OpenSTLinux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 4:49 PM
Does this Linux expose GPIOs in sysfs? /sys/class/... ?
Is this an interview question? :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-11 6: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/
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-14 2: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
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-14 5: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-14 6: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
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
