Run homebridge as a service upon reboot

This post shows how to run homebridge automatically upon reboot using upstart.

Install upstart

sudo apt-get install upstart

Create configuration file /etc/init/homebridge.conf with

start on stopped rc
stop on shutdown

setuid pi

    export HOME="/home/pi"
    export NODE_PATH=$HOME/node_modules/
    gpio -g mode 27 out
    gpio -g mode 27 down
    gpio export 27 out
    exec /usr/local/bin/homebridge
end script

start on stopped rc ensures that avahi-daemon has been started by its SysV script under /etc/init.d before homebridge is started.

Test the job by running it thus

sudo start homebridge

Use the following command to check the output of the job

sudo tail -f /var/log/upstart/homebridge.log

The following command can be used to verify that homebridge job has been started

sudo initctl list | grep homebridge

To stop the above job

sudo stop homebridge

To run job as a service that will run automatically at boot

sudo service homebridge start

To stop the service forever

sudo service homebridge stop

Toggle GPIO on Raspberry Pi using HomeKit

In this post, I take my HomeKit Raspberry Pi integration a step further, by turning on/off a LED using the homebridge-gpio-wpi plugin. With the ability to control the GPIO pins, I should be able to turn on/off much bigger things using solid state relays and such.

Install homebridge-gpio-wpi

The installation should be pretty straightforward. Assuming you are at the command line in the home folder, run

npm install homebridge-gpio-wpi

That should install all node modules under ~/node_modules/.

Configure homebridge by editing ~/.homebridge/config.json. Here’s mine

    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:32",
        "port": 51826,
        "pin": "031-45-155"
    "description": "This has some fake accessories",

    "accessories": [
            "accessory":      "FakeBulb",
            "name":           "Test lamp",
            "bulb_name":      "Lamp 1"
            "accessory": "GPIO",
            "name": "GPIO2",
            "pin": 27

    "platforms": []

Configure GPIO2 using the gpio utility, and start homebridge

gpio -g mode 27 out
gpio -g mode 27 down
gpio export 27 out
export NODE_PATH=$HOME/node_modules/

See also how to run homebridge as a service upon reboot.

Test with HomeKit

If you’ve configured the Homebridge peripheral in an iOS app such as Hesperus, it should now show you a new device called GPIO2, and allow you to switch it on/off.


Hesperus allows you to create a schedule to turn on and off devices.


Embedded Linux system for BeagleBoard-xM with Yocto Project

I’ve mostly abandoned a BeagleBoard-xM that I have, and am using Raspberry Pi for most of my embedded Linux hacks. I have built a Linux system for BeagleBoard-xM using Yocto Project though, so thought I’d put the instructions out there.

I’m performing the following build on an Ubuntu 14.04 Parallels Desktop 9 VM. The steps below were mostly discovered from the Yocto Project Quick Start. Look there if you need further help.

The following dependencies are required on the build machine before you proceed

sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath libsdl1.2-dev xterm

Next, clone the the dora branch from the git repo of Yocto Project, and prepare the build environment

git clone -b dora
source poky/oe-init-build-env build

You’ll be in the the build folder when that is done.

Add the following to conf/local.conf

MACHINE ?= "beagleboard"

Go ahead and perform the build

bitbake core-image-minimal

After the build is done, grab and deploy the images from tmp/deploy/images/beagleboard.

Embedded Linux system for Raspberry Pi with Buildroot

This post shows how easy it is to make a custom embedded Linux system for Raspberry Pi using Buildroot. I used an Ubuntu 13.04 VM for Parallels Desktop 9 to perform the build.

The Ubuntu VM required only two dependencies and I could go ahead with the build. These I installed by executing

sudo apt-get install ncurses-dev git g++

I then obtained Buildroot release buildroot-2014.05.tar.gz and extracted it to a local folder using tar xvzf buildroot-2014.05.tar.gz. The procedure to perform the build and prepare an SD card is well documented in file board/raspberrypi/readme.txt.

I headed into the buildroot-2014.05 folder and prepared the appropriate .config file required by buildroot

cd buildroot-2014.05
make raspberrypi_defconfig

Since I wanted to generate a persistent root file system, I followed that by executing


The build takes a while to finish. Once done, I followed the steps in readme.txt mentioned above to prepare an SD card. I already had an appropriately formatted SD card so I copied the relevant output files

rm /media/parallels/boot/*
cp output/images/rpi-firmware/* /media/parallels/boot/
cp output/images/zImage /media/parallels/boot/
sudo rm -rf /media/parallels/fc254b57-8fff-4f96-9609-ea202d871acf/*
sudo tar xf output/images/rootfs.tar -C /media/parallels/fc254b57-8fff-4f96-9609-ea202d871acf/

I was able to boot Raspberry Pi with the newly minted headless embedded Linux system, use an HDMI display to log in, and bring up the ethernet interface eth0.

Monthly news review

This post begins a new series of monthly posts where I’ll review news of the month that has passed.

Facebook releases Paper for iOS

Before Paper, I was spending less time in Facebook and more time in FlipBoard. After Paper, I am spending less time in FlipBoard. FlipBoard still gives me more (still relevant) news than Paper, such as new and on-sale app recommendations. One curious fact, the Paper app was designed using a prototyping toolkit called Origami.

Google releases Cast SDK

This was also the month I bought a Chromecast, my first Android device purchase actually.

Here’s what I like about it:

  • Price
  • Ease of use
  • Cast content of any tab in Chrome, including videos, using the Google Cast extension
  • Over the air updates

Here’s what I don’t like about it:

  • Doesn’t ever go into sleep mode, so it is sucking power all the time
  • Not as many apps as there should be, but that should change quickly now

Telerik Platform

It’s a comprehensive platform for building cross-platform native, hybrid, and web applications. Developers can use Visual Studio, or a web-based IDE.

MasterCard and Visa endorse Host-based Card Emulation (HCE)

With this endorsement payment card information can now be stored in the cloud. An Android app can then communicate that information to a NFC reader.

Atmel releases beta of Atmel Studio 6.2

Atmel is steadily improving its unified IDE for AVR and ARM MCUs. This release improves debugging and tracing capabilities. I’ve been using the IDE on a continuous basis for AVR and Arduino-based projects, and find it to be quite a productive tool.

Broadcom releases source code of VideoCore driver stack

VideoCore is also used in their SoC that runs the Raspberry Pi. Releasing the source code should allow community driven improvements and fixes to proliferate.

Nokia releases an Android-based device

It doesn’t sport the Google Play store though. They are reportedly porting Windows Phone apps to Android using Xamarin. I love how Xamarin has been enabling .NET for cross-platform development.

Driving an LED with a Raspberry Pi

I recently began tinkering with a Raspberry Pi Model B rev2. This post shows how you can drive an LED using the GPIO pins on a Pi running Raspbian. If you are unfamiliar with Pi take a look at their quick start guide.

GPIO Pin Numbering

There are two ways to specify the GPIO you want to control. One is based on the numbering of the pin on the P1 connector, the other is based on the Broadcom SOC (BCM2835) GPIO numbering. For instance, pin 12 on P1 connector corresponds to pin GPIO18 on BCM2835.

This can be derived from the screenshots of the schematic below, and is also documented elsewhere on the internet for easier consumption.



RPi.GPIO Python module

The RPi.GPIO module is available on Raspbian. Let’s assume you connect the LED as shown below. I have come to realize that the current driven by GPIO is low enough, that you can drive the LED shown without need for a resistor in series.

Driving a LED using Pi (Fritzing)

This is how you can blink an LED using P1 connector pin numbering, on the command line.

sudo python
import RPi.GPIO as gpio
gpio.setup(12, gpio.OUT)
gpio.output(12, gpio.HIGH)
gpio.output(12, gpio.LOW)

This is how you do the same thing using BCM2835 GPIO numbering.

sudo python
import RPi.GPIO as gpio
gpio.setup(18, gpio.OUT)
gpio.output(18, gpio.HIGH)
gpio.output(18, gpio.LOW)

The project Wiki has many more examples.

Using GPIO filesystem

You can achieve the same result from the shell using the GPIO filesystem under /sys/class/gpio. The pin number needs to be the GPIO number specified for BCM2835. You cannot do PWM with this mechanism, except at very low frequencies.

sudo echo "18" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio18/direction
sudo echo "1" > /sys/class/gpio/gpio18/value
sudo echo "0" > /sys/class/gpio/gpio18/value
sudo echo "18" > /sys/class/gpio/unexport

The first two lines initialize and set the direction for GPIO18. The possible values for direction are “in” and “out”. This approach can be used from any programming language, using its text file input/output implementation.

If you have installed mono (sudo apt-get install mono-complete), you can use csharp shell to achieve the same results.

sudo csharp
using System.IO;
File.WriteAllText("/sys/class/gpio/export", "18");
File.WriteAllText("/sys/class/gpio/gpio18/direction", "out");
File.WriteAllText("/sys/class/gpio/gpio18/value", "1");
File.WriteAllText("/sys/class/gpio/gpio18/value", "0");
File.WriteAllText("/sys/class/gpio/unexport", "18");

The example above was inspired by the RaspberryPi.NET implementation.

Android on BeagleBoard-xM

I just crossed paths with a BeagleBoard-xM and thought I’d try Android on it. I tried pre-built binary images for Android 4.0.3 from Texas Instruments (TI), and Android 4.1.1 Jelly Bean image from project rowboat. The source code is available from gitorious.


Beagle is a set of embedded development boards that can run Android. The original BeagleBoard uses an OMAP 3 processor, specifically OMAP3530 with an ARM Cortex-A8 core running at 720 MHz. The BeagleBoard-xM uses the TI Sitara AM37x running at 1 GHz. I have Rev C of that board. The BeagleBone and BeagleBone Black use the TI Sitara AM335x.

Android 4.0.3 (Ice Cream Sandwich)

I downloaded the pre-built binary image, a part of TI Android Developer Kit.

Next, I used an Ubuntu 12.04 VM running in Parallels on a MacBook, and a MicroUSB USB adaptor, to write the binary image to a MicroSD card. The binary image includes a bash script that does the job

sudo ./ /dev/sdb

Change /dev/sdb to whatever device appears in dmesg | tail after you plug in the MicroSD card.

Some cursory findings follow

  1. Graphics acceleration looks good. Sample video in Gallery app plays well, but without any sound from audio out jack.
  2. Ethernet interface seems to be supported as device usb0, didn’t test it though.
  3. The Gallery app has some nice images, and the slideshow option shows images with the Ken Burns effect.
  4. adb with USB OTG connector does not seem to work. In fact the board does not appear on my MacBook.

Android 4.1.1 (Jelly Bean)

The pre-built binary for Jelly Bean is available from rowboat.

Findings are similar to the ones above. Surprisingly there is no Ethernet configuration under settings, so Ethernet needs to be started from the serial port shell

screen /dev/cu.usbserial 115200
netcfg usb0 up

It may probably work automatically if the ethernet cable is plugged in before the board boots up.

BeagleBone and BeagleBone Black

Pre-built Jelly Bean images for BeagleBone are available from TI and rowboat. There are no pre-built images for BeagleBone Black yet.