using GPIO pins with C++ on the nano

hello =)

I need to access the gpio pins from inside a c++ program to be able write a pin high or low.

perhaps there’s a c++ library to access/control the pins?

perhaps i could wrap the Jetson.GPIO python library?

perhaps i could use shell scripts to write pins high and low with Jetson.GPIO?

surely someone will develope somthing to do this at some stage?

additional info;

I want to make a machine which triggers a relay if the camera senses that two or more people are in shot. I’ve followed along with the steps in the following tutorial; https://www.pyimagesearch.com/2019/05/06/getting-started-with-the-nvidia-jetson-nano/

It’s worked really well, and now I simply need to send a pin high/low from inside the c++ program.

thanks for reading =)

Hi jwalley, you can use the GPIO sysfs files from C/C++, please see this post for more information and a code example:

https://devtalk.nvidia.com/default/topic/1052379/jetson-nano/how-to-use-gpio-in-c-language/post/5342398/#5342398

thanks dusty_nv. i will explore these options, and report back =)

I’m just starting to look into this myself. Unfortunately I’m not far enough along the path to offer much help but one thing I’d note is that using SYSFS to access GPIOs is apparently being depreciated at some point in the future.

The replacement is GPIOCHIP which is a character based file system interface (I’m parroting words here, could have that totally wrong :-) ).

libgpiod https://github.com/brgl/libgpiod seems to work on the Nano under c++ with the basic tests I’ve run so far.

[edit] Realised that I wasn’t very clear above. Libgpiod gives you command line tools to use to test GPIOCHIP functionality but if you look at the source code for the tools it gives you an understanding of how to use the new interface.

I wrote a library for working with GPIO pins and I2C sensors for the Raspberry Pi 3.
The library is here https://github.com/blademoon/sensum-library . If you want, I can modify it for Jetson Nano. But I will need help, I need to test it on Jetson Nano.
I do not have my own board. If you want to contact me, write blademoon@yandex.ru. In the subject line of the letter, indicate on what issue.

1 Like

If you want, I can make a description of the library (github) in English.

1 Like

Hi I made a simple C++ GPIO Library for NVIDIA Jetson Series.
It’s basically a C++ port of Jetson.GPIO Python libarary and has almost same API as Jetson.GPIO.

https://github.com/pjueon/JetsonGPIO

If you’re interested in, please check it out. Thanks.

3 Likes

This is good. Does your library also do Direct Register Access (DRA) for very fast, low latency GPIO access? Or is it based solely on the filesys approach?

The only working DRA library that I have tested is in the link below by @valentis, but it only works on seven of the many J41 header pins. It’s a good start though.

https://github.com/valentis/jetson-nano-gpio-example

Hi xplanescientist.

Unfortunately, my libarary is based solely on the filesys approach. I just translated the Jetson.GPIO python library to C++.