gobot.io/x/gobot/v2@v2.1.0/platforms/chip/README.md (about)

     1  # C.H.I.P.
     2  
     3  The [C.H.I.P.](http://www.getchip.com/) is a small, inexpensive ARM based single board computer, with many different IO interfaces available on the [pin headers](http://docs.getchip.com/#pin-headers).
     4  
     5  For documentation about the C.H.I.P. platform click [here](http://docs.getchip.com/).
     6  
     7  The [C.H.I.P. Pro](https://getchip.com/pages/chippro) is a version of C.H.I.P. intended for use in embedded product development. Here is info about the [C.H.I.P. Pro pin headers](https://docs.getchip.com/chip_pro.html#pin-descriptions).
     8  
     9  
    10  ## How to Install
    11  
    12  We recommend updating to the latest Debian OS when using the C.H.I.P., however Gobot should also support older versions of the OS, should your application require this.
    13  
    14  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 C.H.I.P and run the program on the C.H.I.P. itself as documented here.
    15  
    16  ```
    17  go get -d -u gobot.io/x/gobot/v2/...
    18  ```
    19  
    20  ### PWM support
    21  Note that PWM might not be available in your kernel. In that case, you can install the required device tree overlay
    22  from the command line using [Gort](https://gobot.io/x/gort) CLI commands on the C.H.I.P device.
    23  Here are the steps:
    24  
    25  Install the required patched device tree compiler as described in the [C.H.I.P docs](https://docs.getchip.com/dip.html#make-a-dtbo-device-tree-overlay-blob):
    26  ```
    27  gort chip install dtc
    28  ```
    29  
    30  Now, install the pwm overlay to activate pwm on the PWM0 pin:
    31  ```
    32  gort chip install pwm
    33  ```
    34  
    35  Reboot the device to make sure the init script loads the overlay on boot.
    36  
    37  
    38  ## How to Use
    39  
    40  The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.
    41  
    42  ```go
    43  package main
    44  
    45  import (
    46      "fmt"
    47  
    48      "gobot.io/x/gobot/v2"
    49      "gobot.io/x/gobot/v2/drivers/gpio"
    50      "gobot.io/x/gobot/v2/platforms/chip"
    51  )
    52  
    53  func main() {
    54      chipAdaptor := chip.NewAdaptor()
    55      button := gpio.NewButtonDriver(chipAdaptor, "XIO-P0")
    56  
    57      work := func() {
    58          gobot.On(button.Event("push"), func(data interface{}) {
    59              fmt.Println("button pressed")
    60          })
    61  
    62          gobot.On(button.Event("release"), func(data interface{}) {
    63              fmt.Println("button released")
    64          })
    65      }
    66  
    67      robot := gobot.NewRobot("buttonBot",
    68          []gobot.Connection{chipAdaptor},
    69          []gobot.Device{button},
    70          work,
    71      )
    72  
    73      robot.Start()
    74  }
    75  ```
    76  
    77  If you want to use the C.H.I.P. Pro, use the `NewProAdaptor()` function like this:
    78  
    79  ```go
    80  chipProAdaptor := chip.NewProAdaptor()
    81  ```
    82  
    83  ## How to Connect
    84  
    85  ### Compiling
    86  
    87  Compile your Gobot program on your workstation like this:
    88  
    89  ```bash
    90  $ GOARM=7 GOARCH=arm GOOS=linux go build examples/chip_button.go
    91  ```
    92  
    93  Once you have compiled your code, you can you can upload your program and execute it on the C.H.I.P. from your workstation using the `scp` and `ssh` commands like this:
    94  
    95  ```bash
    96  $ scp chip_button root@192.168.1.xx:
    97  $ ssh -t root@192.168.1.xx "./chip_button"
    98  ```