It is time to start playing with BLE, or Bluetooth Smart as it’s really called, now that Android supports it. I’ve bought the Bluegiga BLE113 dev kit and worked through the examples that come with it. It’s really quite cool and user friendly once you get past the initial barriers.
The BLE113 is a module with the TI CC2541 chip. They have made various tools and stacks that abstract the difficulties of making embedded applications, including the potentially quite expensive build tools. BLE-apps are quite large, because of the stack, which means that the free code-restricted version of IAR doesn’t apply. So Bluegiga made a BASIC-like scripting language and a tool that compiles the script into firmware and gets uploaded onto the BLE module. The concept is called BGScript, and is powerful enough to do some interesting projects in just a few lines of code. Unfortunately it’s proprietary to Bluegiga. I guess other vendors have similar concepts. Here’s a blog with some more detailed info on BGScript, but don’t do as he does and use the TI uploader. This will remove the Bluegiga license key, and you’ll have to email Bluegiga support to get a new one. Use the Bluegiga update tool instead.
Here is a short snippet of a BGScript. This is an interrupt handler which takes the IRQ mask and sends it using BLE to your listening device.
event hardware_io_port_status(delta, port, irq, state)
# Write I/O status to GATT
Every time you press P0.0 or P0.1, the IRQ fires, and the value 1 or 2 gets sent to the subscribing device. If you for example wanted to send the number 0×34 instead of the IRQ mask, the call would be “call attributes_write(xgatt_io,0,1,$34)“.
The xgatt_io is a parameter that is defined in an XML file, and can be read, written or subscribed to, based on the content of the XML definition. I’m showing below how you define the xgatt_io variable (some of the XML file is removed). You can see that the property can either be read directly from a device (read=”true”) or you can subscribe to notifications (notify=”true”). If I could write it, it would say write=”true”…
<characteristic uuid=”f1b41cde-dbf5-4acf-8679-ecb8b4dca6fe” id=”xgatt_io”>
<properties read=”true” notify=”true”/>
<value type=”hex” length=”1″></value>
BLE has two types of service ids (uuids), one short one for pre-defined services and a long one you can define yourself. In this case, I used a long one. If you for example were defining a heart rate monitor value, or a find-me gadget, you could use a predefined one (for example service uuid=”1802″).
In one evening, I’ve sent and received various values to my ipad, computer and Android phone, from the BLE dev kit. I’ve now also designed a small breakout-board and have ordered it from Elecrow, so I can play around with some smaller designs than the quite large development kit. I really think this can be a basis for quite a lot of cool projects. The next will be to play around with the Android APIs to make my own app.