Friday, May 2, 2014

Get Started with Bluetooth Low Energy

This tutorial will show you how to develop an application with Bluetooth Low Energy and do something useful. Going through all the steps in this post will take between 30-60 minutes, depending on if you run into any issues. Bluetooth Low Energy (aka BLE) is all the rage right now, and rightfully so, as it is an easy to use low power RF communications protocol. All the new iPhones and some Android phones incorporate a BLE radio, so you can now easily design RF peripherals to communicate with the iPhone.

I like to use a module for BLE because it is easier and less expensive for quantities less than 10k. For this post I'm trying out the Anaren BLE Module which is available on a Development kit from Digikey for $60. You will also need a Texas Instruments Launchpad. I'm using the TI Tiva Launchpad which available from Digikey for about $14. These are so cheap that I recommend buying two. Below is a picture of the Anaren Board mounted on the Tiva Development Board.
 For this tutorial, you will need:
  • Anaren BLE Development Kit
  • Mini-USB cable for above (comes with the kit)
  • Texas Instruments Tiva Launchpad
  • Micro-USB cable for above (comes with the kit)
  • iPhone, 4S or later to run phone examples
  • iPhone apps "Em-Blinker" & "Em-Browser", available for free from the App Store
  • Basic knowledge of C

Hardware Connections

First, mate the two boards as shown above. Next, connect the Tiva's "Debug" USB port to your computer. Be sure that the slider switch is in the "DEBUG" position. Finally connect the "Admin UART" USB port on the Anaren Board to your computer.

Get the Software

The Anaren module uses a framework from Emmoco to make development easier. Go to www.em-hub.com. You will need to create an account to be able to download the software. Click on the "Sign-Up" link. The access code that it wants is printed on a sticker on the Anaren board. It is on the black connector, on the far left of the above image. Enter that code and your other information. Next, click on the "Downloads" link and select v13, and then "Em-Builder IDE Container" for your operating system.

Install the Software

After it downloads, install the software. It will also install some drivers too. When you first start the application it will look rather empty, like below.
Now we'll follow along the instructions in the left pane. Select Help > Em-Builder > Em-Hub Credentials and enter the same username and password you used to create your account.

Update Development Board Firmware

Next, you'll connect to the board and update the firmware. The hardest part on this step is figuring out which serial port is used for the "UART-ADMIN" port. I tried each of them but figured out finally that it was COM75 on mine. If the application is showing an error, then one thing to try is to press the "MCU Reset SOC" button on the Anaren Board; that allowed the two devices to connect. This took me awhile to figure out.

Once you have updated the firmware, it will be happy:
If you want, you can also change the name of the device here. Call it "SHAMU" or whatever you would like as long as it's all upper case. Now we're done updating the module firmware. If you want, you can remove the USB cable from the "ADMIN UART" port now.

Get the Example Projects

Now we need to import some examples so that we can start playing with them. GO to File > Import > Em-Builder > Example Projects, and select EK-TM4C123GXL as shown below.



Now, the application should have a few example projects:

Running an Example Application

Now we are ready to do something useful. Be sure that the USB cable to the Tiva board is connected to your computer. Right-click on the "Blinker-EK-TM4C123GXL" example and select "Run Em-Builder Example". It should compile and build, as shown below.
Now, open the "Em-Blinker" application on your phone. It should look something like below:
It doesn't do anything yet, you need to tell it to connect to your board. Press the button in the upper right corner to select the board. Previously we named our board "SHAMU" so we select that one. On the Tiva board, the Red LED should illuminate to indicate that it is connected to a phone.
Now, press "Start" or "On" depending on your version of Em-Blinker, and you should now see the blue LED on the Tiva board blink.

Conclusion

In this tutorial we started from zero and ended with a phone connected to our embedded device. Next time we'll look at making our own application.

No comments:

Post a Comment