Android Things for Raspberry Pi 3 (起步篇)

Raspberry Pi 3 Mode B:

  • 1.2G 4核 64位 ARM Cortex-A53 CPU
  • 4個USB2.0接口
  • 40針 GPIO 接口
  • 有線和無線 Wi-Fi 網(wǎng)絡(luò)
  • HDMI

刷入系統(tǒng)鏡像

所需硬件:

  • HDMI 線
  • HDMI 顯示器
  • Micro-USB 線
  • RJ45 網(wǎng)線
  • MicroSD 讀卡器

下載 Android Things 最新 Preview 版鏡像:

  • 容量至少8G 的 microSD 卡

  • 解壓下載的 Things 系統(tǒng)鏡像

  • 按RaspberryPi 官方的教程燒寫鏡像到 SD 卡:

  • 把寫好鏡像的 SD 卡插入 RaspberryPi 板子

  • 連接電源線、HDMI顯示器、網(wǎng)線


  • 驗證 AndroidThings 是否運行在 RaspberryPi 上。AndroidThings Launcher 會在顯示器上顯示板卡的信息,包含 IP 地址。

  • 通過 adb 連接 RaspberryPi 的 IP

    $ adb connect <ip-address>
    connected to <ip-address>:5555
    

連接 Wi-Fi

使用 adb 進行 Wi-Fi 設(shè)置:

  • 向 Wi-Fi Service 發(fā)送一個 intent,參數(shù)包含 SSID 和 本地網(wǎng)絡(luò)的 passcode:

    $ adb shell am startservice \
        -n com.google.wifisetup/.WifiSetupService \
        -a WifiSetupService.Connect \
        -e ssid <Network_SSID> \
        -e passphrase <Network_Passcode>
    

如果沒有密碼,可以不用 passphrase 參數(shù)

  • 使用 logcat 驗證是否連接成功:

    $ adb logcat -d | grep Wifi
    ...
    V WifiWatcher: Network state changed to CONNECTED
    V WifiWatcher: SSID changed: ...
    I WifiConfigurator: Successfully connected to ...
    
  • 測試是否可以 ping 通遠程 IP:

    $ adb shell ping 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
    64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=6.67 ms
    64 bytes from 8.8.8.8: icmp_seq=2 ttl=57 time=55.5 ms
    64 bytes from 8.8.8.8: icmp_seq=3 ttl=57 time=23.0 ms
    64 bytes from 8.8.8.8: icmp_seq=4 ttl=57 time=245 ms
    
    

串口調(diào)試 Console

串口控制臺是一個很有用的工具,用于調(diào)試主板和系統(tǒng)的 log 信息。串口 console 是系統(tǒng) kernel 的日志默認(rèn)的輸入位置(如 dmesg),并且提供了一個全功能的 shell 環(huán)境可以使用諸如logcat的命令。在沒有網(wǎng)絡(luò)連接時,如果你沒有其他方式連接 adb,串口 console 會很有用。

接線方式(使用 USB 轉(zhuǎn) TTL 串口線連接設(shè)備 UART 針腳):

使用終端工具訪問 USB 串口設(shè)備。不同平臺的可以用的工具: PuTTY (Windows), Serial (Mac OS), Minicom (Linux)。

串口參數(shù)如下:

  • Baud Rate: 115200
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1

禁用串口 console

Raspberry Pi 的調(diào)試 console 和 UART0 共用I/O針腳,因此在用 UART 連接其他外圍設(shè)備時,會產(chǎn)生沖突。在 app 訪問 UART0 之前,需要按以下步驟禁用串口 console:

  • 斷開電源,移除 SD 卡

  • 把 SD 卡插到開發(fā)機

  • 在開發(fā)機上訪問 SD 卡分區(qū):

    • Linux: Use dmesg to discover the disk name (e.g. sdX), followed by mount to make the first partition accessible:
    $ dmesg
    ...
    [...] sd 9:0:0:0: [sda] Attached SCSI removable disk
    ...
    $ mount /dev/sda1 /mnt/pisdcard
    
    • Mac: Use diskutil list to discover the disk name (e.g. diskX), followed by mount to make the first partition accessible:
    $ diskutil list
    /dev/disk0 (internal, physical):
       ...
    /dev/disk1 (internal, virtual):
       ...
    /dev/disk2 (external, physical):
       ...
    $ mount -t msdos /dev/disk2s1 /Volumes/pisdcard
    
    • Windows: Open File Explorer and locate the RPIBOOT volume.
  • 找到cmdline.txt文件,刪除以下行:

    console=serial0,115200
    

    如果需要再次啟用,可以把這行再加回來

  • 保存 cmdline.txt文件,卸載 SD 卡

  • 把 SD 卡插入 RaspberryPi,通電啟動

RaspberryPi I/O 口

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容