Sunday, May 21, 2017

Android/BeagleBone interaction via Bluetooth RFCOMM

In this posting I will demonstrate how to connect between an Android phone and a BeagleBone Black Wireless (BBBW) using bluetooth RFCOMM (basically a wireless RS-232 link).

For this demonstration I have created an Android application which
  1. discovers bluetooth devices
  2. connects to a bluetooth device
  3. toggles LED connected to bluetooth device
The BBBW hosts a python application which accepts a connection request and manages three LED which are remotely controlled from the Android application.

BBBW Preparation

  1. Flash your BBBW w/the latest image, currently  bone-debian-8.7-iot-armhf-2017-03-19-4gb.img
  2. apt-get update; apt-get upgrade
  3. apt-get install python-bluez
  4. Pull the python sources from github
  5. Add green/red/yellow LED to BBGW.  You can changes the port assignments in perky_blue.py
    LEDGPIO
    green48
    red49
    yellow60
  6. As root, make BBBW discoverable for bluetooth by invoking bluetoothctl(1)
  7.  You might see an error like the screenshot below:
  8. If so, you need to tweak /etc/systemd/system/dbus-org.bluez.service.   Change this line:  ExecStart=/usr/lib/bluetooth/bluetoothd  to ExecStart=/usr/lib/bluetooth/bluetoothd -C Save the file and reboot.  Start again at item 6.
  9. BBBW should now be ready for Android commands.

Android Preparation

  1. Pull the source from github 
  2. Compile using Android Studio and deploy to phone.
  3. Ensure bluetooth is enabled on your phone
  4. Start the application ("PerkyBlue")
  5. Press "Start Discovery" and wait ~20 seconds for completion.
  6. Usually the host name is "beaglebone" (in this case it is "porkchop").  Press on the host to connect.  When connection succeeds you will see both the Android app and the python app update.
  7. You can now press for red/yellow/green LED toggle, the corresponding LED should light on BeagleBone.

No comments:

Post a Comment