Difference between revisions of "Bluetooth"
SebastienSz (Talk | contribs) (→Controlling your board from an android device via (rfcomm)) |
SebastienSz (Talk | contribs) (Add OPOS8MM to bring up section) |
||
(45 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
==Hardware== | ==Hardware== | ||
− | First you have to get a compatible hardware. Currently there are | + | First you have to get a compatible hardware. Currently there are 6 solutions: |
+ | * You have an [[OPOS8MM]] or an [[OPOS6UL]] board with the Wi-Fi/Bluetooth chip integrated. | ||
+ | * You have an [[APF6]] board with the Wi-Fi/Bluetooth chip integrated. The chip is on the [[APF6]] Dual and Quad boards by default. | ||
* You have an [[APF51Dev]] board, then you're a lucky man because Bluetooth is integrated on the board ;-) | * 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 | + | * If you have an [[APF27Dev]], then you can get a [[Wireless extension board]] with Wi-Fi/Bluetooth option from Armadeus Systems |
* Otherwise: get a cheap USB<->Bluetooth adapter (requires an USB Host port) or a RS232<->Bluetooth adapter | * Otherwise: get a cheap USB<->Bluetooth adapter (requires an USB Host port) or a RS232<->Bluetooth adapter | ||
Line 39: | Line 41: | ||
===Driver installation=== | ===Driver installation=== | ||
− | * (Done by default on [[APF27]] | + | * (Done by default on [[APF27]], [[APF51]], [[APF6]] and [[OPOS6UL]]) |
<pre class="host"> | <pre class="host"> | ||
$ make linux-menuconfig | $ make linux-menuconfig | ||
Line 72: | Line 74: | ||
===Bluez installation=== | ===Bluez installation=== | ||
− | (Done by default on [[APF51]]) | + | (Done by default on [[APF51]], [[APF6]] and [[OPOS6UL]]) |
<pre class="host"> | <pre class="host"> | ||
$ make menuconfig | $ make menuconfig | ||
Line 95: | Line 97: | ||
==Custom Bring up (each hardware may have a different init sequence)== | ==Custom Bring up (each hardware may have a different init sequence)== | ||
+ | |||
+ | ===OPOS8MM=== | ||
+ | |||
+ | OPOS8MM has a Bluetooth chip connected to the i.MX8MM UART2 (''/dev/ttymxc2''). | ||
+ | |||
+ | * Start the Bluetooth deamon | ||
+ | <pre class="apf"> | ||
+ | # /usr/libexec/bluetooth/bluetoothd & | ||
+ | # | ||
+ | </pre> | ||
+ | |||
+ | * Power on the chip. | ||
+ | <pre class="apf"> | ||
+ | # gpioset 2 16=1 | ||
+ | </pre> | ||
+ | |||
+ | * Attach the chip. | ||
+ | <pre class="apf"> | ||
+ | # btattach -B /dev/ttymxc1 -P bcm -S 921600 & | ||
+ | Attaching Primary controller to /dev/ttymxc1 | ||
+ | Switched line discipline from 0 to 15 | ||
+ | Device index 0 attached | ||
+ | Bluetooth: hci0: BCM: chip id 107 | ||
+ | Bluetooth: hci0: BCM: features 0x2f | ||
+ | Bluetooth: hci0: BCM4345C0 | ||
+ | Bluetooth: hci0: BCM4345C0 (003.001.025) build 0000 | ||
+ | Bluetooth: hci0: BCM4345C0 (003.001.025) build 0127 # this message takes few seconds to appear | ||
+ | # | ||
+ | </pre> | ||
+ | |||
+ | * [[Bluetooth#Common Bring up|Go to "Common Bring up" section]] | ||
+ | |||
+ | ===OPOS6UL=== | ||
+ | {| border="1" cellpadding="5" cellspacing="0" summary="put summary here" | ||
+ | |- style="background:#efefef;" align="center" | ||
+ | ! width="50%" | OPOS6UL !! width="50%" | OPOS6ULNANO | ||
+ | |- | ||
+ | | OPOS6UL has a CM-43438 chip (based on BCM43438), connected to the i.MX6UL UART8 (''/dev/ttymxc7'') | ||
+ | | OPOS6ULNANO has a Murata module with CYM4343 chipset, connected to the i.MX6UL UART3 (''/dev/ttymxc2'') | ||
+ | |- | ||
+ | | <pre class="apf"># export BTRESET=42</pre> <pre class="apf"># export BTDEV=/dev/ttymxc7</pre> | ||
+ | | <pre class="apf"># export BTRESET=99</pre> <pre class="apf"># export BTDEV=/dev/ttymxc2</pre> | ||
+ | |} | ||
+ | |||
+ | * Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver: | ||
+ | <pre class="apf"> | ||
+ | # /usr/libexec/bluetooth/bluetoothd & | ||
+ | # | ||
+ | </pre> | ||
+ | |||
+ | * Wake up the chip | ||
+ | <pre class="apf"> | ||
+ | # echo $BTRESET > /sys/class/gpio/export | ||
+ | # echo out > /sys/class/gpio/gpio$BTRESET/direction | ||
+ | # echo 0 > /sys/class/gpio/gpio$BTRESET/value | ||
+ | # sleep 1 | ||
+ | # echo 1 > /sys/class/gpio/gpio$BTRESET/value | ||
+ | # sleep 1 | ||
+ | </pre> | ||
+ | |||
+ | * Attach the chip. Before running the following command, be sure that the file ''/etc/firmware/BCM43430A1.hcd'' exists (if not, it can be obtained (wget) [https://github.com/OpenELEC/misc-firmware/blob/master/firmware/brcm/BCM43430A1.hcd here ?] or [https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth here]) ! | ||
+ | <pre class="apf"> | ||
+ | # hciattach -t 30 $BTDEV bcm43xx 921600 flow | ||
+ | bcm43xx_init | ||
+ | Set Controller UART speed to 921600 bit/s | ||
+ | Flash firmware /etc/firmware/BCM43430A1.hcd | ||
+ | Set Controller UART speed to 921600 bit/s | ||
+ | Device setup complete | ||
+ | # | ||
+ | </pre> | ||
+ | * To choose bluetooth MAC address, add it to ''hciattach'' command | ||
+ | <pre class="apf"> | ||
+ | # hciattach -t 30 $BTDEV bcm43xx 921600 flow bdaddr 11:22:33:44:55:66 | ||
+ | </pre> | ||
+ | * [[Bluetooth#Common Bring up|Go to "Common Bring up" section]] | ||
+ | |||
+ | ===APF6=== | ||
+ | * APF6 has a jorjin chip connected to the i.MX6 UART2 (ttymxc1) | ||
+ | |||
+ | * Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver: | ||
+ | <pre class="apf"> | ||
+ | # /usr/sbin/bluetoothd | ||
+ | NET: Registered protocol family 31 | ||
+ | Bluetooth: HCI device and connection manager initialized | ||
+ | Bluetooth: HCI socket layer initialized | ||
+ | Bluetooth: L2CAP socket layer initialized | ||
+ | Bluetooth: SCO socket layer initialized | ||
+ | Bluetooth: BNEP (Ethernet Emulation) ver 1.3 | ||
+ | Bluetooth: BNEP socket layer initialized | ||
+ | </pre> | ||
+ | |||
+ | or if you are using BlueZ 5 | ||
+ | <pre class="apf"> | ||
+ | # /usr/libexec/bluetooth/bluetoothd & | ||
+ | </pre> | ||
+ | |||
+ | * Wake up the chip | ||
+ | <pre class="apf"> | ||
+ | # export BTRESET=43 | ||
+ | # echo $BTRESET > /sys/class/gpio/export | ||
+ | # echo out > /sys/class/gpio/gpio$BTRESET/direction | ||
+ | # echo 0 > /sys/class/gpio/gpio$BTRESET/value | ||
+ | # sleep 1 | ||
+ | # echo 1 > /sys/class/gpio/gpio$BTRESET/value | ||
+ | # sleep 1 | ||
+ | </pre> | ||
+ | |||
+ | * Attach the chip. Before running the following command, be sure that the file ''/lib/firmware/TIInit_7.6.15.bts'' exists ! You can download it [https://github.com/TI-ECS/bt-firmware/blob/master/TIInit_7.6.15.bts here] (click on the 'Raw' button) | ||
+ | <pre class="apf"> | ||
+ | # /usr/sbin/hciattach -s 115200 ttymxc1 texas 115200 | ||
+ | Found a Texas Instruments' chip! | ||
+ | Firmware file : /lib/firmware/TIInit_7.6.15.bts | ||
+ | Loaded BTS script version 1 | ||
+ | Device setup complete | ||
+ | |||
+ | # | ||
+ | </pre> | ||
+ | |||
+ | * [[Bluetooth#Common Bring up|Go to "Common Bring up" section]] | ||
===APF51Dev=== | ===APF51Dev=== | ||
* [[APF51Dev]] has a CSR BlueCore 4 chipset connected to the i.MX51 UART3 (ttymxc1) | * [[APF51Dev]] has a CSR BlueCore 4 chipset connected to the i.MX51 UART3 (ttymxc1) | ||
+ | |||
+ | * On recent kernel using device tree, you have to "wake up" the chip: | ||
+ | <pre class="apf"> | ||
+ | # export BTRESET=60 | ||
+ | # echo $BTRESET > /sys/class/gpio/export | ||
+ | # echo out > /sys/class/gpio/gpio$BTRESET/direction | ||
+ | # echo 0 > /sys/class/gpio/gpio$BTRESET/value | ||
+ | # sleep 1 | ||
+ | # echo 1 > /sys/class/gpio/gpio$BTRESET/value | ||
+ | # sleep 1 | ||
+ | </pre> | ||
+ | |||
* Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver: | * Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver: | ||
<pre class="apf"> | <pre class="apf"> | ||
Line 112: | Line 245: | ||
Bluetooth: HCI BCSP protocol initialized | Bluetooth: HCI BCSP protocol initialized | ||
</pre> | </pre> | ||
+ | |||
* [[Bluetooth#Common Bring up|Go to "Common Bring up" section]] | * [[Bluetooth#Common Bring up|Go to "Common Bring up" section]] | ||
Line 141: | Line 275: | ||
==Common Bring up== | ==Common Bring up== | ||
− | * | + | * Now that your hardware Bluetooth interface is up, check if it was correctly detected by BlueZ: |
<pre class="apf"> | <pre class="apf"> | ||
# hciconfig | # hciconfig | ||
Line 159: | Line 293: | ||
Devices: | Devices: | ||
hci0 00:10:60:D1:92:0F | hci0 00:10:60:D1:92:0F | ||
+ | </pre> | ||
+ | * From Bluez5, everything can now be done with ''bluetoohctl'' interactive command: | ||
+ | <pre class="apf"> | ||
+ | # bluetoothctl | ||
+ | [NEW] Controller 5C:F3:70:34:D6:66 BlueZ 5.43 [default] | ||
+ | [bluetooth]# power on | ||
+ | Changing power on succeeded | ||
+ | [CHG] Controller 5C:F3:70:34:D6:66 Powered: yes | ||
+ | |||
+ | [bluetooth]# scan on | ||
+ | Discovery started | ||
+ | [CHG] Controller 5C:F3:70:34:D6:66 Discovering: yes | ||
+ | |||
+ | [bluetooth]# agent on | ||
+ | Agent registered | ||
</pre> | </pre> | ||
Line 190: | Line 339: | ||
Here 00:19:0E:xx:xx:xx is the Bluetooth MAC address of the Host. | Here 00:19:0E:xx:xx:xx is the Bluetooth MAC address of the Host. | ||
− | == | + | ===Change advertising name=== |
− | ===Setup a Terminal between a PC and your APF through Bluetooth | + | * to change your module's name on Bluetooth network: |
− | On the APF | + | <pre class="apf"> |
+ | # hciconfig hci0 name ARMADEUS | ||
+ | </pre> | ||
+ | * From bluez5, you can also specify advertising name in ''/etc/bluetooth/main.conf'' file (%h = hostname, %d = device number): | ||
+ | <pre class="apf"> | ||
+ | [General] | ||
+ | Name = OPOS | ||
+ | </pre> | ||
+ | or specify it from ''bluetoothctl'' tool: | ||
+ | <pre class="apf"> | ||
+ | # bluetoothctl | ||
+ | [bluetooth]# system-alias OPOSxxx | ||
+ | </pre> | ||
+ | |||
+ | ==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: | * the first step is to create the corresponding node for the future connection: | ||
<pre class="apf"> | <pre class="apf"> | ||
# mknod /dev/rfcomm0 c 216 0 | # mknod /dev/rfcomm0 c 216 0 | ||
</pre> | </pre> | ||
− | * then, listen to an incoming connection, on the rfcomm0 (here channel 7 is | + | * then, listen to an incoming connection, on the ''rfcomm0'' (here channel 7 is chosen): |
<pre class="apf"> | <pre class="apf"> | ||
# rfcomm -i hci0 listen /dev/rfcomm0 7 & | # rfcomm -i hci0 listen /dev/rfcomm0 7 & | ||
</pre> | </pre> | ||
+ | {{Note|If RFCOMM protocol is not built statically in your kernel, you might need to load it before use with: <pre class="apf"># modprobe rfcomm </pre>}} | ||
+ | |||
+ | {{Note|If you plan to connect from your smartphone, don't specify a channel number as most apps will try to connect to channel 1: <pre class="apf"># rfcomm -i hci0 listen /dev/rfcomm0 &</pre>}} | ||
* and the last step, when the connection is open, is to connect a terminal (through getty) to the device ''/dev/rfcomm0'': | * and the last step, when the connection is open, is to connect a terminal (through getty) to the device ''/dev/rfcomm0'': | ||
<pre class="apf"> | <pre class="apf"> | ||
Line 206: | Line 373: | ||
</pre> | </pre> | ||
− | On | + | ===On your Host PC=== |
− | *after the two first steps on the APF, you need to connect the PC to the APF with the same channel (7): | + | * after the two first steps on the APF, you need to connect the PC to the APF with the same channel (7): |
<pre class="host"> | <pre class="host"> | ||
$ rfcomm connect 0 00:19:88:2B:xx:xx 7 (replace 00:19:88:2B:xx:xx with the Bluetooth @ of your APF) | $ rfcomm connect 0 00:19:88:2B:xx:xx 7 (replace 00:19:88:2B:xx:xx with the Bluetooth @ of your APF) | ||
</pre> | </pre> | ||
− | * and configure minicom (''$HOME/.minirc.dfl''): | + | * and configure ''minicom'' (''$HOME/.minirc.dfl''): |
pu port /dev/rfcomm0 | pu port /dev/rfcomm0 | ||
pu baudrate 38400 | pu baudrate 38400 | ||
Line 217: | Line 384: | ||
pu parity N | pu parity N | ||
pu stopbits 1 | pu stopbits 1 | ||
− | * when getty is running on the APF, you could you connect with minicom: | + | * when ''getty'' is running on the APF/OPOS, you could you connect with ''minicom'': |
<pre class="host"> | <pre class="host"> | ||
$ minicom -o | $ minicom -o | ||
</pre> | </pre> | ||
* it could be a good idea to create an additional user account for remotely login through Bluetooth, by following [[Adding_users|these instructions]]. | * it could be a good idea to create an additional user account for remotely login through Bluetooth, by following [[Adding_users|these instructions]]. | ||
− | === | + | |
− | + | ===On your Android smartphone=== | |
− | <pre class=" | + | You can also setup a serial terminal connection between your OPOS and your Android smartphone. Procedure is quite similar to the one above for PC, except: |
− | + | * install "BlueTerm" or "Serial Bluetooth Terminal" app on your smartphone | |
+ | * if using bluez-5, launch bluetooth daemon in compatibility mode: | ||
+ | <pre class="apf"> | ||
+ | # bluetoothctl --version | ||
+ | bluetoothctl: 5.54 | ||
+ | # /usr/libexec/bluetooth/bluetoothd --compat & | ||
</pre> | </pre> | ||
+ | * use sdptool to add RFCOMM profile to Bluetooth stack: | ||
+ | <pre class="apf"> | ||
+ | # sdptool add SP | ||
+ | </pre> | ||
+ | * connect your app to right Bluetooth device... that's it ;-) (you may have to configure your app in terminal mode, with no echo and extended receive buffer) | ||
+ | |||
+ | ==Advanced usages: Using a Bluetooth keyboard on your APF== | ||
+ | The only thing needed after having a Bluetooth correctly configured is to use this command : | ||
+ | <pre class="apf"> | ||
+ | # hidd --connect keyboard_bdaddr | ||
+ | </pre> | ||
+ | |||
+ | ==Advanced usages: Controlling your board from an android device (using rfcomm)== | ||
− | === | + | ===With your own App=== |
− | The following section shows how to send commands to the board from an android device via Bluetooth. The goal is to control the two | + | 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. An [[APF51Dev]] and a Samsung Galaxy Tab 2 are used in this example. |
− | On the APF | + | On the APF: |
* Enable the SPP profile. Here, it is using the channel 1. | * Enable the SPP profile. Here, it is using the channel 1. | ||
Line 240: | Line 425: | ||
</pre> | </pre> | ||
− | * Listen | + | * Listen incoming connections on the channel 1. The script ''serial-server.sh'' is located in ''demos/android/android_remote_controller''. |
<pre class="apf"> | <pre class="apf"> | ||
# rfcomm listen hci0 1 ./serial-server.sh {} | # rfcomm listen hci0 1 ./serial-server.sh {} | ||
Line 246: | Line 431: | ||
</pre> | </pre> | ||
− | On the android device | + | On the android device: |
− | * Deploy the app on your device. The app is | + | * Deploy the app on your device. The app is available [ftp://ftp2.armadeus.com/armadeusw/apf-remote-controller.tar.gz here as source] or [ftp://ftp2.armadeus.com/armadeusw/apf-remote-controller.apk here as apk]. |
* Start the app. | * Start the app. | ||
* Enjoy :-) | * Enjoy :-) | ||
− | === | + | ===With Bluetooth Electronics App=== |
+ | * This application from [http://www.keuwl.com/apps/bluetoothelectronics/ keuwl.com], can be found on Google store and is very practical to design control panel on your Android device and make then control your Bluetooh device). It is generally used with Arduino and HC-06 Bluetooth module but we will see it works perfectly on APF/OPOS SoM. | ||
+ | * Bluetooth Electronics uses RFCOMM to talk with device and so communication can be seen as a serial port | ||
+ | * Again, use ''rfcomm'' command line tool to listen for your Android device connection: | ||
+ | <pre class="apf"> | ||
+ | [bluetooth]# power on | ||
+ | ... | ||
+ | # rfcomm -i hci0 listen /dev/rfcomm0 & | ||
+ | </pre> | ||
+ | * Discover/pair/connect the APF/OPOS SoM from Bluetooth Electronics app | ||
+ | * Then configure ''/dev/rfcomm0'' created by rfcomm: | ||
+ | <pre class="apf"> | ||
+ | # stty -F /dev/rfcomm0 raw -echo -echoe -echok 9600 | ||
+ | </pre> | ||
+ | * and use this new serial port from your application... | ||
+ | * here a sample application is given; it runs on [[OPOS6UL]] and allows to light on/off the user LED, get processor temperature, get CPU usage and send text to LCD from Bluetooth Electronics panel. Serial protocol is very simple and can be guessed from [https://sourceforge.net/p/armadeus/code/ci/master/tree/target/demos/android/bluetooth-electronics/opos6ul-server.py source code]. | ||
+ | |||
+ | [[File:Bluetooth_Electronics.png]] | ||
+ | |||
+ | ==Advanced usages: Others== | ||
* [[TCP/IP with Bluetooth]] | * [[TCP/IP with Bluetooth]] | ||
* [[OBEX]] transfers | * [[OBEX]] transfers | ||
* [[Wiimote]] | * [[Wiimote]] | ||
+ | |||
+ | {{Note|On iOS, it is '''not''' possible to use standard Bluetooth devices that are not registered through [https://developer.apple.com/programs/mfi/ MFi Program]. The only way to communicate with your modules is to have a Bluetooth Low Energy interface and corresponding iOS software}} | ||
+ | |||
+ | ==Bluetooth Low Energy (BLE)== | ||
+ | * This protocol enhancement for low energy networks is only available on [[APF6]], [[OPOS6UL]] and [[OPOS6UL_NANO]] modules with corresponding Wi-Fi+BLE hardware option. | ||
+ | |||
+ | * To scan for BLE devices (''hci0'' interface should be up): | ||
+ | <pre class="apf"> | ||
+ | # hcitool hci0 lescan | ||
+ | </pre> | ||
+ | |||
+ | * Most operations can then be done with ''bluetoothctl'': | ||
+ | <pre class="apf"> | ||
+ | # bluetoothctl | ||
+ | </pre> | ||
+ | |||
+ | ===APF/OPOS as BLE device=== | ||
+ | * Most of the job consist in developing a GATT server implementing desired functionalities/characteristics. Some examples are given in Bluez sources. For example (''python'' is needed and ''bluetoothd'' should have been launched with ''--experimental'' option): | ||
+ | <pre class="apf"> | ||
+ | # hciconfig hci0 up | ||
+ | # /root/example-gatt-server | ||
+ | # hciconfig hci0 leadv (to start BLE Advertising) | ||
+ | </pre> | ||
+ | * You can then use ''BLE Scanner'' or ''LightBlue'' Android/iOS app. | ||
+ | * For "iBeacon" stuff, [http://www.wadewegner.com/2014/05/create-an-ibeacon-transmitter-with-the-raspberry-pi/ this tutorial] may serve as a starting example. | ||
==Links== | ==Links== |
Latest revision as of 09:34, 7 December 2020
This page will give you all the informations needed to have a running Bluetooth configuration on your Armadeus board.
Contents
- 1 Hardware
- 2 Software
- 3 Custom Bring up (each hardware may have a different init sequence)
- 4 Common Bring up
- 5 Usage
- 6 Advanced usages: Setup a Terminal between a PC and your APF through Bluetooth
- 7 Advanced usages: Using a Bluetooth keyboard on your APF
- 8 Advanced usages: Controlling your board from an android device (using rfcomm)
- 9 Advanced usages: Others
- 10 Bluetooth Low Energy (BLE)
- 11 Links
Hardware
First you have to get a compatible hardware. Currently there are 6 solutions:
- You have an OPOS8MM or an OPOS6UL board with the Wi-Fi/Bluetooth chip integrated.
- You have an APF6 board with the Wi-Fi/Bluetooth chip integrated. The chip is on the APF6 Dual and Quad boards by default.
- 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 Wi-Fi/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 | 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) |
TRUST - Bluetooth 2.1 USB Adapter | TBT | KO | Product: BCM2046B1 Manufacturer: Broadcom |
# hciconfig hci1 up piscan
btusb_submit_intr_urb: hci1 urb c3bdac40 submission failed (28) |
RUEDUCOMMERCE - Mini adaptateur USB Bluetooth | TBT | OK | Manufacturer: Cambridge Silicon Radio | |
GIGABYTE - GN-BTD01 | 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, APF6 and OPOS6UL)
$ 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)
OPOS8MM
OPOS8MM has a Bluetooth chip connected to the i.MX8MM UART2 (/dev/ttymxc2).
- Start the Bluetooth deamon
# /usr/libexec/bluetooth/bluetoothd & #
- Power on the chip.
# gpioset 2 16=1
- Attach the chip.
# btattach -B /dev/ttymxc1 -P bcm -S 921600 & Attaching Primary controller to /dev/ttymxc1 Switched line discipline from 0 to 15 Device index 0 attached Bluetooth: hci0: BCM: chip id 107 Bluetooth: hci0: BCM: features 0x2f Bluetooth: hci0: BCM4345C0 Bluetooth: hci0: BCM4345C0 (003.001.025) build 0000 Bluetooth: hci0: BCM4345C0 (003.001.025) build 0127 # this message takes few seconds to appear #
OPOS6UL
OPOS6UL | OPOS6ULNANO |
---|---|
OPOS6UL has a CM-43438 chip (based on BCM43438), connected to the i.MX6UL UART8 (/dev/ttymxc7) | OPOS6ULNANO has a Murata module with CYM4343 chipset, connected to the i.MX6UL UART3 (/dev/ttymxc2) |
# export BTRESET=42 # export BTDEV=/dev/ttymxc7 |
# export BTRESET=99 # export BTDEV=/dev/ttymxc2 |
- Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver:
# /usr/libexec/bluetooth/bluetoothd & #
- Wake up the chip
# echo $BTRESET > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio$BTRESET/direction # echo 0 > /sys/class/gpio/gpio$BTRESET/value # sleep 1 # echo 1 > /sys/class/gpio/gpio$BTRESET/value # sleep 1
- Attach the chip. Before running the following command, be sure that the file /etc/firmware/BCM43430A1.hcd exists (if not, it can be obtained (wget) here ? or here) !
# hciattach -t 30 $BTDEV bcm43xx 921600 flow bcm43xx_init Set Controller UART speed to 921600 bit/s Flash firmware /etc/firmware/BCM43430A1.hcd Set Controller UART speed to 921600 bit/s Device setup complete #
- To choose bluetooth MAC address, add it to hciattach command
# hciattach -t 30 $BTDEV bcm43xx 921600 flow bdaddr 11:22:33:44:55:66
APF6
- APF6 has a jorjin chip connected to the i.MX6 UART2 (ttymxc1)
- Start the bluetooth deamon and attach your chipset to the kernel bluez UART driver:
# /usr/sbin/bluetoothd NET: Registered protocol family 31 Bluetooth: HCI device and connection manager initialized Bluetooth: HCI socket layer initialized Bluetooth: L2CAP socket layer initialized Bluetooth: SCO socket layer initialized Bluetooth: BNEP (Ethernet Emulation) ver 1.3 Bluetooth: BNEP socket layer initialized
or if you are using BlueZ 5
# /usr/libexec/bluetooth/bluetoothd &
- Wake up the chip
# export BTRESET=43 # echo $BTRESET > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio$BTRESET/direction # echo 0 > /sys/class/gpio/gpio$BTRESET/value # sleep 1 # echo 1 > /sys/class/gpio/gpio$BTRESET/value # sleep 1
- Attach the chip. Before running the following command, be sure that the file /lib/firmware/TIInit_7.6.15.bts exists ! You can download it here (click on the 'Raw' button)
# /usr/sbin/hciattach -s 115200 ttymxc1 texas 115200 Found a Texas Instruments' chip! Firmware file : /lib/firmware/TIInit_7.6.15.bts Loaded BTS script version 1 Device setup complete #
APF51Dev
- APF51Dev has a CSR BlueCore 4 chipset connected to the i.MX51 UART3 (ttymxc1)
- On recent kernel using device tree, you have to "wake up" the chip:
# export BTRESET=60 # echo $BTRESET > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio$BTRESET/direction # echo 0 > /sys/class/gpio/gpio$BTRESET/value # sleep 1 # echo 1 > /sys/class/gpio/gpio$BTRESET/value # sleep 1
- 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
- Now that your hardware Bluetooth interface is up, check if it was correctly detected by BlueZ:
# 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
- From Bluez5, everything can now be done with bluetoohctl interactive command:
# bluetoothctl [NEW] Controller 5C:F3:70:34:D6:66 BlueZ 5.43 [default] [bluetooth]# power on Changing power on succeeded [CHG] Controller 5C:F3:70:34:D6:66 Powered: yes [bluetooth]# scan on Discovery started [CHG] Controller 5C:F3:70:34:D6:66 Discovering: yes [bluetooth]# agent on Agent registered
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.
Change advertising name
- to change your module's name on Bluetooth network:
# hciconfig hci0 name ARMADEUS
- From bluez5, you can also specify advertising name in /etc/bluetooth/main.conf file (%h = hostname, %d = device number):
[General] Name = OPOS
or specify it from bluetoothctl tool:
# bluetoothctl [bluetooth]# system-alias OPOSxxx
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 chosen):
# rfcomm -i hci0 listen /dev/rfcomm0 7 &
Note: If RFCOMM protocol is not built statically in your kernel, you might need to load it before use with: # modprobe rfcomm |
Note: If you plan to connect from your smartphone, don't specify a channel number as most apps will try to connect to channel 1: # rfcomm -i hci0 listen /dev/rfcomm0 & |
- 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 your Host 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/OPOS, 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.
On your Android smartphone
You can also setup a serial terminal connection between your OPOS and your Android smartphone. Procedure is quite similar to the one above for PC, except:
- install "BlueTerm" or "Serial Bluetooth Terminal" app on your smartphone
- if using bluez-5, launch bluetooth daemon in compatibility mode:
# bluetoothctl --version bluetoothctl: 5.54 # /usr/libexec/bluetooth/bluetoothd --compat &
- use sdptool to add RFCOMM profile to Bluetooth stack:
# sdptool add SP
- connect your app to right Bluetooth device... that's it ;-) (you may have to configure your app in terminal mode, with no echo and extended receive buffer)
Advanced usages: 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
Advanced usages: Controlling your board from an android device (using rfcomm)
With your own App
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. 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 incoming connections on the channel 1. The script serial-server.sh is located in demos/android/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 available here as source or here as apk.
- Start the app.
- Enjoy :-)
With Bluetooth Electronics App
- This application from keuwl.com, can be found on Google store and is very practical to design control panel on your Android device and make then control your Bluetooh device). It is generally used with Arduino and HC-06 Bluetooth module but we will see it works perfectly on APF/OPOS SoM.
- Bluetooth Electronics uses RFCOMM to talk with device and so communication can be seen as a serial port
- Again, use rfcomm command line tool to listen for your Android device connection:
[bluetooth]# power on ... # rfcomm -i hci0 listen /dev/rfcomm0 &
- Discover/pair/connect the APF/OPOS SoM from Bluetooth Electronics app
- Then configure /dev/rfcomm0 created by rfcomm:
# stty -F /dev/rfcomm0 raw -echo -echoe -echok 9600
- and use this new serial port from your application...
- here a sample application is given; it runs on OPOS6UL and allows to light on/off the user LED, get processor temperature, get CPU usage and send text to LCD from Bluetooth Electronics panel. Serial protocol is very simple and can be guessed from source code.
Advanced usages: Others
- TCP/IP with Bluetooth
- OBEX transfers
- Wiimote
Note: On iOS, it is not possible to use standard Bluetooth devices that are not registered through MFi Program. The only way to communicate with your modules is to have a Bluetooth Low Energy interface and corresponding iOS software |
Bluetooth Low Energy (BLE)
- This protocol enhancement for low energy networks is only available on APF6, OPOS6UL and OPOS6UL_NANO modules with corresponding Wi-Fi+BLE hardware option.
- To scan for BLE devices (hci0 interface should be up):
# hcitool hci0 lescan
- Most operations can then be done with bluetoothctl:
# bluetoothctl
APF/OPOS as BLE device
- Most of the job consist in developing a GATT server implementing desired functionalities/characteristics. Some examples are given in Bluez sources. For example (python is needed and bluetoothd should have been launched with --experimental option):
# hciconfig hci0 up # /root/example-gatt-server # hciconfig hci0 leadv (to start BLE Advertising)
- You can then use BLE Scanner or LightBlue Android/iOS app.
- For "iBeacon" stuff, this tutorial may serve as a starting example.