Working LED example

main
Drew Bednar 5 days ago
parent 2ec5b1d97e
commit a7a9598bc8

@ -0,0 +1,5 @@
# LED GPIO
- The long end of an LED is the Anode (+) and will need a 220ohm-ish resistor in line with the GPIO pin since it will power it via toggling a 3.3v voltage.
- Hook up the Cathode (-), the shorter end, to ground.
- GPIO17 is the 11th pin on the raspberry pi header.

@ -11,7 +11,7 @@ import (
func main() { func main() {
host.Init() host.Init()
pin := gpioreg.ByName("GPIO11") pin := gpioreg.ByName("GPIO17")
pin.Out(gpio.Low) pin.Out(gpio.Low)
for { for {

@ -2,6 +2,44 @@
Ok, we are going to try the golang periph library with this. 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
```bash
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.
```bash
sudo groupadd gpio
sudo usermod -aG gpio $USER
```
Create a udev rules file
```bash
sudo vim /etc/udev/rules.d/99-gpio.rules
```
Include the following:
```txt
# 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"
```
```bash
sudo udevadm control --reload-rules && sudo udevadm trigger
```
## Periph Library ## 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. 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.

@ -0,0 +1,7 @@
# 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"
Loading…
Cancel
Save