

This is the preferred method of GPIO access. It basically views each property of each GPIO pin as a file. Linux already has a built-in driver for safely accessing the GPIOs.

The second approach is the “Linux approach” (sysfs). Examples of this approach to GPIO coding can be found here. Bypassing the OS however means that if two processes (instances of a programs) are trying to access the same physical GPIO registers at the same time, a unsafe resource conflict can happen. The advantage of this approach is that because the OS (Linux) is being completely bypassed, the GPIO pins can toggle very fast. The first is to directly manipulate the Raspberry Pi’s GPIO’s registers much like one would do when programming a microcontroller without an operating system (OS) or a memory management unit (approach using mmap). There are two approaches to accomplish this. In this blog entry I will demonstrate how one can access the Raspberry Pi’s GPIO in C++.
