Jump to content
JulianR

Direct GPIO access

Recommended Posts

Hi there,

I am trying to port software from RPI4 to the tinkerboard. We used to access the GPIOs not with WiringPI but manually using "nmap" with a file descriptor ("/dev/mem"). To find the peripheral offset address we were reading this file: "/proc/device-tree/soc/ranges". But I can not find this path or a similar one on the tinkerboard. Can someone help me to get on the right track?

Thanks in advance!

Julian R.

Share this post


Link to post
Share on other sites

Thank you for your response.

The paths there do not exist on my board (Tinkerboard2). For example physical pin 3 states: "/sys/class/gpio/gpio73".

If I do an ls on that path, none of them listed there:

$ sudo ls /sys/class/gpio/

export gpio16 gpio25 gpiochip0 gpiochip128 gpiochip32 gpiochip64 gpiochip96 unexport

 

Share this post


Link to post
Share on other sites

Hi @JulianR:

     This is the linux common functions. Need to echo the pin number to export and then show the gpio$number in the path.

Please reference the following website link and reference sample. Thank a lot!

--->  Website link for GPIO Programming: Using the sysfs Interface

https://www.ics.com/blog/gpio-programming-using-sysfs-interface

---> Examples

  1. GPIO input control example

 

0, 8 GPIO: /sys/class/gpio/gpio8   TEST_CLKOUT2 GPIO0_B0 7

* Console command:

- Export the GPIO pin

echo 8 > /sys/class/gpio/export

- Set the GPIO pin to input mode

echo in > /sys/class/gpio/gpio8/direction

- Read input value:

cat /sys/class/gpio/gpio8/value

 

  1. GPIO output control example

 

0, 8 GPIO: /sys/class/gpio/gpio8   TEST_CLKOUT2 GPIO0_B0 7

* Console command:

- Export the GPIO pin

echo 8 > /sys/class/gpio/export

- Set the GPIO pin to output mode

echo out > /sys/class/gpio/gpio8/direction

- Set value to GPIO pin:

echo 1 >  /sys/class/gpio/gpio8/value

- Read the GPIO value

cat /sys/class/gpio/gpio8/value

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...