go-rpio
=======
Native GPIO-Gophers for your Pi!
**Documentation:** [![GoDoc](https://pkg.go.dev/badge/github.com/stianeikeland/go-rpio)](https://pkg.go.dev/github.com/stianeikeland/go-rpio/v4)
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).
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/).
![raspberrypi-blink](https://blog.eikeland.se/images/2013-07-30-go-gpio-library-for-raspberry-pi/animated.gif)
## Releases ##
- 1.0.0 - Supports original rpi A/B/B+
- 2.0.0 - Adds support for rpi 2, by @akramer
- 3.0.0 - Adds support for /dev/gpiomem, by @dotdoom
- 4.0.0 - Adds support for PWM and Clock modes, by @drahoslove
- 4.1.0 - Adds support for edge detection, by @drahoslove
- 4.2.0 - Faster write and toggle of output pins, by @drahoslove
- 4.3.0 - Adds support for SPI, by @drahoslove
- 4.4.0 - Support for disabling interrupts (workaround for #35), by @drahoslove
- 4.5.0 - Improve rpi 4 support, by @wfd3
- 4.6.0 - Adds Balanced PWM mode, by @youngkin
## Usage ##
```go
import "github.com/stianeikeland/go-rpio/v4"
```
If you're using an older go.mod incompatible you should instead use:
```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
```
Pull up/down/off can be set using:
```go
pin.PullUp()
pin.PullDown()
pin.PullOff()
pin.Pull(rpio.PullUp)
```
Unmap memory when done
```go
rpio.Close()
```
Also see example [examples/blinker/blinker.go](examples/blinker/blinker.go)
### SPI
#### setup/teardown
- `rpio.SpiBegin(rpio.Spi0)` has to be called first before using any Spi func. It will change pin modes to `Spi` and initialize default setting.
- `rpio.SpiEnd(rpio.Spi0)` should be called at the end, it will switch pin modes to `Input`.
#### transferring data
- `rpio.SpiTransmit(byte)` or `rpio.SpiTransmit(bytes...)` will transmit byte or bytes to slave.
- `rpio.SpiReceive(n)` will return n bytes received from slave.
- `rpio.SpiExchange(buffer)` will simultaneously transmit data from the buffer to slave and data from slave to the same buffer in full duplex way.
#### settings
- `rpio.SpiSpeed(hz)` will set transmit speed of SPI
- `rpio.SpiChipSelect(n)` will select chip/slave (ce0, ce1, or ce2) to which transferring will be done
- `rpio.SpiChipSelectPolarity(n, pol)` set chip select polarity (low enabled is used by default which usually works most of the time)
- `rpio.SpiMode(cpol, cpha)` set clock/communication mode (=combination of clock polarity and clock phase; cpol=0, cpha=0 is used by default which usually works most of the time)
## Other ##
Currently, it supports basic functionality such as:
- Pin Direction (Input / Output)
- Write (High / Low)
- Read (High / Low)
- Pull (Up / Down / Off)
- PWM (hardware, on supported pins)
- Clock
- Edge detection
It works by memory-mapping the bcm2835 gpio range, and therefore require root/administrative-rights to run.
## Using without root ##
This library can utilize the new [/dev/gpiomem](https://github.com/raspberrypi/linux/pull/1112/files)
memory range if available.
You will probably need to upgrade to the latest kernel (or wait for the next raspbian release) if you're missing /dev/gpiomem. You will also need to add a `gpio` group, add your user to the group, and then set up udev rules. I would recommend using [create_gpio_user_permissions.py](https://github.com/waveform80/rpi-gpio/blob/master/create_gpio_user_permissions.py) if you're unsure how to do this.
PWM modes will still require root.
没有合适的资源?快使用搜索试试~ 我知道了~
用于 go-lang 的 Raspberry Pi GPIO 库.zip
共17个文件
go:10个
txt:2个
sum:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 53 浏览量
2024-12-03
04:18:24
上传
评论
收藏 18KB ZIP 举报
温馨提示
用于 go-lang 的 Raspberry Pi GPIO 库戈里皮奥适合您的 Pi 的原生 GPIO-Gophers!文档 go-rpio 是一个用于访问Raspberry Pi上的GPIO引脚的 Go 库。它不需要外部 c 库,例如 WiringPI或bcm2835。我的博客上还有一些额外的信息。发行1.0.0 - 支持原始 rpi A/B/B+2.0.0 - 添加对 rpi 2 的支持,作者@akramer3.0.0 - 添加对 /dev/gpiomem 的支持,作者@dotdoom4.0.0 - 增加了对 PWM 和时钟模式的支持,作者@drahoslove4.1.0 - 增加了对边缘检测的支持,作者@drahoslove4.2.0 - 更快地写入和切换输出引脚,作者@drahoslove4.3.0 - 添加对 SPI 的支持,作者@drahoslove4.4.0 - 支持禁用中断(#35 的解决方法),作者@drahoslove4.5.0 - 改进 rpi 4 支持,作者@wfd34.6.0 - 添加平衡 PWM 模式,作者@
资源推荐
资源详情
资源评论
收起资源包目录
用于 go-lang 的 Raspberry Pi GPIO 库.zip (17个子文件)
go.mod 52B
标签.txt 2B
go.sum 0B
LICENSE 1KB
examples
pwmbalanced
pwm.go 933B
pullup
pullup.go 567B
spi
spi.go 812B
event
event.go 887B
blinker
blinker.go 701B
pwm
pwm.go 1KB
spi.go 4KB
spi_test.go 421B
资源内容.txt 859B
rpio_test.go 4KB
.gitignore 252B
README.md 4KB
rpio.go 22KB
共 17 条
- 1
资源评论
赵闪闪168
- 粉丝: 1647
- 资源: 4872
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功