Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

An error occurred while submitting your form. Please try again or file a bug report. Close

  1. Blog
  2. Article

elopio
on 11 July 2017

Deploying robotic code as a single package across dev boards


I love playing with my prototyping boards. Here at Ubuntu, we are designing the core operating system to support every single-board computer and keep it safe, updated and simple. I've learned a lot about physical computing, but I always have a big problem when my prototype is done and I want to deploy it. I am working with a Raspberry Pi, a DragonBoard, and a BeagleBone. They are all very different, with different architectures, different pins, onboard capabilities and peripherals, and they can have different operating systems. When I started learning about this, I had to write 3 programs that were very different, if I wanted to try my prototype in all my boards.

Then I found Gobot, a framework for robotics and IoT that supports my three boards, and many more. One major benefit is that you can write all the software in the lovely and clean Go language. The Ubuntu store supports all their architectures too, and packaging Go projects with snapcraft is super simple. So we can combine all of this to make a single snap package that with the help of Gobot will work on every board, and deploy it to all the users of these boards through the snaps store. Let's dig into the code with a very simple example to blink an LED, first for the Raspberry PI only.

package main
import (
 "time"
 "gobot.io/x/gobot"
 "gobot.io/x/gobot/drivers/gpio"
 "gobot.io/x/gobot/platforms/raspi"
)
func main() {
 adaptor := raspi.NewAdaptor()
 led := gpio.NewLedDriver(adaptor, "7")
 work := func() {
   gobot.Every(1*time.Second, func() {
     led.Toggle()
   })
 }
 ro[bot := gobot.NewRobot("snapbot",
   []gobot.Connection{adaptor},
   []gobot.Device{led},
   work,
 )
 robot.Start()
}

In there you will see some of the Gobot concepts. There's an adaptor for the board, a driver for the specific device (in this case the LED), and a robot to control everything. In this program, there are only two things specific to the Raspberry Pi: the adaptor and the name of the GPIO pin ("7"). It works nicely in one of the boards, but let's extend the code a little to support the other two.

package main
import (
 "log"
 "os/exec"
 "strings"
 "time"
 "gobot.io/x/gobot"
 "gobot.io/x/gobot/drivers/gpio"
 "gobot.io/x/gobot/platforms/beaglebone"
 "gobot.io/x/gobot/platforms/dragonboard"
 "gobot.io/x/gobot/platforms/raspi"
)
func main() {
 out, err := exec.Command("uname", "-r").Output()
 if err != nil {
   log.Fatal(err)
 }
 var adaptor gobot.Adaptor
 var pin string
 kernelRelease := string(out)
 if strings.Contains(kernelRelease, "raspi2") {
   adaptor = raspi.NewAdaptor()
   pin = "7"
 } else if strings.Contains(kernelRelease, "snapdragon") {
   adaptor = dragonboard.NewAdaptor()
   pin = "GPIO_A"
 } else {
   adaptor = beaglebone.NewAdaptor()
   pin = "P8_7"
 }
 digitalWriter, ok := adaptor.(gpio.DigitalWriter)
 if !ok {
   log.Fatal("Invalid adaptor")
 }
 led := gpio.NewLedDriver(digitalWriter, pin)
 work := func() {
   gobot.Every(1*time.Second, func() {
   led.Toggle()
   })
 }
 robot := gobot.NewRobot("snapbot",
   []gobot.Connection{adaptor},
   []gobot.Device{led},
   work,
 )
 robot.Start()
}

We are basically adding in there a block to select the right adaptor and pin, depending on which board the code is running. Now we can compile this program, throw the binary in the board, and give it a try.

But we can do better. If we package this in a snap, anybody with one of the boards and an operating system that supports snaps can easily install it. We also open the door to continuous delivery and crowd testing. And as I said before, super simple, just put this in the snapcraft.yaml file:

name: gobot-blink-elopio
version: master
summary: Blink snap for the Raspberry Pi with Gobot
description: |
 This is a simple example to blink an LED in the Raspberry Pi
 using the Gobot framework.
confinement: devmode
apps:
 gobot-blink-elopio:
 command: gobot-blink

parts:
 gobot-blink:
 source: .
 plugin: go
 go-importpath: github.com/elopio/gobot-blink

To build the snap, here is a cool trick thanks to the work that kalikiana recently added to snapcraft. I'm writing this code in my development machine, which is amd64. But the raspberry pi and beaglebone are armhf, and the dragonboard is arm64; so I need to cross-compile the code to get binaries for all the architectures:

$ snapcraft --target-arch=armhf
$ sncapcraft clean
$ snapcraft --target-arch=arm64

That will leave two .snap files in my working directory that then I can upload to the store with snapcraft push. Or I can just push the code to GitHub and let build.snapcraft.io to take care of building and pushing for me. Here is the source code for this simple example: https://github.com/elopio/gobot-blink

Of course, Gobot supports many more devices that will let you build complex robots. Just take a look at the documentation in the Gobot site, and at the guide about deployable packages with Gobot and snapcraft. If you have one of the boards I'm using here to play, give it a try:

$ sudo snap install gobot-blink-elopio --edge --devmode
$ sudo gobot-blink-elopio

Now my experiments will be to try make the snap more secure, with strict confinement. If you have any questions or want to help, we have a topic in the forum.

Related posts


Miguel Divo
19 January 2026

Showcasing open design in action: Loughborough University design students explore open source projects

Design Article

Last year, we collaborated with two design student teams from Loughborough University in the UK. These students were challenged to work on open source project briefs. Team 1 focused on non-code contributions, while Team 2’s brief was to create a unified documentation experience, giving them a chance to apply their design skills to real-wo ...


Canonical
15 January 2026

Canonical Ubuntu and Ubuntu Pro now available on AWS European Sovereign Cloud

Ubuntu Article

Canonical announced it is a launch partner for the AWS European Sovereign Cloud, with Ubuntu and Ubuntu Pro now available. This new independent cloud for Europe enables organizations to run secure, enterprise workloads with full operational autonomy and EU data residency. By combining the performance and expanded security coverage of Ubun ...


Lidia Luna Puerta
14 January 2026

How to build DORA-ready infrastructure with verifiable provenance and reliable support

Ubuntu Article

DORA requires organizations to know what they run, where it came from, and how it’s maintained. Learn how to build infrastructure with verifiable provenance. ...