Posts tagged ubuntu
Using Android to control Lego Mindstorms
Feb 3rd
This is a short post on the more entertaining side of Android showing a project that the Enea team in Linköping, Sweden, prepared for an expo. It is a one minute video from the demonstration.
It is two LEGO Mindstorms robots controlled by one HTC Hero Android phone. The Hero is running an Android application written by Enea Linköping that send motor commands to the LEGO brick. LEGO has been kind enough to put a Bluetooth chip in the Mindstorms NXT controller. By using the built in demonstrational Bluetooth commands the NXT brick provides there is no need for an application to be downloaded into the NXT brick.
There was however one obstacle in the limited Bluetooth support in Android OS version 1.5 (not supporting the Bluetooth serial port profile, SPP). Instead we used the wifi capabilities on the phone to send information to an Ubuntu Linux Laptop with a TCP/IP to Bluetooth tunnel (just a raw tunnel, no logic or programming). HTC has been rumored to be releasing Android OS version 2.1 (with Bluetooth) later in february and we hope to be able to put forth a new version that skip the WiFi laptop step.
Video below:
Android Bluetooth in Eclair
Dec 28th

If you noticed the source code in Eclair branch, you will find few differences in Bluetooth function. There are three new git repositories for bluetooth. “bluez”, “glib” and “hcidump”, all of them are located in /external/bluetooth folder, not /external/bluez anymore.
Eclair is using bluez version 4.47 and the big difference would be bluez API. Since it has a lot of changes between bluez3 (android 1.6) and bluez4 (Android 2.0), we can tell from the documents in doc folder. Or we can use dbus-send to get the detailed information.
# dbus-send --system --type=method_call --print-reply --dest=org.bluez / org.bluez.Manager.DefaultAdaptermethod return sender=:1.2 -> dest=:1.3 object path "/org/bluez/932/hci0" # dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/932/hci0 org.freedesktop.DBus.Introspectable.Introspect
Also, bluetooth service name is changed in Eclair. It’s “bluetoothd” now. Check init.rc in /system/core/rootdir.
service bluetoothd /system/bin/bluetoothd -d -n socket bluetooth stream 660 bluetooth bluetooth socket dbus_bluetooth stream 660 bluetooth bluetooth # init.rc does not yet support applying capabilities, so run as root and # let bluetoothd drop uid to bluetooth with the right linux capabilities group bluetooth net_bt_admin misc disabled
glib
GLib provides the core application building blocks for libraries and applications written in C. It provides the core object system used in GNOME, the main loop implementation, and a large set of utility functions for strings and common data structures. If you are interested in how bluez use glib, you can trace bluez source code.
Bluetooth * Turn on/off Bluetooth * Device and service discovery * Connect to a remote device using RFCOMM and send/receive data * Advertise RFCOMM services and listen for incoming RFCOMM connection
What I am curious? It’s related to using RFCOMM and send/receive data. In the beginning, I am not quite understand and I thought it’s OBEX. After running Bluetooth Chat application, I know what it means now. I installed 0xlab experimental eclair image in Beagle board and installed Bluetooth chat example from Android. I also run a python script in my ubuntu machine and it’s from pybluez. Then, I can chat between Beagle board and my laptop via Bluetooth. When we start to run Bluetooth Chat application, it would create a RFCOMM socket and set it to listen mode. We can retrieve the information from sdptool. Then other BT devices can connect to Android using RFCOMM protocol and set channel to the same one.
# sdptool browse localBrowsing FF:FF:FF:00:00:00 ...Service Name: BluetoothChatService RecHandle: 0x10005Service Class ID List: UUID 128: fa87c0d0-afac-11de-8a39-0800200c9a66Protocol Descriptor List: "L2CAP" (0x0100) "RFCOMM" (0x0003) Channel: 30
![]() |
| From Collages |

