Plug the USB WiFi adapter into one of the free USB ports on the Raspberry Pi. Power up the Raspberry Pi – remember at this point the WiFi adapter does not work yet. You are still going to need some other means of being able to control the Raspberry Pi either via a keyboard or remotely using a wired network connection.
After booting and logging-in you want to make sure that the Raspberry Pi found your new wireless adapter. To look at which peripherals the operating system found when booting run the following command:
dmesg | grep usb
You can use the spacebar to scroll down a page at a time – towards the end you will see something similar to the following lines:
[ 3.282651] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[ 3.394810] usb 1-1.2: New USB device found, idVendor=7392, idProduct=7811
[ 3.407489] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3.420530] usb 1-1.2: Product: 802.11n WLAN Adapter
This means that the operating system recognized the USB WiFi Adapter using one of the built-in drivers (you can return to the terminal by pressing “q”). All that is left is to configure your WiFi connection.
首先搜索Realtek驱动:
1
apt-cache search realtek
firmware-realtek – Binary firmware for Realtek wired and wireless network adapters
安装Realtek驱动:
1
sudo apt-get install firmware-realtek
如果你的树莓派现在不能上网,那么你可以去镜像站点中下载相关驱动。我推荐阿里云的镜像站点,速度比较快。http://mirrors.aliyun.com/raspbian/raspbian/pool/non-free/f/firmware-nonfree
下载firmware-realtek_0.43_all.deb,用winscp上传到树莓派的/tmp目录中。输入命令安装:
1
sudo dpkg -i /tmp/firmware-realtek_0.43_all.deb
Configuring the WiFi network
On the Raspberry Pi (and on Linux in general) you configure your network settings in the file “/etc/network/interfaces”. You can edit this file using the following command:
sudo nano /etc/network/interfaces
This will open the file in an editor called nano it is a very simple text editor that is easy to approach and use; even for users not familiar to a linux based operating systems just use the arrow keys.
After opening the file in nano you will see a screen like this:
interfaces in nano - initialTo configure you wireless network you want to modify the file such that it looks like the following:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid “Your Network SSID”
wpa-psk “Your Password”
You will need to put your own SSID and password into the appropriate places. If you can’t remember your network name – just pull up your phone it will most like display the name in the settings or network settings screens.
After editing the file you should see something like the following:
interfaces in nano - after edit
To save the file press Ctrl+O this will write the file to the disk – afterwards you can exit nano by pressing Ctrl+X. If nano asks if you want to Save modified buffer? press “Y” followed by hitting enter to confirm the filename.
At this point everything is configured – all we need to do is reload the network interfaces. This can be done by running the following command (warning: if you are connected using a remote connection it will disconnect now):
sudo service networking reload
After reloading the network interface (and re-connecting to the pi if you are using a remote connection) – you can now check the status of our WiFi connection by running:
ifconfig
The result should look something like this:
wlan0 Link encap:Ethernet HWaddr 80:1f:02:aa:12:58
inet addr:192.168.1.8 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:154 errors:0 dropped:173 overruns:0 frame:0
TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32399 (31.6 KiB) TX bytes:13036 (12.7 KiB)
If you see a valid IP address under “inet addr” you can now disconnect the network cable, and enjoy your freedom to move your Raspberry Pi around – because the WiFi connection is up and running!