Skip to main content

4-4 Control GPIO Hardware from C/ C++ Program

Access GPIO pins through the file system using the sysfs interface.

how-control-gpio

Example code :

int fd = open("/sys/class/gpio/export", O_WRONLY);
if (write(fd, "460", 2) != 2) {
perror("Error writing to /sys/class/gpio/export");
exit(1);
}
close(fd);

Find out where is the hardware pin for P42_4?

RZ SMARC Series Carrier Board User’s Manual: Hardware

Check Page 34, Figure 2.16 Block Diagram of PMOD1 I/F

GPIO_02

GPIO_03

We can test GPIO P42_4 at PMOD1 #9 Pin with a multimeter.

:::[Caution] Be careful not to burn your board!
:::

GPIO_04

Reference program

Check out the example code at Github Repo :

rzgpio

Please follow the instructions in the README.md to build the project, then copy the output executable to RZ/G2L for testing.