1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-13 19:29:10 +08:00

92 lines
2.6 KiB
Markdown
Raw Normal View History

# Raspberry Pi
2014-11-04 17:14:36 -08:00
2014-11-28 15:34:42 -08:00
The Raspberry Pi is an inexpensive and popular ARM based single board computer with digital & PWM GPIO, and i2c interfaces built in.
2014-11-04 17:14:36 -08:00
The Gobot adaptor for the Raspberry Pi should support all of the various Raspberry Pi boards such as the Raspberry Pi 3 Model B, Raspberry Pi 2 Model B, Raspberry Pi 1 Model A+, Raspberry Pi Zero, and Raspberry Pi Zero W.
We recommend updating to the latest Raspian Jessie OS when using the Raspberry Pi, however Gobot should also support older versions of the OS, should your application require this.
2014-11-28 15:34:42 -08:00
For more info about the Raspberry Pi platform, click [here](http://www.raspberrypi.org/).
You would normally install Go and Gobot on your workstation. Once installed, cross compile your program on your workstation, transfer the final executable to your Raspberry Pi, and run the program on the Raspberry Pi as documented here.
2015-01-02 07:05:24 -08:00
## How to Install
2015-01-02 07:05:24 -08:00
```
go get -d -u gobot.io/x/gobot/...
2015-01-02 07:05:24 -08:00
```
## How to Use
2015-06-30 16:33:13 -07:00
The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.
2015-06-30 16:33:13 -07:00
```go
package main
2015-06-30 16:33:13 -07:00
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/raspi"
)
func main() {
r := raspi.NewAdaptor()
led := gpio.NewLedDriver(r, "7")
2014-11-04 17:14:36 -08:00
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
2014-11-04 17:14:36 -08:00
robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{r},
[]gobot.Device{led},
work,
)
robot.Start()
}
2014-11-04 17:14:36 -08:00
```
## How to Connect
2014-11-04 17:14:36 -08:00
### Compiling
2014-11-04 17:14:36 -08:00
Compile your Gobot program on your workstation like this:
2014-11-28 15:34:42 -08:00
2014-11-04 17:14:36 -08:00
```bash
$ GOARM=6 GOARCH=arm GOOS=linux go build examples/raspi_blink.go
2014-11-04 17:14:36 -08:00
```
Use the following `GOARM` values to compile depending on which model Raspberry Pi you are using:
`GOARM=6` (Raspberry Pi A, A+, B, B+, Zero)
`GOARM=7` (Raspberry Pi 2, 3)
Once you have compiled your code, you can upload your program over the network from your host computer to the Raspi
2014-11-28 15:34:42 -08:00
```bash
2014-11-04 17:14:36 -08:00
$ scp raspi_blink pi@192.168.1.xxx:/home/pi/
```
and then SSH to your Raspberry Pi
```bash
$ ssh pi@192.168.1.xxx
```
and execute it on the Raspberry Pi itself with
2014-11-28 15:34:42 -08:00
2014-11-04 17:14:36 -08:00
```bash
$ ./raspi_blink
```
### Enabling PWM output on GPIO pins.
2014-11-04 17:14:36 -08:00
For extended PWM support on the Raspberry Pi, you will need to use a program called pi-blaster. You can follow the instructions for pi-blaster install in the pi-blaster repo here:
2014-11-04 17:14:36 -08:00
[https://github.com/sarfata/pi-blaster](https://github.com/sarfata/pi-blaster)