The best tools to make your project dreams come true

Login or Signup

4/13/2018 | By Staff

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

March 14, 2018 marked the 30th year Pi Day has been celebrated since physicist Larry Shaw tied the date to the mathematical constant. Electronic enthusiasts have come to associate the date with one of their favorite single board computers. This year they were not disappointed, with the announcement of the Raspberry Pi 3 Model B+ from the Raspberry Pi foundation. This latest addition combines a 64-bit quad core processor from Broadcom (BCM2837B0) operating at 1.4GHz, dual-band 2.4 GHz and 5 GHz wireless LAN, Bluetooth 4.2/BLE, Gigabit Ethernet over USB 2.0 and supports Power-over-Ethernet (PoE) with the addition of a PoE HAT (Comparison chart below):

Image of the Raspberry Pi 3 B and B+ Comparison chart

Image of the Raspberry Pi 3 B+

With this exciting expansion is excited to provide a reference for those of you new to the Raspberry Pi (and a refresher for those of you already familiar) on how to set up your Wi-Fi and Bluetooth connections on your new Pi. 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 Pi 3 Model B, 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).

Image of the WiFi and Bluetooth Pi 3 - Figure 1

2. Select your Wi-Fi SSID in the drop-down list (Figure 2).

Image of the 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).

Image of the 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).

Image of the 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 set up 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.

The 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).

Image of the 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.

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 may be 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).

Image of the 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 may be prompted to enter a passcode 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).

Image of the 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 passcode 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

Image of the 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.