Howto: Getting Bluetooth (serial console) working on Debian
#1
Information 
Tested on a Pine64+ 1GB running Debian 8 “jessie” (3.10.102-3) using the official WIFI 802.11BGN/BLUETOOTH 4.0 Module.

What's it all about? These were the steps I followed to be able to view the text output of a bluetooth-enabled USB power meter, and most of these steps apply to getting bluetooth working at all if it isn't already configured in your chosen image. If it is already enabled, you can probably jump straight to step 5. Regardless, steps 1-5 should get your bluetooth working and a device paired with your pine64, but what you do after that if you don't want the text output (ie. you instead want a bluetooth mouse, audio) like I did I wouldn't know! ;)


Step 1: Make sure you have the bluetooth stack and utilities installed! If you want to all make sure you have  all of the stuff this guide uses in one hit, you can add "rfkill git screen minicom" to the list of stuff to install.
sudo apt-get install bluez


Step 2:
Get the firmware binaries for the BT from https://github.com/lwfinger/rtl8723bs_bt

This repo contains the programs and firmware to operate the Bluetooth section of the RTL8723BS. This basically loads the firmware into the module, which makes it a bluetooth module! if you don't have git, install it by running "sudo apt-get install git".


Quote:git clone https://github.com/lwfinger/rtl8723bs_bt.git


Step 3:
Compile and load the firmware.
Change into the newly cloned repo, and run "make", which will compile the main program needed, rtk_hciattach. Then run "sudo make install" to install the firmware.

You’ll then want the following command to run at bootup, so perhaps put it in /etc/rc.local. For the moment though, you can run it as shown below.

Quote:sudo ./start_bt.sh


This is the command that does real magic… it configures the BT module and makes it available for use. 


Step 4: Remove soft block, scan for devices
For some reason or another, the device is "soft blocked" (meaning it is blocked by software),  which is easy to fix when you know how. Run

Quote:sudo rfkill list

and you should see something like this (if you don’t, something has gone horribly, horribly wrong already). If you get a message saying rfkill can’t be found, thats ok… just run "sudo apt-get install rfkill" to install it, and try again.

Quote:0: sunxi-bt: Bluetooth
Soft blocked: no
Hard blocked: no
1: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
2: phy1: Wireless LAN
Soft blocked: no
Hard blocked: no
3: hci0: Bluetooth
Soft blocked: yes
Hard blocked: no


The entry of interest is the last one (the one for hci0: Bluetooth). That is the bluetooth adapter we’re trying to use, and as you can see, it is currently soft blocked. To fix that, just run (if yours is listed as 3 also)

Quote:sudo rfkill unblock 3

and it will be unblocked. You sould then see if you run "sudo rfkill list" again that this is the case, and if you run hcitool dev, you should also have something like this as the ouput, listing the MAC address of the pine64’s BT adapter.

Quote:Devices:
hci0 34:C3:D2:71:BE:ED


Step 5: Power on bluetooth module and pair your device
You can then run bluetoothctl (as sudo) in order tha manage the bluetooth connection. Install via ‘sudo apt-get install bluez-utils’ if it is missing. You should get an immediate message about a new bluetooth controller… this is a good sign… everything is working so far if you get that message. If you get a  message about no default controller, something is wrong. Assuming you don’t have any issues, run the following commands, which power on the BT module and sets it as the default BT agent.

Quote:power on
agent on
default-agent

If all has gone well, you should be seeing something like this.

Quote:[NEW] Controller 34:C3:D2:71:BE:ED pine64 [default]
[NEW] Device 00:BA:55:56:D8:7E SPP-CA
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful


You can then then enter "scan on" to start discovery of BT devices, and if you have any devices available for pairing, you should see messages about them appear (prefixed by [NEW]). If they’re not ready for pairing, this is the time to make them ready.

Once your device appears, you can run "scan off" to make the system a bit more responsive again, as it seems pretty laggy at times whilst the scan process is running.

To pair the device you’re trying to pair the pine64 with, enter  the command "pair <your-bluetooth-deviceaddress>" . For example, my USB power meter with BT serial had an address of  “00:BA:55:56:D8:7E”, so I entered “pair 00:BA:55:56:D8:7E” and entered the device pin when prompted. Once you see a message about the pair being successful (I had to do it a couple of times, it didn’t seem to take the first time) you can exit the bluetoothctl program with the quit command.


Step 6: Bind  bluetooth device for usage
This step is what makes the bluetooth device available for you to access. It’s really simple.. just run "sudo rfcomm bind hci0 <your-bluetooth-device-address>"

For example,

Quote:sudo rfcomm bind hci0 00:BA:55:56:D8:7E


This binds hci0 (which you might remember from the rfkill list output from earlier) to the bluetooth device you specificied (usb power meter in my case).


Step 7: Do something with it!
Since I simply wanted to view the serial output from the meter, and I prefer using screen I ran

Quote:sudo screen /dev/rfcomm0 9600

in order to connect to the bluetooth device (made available at /dev/rfcomm0) at 9600 baud. (run "sudo apt-get install screen" to use screen as it’s not installed by default). For those of you who prefer minicom, you could do the same thing by running

Quote:sudo minicom -D /dev/rfcomm0 -b 9600

And then try figuring out how to exit it – hint: it’s Ctrl+a, z, q, enter).I then get a line like this every 5 seconds (the  update rate I have the meter set to) telling me the voltage and amperage being measured by the meter. Success!

Quote:052496,005516
052496,005420

All it needs then is some simple decoding to change the interger values sent to their decimal equivalents (ie. the second line is 5.2496v and 0.5420A).

Assuming you were working with a device that didn’t work one way (the meter only ouputs the data, it doesn’t have any configuration or anything over the BT link), you sould then have proper two-way communication via your device and the pine64 over bluetooth!



Acknowledgements:
This information/guide would not be possible without the following sources:

Errata:

2016-09-25 - removed redundant part of step 3
2016-10-10 - removed reference to bluez-utils as isn't needed (or available!) for jessie
Reply
#2
I will have a go at this some time over the weekend, it's a long weekend here in Western Australia...
Reply
#3
Please help me, I can't connect 

I have some problem

1. 
When I run the apt-get install bluez-utils command, it gave me this message

"E: Package 'bluez-utils' has no installation candidate"

I can't find a solution to install this.

2. I can bind and I create /dev/rfcomm0.
But, when I run the sudo screen /dev/rfcomm0 9600, it gave me this message

"[screen is terminating]"
Reply
#4
(09-30-2016, 09:07 AM)bj_jung Wrote: 1. When I run the apt-get install bluez-utils command, it gave me this message

"E: Package 'bluez-utils' has no installation candidate"

I can't find a solution to install this.

My apologies... I had updated the instructions in my own notes to omit bluez-utils as that was for an older version of debian, but hadn't updated that on the forum as my account was still in limbo. bluez-utils is no longer available, nor needed, as bluetoothctl is in the main bluez package.

(09-30-2016, 09:07 AM)bj_jung Wrote: 2. I can bind and I create /dev/rfcomm0.
But, when I run the sudo screen /dev/rfcomm0 9600, it gave me this message
"[screen is terminating]"

So I take it you've run all the way through to the end, have paired and connected to your device, but screen won't connect to it? For starters, is the baud rate correct? What sort of device are you trying to connect to?
Reply
#5
In bluetoothctl

My phone and pine64 paired, but not connected.

I think I should confirm with bsp build option.

Would you mind checking install process?

I use "Debian Linux Jessie with Mate GUI Image [20160701] by lenny.raposo with Longsleep kernel" file.


Code:
$ wget https://github.com/longsleep/linux-pine64/archive/3.10.102-3-pine64.zip
$ unzip 3.10.102-3-pine64.zip
$ make sun50iw1p1smp_linux_defconfig
$ make menuconfig
$ make clean
# make -j 4 Image

and then I copy form "/arch/arm64/boot/Image" file to SD card


I don't know how to change bluetooth kernel option.

I refer to "http://www.linuxfromscratch.org/blfs/view/svn/general/bluez.html"
Reply
#6
Ok, so if you're trying to connect to your phone, you probaly need to see what bluetooth services it provides, and then work out how to access them. I'll try and look at that sometime tomorrow afternoon, but it's not an area I'm parciuarlly intereted in so don't know much about that. If you're running the debian MATE GUI image, is there any reason you're not using the GUI bluetooth tools? IIRC, that particular image is already setup for bluetooth access - I beleive you just need to run a command to enable it... there was a readme.txt on the desktop which detailed what was needed.

I don't think you'll need to fiddle with kernel images and settings, the 3.10.103-longsleep kernel image appears to be correctly setup already for that.
Reply
#7
I use this commands added to `/etc/rc.local`:

Quote:echo 1 > /sys/class/rfkill/rfkill0/state
rtk_hciattach /dev/ttyS1 rtk_h5 # BT on Pine is always connected to UART1
hciconfig hci0 up

You also have to compile `rtk_hciattach`:

Quote:apt-get install bluez git-core
git clone https://github.com/lwfinger/rtl8723bs_bt.git
cd rtl8723bs_bt
make
sudo make install
sudo cp rtk_hciattach /usr/local/bin/
Homepage: https://ayufan.eu
Buy me a Beer (PayPal): ayufan@osk-net.pl
Reply
#8
(10-16-2016, 05:51 AM)ayufan Wrote: I use this commands added to `/etc/rc.local`:

Quote:echo 1 > /sys/class/rfkill/rfkill0/state
rtk_hciattach /dev/ttyS1 rtk_h5 # BT on Pine is always connected to UART1
hciconfig hci0 up

You also have to compile `rtk_hciattach`:

Quote:apt-get install bluez git-core
git clone https://github.com/lwfinger/rtl8723bs_bt.git
cd rtl8723bs_bt
make
sudo make install
sudo cp rtk_hciattach /usr/local/bin/

thanks for that !   ... very nice.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697
Reply
#9
After following the steps described here I am getting outputs that look like this:

howardr@pine64:~/rtl8723bs_bt$ sudo rfkill list
0: sunxi-bt: Bluetooth
        Soft blocked: no
        Hard blocked: no
1: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
2: phy1: Wireless LAN
        Soft blocked: no
        Hard blocked: no
howardr@pine64:~/rtl8723bs_bt$ sudo rtk_hciattach /dev/ttyS1 rtk_h5
Realtek Bluetooth init uart with init speed:115200, final_speed:115200, type:HCI UART H5
Realtek Bluetooth :Realtek hciattach version 2.5

Realtek Bluetooth :3-wire sync pattern resend : 1, len: 8
[...]
Realtek Bluetooth :3-wire sync pattern resend : 40, len: 8
Realtek Bluetooth ERROR: H5 sync timed out

howardr@pine64:~/rtl8723bs_bt$ sudo hciconfig hci0 up
Can't get device info: No such device

I do have the "official WIFI 802.11BGN/BLUETOOTH 4.0 Module" and I'm using Debian Mate img 3.10.104-1-pine64-longsleep

As it appears that the OS isn't seeing Bluetooth, I assume as Peefrick said "something has gone horribly, horribly wrong already."

Any suggestions for getting my Pine64 to see my BT module?
(WiFi works fine, just as a point of info)

Thank you
Reply
#10
(12-01-2016, 12:07 PM)HayseedGeek Wrote: After following the steps described here I am getting outputs that look like this:

howardr@pine64:~/rtl8723bs_bt$ sudo rfkill list
0: sunxi-bt: Bluetooth
        Soft blocked: no
        Hard blocked: no
1: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
2: phy1: Wireless LAN
        Soft blocked: no
        Hard blocked: no
howardr@pine64:~/rtl8723bs_bt$ sudo rtk_hciattach /dev/ttyS1 rtk_h5
Realtek Bluetooth init uart with init speed:115200, final_speed:115200, type:HCI UART H5
Realtek Bluetooth :Realtek hciattach version 2.5

Realtek Bluetooth :3-wire sync pattern resend : 1, len: 8
[...]
Realtek Bluetooth :3-wire sync pattern resend : 40, len: 8
Realtek Bluetooth ERROR: H5 sync timed out

howardr@pine64:~/rtl8723bs_bt$ sudo hciconfig hci0 up
Can't get device info: No such device

I do have the "official WIFI 802.11BGN/BLUETOOTH 4.0 Module" and I'm using Debian Mate img 3.10.104-1-pine64-longsleep

As it appears that the OS isn't seeing Bluetooth, I assume as Peefrick said "something has gone horribly, horribly wrong already."

Any suggestions for getting my Pine64 to see my BT module?
(WiFi works fine, just as a point of info)

Thank you

hm... on the Debian Mate build, Lenny had already set up all the Bluetooth stuff out of the box... IIRC, there was just a single command you needed to run, and that was the last bit of info in the readme that was on the desktop. I'll see if I still have the image on a card, and see what the command was.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  WIFI & Bluetooth? 7777777 14 4,482 12-24-2016, 05:01 AM
Last Post: Toriless
  Using Bluetooth for Sending serial data Arjun 9 650 10-19-2016, 10:19 PM
Last Post: Arjun
  How can you get the WIFI/Bluetooth module separate? GoZone 8 1,047 07-06-2016, 05:23 PM
Last Post: JasperBrown
  WiFi/BT module, no bluetooth riviera89 5 867 06-24-2016, 04:32 PM
Last Post: srinivas.s34@gmail.com
  Board doesn't boot when wifi/Bluetooth connected with Lcd screen Krinilssen 4 261 06-16-2016, 07:22 AM
Last Post: Krinilssen
  WIFI/Bluetooth Chipset monmoonmooonmoooon 2 580 01-20-2016, 06:02 AM
Last Post: monmoonmooonmoooon

Forum Jump:


Users browsing this thread: 1 Guest(s)