mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-02-09 02:34:56 +01:00
Added basic description to README.md
This commit is contained in:
parent
df0edecd6c
commit
7136a1a68f
64
README.md
64
README.md
|
@ -1,7 +1,65 @@
|
||||||
go-rpio
|
go-rpio
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Raspberry Pi GPIO library for go-lang with limited functionality
|
Native GPIO-Gophers for your Pi!
|
||||||
Native, no c libraries needed.
|
|
||||||
|
|
||||||
Work in progress
|
go-rpio is a Go library for accessing [GPIO](http://elinux.org/Rpi_Low-level_peripherals)-pins
|
||||||
|
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).
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
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.
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
Would be nice to add in the future:
|
||||||
|
- PWM
|
||||||
|
- PullUp
|
||||||
|
- PullDown
|
||||||
|
- I2C
|
||||||
|
- SPI
|
||||||
|
- etc...
|
||||||
|
|
||||||
|
It works by memory-mapping the bcm2835 gpio range, and therefor require root/administrative-rights to run.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user