The Bluetooth LE doc-a-thon at ITP Camp

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.

I’m currently in New York for this year’s ITP Camp, a 4 week unconference and technology playground for busy people. Held every June at ITP it brings together a diverse group of makers, artists, musicians, and creatives of all sorts—to make stuff, hear speakers at the cutting edge in technology and art, and collaborate with people they just wouldn’t normally meet.

All of us have been working with Bluetooth LE devices—along with Don and Sandeep I’m writing a book for Make: on Bluetooth LE, cellphones and sensors, while Guan and JB have a startup building Bluetooth LE devices—but all of us agreed that getting started using Bluetooth LE was much harder than it should be, and that a lot of great work people were doing was getting dropped on the floor (or worse yet done again) because people didn’t know it existed. We decided to sit down and do something about that.

How is Bluetooth LE different?

You’re probably used to thinking about radios as sort of like a serial connection working similarly to a phone call between two phones—once you establish a connection, each person talks as the other listens and vice versa. They stay connected, even if neither is saying anything, until one hangs up and the call is ended.

In systems like these, data is transferred using a queue, and when data is read by the receiver, it’s erased from the queue, just as once my words reach your ears over the phone, they’re out of the communications channel. Effectively this is how “Classic” Bluetooth works.

Bluetooth LE is very different. Instead of communicating via a point-to-point connection like a phone, a Bluetooth LE radio acts like a community bulletin board, with each radio acting as either a board or a reader of the board.

If your radio is a bulletin board—called a peripheral device in Bluetooth LE parlance—it posts data on its board for everyone in the community to read. If your radio is a reader—called a central device in Bluetooth LE terms—it can read from any of the boards (the peripheral devices) that have information which it cares about.

If you don’t like that analogy, you can also think of peripheral devices as the servers in a client-server transaction. Similarly, central devices are the clients of the Bluetooth LE world because they read information from the peripherals.

But I like serial connections?

Most (perhaps all?) of the Bluetooth LE radios breakout boards available to makers right now—the RedBearLab BLE mini and the Adafruit Bluefruit LE for instance—pretend to look like serial devices for simplicity’s sake and present a UART service to the user. Effectively these radios are “faking” old style serial communication on top of the underlying bulletin board paradigm. It’s a hack, and actually not a good hack.

While it simplifies things from the Arduino side of things, by using the radio in this way you’re negating the “low energy” part of Bluetooth LE. The radios will be constantly on all the time, and if your project is battery based, that’s a big problem.

Imagine a example where you want to control an LED connected to an Arduino board from our phone via Bluetooth LE. If we use a serial connection that connection will be open continuously, but it’s only going to get used periodically—when we send a 1 or a 0 over the air to the Arduino board to turn the LED on, or off.

As an alternative, you can heavily reduce the power consumption of your project by using Bluetooth LE like it’s supposed to be used and implementing a custom service for the radio connected to the Arduino to advertise its ability to turn the LED on or off.

Returning to our bulletin board example we’re creating a board (the service) which has a post-it note attached (known as a characteristic in Bluetooth LE parlance) which we can both read, letting us know if the LED is on or off, or write to—allowing us to control the LED.

Building a custom service

Unfortunately until recently building custom services for Bluetooth LE has actually been fairly complicated and not for the faint hearted. However it’s getting simpler as there’s now several good tools to do most of the heavy lifting for you.

In light of that we decided to look at one platform—the Nordic Semiconductor nRF8001 radio—and figure out a complete toolchain that would allow you to build a custom service for the radio, and make use of that service from an Arduino project. We picked this particular radio because it’s readily available and there is good library support.

The “smart light switch”

We wanted to build something with multiple services, so we decided to build a “smart” light switch where you could not just turn the light on, or off, via Bluetooth LE but get the current status of the light switch (which also could independently control the light) and get notified when the switch was toggled.

Controlling a light via Bluetooth LE.

The nice thing about this example is how simple it is, beyond the Arduino board and the nRF8001 radio—we decided to use the Adafruit Bluefruit LE breakout board—you really only need a few wires, resistors and other commonly available parts.

Building the services.h configuration file using nRFGo Studio is probably the trickiest part of the whole toolchain, and we spent a lot of time figuring out the easiest way to allow you to include the generated services.h file inside your Arduino project, instead of having to include it inside the nRF8001 Arduino library.

More details, and all the source code for the example projects, are available on Github as part of the documentation and code examples we put up during the doc-a-thon.

Conclusion

There now a huge number of off-the-shelf Bluetooth LE devices ranging from wearables to locks, from drones to lightbulbs—and of course the there’s always the now ubiquitous iBeacon—but there’s also a growing number of developer boards that mean making use of these off-the-shelf devices from your Arduino project (or becoming one) is also getting simpler. Hopefully our doc-a-thon is going to prove to be helpful to speed that process, and as it’s all up on Githubcontributions are of course very welcome.

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.