Bluetooth

From ArmadeusWiki
Revision as of 15:32, 18 December 2013 by SebastienSz (Talk | contribs) (Controlling your board from an android device via (rfcomm))

Jump to: navigation, search

This page will give you all the informations needed to have a running Bluetooth configuration on your Armadeus board.

Hardware

First you have to get a compatible hardware. Currently there are 3 solutions:

  • You have an APF51Dev board, then you're a lucky man because Bluetooth is integrated on the board ;-)
  • If you have an APF27Dev, then you can get a Wireless extension board with WiFi/Bluetooth option from ARMadeus Systems
  • Otherwise: get a cheap USB<->Bluetooth adapter (requires an USB Host port) or a RS232<->Bluetooth adapter

Tested USB adapters

Model Status
APF9328 / APF27
Chipset Comments
BELKIN - Mini Bluetooth Adapter Belkin Mini Bluetooth.jpg TBT KO Product: BLUETOOTH USB +EDR ADAPTER v2.1 UHE
Manufacturer: Broadcom Corp
# hciconfig hci1 up piscan

btusb_submit_intr_urb: hci1 urb c3bdac40 submission failed (28)
Can't init device hci1: Input/output error (5)

TRUST - Bluetooth 2.1 USB Adapter Trust Small Bluetooth.jpg TBT KO Product: BCM2046B1
Manufacturer: Broadcom
# hciconfig hci1 up piscan

btusb_submit_intr_urb: hci1 urb c3bdac40 submission failed (28)
Can't init device hci1: Input/output error (5)

RUEDUCOMMERCE - Mini adaptateur USB Bluetooth RDC USB Bluetooth.jpg TBT OK Manufacturer: Cambridge Silicon Radio
GIGABYTE - GN-BTD01 Gigabyte gn-btd01.jpg TBT OK Manufacturer: Cambridge Silicon Radio Bluetooth 1.1 ?
BELKIN - F8T003 v2 TBT OK Manufacturer: Cambridge Silicon Radio
D-LINK - DBT-122 TBT OK Product: BCM2035
Manufacturer: Broadcom


Software

Bluetooth Linux stack is divided into several parts:

  • kernel drivers
  • userland libraries/daemon (bluez)

Driver installation

$ make linux-menuconfig
[*] Networking support  --->
    <M>   Bluetooth subsystem support  --->
        --- Bluetooth subsystem support
            <M>   L2CAP protocol support 
            <M>   SCO links support
            <M>   RFCOMM protocol support
                [*]     RFCOMM TTY support
            <M>   BNEP protocol support
                [ ]     Multicast filter support (NEW)
                [ ]     Protocol filter support (NEW)
            <M>   HIDP protocol support
            Bluetooth device drivers  --->
                <M> HCI USB driver 
                < > HCI SDIO driver (NEW)
                <M> HCI UART driver
                    [*]   UART (H4) protocol support 
                    [*]   BCSP protocol support 
                    [ ]   HCILL protocol support (NEW)
                < > HCI BCM203x USB driver (NEW)
                < > HCI BPA10x USB driver (NEW)
                < > HCI BlueFRITZ! USB driver (NEW)
                < > HCI VHCI (Virtual HCI device) driver (NEW)
$ make

Bluez installation

(Done by default on APF51)

$ make menuconfig
Package Selection for the target  --->
    ...
    [*] XML handling  --->
        [*]   libxml2
    ...
    [*] Hardware handling  --->
        [*]   dbus
              XML library to use (libxml2)
    ...
    Networking applications  --->
    [*] bluez
    [*] bluez-utils
$ make

Custom Bring up (each hardware may have a different init sequence)

APF51Dev

  • APF51Dev has a CSR BlueCore 4 chipset connected to the i.MX51 UART3 (ttymxc1)
  • Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver:
# /usr/sbin/bluetoothd
# /usr/sbin/hciattach -s 115200 ttymxc1 csr 115200

CSR build ID 0x00-0x37
Bluetooth: Core ver 2.15
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: HCI UART driver ver 2.2
Bluetooth: HCI H4 protocol initialized
Bluetooth: HCI BCSP protocol initialized

APF27Dev + APW

  • APW has a CSR BlueCore 4 chipset connected to the i.MX27 serial port ttySMX5 (UART6)
  • Reset it:
# source /usr/bin/gpio_helpers.sh
# gpio_mode PB14 1
# gpio_set_value PB14 0; sleep 1; gpio_set_value PB14 1; sleep 1
  • Attach it to the kernel bluez UART driver:
# /usr/sbin/hciattach -s 921600 ttySMX5 csr 921600

USB module

  • Make sure your hardware is connected to the APF. If using an USB dongle, load corresponding driver:
# modprobe btusb
Bluetooth: Core ver 2.14
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: Generic Bluetooth USB driver ver 0.4
usbcore: registered new interface driver btusb

Common Bring up

  • Check if Bluetooth interface was detected:
# hciconfig
hci0:   Type: USB or UART
        BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
        DOWN
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:0 acl:0 sco:0 commands:0 errors:0
  • If interface is DOWN, bring it up:
# hciconfig hci0 up piscan
  • Check your Bluetooth device is correctly initialized:
# hcitool dev
Devices:
        hci0    00:10:60:D1:92:0F

Usage

Scanning network

  • To get surrounding devices addresses and names:
# hcitool scan
Scanning ...
  • To get surrounding devices addresses and classes:
# hcitool inq
Inquiring ...

Get info on a given device

# hcitool info 00:19:0E:xx:xx:xx
...

Pinging other devices

# l2ping 00:19:0E:xx:xx:xx
Ping: 00:19:0E:xx:xx:xx from 00:19:88:xx:xx:xx (data size 44) ...
44 bytes from 00:19:0E:xx:xx:xx id 0 time 38.05ms
44 bytes from 00:19:0E:xx:xx:xx id 1 time 37.09ms
...

Here 00:19:0E:xx:xx:xx is the Bluetooth MAC address of the Host.

Advanced usages

Setup a Terminal between a PC and your APF through Bluetooth

On the APF :

  • the first step is to create the corresponding node for the future connection:
# mknod /dev/rfcomm0 c 216 0
  • then, listen to an incoming connection, on the rfcomm0 (here channel 7 is choosen):
# rfcomm -i hci0 listen /dev/rfcomm0 7 &
  • and the last step, when the connection is open, is to connect a terminal (through getty) to the device /dev/rfcomm0:
# getty 38400 /dev/rfcomm0

On the PC :

  • after the two first steps on the APF, you need to connect the PC to the APF with the same channel (7):
$ rfcomm connect 0 00:19:88:2B:xx:xx 7             (replace 00:19:88:2B:xx:xx with the Bluetooth @ of your APF)
  • and configure minicom ($HOME/.minirc.dfl):
pu port             /dev/rfcomm0
pu baudrate         38400
pu bits             8
pu parity           N
pu stopbits         1
  • when getty is running on the APF, you could you connect with minicom:
$ minicom -o
  • it could be a good idea to create an additional user account for remotely login through Bluetooth, by following these instructions.

Using a Bluetooth keyboard on your APF

The only thing needed after having a bluetooth correctly configured is to use this command :

$ hidd --connect keyboard_bdaddr

Controlling your board from an android device (using rfcomm)

The following section shows how to send commands to the board from an android device via Bluetooth. The goal is to control the two leds present on the board from an app on the tablet. An APF51dev and a Samsung Galaxy Tab 2 are used in this example.

On the APF

  • Enable the SPP profile. Here, it is using the channel 1.
# sdptool add --channel=1 SP
Serial Port service registered
#
  • Listen incomming connections on the channel 1. The script serial-server.sh is located in demos/android_remote_controller.
# rfcomm listen hci0 1 ./serial-server.sh {}
Waiting for connection on channel 1

On the android device

  • Deploy the app on your device. The app is located in demos/android_remote_controller.
  • Start the app.
  • Enjoy :-)

Others

Links