Setting up serial ports on BT

This for Raspberry Pi with standard Raspbian build.

Plug in BT dongle

Using standard BT config app from SysTray – Change Bluetooth adaptor to be always visible.

Use command line to scan for services available on the adaptor:

hcitool scan
(shows adaptors available on RPi)

sdptool browse
(lists services available on visible devices)
Find the address of the device to connected to e.g. Browsing 20:68:…
Find the com port e.g. COM6 (this is the port on the other device)
Find the channel e.g. 0 (on the other device)

Bind the local port to the channel on the remote device address:
Sites say use rfcommN e.g.
rfcomm bind /dev/rfcomm1 AA:BB:CC:AA:BB:CC 1
BUT Java RXTXComm library has a list of serial ports it recognizes by default.

So do something like:

  • ?? bind the port as ttySnn in the first place (does this work = may have to be an existing port?)
    sudo rfcomm bind /dev/rfcomm1 AA:BB:CC:AA:BB:CC 1
  • create symbol to point a searched for port name to the physical rfcomm1 port worked but can’t find ref to creating the symbol)
  • use a command line property, i.e. -Dgnu.io.rxtx.SerialPorts=/dev/rfcomm1
  •  ?? Modified in code using gnu.io.rxtx.SerialPorts. see http://marc.info/?l=rxtx&m=108475711131501

This post also describes the name issue.

The binding can be put in /etc/bluetooth/rfcomm.conf (not working yet though)

Set permission on port: chmod a+rw /dev/rfcomm0

Get the Java library using:

sudo apt-get install librxtx-java

Now can reboot RPi
# . bindBT.bash
# . demo
sudo rfcomm release 0
sudo rfcomm listen /dev/rfcomm0 22
paplay file.wav

Other useful commands

pulseaudio –-start
sudo leafpad {filename} to edit a system file

Setting up serial port service so other device can initiate connection

Now I can reliably connect from the other device but no services are offered by the RPi.

https://wiki.archlinux.org/index.php/bluetooth#Bluetoothctl useful info about Bluetooth and UIs to Bluetooth.

Added pi to Bluetooth group (http://plugable.com/2015/05/11/quick-fix-for-problems-using-bluetooth-from-the-raspberry-pi-desktop):

sudo usermod -G bluetooth -a <username>

https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=125922

Identifies how to start bluetooth daemon with –compat property set.

Then can run sudo sdptool browse local to see what services are available:

http://unix.stackexchange.com/questions/92255/how-do-i-connect-and-send-data-to-a-bluetooth-serial-port-on-linux

and can add one for serial SPP

sdptool add --channel=22 SP
sudo rfcomm listen /dev/rfcomm0 22

If you lose connection need to issue:
sudo rfcomm release 0
before trying to listen again.

Getting audio sink to work

bluez V5 causes some problems because it doesn’t support alsa. However bluetoothctl should work now in its place.

See page 2 of a post for a detailed description of how to make audio work over BT (not specifically for RPi): https://bbs.archlinux.org/viewtopic.php?id=166678&p=2

Where the guide mentions pacman use

sudo apt-get install {packagename}

  • dbus (interprocess communication) – already at latest
  • alsa-plugins ### Not available!!! ###
  • pulseaudio (audio interfacing that supports bluetooth)
  • pulseaudio-alsa  ### Not available!!! ###
  • pavucontrol (mixer for graphical desktop machines) or
  • ponymix (CLI mixer for pulseaudio for headless machines) ### Not available!!! ###
  • pulseaudio-module-bluetooth (from https://wiki.archlinux.org/index.php/Bluetooth_headset)

pulseaudio-module-bluetooth fllowed by a reboot) enabled the headset in the PulseAudio volume control (accessible from the Start Menu).

To test audio:

paplay file.wav

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s