Jump to content

Accessing GPIO pins


RickR

Recommended Posts

Hello,

 

I have installed ARMBIAN 5.60 stable Debian GNU/Linux 9 (stretch) 4.14.70-sunxi on a Banana Pi M2+ and I need to read and write to the GPIO pins from a bash script, does anyone have a workable solution?

 

I tried with an Orange Pi in the past and I compiled a binary to access the gpio values but it did not work and I cannot find that source any more.

 

Thanks in advance. 

 

Link to comment
Share on other sites

On 11/2/2018 at 11:43 PM, martinayotte said:

The simplest way is to use gpio sysfs ...


echo 20 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio20/direction
echo 1 > /sys/class/gpio/gpio20/value

Thank you Martinayotte, I have had limited success with this approach and it requires superuser privileges which makes it a bit risky for me to call from the web server, but then I may be able to work out a secure way to access that interface.  The "gpio" command from the WiringOP github repo seems to be very promising as well.

Thank you Martinayotte, that is very helpful.  The difficulty I found is that it required superuser permissions and I managed to get the gpio utility compiled and finally working late last night and it does not require superuser permissions 

Link to comment
Share on other sites

On 11/2/2018 at 8:43 AM, martinayotte said:

The simplest way is to use gpio sysfs ...


echo 20 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio20/direction
echo 1 > /sys/class/gpio/gpio20/value

 

Hi,I am a developing a c++ application with OPI 0+2 (h5 + mainline kernel), controls a motor with an encoder and a driver. I did it , but it consume to much cpu power (%8) . I could access with using sysfs and character device. Both of them works like open->read->close .Actually it works very well with polling. Unfortunately consume to much cpu. Interrupt freq around 6600hz (150 us) . Is there anyway to control interrupt with dev mem? Or could anyone give me a startup point to access (c++) gpio interrupts efficiently. Btw i tyied libgpiod based on character device. Thank you.

Link to comment
Share on other sites

1 hour ago, Levent Erenler said:

Or could anyone give me a startup point to access (c++) gpio interrupts efficiently.

 ArmbianIO API - in C
https://forum.armbian.com/topic/5655-armbianio-api-proposal/

 

 User Space IO - is Python 3 and Java 8 bindings for user space GPIO, SPI, I2C, PWM and Serial interfaces
https://forum.armbian.com/topic/6523-user-space-io-is-python-3-and-java-8-bindings-for-user-space-gpio-spi-i2c-pwm-and-serial-interfaces/ and his improvement: https://github.com/sgjava/java-periphery

 


 pyGPIO - A 'more general' python GPIO library based on pyA20
https://forum.armbian.com/topic/5662-pygpio-a-more-general-python-gpio-library

 

Link to comment
Share on other sites

1 hour ago, Tido said:

 ArmbianIO API - in C
https://forum.armbian.com/topic/5655-armbianio-api-proposal/


 pyGPIO - A 'more general' python GPIO library based on pyA20
https://forum.armbian.com/topic/5662-pygpio-a-more-general-python-gpio-library

 

Thanks for your answer, i checked ArmbianIO, it is based on sysfs.

pyGPIO is based on dev/mem, this is what i am looking unfortunatelly it does not support interrupts. I could not find a way to get gpio int from memory.

thank you.

Link to comment
Share on other sites

Hello Gabor,

 

Sorry, I do not have a valid Banana Pi platform to test this again as this project was done many years ago.  If I do get a chance to test the compilation once again I shall send you the details.

 

Best of luck,

 

Rick

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines