20. USB网卡

野火IMX8M MINI开发板可以使用usb网卡来连接wifi和蓝牙

20.1. 使用USB wifi

前期准备

笔者使用的USB网卡为RTL8821uc,该模组是wifi+bt一体的模组。

未找到图片

iw是linux系统上的一款无线配置工具,使用以下命令下载iw工具。 关于iw工具的使用可以参考以下链接: https://wireless.wiki.kernel.org/en/users/documentation/iw

sudo apt update

sudo apt install iw

将usb wifi插到开发板的USB接口上。

[   59.939344] usb 1-1.1: new high-speed USB device number 3 using ci_hdrc
[   60.611678] usbcore: registered new interface driver btusb
[   60.621576] Bluetooth: hci0: RTL: examining hci_ver=08 hci_rev=000c lmp_ver=08 lmp_subver=8821
[   60.631540] Bluetooth: hci0: RTL: rom_version status=0 version=1
[   60.637732] Bluetooth: hci0: RTL: loading rtl_bt/rtl8821c_fw.bin
[   60.645389] Bluetooth: hci0: RTL: loading rtl_bt/rtl8821c_config.bin
[   60.652649] Bluetooth: hci0: RTL: cfg_sz 10, total sz 31990
[   61.115928] Bluetooth: hci0: RTL: fw version 0x829a7644
[   61.847073] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

20.1.1. 操作步骤

  1. 使用sudo ifconfig -a 查看网口相关信息,会增加一个wifi相关网卡wlan0

#命令
ifconfig -a

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    ether 3a:6c:0f:7d:5e:c6  txqueuelen 1000  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  1. 使用sudo rfkill list all查看射频管理

#命令
sudo rfkill list all

0: phy0: Wireless LAN
    Soft blocked: no
    Hard blocked: no
  1. 使用sudo rfkill unblock all打开所有的射频

#命令
sudo rfkill unblock all
  1. 打开wifi

sudo ip link set wlan0 up
  1. 搜索附近的wifi

iw dev wlan0 scan | grep SSID
  1. 创建/etc/wpa_supplicant/wpa_supplicant.conf,存在则直接打开。文件配置wifi相关账号密码

network={
    ssid="wifi账号"
    psk="wifi密码"
    priority=1
}
  1. 保存内容后退出,并使用以下命令连接wifi

sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf &
  1. 申请动态ip

udhcpc -b -i wlan0

20.2. 使用USB 蓝牙

20.2.1. 操作步骤

使用命令行配置蓝牙,我们需要使用工具—-bluetoothctl

# 进入bluetoothctl命令行
bluetoothctl
# 进入bluetoothctl命令行后,类似:[bluetooth]#
# Controller代表arm板上的蓝牙设备,Device代表蓝牙耳机
# 按如下步骤初始化蓝牙设备,并连接蓝牙耳机
# 查看帮组
help

power on
agent on
default-agent
# 启动扫描
scan on
# 假如蓝牙耳机地址为:04:8C:9A:F2:54:4B
trust 04:8C:9A:F2:54:4B
# 配对
pair 04:8C:9A:F2:54:4B
# 连接
connect 04:8C:9A:F2:54:4B

# 查看蓝牙耳机信息
info 04:8C:9A:F2:54:4B

# 断开连接
disconnect 04:8C:9A:F2:54:4B
# 不想自动连接上蓝牙耳机,可以删除配对信息
remove 04:8C:9A:F2:54:4B

20.3. 常见问题

1.若不能成功连上wifi,请检查wifi账号密码是否正常,检查无误再尝试重新配置。