I want to synchronize a stereo camera for either stills or video. The goal is the smallest possible delay between GPIO trigger input and camera shutter actuation (so that stereo is possibly in sync) so I guess a good way to go would be to get as close to metal as possible - doing it all in C by modifying raspistill and raspivid applications.

I was already able to compile whole userland (= both raspistill and raspivid together) by following this post - I can alter the code and it compiles correctly again. However, I need to get the GPIO input into the C code - I guess WiringPi might be one of the easier working options. I see there are CMakeLists.txt files at various level of userland (root or raspicam folders). I do not know how these cmake files work, but I guess I need to add WiringPi into one of them so that the library is then included when compiler needs it. Could anyone help me how to do this?

I think I can write the C code but I just need to be able to compile both WiringPi and raspistill/raspivid together into a single binary.

Thanks for help in advance!

2 Answers 2


If all you want to do is monitor a gpio there are several light weight methods from C.

Have a look at http://abyz.me.uk/rpi/pigpio/examples.html#Misc_code for "Minimal gpio access". Just delete any code you don't want.

Plenty of other examples at http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples


The simplest and most effective way to monitor or manipulate a GPIO pin in C is to use the existing kernel sysfs interface,1 which is actually language agnostic since it makes use of file nodes in /sys. Some programmers naively believe this is a clunky choice because it is file node based, but note that these are not files on disk, they are communication lines with the kernel, and read() and write(), etc. are system calls. This means it is equivalent to the direct memory addressing via mmap() method used by wiringPi and recommended in the links from joan's answer, except it is much less esoteric and obviously more portable (if that matters).

The kernel docs explain this pretty well; note the point about using poll() in the discussion of the value and edge nodes.

1. Ignore the "Exporting from Kernel code" section there. That's not what you are doing, you're writing userland code and there are no special C functions involved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.