The document describes three methods for configuring WiFi connectivity on a Raspberry Pi:
1) Using the Raspberry Pi Imager software to enter WiFi credentials before flashing an SD card
2) Configuring WiFi through the Raspberry Pi OS desktop user interface
3) Using the raspi-config command to configure WiFi from the command line
It also provides instructions for setting up WiFi on a "headless" Raspberry Pi without a monitor or keyboard through SSH and editing configuration files.
Elevate Developer Efficiency & build GenAI Application with Amazon Qâ
Â
Ex.no1
1. Aim:
To Setting up of Raspberry Pi and connect to a network
Procedure:
There are three ways to configure WiFi on your Raspberry Pi with both Raspberry Pi OS desktop and
server.
Wired Ethernet Connection
To set up a wired internet connection, simply connect your Raspberry Pito the back of your network router
with an ethernet or RJ45 cable. Once plugged in, you should observe the network LED blinking on your
Raspberry Pi.
In most cases,your wired internet connection will now be up and ready for use, provided that your router
has DHCP enabled. DHCP stands for Dynamic Host Configuration Protocol, and basically assigns IP
addresses to devices that connect to your router.
To enable DHCP,access your home routerâs management console with another computer that has already
been connected. You can typically do this by entering your routerâs IP address into the address bar of any
internet browser.
Wireless Connection â WiFi Hardware
To set up a WiFi connection, we will first need a WiFi module for our Raspberry Pi. Fortunately, all
Raspberry Pi models from the Raspberry Pi 3 Model B (2016) and later ship with on-board WiFi. If you
have an older model on hand, or if your on-board WiFi module is not functioning, you will need to use an
external USB WiFi adapter.
When choosing a WiFi adapter, ensure that there is driver support. For example, WiFi adapters with the
RTL8192cu chipset will work readily since there is Raspberry Pi OS support built in.
Another consideration is the power draw. WiFi can require a lot of power, especially if a heavy amount of
data is being transmitted. For older Raspberry Pi in particular, you may require an external power supply
like a powered USB hub to power the WiFi adapter.
Ex.No:1
Setting up of Raspberry Pi and connect to a network
Date:
2. Method 1:
Step 1: Install the latest version of the Raspberry Pi Imager for your operating system
Step 2: Open the Raspberry Pi Imager. You should be greeted with the same screen as always.
Step 3: Press Ctrl + Shift + x to open the advanced menu (CMD + Shift + x for Mac OSX).
3. Step 4: Scroll down to Configure wifi, check the box and enter your WiFi credentials.
Note: Be sure to change your Wifi country according to your country code!
Step 5: Click SAVE and flash your OS to your microSD card for your Raspberry Pi!
Method 2: Configure WiFi with Raspberry Pi OS GUI
For users running Raspberry Pi OS Desktop on their Raspberry Pi, you can simply use the provided GUI
to set up your WiFi connection.
4. Method 3: Configure WiFi from Command Line with Raspi-Config
If you are running a server distribution of Raspberry Pi OS without a GUI, you will have to use Raspi-
Config instead. This method works in Raspberry Pi OS Desktop as well.
Raspi-Config is a console based application used to configure various settings on the Raspberry Pi. It can
be used for network configuration, setting up remote access, boot options etc.
To open Raspi-Config n the command line, type the command:
sudo raspi-config
Using the arrow keys on your keyboard, navigate to âNetwork Optionsâ and press Enter.
Select Wi-fi, then follow the on-screen instructions to enter your networkâs SSID and password. When
youâre done, select âFinishâ on the main menu to close Raspi-Config.
Finally, reboot the Raspberry Pi to apply the settings weâve just changed. Your WiFi connection should
then be good to go!
5. Configuring WiFi on a Headless Raspberry Pi
A headless Raspberry Pi is one that we would like to run without a monitor, keyboard, or mouse. As you
can imagine, it wonât be as straightforward to apply the methods weâve covered so far.
Enable SSH (Secure Shell)
For this section, we will first want to enable SSH on our Raspberry Pi. This is something that youâll want
to do if youâre running your raspberry pi headless anyway.
With SSH, you can use an internet connection to remotely run terminal commands on the Raspberry Pi
from your primary computer through an internet connection.
To enable SSH on a headless Raspberry Pi, simply place a file named âsshâ, without any extension, onto
the boot partition of the SD card from another computer. This will tell Raspberry Pi to enable SSH when
booting. The content of the file does not matter.
Note: Do not connect your Raspberry Pi directly to a public network if you have not yet set up secure
passwords for all users. Your device may be compromised by hackers.
Method 1: Enable WiFi Via Ethernet Cable
This method involves using an ethernet connection to utilise SSH for setting up our WiFi.
Once our ethernet connection is established via wired connection with our router, refer to the DHCP
allocation table on your router management console to obtain the IP address of your Raspberry Pi.
6. Once we have obtained the IP address, we can use any SSH client such as PuTTY on Windows to access
the Raspberry Pi. Linux and MacOS users can utilise SSH without any additional software.
On Linux or MacOS, simply enter the following command with the <IP> for your device.
ssh pi@<IP>
Once the connection is successful, we can simply use:
sudo raspi-config
to configure our WiFi connection like we covered before!
Method 2: Enable Wifi via wpa_supplicant
This method involves replacing the wpa_supplicant.conf file on our Raspberry Pi to provide our WiFi
configuration.
First, youâll want to create a wpa_supplicant.conf file with the following content. You can do this with
any text editor.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Country Code>
network={
ssid="<SSID>"
psk="<PASSWORD>"
scan_ssid=1
}
Rememberto replace <CountryCode>,<SSID>,and <PASSWORD> with your own country code,WiFi
SSID and password.
7. Then, mount your SD card with Raspberry Pi OS onto your computer and copy the wpa_supplicant.conf
file to the root of the /boot partition of your SD card. Similar to how we enabled SSH, the file will be used
on boot to apply our new WiFi settings to our Raspberry Pi.
Since we are going entirely headless, it can be difficult to troubleshoot this method of Wifi configuration.
If it doesnât work the first time, check and ensure that the name of your wpa_supplicant.conf file and its
contents are correct before trying again.
Once we successfully configure our WiFi connection using either method above, we can now use SSH over
WiFi to interface with our Raspberry Piâs command line!
Test Your WiFi Connection
Check IP Address
To ensure that our WiFi connection has been established correctly, first unplug your ethernet cable. We can
check our IP address through the command line with:
ifconfig wlan0
Next to âinetâ, we should see our IP address, which indicates a successful connection.
Ping a Website
Next, we can check if our WiFi connection successfully allows us to send and retrieve data to and from our
favourite websites. Try ping google.com to see if you can reach it!