1. 程式人生 > >初始配置RaspberryPi Zero W(macOS Sierra 10.12.6環境下)

初始配置RaspberryPi Zero W(macOS Sierra 10.12.6環境下)

修改boot盤下檔案

使用USB Gadget驅動將USB-OTG模擬為有線網絡卡:
1. 修改boot分割槽裡的config.txt檔案,在新一行新增:

dtoverlay=dwc2

2. 修改boot分割槽裡的cmdline.txt檔案,在rootwait後新增:

modules-load=dwc2,g_ether

注意新增內容前後需要有空格。

連線電腦

先接通電源,然後使用USB連線電腦,利用SSH登入樹莓派,初始密碼為raspberry:

ssh pi@raspberrypi.local

如果出現Host key verification failed.

的錯誤,只要清除已存的公鑰資訊就可以:

ssh-keygen -R raspberrypi.local

配置網路連線檔案

1. 更改interfaces檔案:

sudo nano /etc/network/interfaces

在檔案中更改:

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

2. 更改wpa_supplicant.conf檔案:

sudo nano /etc/wpa_supplicant
/wpa_supplicant.conf

在檔案最後新增:

network={
    ssid="YourAP"
    key_mgmt=WPA-PSK
    psk="YourPassword"
    priority=5
}

network={
    ssid="YourAP"
    key_mgmt=NONE
    priority=4
}

其中priority為優先順序,數字大的優先順序較高

連線無線網路

1. 輸入以下命令(用於連線無密碼的Wi-Fi網路):

sudo iwconfig wlan0 essid "YourAP"

使用iwconfig wlan0命令檢視連線狀態。

2. 完成後重啟網路:

sudo /etc/init.d/networking restart

重啟網路後可以ping下其他網路看是否連線成功。

更換源

1. 開啟sources.list檔案:

sudo nano /etc/apt/sources.list

2. 加入阿里源(可選擇其他國內源):

deb http://mirrors.aliyun.com/raspbian/raspbian/ wheezy main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ wheezy main non-free contrib

deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib

3. 更新:

sudo apt-get update && apt-get upgrade -y