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 网络
  • HDMI

刷入系统镜像

所需硬件:

  • HDMI 线
  • HDMI 显示器
  • Micro-USB 线
  • RJ45 网线
  • MicroSD 读卡器

下载 Android Things 最新 Preview 版镜像:

  • 容量至少8G 的 microSD 卡

  • 解压下载的 Things 系统镜像

  • 按RaspberryPi 官方的教程烧写镜像到 SD 卡:

    • Linux
    • Mac
    • Windows
  • 把写好镜像的 SD 卡插入 RaspberryPi 板子

  • 连接电源线、HDMI显示器、网线


  • 验证 AndroidThings 是否运行在 RaspberryPi 上。AndroidThings Launcher 会在显示器上显示板卡的信息,包含 IP 地址。

  • 通过 adb 连接 RaspberryPi 的 IP

    $ adb connect 
    connected to :5555
    

连接 Wi-Fi

使用 adb 进行 Wi-Fi 设置:

  • 向 Wi-Fi Service 发送一个 intent,参数包含 SSID 和 本地网络的 passcode:

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

如果没有密码,可以不用 passphrase 参数

  • 使用 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
    
    

串口调试 Console

串口控制台是一个很有用的工具,用于调试主板和系统的 log 信息。串口 console 是系统 kernel 的日志默认的输入位置(如 dmesg),并且提供了一个全功能的 shell 环境可以使用诸如logcat的命令。在没有网络连接时,如果你没有其他方式连接 adb,串口 console 会很有用。

接线方式(使用 USB 转 TTL 串口线连接设备 UART 针脚):

使用终端工具访问 USB 串口设备。不同平台的可以用的工具: PuTTY (Windows), Serial (Mac OS), Minicom (Linux)。

串口参数如下:

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

禁用串口 console

Raspberry Pi 的调试 console 和 UART0 共用I/O针脚,因此在用 UART 连接其他外围设备时,会产生冲突。在 app 访问 UART0 之前,需要按以下步骤禁用串口 console:

  • 断开电源,移除 SD 卡

  • 把 SD 卡插到开发机

  • 在开发机上访问 SD 卡分区:

    • 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 口

你可能感兴趣的:(Android Things for Raspberry Pi 3 (起步篇))