Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Monday, March 3, 2014

Raspberry Pi bluetooth

Just noting some success with setting up a Raspberry Pi with Bluetooth support.  My goal is to get it working with the Wii Remote for projects that I and my son find.

Raspberry Pi Model B
Cirago Bluetooth 3.0 High Speed & Wi-Fi combo USB mini adapter; BTA7300

Linux version 3.10.32+ (dc4@dc4-arm-01)
(gcc version 4.7.2 20120731 (prerelease) (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08) ) #648 PREEMPT Fri Feb 28 16:29:56 GMT 2014

Notes:
  • Plugged directly into PI.
  • Had previously used a different Wi-fi adapter but unplugged it, plugged this in and wi-fi worked (once I added the MAC to the router filter to allow access)
  • I keep the os/firmware updated fairly regularly – updated before these installs
  • Using the default available Bluez modules (4.x) instead of the 5.0 which I would have to compile.  I may try to compile 5.0 at some point it appears this should work for some things.  Here is what I installed.
    • sudo apt-get install bluez
    • sudo apt-get install bluez-tools
    • sudo apt-get install bluez-utils
    • sudo apt-get install bluez-firmware
  • I have not fully played with the Bluetooth but was able to see my cell phone and briefly had it paired (left a registration on the phone) but I couldn’t think of anything useful at the time to try other than list out some info.
    • bt-device --connect <mac>
    • bt-device --services <mac> 
I have not fully decided what language to use when playing with the Bluetooth.  It appears that C, Python and Java are possible.  I will likely install the wrapper libs and such for Python and try that since that is likely easier for my son.  The Java support appears to be via JSR-82 but it sounds like that has some shortcomings.

Python bindings
sudo apt-get install python-smbus python-cwiid python-scipy python-numpy python-pygame python-setuptools libsdl-dev

Successful testing of wii Remote!
Using the site below related to Python & Wii Remote, I was able to see the button values changing and mess with the LEDs.

Partial excerpts from the www.cl.cam.ac.uk site [mentioned below].  Pulling the example in here just to have a small but functional one in a single place.  Refer to the source site referenced for more details on what the steps are doing.

sudo hciconfig hci0 piscan

python

import cwiid
 
# I found it most reliable to press buttons 1 & 2 just
# prior to executing the next statement interactively.
 
wm = cwiid.Wiimote()
 
import time
for i in range(16):
  wm.led = i
  time.sleep(0.5)
 
# Interactively, I pressed an extra return to get it running. I am
# not a Python programmer so even little things are nice to note...
  
Resources
I found this helpful for the Bluetooth.

man –k bt was helpful in finding the related commands after installing everything.
bt-device
bt-adapter
bt-agent
bt-input
bt-monitor
bt-network
bt-obex
bt-serial

JSR 82 - Bluetooth

Some Bluetooth/Python info
http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/downloads/

Python interacting with Wiimote
http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/wiimote/

Another good reference & example is:
http://www.raspberrypi-spy.co.uk/2013/02/nintendo-wii-remote-python-and-the-raspberry-pi/