Wednesday, 27 April 2016

raspberry pi-3 setup with blue tooth  GKARTHIK

 



Now that it has been a few weeks since the release of the Raspberry Pi 3, support for the WiFi and Bluetooth chip has settled and you can use it with Raspbian. Support with Windows 10 IoT Core will be available in the early days via the Insider Program before it is pushed through to the full release.

As usual, with Raspbian ensure that you have your distribution up to date, with this guide we will be using Raspbian Jessie, at present it is still the ARMv7 32bit kernel. Connect your Raspberry Pi to the internet either via WiFi or Ethernet and run the following commands:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo rpi-update

Installing the Software


From a console terminal, either from within your desktop environment, which at the time of writing the window manager is still LXDE. This will ensure your system is up to date.

Now you have a few options, you can install the following package:

sudo apt-get install pi-bluetooth

Which should install what you need to use the bluetooth portion of the chip, this installs the following packages which you can, if you want, install instead of pi-bluetooth:

sudo apt-get install bluez bluez-firmware

As the chip requires a firmware blob to work along with the driver. Bluez also installs a suite of tools. These will work from the console terminal. Should you wish to manage your bluetooth devices from your X environment, aka your windows manager, aka your desktop then you can install the following package:

sudo apt-get install blueman

After installing the software and drivers, reboot your Raspberry Pi. Unless you know otherwise, to load the driver for the adapter.

Terminal / Console


Bluez comes with a tool called 'bluetoothctl' which you can run from the console terminal, typing 'man bluetoothctl' does not give you a great deal of detail, so you have to type 'help' from within the software:
pi@raspberrypi:~ $ bluetoothctl
[bluetooth]# help
Available commands:
  list                       List available controllers
  show [ctrl]                Controller information
  select <ctrl>              Select default controller
  devices                    List available devices
  paired-devices             List paired devices
  power <on/off>             Set controller power
  pairable <on/off>          Set controller pairable mode
  discoverable <on/off>      Set controller discoverable mode
  agent <on/off/capability>  Enable/disable agent with given capability
  default-agent              Set agent as the default one
  scan <on/off>              Scan for devices
  info <dev>                 Device information
  pair <dev>                 Pair with device
  trust <dev>                Trust device
  untrust <dev>              Untrust device
  block <dev>                Block device
  unblock <dev>              Unblock device
  remove <dev>               Remove device
  connect <dev>              Connect device
  disconnect <dev>           Disconnect device
  version                    Display version
  quit                       Quit program

Now we are in bluetoothctl we can run the commands, first lets make sure that bluetooth is on, running and discovering devices:


With the commands 'power on', 'agent on' and 'scan on'. Though we likely only need 'power on' and 'scan on'.


Devices! and while the software is running we will see devices appear, change, delete, etc. We can then connect to a device using its MAC address. Basically, we are talking to the devices directly at the hardware layer, usually on your typical WiFi or Ethernet network this is done transparently to you and we only work with IP addresses. However with Bluetooth at this point, no.


We can also then pair and trust the device and do all the fun features of Bluetooth, provided these are successful.

GUI

Some consider the blueman package and software to be unstable, though the sources saying so are a bit dated by now and it may be somewhat more stable.



When you have the blueman package installed, you should have a nice Bluetooth icon in your system tray. If you left-click with a mouse connected to your Raspberry Pi you should get a menu with all of the, hopefully, self explanatory options for you to play with, which for some reason I could not capture with scrot/imagemagick, so you get a nice photograph:

IMG_20160316_000640.jpg

Yum, pixelated (it was an old Dell monitor). If we want to scan for devices, similarly to using the 'scan' command for bluetoothctl then we select 'Devices' on the menu:


And from here we can see what is available in the vicinity, you may be surprised at suddenly finding your neighbours smart television or phone, you will find out how thin your walls really are. It can be more fun in the office at work.

However, let us select "setup a new device":

Add New Device
Choose a pairing code
×
3 / 3

However, what I discovered is that the passkey method is practically deprecated or ignored, it may be applicable for older Bluetooth software or devices, but these days you will get a prompt appear (and for myself, then hide) on Raspbian, next to the icon for blueman, there will be a message, and in this message it will display a message like:

This device wants to pair with this machine, with this code xxxxxxxx, do you want to permit or deny?

This likely happens with new devices such as smart phones and televisions, as a security measure that you are physically holding or looking at the device in question. Of course you then 'permit' on either the device or Raspbian and the two will be paired. Allowing you to then setup drivers for your Bluetooth device functionality, to use it as a modem, in the case of a phone, share its internet access or simply send files to and from it. Potentially, you can even use it as an audio device!

Attaching to devices such as headsets tends to be easier, and usually does not use a pairing code. A standard is usually four zeroes (0000) with most consumer devices.

gkarthik pi

Raspberry Pi 3 - How to Configure Wi-Fi and Bluetooth

Now that Raspberry Pi 3 has been released with wireless capabilities including Wi-Fi and Bluetooth, I thought I’d write a quick guide in order to get up and running. This guide includes setting up the Wi-Fi via the graphical user interface (GUI) and command line (CLI), connecting a Bluetooth keyboard, and connecting a Bluetooth speaker to play audio. The following examples will also work with Raspberry B+ and Raspberry Pi 2 using universal serial bus (USB) dongles.
Setting up Wi-Fi via the Graphical Interface
 This process is probably the most effective method of connecting to your Wi-Fi and also the quickest. First of all, before we get started, please make sure you are running the latest Raspberry Pi operating system; if you’re not sure, then you can head to the Downloads section on the Raspberry Pi website. Follow these steps:
1. In the Desktop environment locate the network icon in the top right hand side and click on the icon to see the list of available Wi-Fi networks to connect to (Figure 1).
WiFi and Bluetooth Pi 3 - Figure 1
2. Select your Wi-Fi SSID in the drop down list (Figure 2).
WiFi and Bluetooth Pi 3 - Figure 2
3. You will be prompted to enter your Wi-Fi password into the text box, so go ahead and do so (Figure 3).
WiFi and Bluetooth Pi 3 - Figure 3
4. Finally, click ok and you will be connected to your Wi-Fi. You should now see your signal strength displayed in the upper task bar on the right (Figure 4).
WiFi and Bluetooth Pi 3 - Figure 4
5. You should now be connected to your Wi-Fi successfully; test your connection by opening up the web browser.

Setting up Wi-Fi via the Command Line Interface
This method is suitable for those who don’t have access to the GUI normally used to setup Wi-Fi on the Raspberry Pi. It’s especially suitable for those with a serial console cable if you don’t have access to a screen or wired Ethernet. No additional software is required; everything is already included on the standard Raspberry Pi image.
First thing you need to do is scan for local wireless networks using the command sudo iwlist wlan0 scan . This will list all available Wi-Fi networks including all sorts of other useful information (Figure 5).
WiFi and Bluetooth Pi 3 - Figure 5
1. Locate the name of your Wi-Fi network in the list; this will be listed next to ESSID.
2. Under the ESSID you should also see your authentication method, which could look like the following IEEE 802.11i/WPA2 Version 1. In my case the authentication method is WPA2, which is the newer and more secure method; this quick guide will work with both WPA and WPA2. You will also need the password for your Wi-Fi. If you don’t already know this, it is usually located on the reverse side of your modem/router.
3. Now you need to add your Wi-Fi settings to the wpa-supplicant configuration file. Type the following in the command line to the configuration file: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf. Go to the bottom of the file and add the following Wi-Fi setting, adding your setting in the quotation marks.
network={
    ssid="The_ESSID_from_earlier"
    psk="Your_wifi_password"
}
Save the file by pressing CTRL+X and then Y on the keyboard and press enter to confirm. At this point, the wpa-supplicant configuration file will normally notice within a few seconds when a change has occurred and it will try to connect to the Wi-Fi network. If the Wi-Fi does not connect then a reboot maybe required with sudo reboot . Once your Wi-Fi has connected successfully you can verify it by typing ifconfig wlan0; if the inet addr field has an IP address in it then it has successfully connected (Figure 6).
WiFi and Bluetooth Pi 3 - Figure 6
Connecting a Bluetooth Keyboard

The best method for connecting a Bluetooth device is using the bluetoothctl command from the common line interface. There is a GUI application called blueman, but this is not stable on the Raspberry Pi and will cause it to crash.
If you are running the latest Raspberry Pi OS, then all the software has already been installed. If not, then you can simply type the following to install the Bluetooth module: sudo apt-get install pi-bluetooth . Once installed, follow these next steps to pair with your Bluetooth keyboard:
1. Run the Bluetooth program by typing bluetoothctl.
2. Turn on the Bluetooth, if not already on, by typing power on.
3. Enter device discovery mode with scan on command if device is not yet listed in devices.
4. Turn the agent on with agent on.
5. Enter pair MAC Address to do the pairing between devices.
6. You maybe prompted to enter a pass code on the Bluetooth keyboard; if so, type this on the keyboard and press enter.
7. You will need to add the device to a list of trusted devices with trust MAC Address.
8. Finally, connect to your device with connect MAC Address.
Note: For a list of Bluetooth commands type help in the command line (Figure 7).
WiFi and Bluetooth Pi 3 - Figure 7
Connecting a Bluetooth Speaker
Before you get connected to your Bluetooth speaker, you will need to install Pulse Audio and its associated Bluetooth module. Pulse Audio is a sound server that receives audio input from multiple channels and filters them through to one single output or sink, as it’s known. Needless to say, go ahead and install it by typing the following in the command line: sudo apt-get install pulseaudio pulseaudio-module-bluetooth . Once installed give the Raspberry Pi a quick reboot to make sure everything is in order before we start: sudo reboot .
Now that everything we need to connect to the Bluetooth speaker is installed, you can follow these steps in order to connect. The process is the same as connecting to a Bluetooth keyboard (Figure 8):
1. Turn on the Bluetooth speaker and enter discovery mode
2. Open up the command line terminal on the Raspberry Pi and run bluetoothctl
3. Power on the Bluetooth device: power on
4. Turn the agent on:  agent on
5. Scan for devices: scan on
6. Pair with your Bluetooth speaker pair MAC Address, at this point there should be no pass code to enter
7. Add the new Bluetooth speaker to the list of trusted devices: trust MAC Address
8. Now finally connect to the Bluetooth speaker: connect MAC Address
WiFi and Bluetooth Pi 3 - Figure 8
Now that you are connected to the Bluetooth speaker, you can test the connection by opening up the web browser and playing a YouTube video or something similar.