IlliniHyperloopComputing/Pod

[GPIO] Develop C++ method of turning GPIOs on and off

rgw3d opened this issue · 0 comments

rgw3d commented

The method of interacting with a GPIO is described in the README in the branch pod4-bbb-dev.

There needs to be a way of interacting with GPIOs without using the command line utilities echo or cat. Although these technically work, we ought to do it via some C/C++ style code.

For example, to setup GPIO P8_22 (the position on the pin out header), GPIO No. 37 (an internal number), which is GPIO1_5 (another internal name/number) (yes all of the names are confusing) we do the following:
echo 37 > /sys/class/gpio/export which "exports" or enables the GPIO for easy access
echo "out" > /sys/class/gpio/gpio37/direction
Then echo either 0 or 1 as follows to change the output
echo 1 > /sys/class/gpio/gpio37/value

More info about the /sys file system: https://en.wikipedia.org/wiki/Sysfs

There should be a way to do this easily in C++ or C, other than using system(). What we are doing is actually just overwriting (not appending). Some sort of open() and write() combination should work, something like this: https://stackoverflow.com/questions/9165344/how-to-overwrite-a-file-in-c

Note: There might be a way of writing to a /sys/ file by using some functions found in the adc_testing/generic_buffer.c directory inside BBBSetup/ folder. Look specifically for functions like write_sysfs_int