You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
GPIO Via Golang
Ok, we are going to try the golang periph library with this.
Permissions
The user running this binary must have gpio permissions on the Raspberry Pi.
Check if you can read the device without being root
head -c 1 /dev/gpiomem > /dev/null && echo "Success" || echo "Access Denied"
If you get access denied then we can create a gpio user group with udev runs that grant permissions to the /dev/gpiomem device.
sudo groupadd gpio
sudo usermod -aG gpio $USER
Create a udev rules file
sudo vim /etc/udev/rules.d/99-gpio.rules
Include the following:
# Access to the memory-mapped GPIO
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
# Access to the gpiochip character devices (periph.io uses these)
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", GROUP="gpio", MODE="0660"
sudo udevadm control --reload-rules && sudo udevadm trigger
Periph Library
The Periph library is broken up into a number of sub libraries that are imported as needed. This allows the developers to decouple board implementations from drivers and devices.
go get periph.io/x/host/v3
go get periph.io/x/conn/v3