Categorygithub.com/stianeikeland/go-rpio
modulepackage
1.0.0
Repository: https://github.com/stianeikeland/go-rpio.git
Documentation: pkg.go.dev

# README

go-rpio

Native GPIO-Gophers for your Pi!

go-rpio is a Go library for accessing GPIO-pins on the Raspberry Pi.

It requires no external c libraries such as WiringPI or bcm2835.

There's a tiny bit of additional information over at my blog.

raspberrypi-blink

Usage

import "github.com/stianeikeland/go-rpio"

Open memory range for GPIO access in /dev/mem

err := rpio.Open()

Initialize a pin, run basic operations. Pin refers to the bcm2835 pin, not the physical pin on the raspberry pi header. Pin 10 here is exposed on the pin header as physical pin 19.

pin := rpio.Pin(10)

pin.Output()       // Output mode
pin.High()         // Set pin High
pin.Low()          // Set pin Low
pin.Toggle()       // Toggle pin (Low -> High -> Low)

pin.Input()        // Input mode
res := pin.Read()  // Read state from pin (High / Low)

pin.Mode(rpio.Output)   // Alternative syntax
pin.Write(rpio.High)    // Alternative syntax

Pull up/down/off can be set using:

pin.PullUp()
pin.PullDown()
pin.PullOff()

pin.Pull(rpio.PullUp)

Unmap memory when done

rpio.Close()

Also see example examples/blinker/blinker.go

Other

Currently, it supports basic functionality such as:

  • Pin Direction (Input / Output)
  • Write (High / Low)
  • Read (High / Low)
  • Pull (Up / Down / Off)

Would be nice to add in the future:

  • PWM
  • I2C
  • SPI
  • etc...

It works by memory-mapping the bcm2835 gpio range, and therefore require root/administrative-rights to run.

# Packages

No description provided by the author

# Functions

Close unmaps GPIO memory.
Open and memory map GPIO memory range from /dev/mem .
PinMode sets the direction of a given pin (Input or Output).
No description provided by the author
Read the state of a pin.
Toggle a pin state (high -> low -> high) TODO: probably possible to do this much faster without read.
WritePin sets a given pin High or Low by setting the clear or set registers respectively.

# Constants

State of pin, High / Low.
Pin direction, a pin can be set in Input or Output mode.
State of pin, High / Low.
Pin direction, a pin can be set in Input or Output mode.
Pull Up / Down / Off.
Pull Up / Down / Off.
Pull Up / Down / Off.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author