Preparation:
Hardware: Raspberry Pi 4 B (Raspberry Pi mainboard) Power cable Memory card reader
software:
Raspeberry Pi Imager (programming the image source file, Tsinghua source is recommended, configure the host name and password, ssh, and wifi account password)
MobaXterm connects to Xshell (commonly known as SSH, connects to Raspberry Pi terminal)
The installation environment preparation work is available online, so I won’t introduce it much.
Start connecting to laptop wifi
I feel that it is very inconvenient for the Raspberry Pi to use wifi to connect. The connection speed is much slower than that of the network cable. It is very inconvenient during normal debugging. I suggest that you usually use a network cable to connect, and use wifi when you need to use wifi to connect.
1. Simple use of wifi connection
1.1 Turn on the laptop wifi mobile hotspot
Right click on the mobile hotspot, go to "Settings"
Turn on Sharing Internet Connection with Other Devices
Edit the network name and password, and set the network frequency band to 2.4Ghz
1.2 Put the SD card into the card reader and insert it into the computer to edit the file
Create a new file name ssh (blank content does not need to be edited, no suffix)
Create a new file named wpa_supplicant.txt with the following contents
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="pi" //wifi名称
psk="12345678" //wifi密码
priority=2 //优先级,多个网络时优先级大的先连接
}
Then save, modify wpa_supplicant.txt to wpa_supplicant.conf
Put the files ssh and wpa_supplicant.conf into the memory card.
Insert the memory card into the Raspberry Pi, and start the Raspberry Pi. If it is connected, open the mobile hotspot to check the IP, then use ssh to open the Raspberry Pi terminal.
Note: But I can't connect life and death, and the ip is not displayed.
2. Connect the Raspberry Pi with a network cable
Connect the Raspberry Pi and the computer with a network cable to check the IP
Open Windows Computer Settings → Open Network and Internet → Change Adapter Options
Right-click WLAN properties → click sharing → open to allow other network users through... → home network connection select Ethernet
Right-click Ethernet Properties → click Internet Protocol Version 4
Note down the IP address (192.1688.137.1, this IP address is used to check the Raspberry Pi IP)
win+R to open the windows command terminal, enter cmd, and then enter
arp -a
Find the one whose interface is the above IP (192.167.137.1)
There are not so many IPs for the first connection, because I have explored for a long time before and haven't done it well.
Usually two (except the other one at 192.168.137.255)
然后打开Xshell(SSH)输入IP就能连接成功
网线这就连接成功了。
wifi连接不成功是因为里面没有配置好。然后我们利用网线连接打开树莓派终端开始配置wifi。
3.配置wifi
3.1 wlan0没打开
在终端输入
ifconfig
查看是否有wlan0
如果没有wlan0 就证明你没有wifi驱动,需要打开射频,
rfkill list
这里就被锁住了,需要打开
rfkill unblock all
在打开wlan0
sudo ifconfig wlan0 up
3.2 能否正常搜索到wifi
在树莓派终端输入
sudo iwlist wlan0 scan | grep ESSID
查看是否能搜素到wiifi
如果没有搜素到,怎证明你的移动热点有问题。
3.3 配置interfaces文件
输入
sudo nano /etc/network/interfaces
我这个配置是正常的.
我的配置是
source /etc/network/interfaces.d
auto lo wlan0
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa_conf /etc/wpa_supplicant/wpa_supplicant.conf
3.4 查看ssid和psk是否正确
输入
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
查看wifi配置
如果正常就可以退出。
3.5 查看当前允许频道
输入
iwlist channel
一般来说是13个2.4Ghz 5个5GHz,然后你自己查看下你的wifi是否在这个频道内。
输入
sudo ifup wlan0
查看无线网有无连接上
inet 后面有IP证明连接上wifi了。
3.6 只有inet6无inet
打开wlan0发现并没有IP
输入
sudo ifconfig wlan0 192.168.137.100
就可以自己手动设置一个IP
发现就有inet了。