Android Things:树莓派3上手就是这么简单

来源:互联网 发布:木头马尾原创服装淘宝 编辑:程序博客网 时间:2024/04/30 20:16
一、树莓派3简介
官方推荐的开发板有Intel Edison、NXP Pico i.MX6UL和Raspberry Pi 3(树莓派3)。树莓派是世界上最流行的单板计算机,3 Model B是最新的版本,我们后面就使用它给大家介绍Android Things。它提供了如下配置:

1.一个双核64位ARM Cortext-A53 1.2GHz CPU(512M的内存,在背面);
2.400 MHz GPU;
3.电源接口;
4.HDMI和DSI视频接口;
5.音频接口; 
6.有线、无线网络和蓝牙4.1模块;  
7.4个USB 2.0接口;
8.40-针GPIO连接器用于连接外设;
9.SD卡存储(在侧边);
二、系统安装
1.准备你的硬件设备,如:1-树莓派3开发板,2-电源线,3-HDMI转接线(连接显示器),4-SD卡等和5-网线;

2.在你的电脑上插入8G或者更大的SD卡;
3.下载你的开发板(以树莓派3为例)对应的系统镜像(https://developer.android.com/things/preview/download.html),并解压img文件;

4.下载你使用的操作系统对应的(以Windows7为例)Win32DiskImager,并安装(https://sourceforge.net/projects/win32diskimager/);
5.以管理员用户启动Win32DiskImager,选择解压的ImageFile,选择插入的SD卡磁盘,点击Write等待写入完毕;

注意:千万小心!!如果选择的磁盘不是SD卡,会损坏该磁盘中的数据;
6.将你的SD卡插入到开发板中,连接开发板的1-电源、2-HDMI转接线和3-网线;

7.打开电源,显示器就会输出相关启动信息,启动成功后显示如下;

8.使用adb tools通过ip(通过路由器可查看)连接开发板安装的Androoid Things系统(显示WiFi和网络连接ip);
[plain] view plain copy
  1. C:\Users\chengxiang.peng.QUNARSERVERS>adb connect 192.168.1.101:5555  
  2. connected to 192.168.1.101:5555  
  3. C:\Users\chengxiang.peng.QUNARSERVERS>adb devices  
  4. List of devices attached  
  5. 192.168.1.101:5555      device  
三、连接Wi-Fi
官方强烈建议我们连接网络,这会使得你的设备上传崩溃报告和获取更新。下面我们就看看如何使用Wi-Fi进行连接;
1.发送一个Intent给Wi-Fi Service来连接Wi-Fi;
[plain] view plain copy
  1. C:\Users\chengxiang.peng.QUNARSERVERS>adb shell am startservice \-n com.google.wifisetup/.WifiSetupService \-a WifiSetupService.Connect \-e ssid MERCURY_5CD00C\-e passphrase 30x30x30xx  
  2. Starting service: Intent { act=WifiSetupService.Connect cmp=com.google.wifisetup/.WifiSetupService (has extras) }  
注意:由于我们必须先通过adb tools通过ip连接,才能通过adb shell am startservice启动Wi-Fi Service,所以在连接Wi-Fi前你还必须使用网线连接你的开发板;
提示1:C:\Users\chengxiang.peng.QUNARSERVERS>adb shell am startservice -n com.google.wifisetup.WifiSetupService -a WifiSetupService.Connect -e ssid MERCURY_5CD00C -e p assphrase 30x30x30xx
... ...
Error: Bad component name: com.google.wifisetup.WifiSetupService
处理1:我们实践的是Windows系统,命令中的转义\不能省去;

2.通过查看logcat日志确认是否连接成功(你也可以通过显示器查看WiFi信息是否连接成功 );
[plain] view plain copy
  1. C:\Users\chengxiang.peng.QUNARSERVERS>adb logcat | findstr "Wifi"  
  2. ... ...  
  3. //网络连接成功  
  4. 01-01 00:13:56.412  1254  1254 V WifiWatcher: Network state changed to CONNECTED  
  5. 01-01 00:13:56.414  1254  1254 V WifiWatcher: SSID changed: "MERCURY_5CD00C"  
  6. 01-01 00:13:56.415  1254  1270 I WifiConfigurator: Successfully connected to MERCURY_5CD00C  
  7. 01-01 00:13:56.484   408   456 D WifiNetworkAgent: NetworkAgent: Received signal strength thresholds: []  
  8. .... ...  
  9. //保存连接历史,下次启动自动连接  
  10. 01-01 00:14:08.190   408  1299 D WifiNetworkHistory: saving network history: "MERCURY_5CD00C"WPA_PSK gw: 00:25:86:5c:d0:0c Network Selection-status: NETWORK_SELECTION_ENABLED ephemeral=false choice:null link:0 status:2 nid:0 hasEverConnected: true  
  11. 01-01 00:14:08.190   408  1299 V WifiNetworkHistory: writeKnownNetworkHistory write config "MERCURY_5CD00C"WPA_PSK  
  12. ... ...   
  13. 0:25:86:5c:d0:0c is in blacklist.  
3.我们尝试ping下百度,确认可以访问远程网络;
[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. C:\Users\chengxiang.peng.QUNARSERVERS>adb shell ping www.baidu.com  
  2. PING www.baidu.com (111.13.100.91) 56(84) bytes of data.  
  3. 64 bytes from 111.13.100.91: icmp_seq=1 ttl=52 time=5.99 ms  
  4. 64 bytes from 111.13.100.91: icmp_seq=2 ttl=52 time=5.72 ms  

参考
https://developer.android.com/things/hardware/raspberrypi.html#flashing_the_image
https://www.raspberrypi.org/documentation/installation/installing-images/windows.md
0 0
原创粉丝点击