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