2013-07-30 05:58:34 +02:00
|
|
|
go-rpio
|
|
|
|
=======
|
|
|
|
|
2013-07-30 19:25:43 +02:00
|
|
|
Native GPIO-Gophers for your Pi!
|
2013-07-30 06:10:01 +02:00
|
|
|
|
2013-07-30 19:25:43 +02:00
|
|
|
go-rpio is a Go library for accessing [GPIO](http://elinux.org/Rpi_Low-level_peripherals)-pins
|
2013-07-30 17:16:42 +02:00
|
|
|
on the [Raspberry Pi](https://en.wikipedia.org/wiki/Raspberry_Pi).
|
|
|
|
|
|
|
|
It requires no external c libraries such as
|
|
|
|
[WiringPI](https://projects.drogon.net/raspberry-pi/wiringpi/) or [bcm2835](http://www.open.com.au/mikem/bcm2835).
|
|
|
|
|
2014-08-25 12:38:50 +02:00
|
|
|
There's a tiny bit of additional information over at my [blog](https://blog.eikeland.se/2013/07/30/go-gpio-library-for-raspberry-pi/).
|
2013-07-30 20:27:10 +02:00
|
|
|
|
2013-12-05 19:39:42 +01:00
|
|
|
![raspberrypi-blink](http://stianeikeland.files.wordpress.com/2013/07/animated.gif)
|
|
|
|
|
2015-03-08 14:34:25 +01:00
|
|
|
## Releases ##
|
|
|
|
- 1.0.0 - Supports original rpi A/B/B+
|
|
|
|
- 2.0.0 - Adds support for rpi 2, by @akramer
|
|
|
|
|
2013-07-30 17:16:42 +02:00
|
|
|
## Usage ##
|
|
|
|
|
|
|
|
```go
|
|
|
|
import "github.com/stianeikeland/go-rpio"
|
|
|
|
```
|
|
|
|
|
|
|
|
Open memory range for GPIO access in /dev/mem
|
|
|
|
|
|
|
|
```go
|
|
|
|
err := rpio.Open()
|
|
|
|
```
|
|
|
|
|
|
|
|
Initialize a pin, run basic operations.
|
2013-07-30 19:25:43 +02:00
|
|
|
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.
|
2013-07-30 17:16:42 +02:00
|
|
|
|
|
|
|
```go
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2013-07-30 19:25:43 +02:00
|
|
|
Pull up/down/off can be set using:
|
|
|
|
|
|
|
|
```go
|
|
|
|
pin.PullUp()
|
|
|
|
pin.PullDown()
|
|
|
|
pin.PullOff()
|
|
|
|
|
|
|
|
pin.Pull(rpio.PullUp)
|
|
|
|
```
|
|
|
|
|
2013-07-30 17:16:42 +02:00
|
|
|
Unmap memory when done
|
|
|
|
|
|
|
|
```go
|
|
|
|
rpio.Close()
|
|
|
|
```
|
|
|
|
|
|
|
|
Also see example [examples/blinker/blinker.go](examples/blinker/blinker.go)
|
|
|
|
|
|
|
|
## Other ##
|
|
|
|
|
|
|
|
Currently, it supports basic functionality such as:
|
|
|
|
- Pin Direction (Input / Output)
|
|
|
|
- Write (High / Low)
|
|
|
|
- Read (High / Low)
|
2013-07-30 19:25:43 +02:00
|
|
|
- Pull (Up / Down / Off)
|
2013-07-30 17:16:42 +02:00
|
|
|
|
|
|
|
Would be nice to add in the future:
|
|
|
|
- PWM
|
|
|
|
- I2C
|
|
|
|
- SPI
|
|
|
|
- etc...
|
|
|
|
|
2014-02-12 21:28:37 +01:00
|
|
|
It works by memory-mapping the bcm2835 gpio range, and therefore require root/administrative-rights to run.
|