gobot.io/x/gobot@v1.16.0/platforms/raspi/README.md (about)

     1  # Raspberry Pi
     2  
     3  The Raspberry Pi is an inexpensive and popular ARM based single board computer with digital & PWM GPIO, and i2c interfaces built in.
     4  
     5  The Gobot adaptor for the Raspberry Pi should support all of the various Raspberry Pi boards such as the Raspberry Pi 4 Model B, Raspberry Pi 3 Model B, Raspberry Pi 2 Model B, Raspberry Pi 1 Model A+, Raspberry Pi Zero, and Raspberry Pi Zero W.
     6  
     7  For more info about the Raspberry Pi platform, click [here](http://www.raspberrypi.org/).
     8  
     9  ## How to Install
    10  
    11  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.
    12  
    13  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.
    14  
    15  ```
    16  go get -d -u gobot.io/x/gobot/...
    17  ```
    18  
    19  ## How to Use
    20  
    21  The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.
    22  
    23  ```go
    24  package main
    25  
    26  import (
    27          "time"
    28  
    29          "gobot.io/x/gobot"
    30          "gobot.io/x/gobot/drivers/gpio"
    31          "gobot.io/x/gobot/platforms/raspi"
    32  )
    33  
    34  func main() {
    35          r := raspi.NewAdaptor()
    36          led := gpio.NewLedDriver(r, "7")
    37  
    38          work := func() {
    39                  gobot.Every(1*time.Second, func() {
    40                          led.Toggle()
    41                  })
    42          }
    43  
    44          robot := gobot.NewRobot("blinkBot",
    45                  []gobot.Connection{r},
    46                  []gobot.Device{led},
    47                  work,
    48          )
    49  
    50          robot.Start()
    51  }
    52  ```
    53  
    54  ## How to Connect
    55  
    56  ### Compiling
    57  
    58  Compile your Gobot program on your workstation like this:
    59  
    60  ```bash
    61  $ GOARM=6 GOARCH=arm GOOS=linux go build examples/raspi_blink.go
    62  ```
    63  
    64  Use the following `GOARM` values to compile depending on which model Raspberry Pi you are using:
    65  
    66  `GOARM=6` (Raspberry Pi A, A+, B, B+, Zero)
    67  `GOARM=7` (Raspberry Pi 2, 3)
    68  
    69  Once you have compiled your code, you can upload your program and execute it on the Raspberry Pi from your workstation using the `scp` and `ssh` commands like this:
    70  
    71  ```bash
    72  $ scp raspi_blink pi@192.168.1.xxx:/home/pi/
    73  $ ssh -t pi@192.168.1.xxx "./raspi_blink"
    74  ```
    75  
    76  ### Enabling PWM output on GPIO pins.
    77  
    78  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:
    79  
    80  [https://github.com/sarfata/pi-blaster](https://github.com/sarfata/pi-blaster)