Convert Figma logo to code with AI

hybridgroup logogobot

Golang framework for robotics, drones, and the Internet of Things (IoT)

8,880
1,038
8,880
123

Top Related Projects

14,111

Arduino IDE 1.x

Arduino core for the ESP32

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Your Gateway to Embedded Software Development Excellence :alien:

Quick Overview

Gobot is a framework for building robotics and IoT applications using the Go programming language. It provides a set of packages and abstractions that make it easier to interact with a variety of hardware devices, including microcontrollers, sensors, and actuators.

Pros

  • Cross-Platform Compatibility: Gobot supports a wide range of hardware platforms, including Arduino, Raspberry Pi, Intel Edison, and more, making it a versatile choice for building IoT and robotics applications.
  • Modular and Extensible: Gobot is designed to be modular, with separate packages for different hardware platforms and device types. This makes it easy to add support for new devices or extend the functionality of existing ones.
  • Concurrency and Parallelism: Gobot leverages Go's built-in support for concurrency and parallelism, allowing developers to easily manage multiple devices and tasks simultaneously.
  • Active Community: Gobot has an active community of contributors and users, providing a wealth of resources, examples, and support for developers.

Cons

  • Limited Documentation: While the Gobot documentation is generally good, it can be challenging for newcomers to get started, especially with more complex use cases.
  • Steep Learning Curve: Gobot's flexibility and power come with a steeper learning curve, especially for developers who are new to Go or robotics/IoT development.
  • Dependency on Go: Gobot is tightly coupled with the Go programming language, which may be a limitation for developers who prefer to work with other languages.
  • Hardware Support Limitations: While Gobot supports a wide range of hardware, it may not have built-in support for every possible device or sensor, requiring additional development effort.

Code Examples

Here are a few examples of how to use Gobot:

Connecting to an Arduino Board

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/firmata"
)

func main() {
    board := firmata.NewAdaptor("/dev/ttyUSB0")
    led := firmata.NewLedDriver(board, "13")

    work := func() {
        gobot.Every(1*time.Second, func() {
            led.Toggle()
        })
    }

    robot := gobot.NewRobot("bot",
        []gobot.Connection{board},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

This example demonstrates how to connect to an Arduino board using the Firmata adaptor and control an LED connected to pin 13.

Interacting with a Raspberry Pi

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/raspi"
)

func main() {
    r := raspi.NewAdaptor()
    led := raspi.NewLedDriver(r, "17")

    work := func() {
        gobot.Every(1*time.Second, func() {
            led.Toggle()
        })
    }

    robot := gobot.NewRobot("bot",
        []gobot.Connection{r},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

This example shows how to interact with a Raspberry Pi using the Raspi adaptor and control an LED connected to GPIO pin 17.

Using Sensors

package main

import (
    "fmt"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/drivers/i2c"
    "gobot.io/x/gobot/platforms/raspi"
)

func main() {
    r := raspi.NewAdaptor()
    sensor := i2c.NewHTU21DDriver(r)

    work := func() {
        gobot.Every(1*time.Second, func() {
            temp, _ := sensor.Temperature()
            hum, _ := sensor.Humidity()
            fmt.Printf("Temperature: %v°C Humidity: %v%%\n", temp, hum)

Competitor Comparisons

14,111

Arduino IDE 1.x

Pros of Arduino

  • Extensive documentation and community support
  • Wide range of compatible hardware and shields
  • Simplified programming interface for beginners

Cons of Arduino

  • Limited flexibility and customization options
  • Slower performance compared to other microcontroller platforms
  • Dependency on proprietary hardware and software

Code Comparison

Arduino:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

Gobot:

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/firmata"
)

func main() {
    board := firmata.NewAdaptor("/dev/ttyUSB0")
    led := board.DigitalPin("13", board.Mode())

    work := func() {
        gobot.Every(1*time.Second, func() {
            led.Write(255)
            led.Write(0)
        })
    }

    robot := gobot.NewRobot("bot",
        []gobot.Connection{board},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

Arduino core for the ESP32

Pros of espressif/arduino-esp32

  • Provides a comprehensive Arduino-based development environment for the ESP32 microcontroller, making it easier for Arduino developers to work with the ESP32.
  • Includes a wide range of example sketches and libraries, covering various functionalities like Wi-Fi, Bluetooth, sensors, and more.
  • Offers a user-friendly IDE integration, allowing developers to leverage the familiar Arduino IDE for their ESP32 projects.

Cons of espressif/arduino-esp32

  • The project is primarily focused on the ESP32 microcontroller, while Gobot supports a broader range of hardware platforms, including various IoT devices and robotics.
  • The Arduino-based approach may limit the flexibility and low-level control that some developers might require for more advanced projects.
  • The project's documentation and community support may not be as extensive as some other IoT and robotics frameworks.

Code Comparison

Gobot:

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/firmata"
)

func main() {
    board := firmata.NewAdaptor("/dev/ttyUSB0")
    led := firmata.NewLedDriver(board, "13")

    work := func() {
        gobot.Every(1*time.Second, func() {
            led.Toggle()
        })
    }

    robot := gobot.NewRobot("bot",
        []gobot.Connection{board},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

Arduino-ESP32:

#include <WiFi.h>

const char* ssid = "your_ssid";
const char* password = "your_password";

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // Your main program logic goes here
}

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Pros of MicroPython

  • MicroPython is a full-featured, Python-based programming language that can run on microcontrollers, making it a powerful tool for embedded systems development.
  • The MicroPython project has a large and active community, with a wealth of resources and support available.
  • MicroPython is highly portable, with support for a wide range of microcontroller platforms, including the popular ESP32 and Raspberry Pi Pico.

Cons of MicroPython

  • The Gobot framework, while not as widely known as MicroPython, may have a more streamlined and focused feature set for certain robotics and IoT applications.
  • The learning curve for MicroPython may be steeper than Gobot, especially for developers who are more familiar with the Go programming language.

Code Comparison

MicroPython (blink.py):

from machine import Pin
import time

led = Pin(2, Pin.OUT)

while True:
    led.value(not led.value())
    time.sleep(0.5)

Gobot (blink.go):

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/drivers/gpio"
    "gobot.io/x/gobot/platforms/raspi"
)

func main() {
    r := raspi.NewAdaptor()
    led := gpio.NewLedDriver(r, "4")

    work := func() {
        gobot.Every(500*time.Millisecond, func() {
            led.Toggle()
        })
    }

    robot := gobot.NewRobot("blinkBot",
        []gobot.Connection{r},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Pros of nodemcu/nodemcu-firmware

  • Provides a comprehensive firmware for the NodeMCU development board, which is based on the ESP8266 Wi-Fi SoC.
  • Supports a wide range of hardware peripherals and protocols, making it suitable for a variety of IoT and embedded projects.
  • Offers a Lua scripting language, which can be more accessible for some developers compared to the lower-level C/C++ programming used in Gobot.

Cons of nodemcu/nodemcu-firmware

  • Primarily focused on the NodeMCU board, which may limit its applicability to other hardware platforms.
  • The Lua scripting language may not be as widely used or supported as other programming languages, such as Go or Python.
  • The firmware may have a steeper learning curve for developers who are more familiar with traditional embedded programming approaches.

Code Comparison

Gobot (Go):

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/firmata"
)

func main() {
    board := firmata.NewAdaptor("/dev/ttyUSB0")
    led := firmata.NewLedDriver(board, "13")

    work := func() {
        gobot.Every(1*time.Second, func() {
            led.Toggle()
        })
    }

    robot := gobot.NewRobot("bot",
        []gobot.Connection{board},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

nodemcu-firmware (Lua):

-- Blink an LED on GPIO2
gpio.mode(2, gpio.OUTPUT)
while true do
    gpio.write(2, gpio.HIGH)
    tmr.delay(1000000)
    gpio.write(2, gpio.LOW)
    tmr.delay(1000000)
end

Your Gateway to Embedded Software Development Excellence :alien:

Pros of PlatformIO Core

  • PlatformIO Core provides a comprehensive set of tools and libraries for embedded development, including support for a wide range of microcontrollers and development boards.
  • The platform offers a unified build system that simplifies the process of compiling, uploading, and debugging code across different platforms.
  • PlatformIO Core integrates with popular IDEs like Visual Studio Code, making it easy to manage embedded projects within a familiar development environment.

Cons of PlatformIO Core

  • The learning curve for PlatformIO Core may be steeper compared to Gobot, as it requires understanding the platform's specific configuration and build system.
  • The project's focus on embedded development may not be as broad as Gobot, which covers a wider range of IoT and robotics use cases.

Code Comparison

Gobot:

package main

import (
    "time"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/firmata"
)

func main() {
    board := firmata.NewAdaptor("/dev/ttyUSB0")
    led := firmata.NewLedDriver(board, "13")

    work := func() {
        gobot.Every(1*time.Second, func() {
            led.Toggle()
        })
    }

    robot := gobot.NewRobot("bot",
        []gobot.Connection{board},
        []gobot.Device{led},
        work,
    )

    robot.Start()
}

PlatformIO Core:

from machine import Pin
from time import sleep

led = Pin(2, Pin.OUT)

while True:
    led.value(not led.value())
    sleep(1)

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Gobot

GoDoc CircleCI Build status Appveyor Build status codecov Go Report Card License

Gobot (https://gobot.io/) is a framework using the Go programming language (https://golang.org/) for robotics, physical computing, and the Internet of Things.

It provides a simple, yet powerful way to create solutions that incorporate multiple, different hardware devices at the same time.

Want to run Go directly on microcontrollers? Check out our sister project TinyGo (https://tinygo.org/)

Getting Started

Get in touch

Get the Gobot source code by running this commands:

git clone https://github.com/hybridgroup/gobot.git
git checkout release

Afterwards have a look at the examples directory. You need to find an example matching your platform for your first test (e.g. "raspi_blink.go"). Than build the binary (cross compile), transfer it to your target and run it.

env GOOS=linux GOARCH=arm GOARM=5 go build -o ./output/my_raspi_bink examples/raspi_blink.go

Building the code on your local machine with the example code above will create a binary for ARMv5. This is probably not what you need for your specific target platform. Please read also the platform specific documentation in the platform subfolders.

Create your first project

Create a new folder and a new Go module project.

mkdir ~/my_gobot_example
cd ~/my_gobot_example
go mod init my.gobot.example.com

Copy your example file besides the go.mod file, import the requirements and build.

cp /<path to gobot folder>/examples/raspi_blink.go ~/my_gobot_example/
go mod tidy
env GOOS=linux GOARCH=arm GOARM=5 go build -o ./output/my_raspi_bink raspi_blink.go

Now you are ready to modify the example and test your changes. Start by removing the build directives at the beginning of the file.

Examples

Gobot with Arduino

package main

import (
  "time"

  "gobot.io/x/gobot/v2"
  "gobot.io/x/gobot/v2/drivers/gpio"
  "gobot.io/x/gobot/v2/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()
}

Gobot with Sphero

package main

import (
  "fmt"
  "time"

  "gobot.io/x/gobot/v2"
  "gobot.io/x/gobot/v2/platforms/sphero"
)

func main() {
  adaptor := sphero.NewAdaptor("/dev/rfcomm0")
  driver := sphero.NewSpheroDriver(adaptor)

  work := func() {
    gobot.Every(3*time.Second, func() {
      driver.Roll(30, uint16(gobot.Rand(360)))
    })
  }

  robot := gobot.NewRobot("sphero",
    []gobot.Connection{adaptor},
    []gobot.Device{driver},
    work,
  )

  robot.Start()
}

"Metal" Gobot

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:

package main

import (
  "gobot.io/x/gobot/v2/drivers/gpio"
  "gobot.io/x/gobot/v2/platforms/intel-iot/edison"
  "time"
)

func main() {
  e := edison.NewAdaptor()
  e.Connect()

  led := gpio.NewLedDriver(e, "13")
  led.Start()

  for {
    led.Toggle()
    time.Sleep(1000 * time.Millisecond)
  }
}

"Master" Gobot

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:

package main

import (
  "fmt"
  "time"

  "gobot.io/x/gobot/v2"
  "gobot.io/x/gobot/v2/api"
  "gobot.io/x/gobot/v2/platforms/sphero"
)

func NewSwarmBot(port string) *gobot.Robot {
  spheroAdaptor := sphero.NewAdaptor(port)
  spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
  spheroDriver.SetName("Sphero" + port)

  work := func() {
    spheroDriver.Stop()

    spheroDriver.On(sphero.Collision, func(data interface{}) {
      fmt.Println("Collision Detected!")
    })

    gobot.Every(1*time.Second, func() {
      spheroDriver.Roll(100, uint16(gobot.Rand(360)))
    })
    gobot.Every(3*time.Second, func() {
      spheroDriver.SetRGB(uint8(gobot.Rand(255)),
        uint8(gobot.Rand(255)),
        uint8(gobot.Rand(255)),
      )
    })
  }

  robot := gobot.NewRobot("sphero",
    []gobot.Connection{spheroAdaptor},
    []gobot.Device{spheroDriver},
    work,
  )

  return robot
}

func main() {
  master := gobot.NewMaster()
  api.NewAPI(master).Start()

  spheros := []string{
    "/dev/rfcomm0",
    "/dev/rfcomm1",
    "/dev/rfcomm2",
    "/dev/rfcomm3",
  }

  for _, port := range spheros {
    master.AddRobot(NewSwarmBot(port))
  }

  master.Start()
}

Hardware Support

Gobot has a extensible system for connecting to hardware devices. The following robotics and physical computing platforms are currently supported:

Support for many devices that use General Purpose Input/Output (GPIO) have a shared set of drivers provided using the gobot/drivers/gpio package:

  • GPIO <=> Drivers
    • AIP1640 LED Dot Matrix/7 Segment Controller
    • Button
    • Buzzer
    • Direct Pin
    • EasyDriver
    • Grove Button (by using driver for Button)
    • Grove Buzzer (by using driver for Buzzer)
    • Grove LED (by using driver for LED)
    • Grove Magnetic Switch (by using driver for Button)
    • Grove Relay (by using driver for Relay)
    • Grove Touch Sensor (by using driver for Button)
    • HC-SR04 Ultrasonic Ranging Module
    • HD44780 LCD controller
    • LED
    • Makey Button (by using driver for Button)
    • MAX7219 LED Dot Matrix
    • Motor
    • Proximity Infra Red (PIR) Motion Sensor
    • Relay
    • RGB LED
    • Servo
    • Stepper Motor
    • TM1638 LED Controller

Support for many devices that use Analog Input/Output (AIO) have a shared set of drivers provided using the gobot/drivers/aio package:

  • AIO <=> Drivers
    • Analog Actuator
    • Analog Sensor
    • Grove Light Sensor
    • Grove Piezo Vibration Sensor
    • Grove Rotary Dial
    • Grove Sound Sensor
    • Grove Temperature Sensor
    • Temperature Sensor (supports linear and NTC thermistor in normal and inverse mode)
    • Thermal Zone Temperature Sensor

Support for devices that use Inter-Integrated Circuit (I2C) have a shared set of drivers provided using the gobot/drivers/i2c package:

  • I2C <=> Drivers
    • Adafruit 1109 2x16 RGB-LCD with 5 keys
    • Adafruit 2327 16-Channel PWM/Servo HAT Hat
    • Adafruit 2348 DC and Stepper Motor Hat
    • ADS1015 Analog to Digital Converter
    • ADS1115 Analog to Digital Converter
    • ADXL345 Digital Accelerometer
    • BH1750 Digital Luminosity/Lux/Light Sensor
    • BlinkM LED
    • BME280 Barometric Pressure/Temperature/Altitude/Humidity Sensor
    • BMP180 Barometric Pressure/Temperature/Altitude Sensor
    • BMP280 Barometric Pressure/Temperature/Altitude Sensor
    • BMP388 Barometric Pressure/Temperature/Altitude Sensor
    • DRV2605L Haptic Controller
    • Generic driver for read and write values to/from register address
    • Grove Digital Accelerometer
    • GrovePi Expansion Board
    • Grove RGB LCD
    • HMC6352 Compass
    • HMC5883L 3-Axis Digital Compass
    • INA3221 Voltage Monitor
    • JHD1313M1 LCD Display w/RGB Backlight
    • L3GD20H 3-Axis Gyroscope
    • LIDAR-Lite
    • MCP23017 Port Expander
    • MMA7660 3-Axis Accelerometer
    • MPL115A2 Barometric Pressure/Temperature
    • MPU6050 Accelerometer/Gyroscope
    • PCA9501 8-bit I/O port with interrupt, 2-kbit EEPROM
    • PCA953x LED Dimmer for PCA9530 (2-bit), PCA9533 (4-bit), PCA9531 (8-bit), PCA9532 (16-bit)
    • PCA9685 16-channel 12-bit PWM/Servo Driver
    • PCF8583 clock and calendar or event counter, 240 x 8-bit RAM
    • PCF8591 8-bit 4xA/D & 1xD/A converter
    • SHT2x Temperature/Humidity
    • SHT3x-D Temperature/Humidity
    • SSD1306 OLED Display Controller
    • TSL2561 Digital Luminosity/Lux/Light Sensor
    • Wii Nunchuck Controller
    • YL-40 Brightness/Temperature sensor, Potentiometer, analog input, analog output Driver

Support for devices that use Serial Peripheral Interface (SPI) have a shared set of drivers provided using the gobot/drivers/spi package:

  • SPI <=> Drivers
    • APA102 Programmable LEDs
    • MCP3002 Analog/Digital Converter
    • MCP3004 Analog/Digital Converter
    • MCP3008 Analog/Digital Converter
    • MCP3202 Analog/Digital Converter
    • MCP3204 Analog/Digital Converter
    • MCP3208 Analog/Digital Converter
    • MCP3304 Analog/Digital Converter
    • MFRC522 RFID Card Reader
    • SSD1306 OLED Display Controller

More platforms and drivers are coming soon...

API

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.

To activate the API, import the gobot.io/x/gobot/v2/api package and instantiate the API like this:

  master := gobot.NewMaster()
  api.NewAPI(master).Start()

You can also specify the api host and port, and turn on authentication:

  master := gobot.NewMaster()
  server := api.NewAPI(master)
  server.Port = "4000"
  server.AddHandler(api.BasicAuth("gort", "klatuu"))
  server.Start()

You may access the robeaux React.js interface with Gobot by navigating to http://localhost:3000/index.html.

CLI

Gobot uses the Gort 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!

Documentation

We're always adding documentation to our web site at https://gobot.io/ please check there as we continue to work on Gobot

Thank you!

Need help?

Contributing

For our contribution guidelines, please go to https://github.com/hybridgroup/gobot/blob/master/CONTRIBUTING.md .

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.

License

Copyright (c) 2013-2020 The Hybrid Group. Licensed under the Apache 2.0 license.

The Contributor Covenant is released under the Creative Commons Attribution 4.0 International Public License, which requires that attribution be included.