diff --git a/docs/img/2020-06-15-gpio.jpg b/docs/img/2020-06-15-gpio.jpg new file mode 100644 index 0000000..533c712 Binary files /dev/null and b/docs/img/2020-06-15-gpio.jpg differ diff --git a/docs/img/2020-06-15-gpio.thumb.2x.jpg b/docs/img/2020-06-15-gpio.thumb.2x.jpg new file mode 100644 index 0000000..85d0fcd Binary files /dev/null and b/docs/img/2020-06-15-gpio.thumb.2x.jpg differ diff --git a/docs/img/2020-06-15-gpio.thumb.3x.jpg b/docs/img/2020-06-15-gpio.thumb.3x.jpg new file mode 100644 index 0000000..44ed10c Binary files /dev/null and b/docs/img/2020-06-15-gpio.thumb.3x.jpg differ diff --git a/docs/img/2020-06-15-gpio.thumb.jpg b/docs/img/2020-06-15-gpio.thumb.jpg new file mode 100644 index 0000000..b58f195 Binary files /dev/null and b/docs/img/2020-06-15-gpio.thumb.jpg differ diff --git a/docs/img/raspberry-pi-pinout.png b/docs/img/raspberry-pi-pinout.png new file mode 100644 index 0000000..bb4f899 Binary files /dev/null and b/docs/img/raspberry-pi-pinout.png differ diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 159fdc8..d8b462a 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,6 +2,10 @@ + + https://gokrazy.org/userguide/gpio/ + + https://gokrazy.org/userguide/remotesyslog/ diff --git a/docs/userguide/gpio/index.html b/docs/userguide/gpio/index.html new file mode 100644 index 0000000..e8fed23 --- /dev/null +++ b/docs/userguide/gpio/index.html @@ -0,0 +1,122 @@ + + + + + +Controlling a GPIO input/output pin + + + + + + + +
+

gokrazy

+
+ +

Controlling a GPIO input/output pin

+

In this guide, we are using periph.io, a library for +peripheral I/O in Go, to set one of the Raspberry Pi’s General Purpose I/O +(GPIO) pins to a logical high (3.3V) or low (0V) signal.

+

periph.io supports the Raspberry Pi 3 and Raspberry Pi 4, starting with version +v3.6.4.

+

Connect GPIO pins based on pinout

+

+

To verify the code is doing what we expect, let’s connect a multimeter as per +pinout.xyz’s pinout:

+ +

We need to set the multimeter to “Voltage measurement, DC (direct current)”.

+

Setting an output pin signal

+

To set the pin high and low, alternatingly, with a 5 second frequency, we will +be using the hello-gpio program, which is a slightly modified version of the +example at periph.io/device/led:

+
package main
+
+import (
+	"log"
+	"time"
+
+	"periph.io/x/periph/conn/gpio"
+	"periph.io/x/periph/host"
+	"periph.io/x/periph/host/rpi"
+)
+
+func doGPIO() error {
+	log.Printf("Loading periph.io drivers")
+	// Load periph.io drivers:
+	if _, err := host.Init(); err != nil {
+		return err
+	}
+	log.Printf("Toggling GPIO forever")
+	t := time.NewTicker(5 * time.Second)
+	for l := gpio.Low; ; l = !l {
+		log.Printf("setting GPIO pin number 18 (signal BCM24) to %v", l)
+		// Lookup a pin by its location on the board:
+		if err := rpi.P1_18.Out(l); err != nil {
+			return err
+		}
+		<-t.C
+	}
+	return nil
+}
+
+func main() {
+	if err := doGPIO(); err != nil {
+		log.Fatal(err)
+	}
+}
+

Install the program on your Raspberry Pi using gokrazy (see Quickstart):

+
gokr-packer \
+  -update=yes \
+  github.com/gokrazy/hello \
+  github.com/gokrazy/breakglass \
+  github.com/gokrazy/serial-busybox \
+  github.com/gokrazy/hello-gpio
+

…and wait a few seconds for it to reboot.

+

At this point, we should be able to see the high/low signal on the multimeter, +alternating between 3.3V (high) and 0V (low) every 5 seconds:

+

+ +
+

© 2017 gokrazy authors (Michael Stapelberg and contributors)

+
+
+ + + + + diff --git a/docs/userguide/index.html b/docs/userguide/index.html index ec999ab..4c55375 100644 --- a/docs/userguide/index.html +++ b/docs/userguide/index.html @@ -57,6 +57,10 @@ GitHub.