What is Gobot?
Gobot is a framework for robotics, physical computing, and the Internet of Things (IoT), written in the Go programming language.
Gobot provides drivers and adapters for controlling a wide variety of physical devices from low-level Arduino and Raspberry Pi, as well as drones, toys, and other complete devices that themselves have APIs.
The "Robot" is the main software abstraction that makes it easy to build interesting high-level functionality for supported devices.
Robots (Go programs) written with Gobot can run on a host machine communicating to connected devices, or directly on a single-board Linux computer, or anywhere in between.
Gobot can also provide an external facing API to allow other programs to control from individual devices to entire groups of Robots on a shared network, implemented using JSON-over-HTTP API.
Gobot's approach to standardization and abstraction makes it easy to write a program that works on multiple hardware platforms with little modification.
Set Up Your Environment
Installing Go
Go is an open-source programming language that makes it easy to develop simple, reliable, and efficient software.
Follow the official installation instructions to get started.
Installing Gobot
With Go installed, the go get
tool will help you install Gobot and its required dependencies:
$ go get -d -u gobot.io/x/gobot/...
Writing Your First Robot
Once you have the Gobot packages installed, you're ready to start writing your own code. The first program we are going to create is the "Hello, World" of things, which is a program to blink an LED on and off every second.
Hello, World of Things
package main import ( "time" "gobot.io/x/gobot" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/firmata" ) func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
To run your Robot, you can just pass the source file to go run
:
$ go run blink.go
You should see the LED turn on and off every second.
Adding Input
Now that you have basic output, let's add some input in the form of a push-button.
Button and LED
package main import ( "gobot.io/x/gobot" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/firmata" ) func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") button := gpio.NewButtonDriver(firmataAdaptor, "5") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { button.On(gpio.ButtonPush, func(data interface{}) { led.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{button, led}, work, ) robot.Start() }
This time when you run your program, you should see the LED turn on when you push the button, and then off when you release the button.
What's Next?
Where do we go from here?
Well, if you're interested in seeing some more examples of Gobot in action, check out our Examples page.
If you'd like to find out more about a specific platform, our Platforms page will point you in the right direction.
Instead, if you'd rather explore at your leisure, the sidebar should help you find what you're looking for.
If you have any questions, please don't hesitate to get in touch with us and we'll try to help as best we can.
Contributing
We welcome your contributions! If you want to make Gobot even better (even fixing typos!), check out the GitHub page!
Have you noticed an error in our docs site? Think a paragraph could be worded better? Please send us an issue or pull request! The site has it's own GitHub page too!
Want to suggest a feature? Report a bug? Show us something cool you made? Just say hi? You can also get in touch with us on Twitter, or ping us on our Google Group.