The best tools to make your project dreams come true

Login or Signup
USD

4/13/2018 | By Maker.io Staff

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

June 24, 2019 marked the largest new product introduction to date for the Raspberry Pi community: The Raspberry Pi 4 B. With this latest incarnation the Raspberry Pi now has a more powerful ARM Cortex A72 based processor, expanded memory options of 1, 2 or 4 GB LPDDR4, USB 3.0, Bluetooth 5.0, Gigabit Ethernet and two Micro HDMI connectors. It even has H.265 decode capability. Of course, the beauty of the Raspberry Pi family is consistent support for the entire existing Raspberry Pi ecosystem. Below is a chart highlighting the key differences between the new Raspberry Pi 4 and its predecessors:

Table for Raspberry Pi 4 B, 3 B, and B+

Raspberry Pi 4 Model B

Raspberry Pi 3 Model B+

With this exciting expansion Maker.io 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 4 B, 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).

Wi-Fi and Bluetooth P4-figure 1 

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

Wi-Fi and Bluetooth P4-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).

Wi-Fi and Bluetooth P4-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).

Wi-Fi and Bluetooth P4-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.
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 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.

Resource:

Raspberry Pi 4 Model B - Raspberry Pi’s first 28 nm-based product moves to a more modern process node making Raspberry Pi 4 a true PC replacement