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

     1  [![Gobot](https://raw.githubusercontent.com/hybridgroup/gobot-site/master/source/images/elements/gobot-logo-small.png)](http://gobot.io/)
     2  
     3  [![GoDoc](https://godoc.org/gobot.io/x/gobot?status.svg)](https://godoc.org/gobot.io/x/gobot)
     4  [![CircleCI Build status](https://circleci.com/gh/hybridgroup/gobot/tree/dev.svg?style=svg)](https://circleci.com/gh/hybridgroup/gobot/tree/dev)
     5  [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/ix29evnbdrhkr7ud/branch/dev?svg=true)](https://ci.appveyor.com/project/deadprogram/gobot/branch/dev)
     6  [![codecov](https://codecov.io/gh/hybridgroup/gobot/branch/dev/graph/badge.svg)](https://codecov.io/gh/hybridgroup/gobot)
     7  [![Go Report Card](https://goreportcard.com/badge/hybridgroup/gobot)](https://goreportcard.com/report/hybridgroup/gobot)
     8  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/hybridgroup/gobot/blob/master/LICENSE.txt)
     9  
    10  Gobot (https://gobot.io/) is a framework using the Go programming language (https://golang.org/) for robotics, physical computing, and the Internet of Things.
    11  
    12  It provides a simple, yet powerful way to create solutions that incorporate multiple, different hardware devices at the same time.
    13  
    14  Want to run Go directly on microcontrollers? Check out our sister project TinyGo (https://tinygo.org/)
    15  
    16  ## Getting Started
    17  
    18  Get the Gobot package by running this command: `go get -d -u gobot.io/x/gobot`
    19  
    20  ## Examples
    21  
    22  #### Gobot with Arduino
    23  
    24  ```go
    25  package main
    26  
    27  import (
    28  	"time"
    29  
    30  	"gobot.io/x/gobot"
    31  	"gobot.io/x/gobot/drivers/gpio"
    32  	"gobot.io/x/gobot/platforms/firmata"
    33  )
    34  
    35  func main() {
    36  	firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
    37  	led := gpio.NewLedDriver(firmataAdaptor, "13")
    38  
    39  	work := func() {
    40  		gobot.Every(1*time.Second, func() {
    41  			led.Toggle()
    42  		})
    43  	}
    44  
    45  	robot := gobot.NewRobot("bot",
    46  		[]gobot.Connection{firmataAdaptor},
    47  		[]gobot.Device{led},
    48  		work,
    49  	)
    50  
    51  	robot.Start()
    52  }
    53  ```
    54  
    55  #### Gobot with Sphero
    56  
    57  ```go
    58  package main
    59  
    60  import (
    61  	"fmt"
    62  	"time"
    63  
    64  	"gobot.io/x/gobot"
    65  	"gobot.io/x/gobot/platforms/sphero"
    66  )
    67  
    68  func main() {
    69  	adaptor := sphero.NewAdaptor("/dev/rfcomm0")
    70  	driver := sphero.NewSpheroDriver(adaptor)
    71  
    72  	work := func() {
    73  		gobot.Every(3*time.Second, func() {
    74  			driver.Roll(30, uint16(gobot.Rand(360)))
    75  		})
    76  	}
    77  
    78  	robot := gobot.NewRobot("sphero",
    79  		[]gobot.Connection{adaptor},
    80  		[]gobot.Device{driver},
    81  		work,
    82  	)
    83  
    84  	robot.Start()
    85  }
    86  ```
    87  
    88  #### "Metal" Gobot
    89  
    90  You can use the entire Gobot framework as shown in the examples above ("Classic" Gobot), or you can pick and choose from the various Gobot packages to control hardware with nothing but pure idiomatic Golang code ("Metal" Gobot). For example:
    91  
    92  ```go
    93  package main
    94  
    95  import (
    96  	"gobot.io/x/gobot/drivers/gpio"
    97  	"gobot.io/x/gobot/platforms/intel-iot/edison"
    98  	"time"
    99  )
   100  
   101  func main() {
   102  	e := edison.NewAdaptor()
   103  	e.Connect()
   104  
   105  	led := gpio.NewLedDriver(e, "13")
   106  	led.Start()
   107  
   108  	for {
   109  		led.Toggle()
   110  		time.Sleep(1000 * time.Millisecond)
   111  	}
   112  }
   113  ```
   114  
   115  #### "Master" Gobot
   116  
   117  You can also use the full capabilities of the framework aka "Master Gobot" to control swarms of robots or other features such as the built-in API server. For example:
   118  
   119  ```go
   120  package main
   121  
   122  import (
   123  	"fmt"
   124  	"time"
   125  
   126  	"gobot.io/x/gobot"
   127  	"gobot.io/x/gobot/api"
   128  	"gobot.io/x/gobot/platforms/sphero"
   129  )
   130  
   131  func NewSwarmBot(port string) *gobot.Robot {
   132  	spheroAdaptor := sphero.NewAdaptor(port)
   133  	spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
   134  	spheroDriver.SetName("Sphero" + port)
   135  
   136  	work := func() {
   137  		spheroDriver.Stop()
   138  
   139  		spheroDriver.On(sphero.Collision, func(data interface{}) {
   140  			fmt.Println("Collision Detected!")
   141  		})
   142  
   143  		gobot.Every(1*time.Second, func() {
   144  			spheroDriver.Roll(100, uint16(gobot.Rand(360)))
   145  		})
   146  		gobot.Every(3*time.Second, func() {
   147  			spheroDriver.SetRGB(uint8(gobot.Rand(255)),
   148  				uint8(gobot.Rand(255)),
   149  				uint8(gobot.Rand(255)),
   150  			)
   151  		})
   152  	}
   153  
   154  	robot := gobot.NewRobot("sphero",
   155  		[]gobot.Connection{spheroAdaptor},
   156  		[]gobot.Device{spheroDriver},
   157  		work,
   158  	)
   159  
   160  	return robot
   161  }
   162  
   163  func main() {
   164  	master := gobot.NewMaster()
   165  	api.NewAPI(master).Start()
   166  
   167  	spheros := []string{
   168  		"/dev/rfcomm0",
   169  		"/dev/rfcomm1",
   170  		"/dev/rfcomm2",
   171  		"/dev/rfcomm3",
   172  	}
   173  
   174  	for _, port := range spheros {
   175  		master.AddRobot(NewSwarmBot(port))
   176  	}
   177  
   178  	master.Start()
   179  }
   180  ```
   181  
   182  ## Hardware Support
   183  Gobot has a extensible system for connecting to hardware devices. The following robotics and physical computing platforms are currently supported:
   184  
   185  - [Arduino](http://www.arduino.cc/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/firmata)
   186  - Audio <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/audio)
   187  - [Beaglebone Black](http://beagleboard.org/boards) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone)
   188  - [Beaglebone PocketBeagle](http://beagleboard.org/pocket/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone)
   189  - [Bluetooth LE](https://www.bluetooth.com/what-is-bluetooth-technology/bluetooth-technology-basics/low-energy) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/ble)
   190  - [C.H.I.P](http://www.nextthing.co/pages/chip) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/chip)
   191  - [C.H.I.P Pro](https://docs.getchip.com/chip_pro.html) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/chip)
   192  - [Digispark](http://digistump.com/products/1) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/digispark)
   193  - [DJI Tello](https://www.ryzerobotics.com/tello) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/dji/tello)
   194  - [DragonBoard](https://developer.qualcomm.com/hardware/dragonboard-410c) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/dragonboard)
   195  - [ESP8266](http://esp8266.net/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/firmata)
   196  - [GoPiGo 3](https://www.dexterindustries.com/gopigo3/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/dexter/gopigo3)
   197  - [Intel Curie](https://www.intel.com/content/www/us/en/products/boards-kits/curie.html) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/intel-iot/curie)
   198  - [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/intel-iot/edison)
   199  - [Intel Joule](http://intel.com/joule/getstarted) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/intel-iot/joule)
   200  - [Joystick](http://en.wikipedia.org/wiki/Joystick) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/joystick)
   201  - [Keyboard](https://en.wikipedia.org/wiki/Computer_keyboard) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/keyboard)
   202  - [Leap Motion](https://www.leapmotion.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/leap)
   203  - [MavLink](http://qgroundcontrol.org/mavlink/start) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/mavlink)
   204  - [MegaPi](http://www.makeblock.com/megapi) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/megapi)
   205  - [Microbit](http://microbit.org/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/microbit)
   206  - [MQTT](http://mqtt.org/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/mqtt)
   207  - [NATS](http://nats.io/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/nats)
   208  - [Neurosky](http://neurosky.com/products-markets/eeg-biosensors/hardware/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/neurosky)
   209  - [OpenCV](http://opencv.org/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/opencv)
   210  - [Particle](https://www.particle.io/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/particle)
   211  - [Parrot ARDrone 2.0](http://ardrone2.parrot.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/parrot/ardrone)
   212  - [Parrot Bebop](http://www.parrot.com/usa/products/bebop-drone/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/parrot/bebop)
   213  - [Parrot Minidrone](https://www.parrot.com/us/minidrones) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/parrot/minidrone)
   214  - [Pebble](https://www.getpebble.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/pebble)
   215  - [Raspberry Pi](http://www.raspberrypi.org/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/raspi)
   216  - [Sphero](http://www.sphero.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero)
   217  - [Sphero BB-8](http://www.sphero.com/bb8) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/bb8)
   218  - [Sphero Ollie](http://www.sphero.com/ollie) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/ollie)
   219  - [Sphero SPRK+](http://www.sphero.com/sprk-plus) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/sprkplus)
   220  - [Tinker Board](https://www.asus.com/us/Single-Board-Computer/Tinker-Board/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/tinkerboard)
   221  - [UP2](http://www.up-board.org/upsquared/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/upboard/up2)
   222  
   223  Support for many devices that use General Purpose Input/Output (GPIO) have
   224  a shared set of drivers provided using the `gobot/drivers/gpio` package:
   225  
   226  - [GPIO](https://en.wikipedia.org/wiki/General_Purpose_Input/Output) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/gpio)
   227  	- AIP1640 LED
   228  	- Button
   229  	- Buzzer
   230  	- Direct Pin
   231  	- EasyDriver
   232  	- Grove Button
   233  	- Grove Buzzer
   234  	- Grove LED
   235  	- Grove Magnetic Switch
   236  	- Grove Relay
   237  	- Grove Touch Sensor
   238  	- LED
   239  	- Makey Button
   240  	- Motor
   241  	- Proximity Infra Red (PIR) Motion Sensor
   242  	- Relay
   243  	- RGB LED
   244  	- Servo
   245  	- Stepper Motor
   246  	- TM1638 LED Controller
   247  
   248  Support for many devices that use Analog Input/Output (AIO) have
   249  a shared set of drivers provided using the `gobot/drivers/aio` package:
   250  
   251  - [AIO](https://en.wikipedia.org/wiki/Analog-to-digital_converter) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/aio)
   252  	- Analog Sensor
   253  	- Grove Light Sensor
   254  	- Grove Piezo Vibration Sensor
   255  	- Grove Rotary Dial
   256  	- Grove Sound Sensor
   257  	- Grove Temperature Sensor
   258  
   259  Support for devices that use Inter-Integrated Circuit (I2C) have a shared set of
   260  drivers provided using the `gobot/drivers/i2c` package:
   261  
   262  - [I2C](https://en.wikipedia.org/wiki/I%C2%B2C) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/i2c)
   263  	- Adafruit Motor Hat
   264  	- ADS1015 Analog to Digital Converter
   265  	- ADS1115 Analog to Digital Converter
   266  	- ADXL345 Digital Accelerometer
   267  	- BH1750 Digital Luminosity/Lux/Light Sensor
   268  	- BlinkM LED
   269  	- BME280 Barometric Pressure/Temperature/Altitude/Humidity Sensor
   270  	- BMP180 Barometric Pressure/Temperature/Altitude Sensor
   271  	- BMP280 Barometric Pressure/Temperature/Altitude Sensor
   272  	- BMP388 Barometric Pressure/Temperature/Altitude Sensor
   273  	- DRV2605L Haptic Controller
   274  	- Grove Digital Accelerometer
   275  	- GrovePi Expansion Board
   276  	- Grove RGB LCD
   277  	- HMC6352 Compass
   278  	- HMC8553L 3-Axis Digital Compass
   279  	- INA3221 Voltage Monitor
   280  	- JHD1313M1 LCD Display w/RGB Backlight
   281  	- L3GD20H 3-Axis Gyroscope
   282  	- LIDAR-Lite
   283  	- MCP23017 Port Expander
   284  	- MMA7660 3-Axis Accelerometer
   285  	- MPL115A2 Barometer
   286  	- MPU6050 Accelerometer/Gyroscope
   287  	- PCA9685 16-channel 12-bit PWM/Servo Driver
   288  	- SHT2x Temperature/Humidity
   289  	- SHT3x-D Temperature/Humidity
   290  	- SSD1306 OLED Display Controller
   291  	- TSL2561 Digital Luminosity/Lux/Light Sensor
   292  	- Wii Nunchuck Controller
   293  
   294  Support for devices that use Serial Peripheral Interface (SPI) have
   295  a shared set of drivers provided using the `gobot/drivers/spi` package:
   296  
   297  - [SPI](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/spi)
   298  	- APA102 Programmable LEDs
   299  	- MCP3002 Analog/Digital Converter
   300  	- MCP3004 Analog/Digital Converter
   301  	- MCP3008 Analog/Digital Converter
   302  	- MCP3202 Analog/Digital Converter
   303  	- MCP3204 Analog/Digital Converter
   304  	- MCP3208 Analog/Digital Converter
   305  	- MCP3304 Analog/Digital Converter
   306  	- SSD1306 OLED Display Controller
   307  
   308  More platforms and drivers are coming soon...
   309  
   310  ## API:
   311  
   312  Gobot includes a RESTful API to query the status of any robot running within a group, including the connection and device status, and execute device commands.
   313  
   314  To activate the API, import the `gobot.io/x/gobot/api` package and instantiate the `API` like this:
   315  
   316  ```go
   317    master := gobot.NewMaster()
   318    api.NewAPI(master).Start()
   319  ```
   320  
   321  You can also specify the api host and port, and turn on authentication:
   322  ```go
   323    master := gobot.NewMaster()
   324    server := api.NewAPI(master)
   325    server.Port = "4000"
   326    server.AddHandler(api.BasicAuth("gort", "klatuu"))
   327    server.Start()
   328  ```
   329  
   330  You may access the [robeaux](https://github.com/hybridgroup/robeaux) React.js interface with Gobot by navigating to `http://localhost:3000/index.html`.
   331  
   332  ## CLI
   333  
   334  Gobot uses the Gort [http://gort.io](http://gort.io) Command Line Interface (CLI) so you can access important features right from the command line. We call it "RobotOps", aka "DevOps For Robotics". You can scan, connect, update device firmware, and more!
   335  
   336  Gobot also has its own CLI to generate new platforms, adaptors, and drivers. You can check it out in the `/cli` directory.
   337  
   338  ## Documentation
   339  We're always adding documentation to our web site at https://gobot.io/ please check there as we continue to work on Gobot
   340  
   341  Thank you!
   342  
   343  ## Need help?
   344  * Issues: https://github.com/hybridgroup/gobot/issues
   345  * Twitter: [@gobotio](https://twitter.com/gobotio)
   346  * Slack: [https://gophers.slack.com/messages/C0N5HDB08](https://gophers.slack.com/messages/C0N5HDB08)
   347  * Mailing list: https://groups.google.com/forum/#!forum/gobotio
   348  
   349  ## Contributing
   350  For our contribution guidelines, please go to [https://github.com/hybridgroup/gobot/blob/master/CONTRIBUTING.md
   351  ](https://github.com/hybridgroup/gobot/blob/master/CONTRIBUTING.md
   352  ).
   353  
   354  Gobot is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. [You can read about it here](https://github.com/hybridgroup/gobot/tree/master/CODE_OF_CONDUCT.md).
   355  
   356  ## License
   357  Copyright (c) 2013-2020 The Hybrid Group. Licensed under the Apache 2.0 license.
   358  
   359  The Contributor Covenant is released under the Creative Commons Attribution 4.0 International Public License, which requires that attribution be included.