Access GPIO Pins using "C" Programming

Hi I want to access the GPIO Pins using C language in Jetson Nano,
I tried using “WiringPi” and i ended with the following error

Oops: Unable to determine board revision from /proc/cpuinfo
 -> No "Hardware" line
 -> You'd best google the error to find out why.

I have tried with Googling i didn’t find any solution and also we tried usinf “sysfs” GPIO access also.In this i couldn’t map the pins.

https://elinux.org/RPi_GPIO_Code_Samples

1 Like

hello nerellasureshkumar7,

you might refer to below kernel header for the GPIO control functions.

$TOP/kernel_src/kernel/kernel-4.9/arch/blackfin/include/asm/gpio.h

static inline void gpio_set_value(unsigned int gpio, int value){...}

please also refer to Tegra Linux Driver Package TX2 Adaptation Guide and check the [GPIO Changes] chapter in page.7 for the GPIO number mapping formula.
thanks

1 Like

Hello JerryChang, Thanks.
I’m using Jetson Nano and i’m a newbie to Jeston Products.I couldn’t find the particular path in Jetson Nano file system.

  1. Do i have to download to entire kernel source code for getting these GPIO wrappers.
  2. The link with your answer referring to TX2, does it work for the Nano also?
    If you can share some examples, it would be very helpful.

Hello JerryChang, Thanks.
I’m using Jetson Nano and i’m a newbie to Jeston Products.I couldn’t find the particular path in Jetson Nano file system.

  1. Do i have to download to entire kernel source code for getting these GPIO wrappers.
  2. The link with your answer referring to TX2, does it work for the Nano also?
    If you can share some examples, it would be very helpful.

hello nerellasureshkumar7,

  1. please access Jetson Download Center, you’re able to download the L4T r32.1 Jetson-Nano sources via l4t-sources-32-1-jetson-nano
  2. it’s same mapping formulas to calculate the GPIO numbers.
  3. suggest you also refer to Release 32.1 Development Guide for public release documentation.
    thanks

Hi Sir,
I’ve booted Jetson nano with this image file “jetson-nano-sd-r32.1-2019-03-18.zip” using microSD card.

  1. Do i have to build and port image from the source files that you suggested or any other easy way?

hello nerellasureshkumar7,

you can use default Jetson-Nano image and customization the L4T r32.1 Jetson-Nano sources,
thanks

Hi,

I have used this application for TX2 to control the GPIO

https://developer.ridgerun.com/wiki/index.php/Gpio-int-test.c

Compile the application

gcc Gpio-int-test.c -o gpio-ctrl

Run application using as parameter the gpio number, This is an example using the gpio number 391

./gpio-ctrl 391

When the gpio value is changed, the application displays this message:

poll() GPIO 391 interrupt occurred

The application also implements functions to set the GPIO.

@nerellasureshkumar7 and @jerrychang, did you get the WiringPi library to function properly on the Jetson Nano? The Direct Memory Access approach would be a very fast and robust method of controlling the GPIO over the slow filesys way. WiringPi should be available to the community.

1 Like

I just modified this code for NVIDIA Jetson Nano.

I’m adding some new features that switch input & LED control simultaneously.

1 Like

@valentis, thanks very much for this. Please see this thread:

[url]Jetson Nano Fast GPIO C++ Example with Direct Register Access - Jetson Nano - NVIDIA Developer Forums

The LED control uses GPIO_12 of the expansion header but I don’t see that defined in the gpionano.h. Correct me if I’m mistaken, thanks.

I got the same problem ,did you slove it now?

Good morning, how can I work the GPIO of the jetson nano working with cuda? I have tried to do it but I have not succeeded if someone has an example or can you explain to me how I would thank you in advance, thank you very much

Hi mario.reyes01,

Please help to open a new topic if it’s still an issue.

Thanks