Using a Raspberry Pi 2 with Ubuntu Snappy installed we’re going to write a simple snap that will flash a piglow attached to the gpio pins.

If you want to skip these steps you can download the snap itself from here

1. A simple piglow flashing binary

To make things simple we’ll use go to produce a simple binary that will flash the legs of the piglow. We’re using go because the static compilation means our snap will have no dependencies to deal with. The code itself is small. https://github.com/mattyw/flasher I modified the piglow library I was using to get a bit more feedback about piglow errors, the change is trivial to revert should you need to.

2. Create the snap

The package structure is simple

1 2 3 4 5 ├── bin │ └── flasher └── meta ├── package.yaml └── readme.md

flasher is the binary I produced in step 1. The package.yaml just contains information about the snap:

1 2 3 4 5 name : hello-piglow version : 1.0.0 vendor : me binaries : - name : bin/flasher

Once you’ve got all this in place build it and send it over to your pi.

1 2 snappy build . snappy-remote --url = ssh://<ip-address>:22 install <snap-name>

3. On the Pi

You need to give your snap permission to access the i2c device

1 sudo snappy hw-assign hello-piglow.sideload /dev/i2c-1

4. You’re done

1 sudo hello-piglow.flasher

If all goes well you should have a flashing piglow