Raspberry Pi Interface with Bluetooth

Bluetooth, USB, UART, Storage, etc.
securd
Posts: 4
Joined: Sat Jun 21, 2014 3:37 pm

Raspberry Pi Interface with Bluetooth

Postby securd » Sat Jun 21, 2014 4:43 pm

Hi guys,

Could you please provide some guidance wrt interfacing the BITalino with Raspberry Pi using a Bluetooth adapter? The example code is written for use of the UART, but I need a wireless application. I have a functioning Bluetooth adapter, but could use some advice interfacing it to the BITalino via Bluetooth connection.

Thank you,
Steve.

securd
Posts: 4
Joined: Sat Jun 21, 2014 3:37 pm

Re: Raspberry Pi Interface with Bluetooth

Postby securd » Sat Jun 21, 2014 7:29 pm

Sorry, I posted too soon! After playing around with Bluetooth on this quiet Saturday morning, I did get it to work. In case anyone else is attempting to use the BITalino with a Raspberry Pi utilizing a Bluetooth interface, I'll post my step-by-step here. Please note these instructions are for Raspbian on the Pi.

1. Acquire a Bluetooth USB adapter for your RPi. You can Google for this and find the ones compatible with the Raspberry Pi (generally those with the Cambridge Silicon Radio). Since USB ports are at a premium, I am decided to use the Cirago combo WiFi / USB adapter from Amazon, which works perfectly with both WiFi and Bluetooth on the Pi: http://www.amazon.com/dp/B005QUQPDA/ref ... 90_TE_dp_1

2. Install Debian Bluetooth utilities.
From an LXTerminal prompt:
sudo apt-get update
sudo apt-get install bluetooth bluez-utils blueman

3. Shutdown the RPi with 'sudo halt', remove power, install the USB adapter, then power the RPi back on

4. Test that the adapter is recognized.
From an LXTerminal prompt:
/etc/init.d/bluetooth status
And look for the response: 'bluetooth is running.'

5. Now pair with the BITalino.
Power-on the BITalino, then run the Bluetooth Manager from your LXTE enviroment (it should have been installed in the Preferences menu).
Click on 'Search', and you should see 'bitalino' appear. Click on 'bitalino', click the green + sign to add the device, then click the yellow star to mark it as trusted.
Now click on 'bitalino', click the 'Setup...' icon, select 'Use Custom Passkey:', enter 1234, then click on 'Forward'.
Next, select the 'Serial Port' radio button, click 'Forward', and if all went well, your BITalino Bluetooth port will now appear as a virtual comm port on the RPi!
(sometimes I needed to repeat this last step several times. For some reason I randomly got failure to connect messages, but it should eventually connect after a retry or two)

6. Go get the Raspberry Pi Python demo code from GIThub: https://github.com/bitalino/bitalino-raspberryPi
Install it as instructed (however since we are utilizing a virtual com port with the Bluetooth adapter, you can probably ignore the steps associated with freeing the console / ttyAMA0)

7. Change the serial port in the Python library you just download to utilize the Bluetooth virtual comm port.
First discover the Bluetooth (rf) comm port alias by entering:
ls /dev/rf*
(mine is 'rfcomm0')
cd to the directory you downloaded the Python demo files into, and edit BITalinoPi.py to correct the comm port:
nano BITalinoPi.py
page down to the class BITalino:, and look for the line:
def open(self, SamplingRate = 1000, dev ="/dev/ttyAMA0")
and change "/dev/ttyAMA0" to your Bluetooth port. Mine is "/dev/rfcomm0"

Save the file, with ctrl-x, y, enter

8. Run the demo!
from the same directory you downloaded the demo files into:
sudo python BITalinoPiExample.py

You should see your BITalino version, followed by a sensor dump.


In summary:
1. Install a Bluetooth adapter on your RPi
2. Install the Bluetooth driver and utilities
3. Pair with the BITalino
4. Install the BITalino / Raspberry Pi demo code
5. Change the comm port to the virtual Bluetooth comm port
6. Run the demo

Hope this helps!

Steve.

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Raspberry Pi Interface with Bluetooth

Postby BITalino » Sat Jun 21, 2014 10:12 pm

Hi Steve,

Great to hear you've sorted out the question you were having; thanks a million for the comprehensive explanation you've provided to the community.

A piece of information that may be interesting for you is the recent release of a highly optimised C++ API that runs on the Raspberry Pi as well:
https://github.com/BITalinoWorld/cpp-api
http://bitalinoworld.github.io/API/C++/

Best regards,
The BITalino Team

securd
Posts: 4
Joined: Sat Jun 21, 2014 3:37 pm

Re: Raspberry Pi Interface with Bluetooth

Postby securd » Sun Jun 22, 2014 4:45 am

Thank you team, for the C++ Linux example! Works perfectly on the Raspberry Pi. I used Bluetooth Manager to pair with the bitalino, edited the test.cpp source to connect to rfcomm0, and we are off to the races.

I intend to further leverage this work to add features, and will describe the results here.

Thanks again! The BITalino (and your support) are incredible.

Sincerely,
Steve.


Return to “I/O”




cron