Google Development Technology expert (GDE) Wangyucheng (York Wang)
The application development of the Internet of Things (IoT) can not be separated from the Development Board, we need to configure the Development Board of the various environments, and finally to use Android Studio for application development.
Today we take Raspberry Pi 3 as an example to build an Android things development environment.
Hardware Preparation
The Raspberry Pi 3 hardware Development Board will look like this:
The Development Board is there, but how should we use the Development Board? Well, let's start by understanding and analyzing the features of the development version:
People who have played Raspberry Pi 3 can skip this paragraph, but for the first time players, there are a few things to note:
Item 1: Do not try to find power, the development Board with the Micro USB port to do power supply interface. Do not find a power adapter, desperately to plug the audio interface, so the manufacturers are also very headache.
Item 2: What kind of position to look for. Each interface has a specific role for each interface. Look at the text on the number, according to the plan to select a specific module on the line.
So many GPIO mouth ah ... What to do? I have a phobia of pins.
-No problem, we will first understand the role of the PIN, you can play the Development Board.
Wait, how do I know which part of the Development Board is the first stitch?
-On the circuit board, find the GPIO pin, from the USB interface farthest from the end, right, the Development Board should have a J8 mark, that is the position of 1th pin, only need to find these pins is enough. Power supply is to lead to 5V or 3.3V power supply pins, and your own circuit, remember to connect the voltage before the connection, otherwise it will burn off the device. Next recognize the UART, SPI, PWM, I²c interface, according to their own needs, find a bread board, you can pull out work.
The hardware is clear, this is the first step, but also to find the development version of the peripherals, generally said peripherals are power supply, display, storage, input these a few chunks.
MicroUSB to power supply;
HDMI for display;
Wired or Wi-Fi is used to connect to the network;
A MicroSD card and a card reader are used to write the system.
With these peripherals and a good breadboard, you can burn your own system.
Download image
Start looking for a place to download the image, the image link here:
Developer.android.com/things/preview/download.html
The 4 development images mentioned in the previous section are available for download.
Raspberry Pi 3 The latest image compression package named Androidthings_rpi3_devpreview_2.zip, after downloading the compressed package, after decompression, only one file iot_rpi3.img, let's see what the format of the file:
This information does not seem enough to allow us to judge the contents of the image, but it is clear that this is an image file that can be started. Let's take a look at what's inside the mirror.
By mirroring the contents, we see the internal structure of the mirror. One of the RPI boot is Raspberry Pi secondary boot, followed by Uboot, Next, is the Uboot the system files to boot. Those who have done uboot level transplant should be very clear bl1, BL2, uboot some concepts, here do not explain in detail.
A few more words here, let's take a look at the Developer Preview 1 version of the image, as an example of the Edison development version of the image:
As you can see, in the Developer Preview 1 edition, there are a number of files, as well as a burn-write script, and FastBoot and ADB tools. However, how to use these tools correctly is a challenge for beginners. So in the Dev Preview 2 version, merging these files into an image file makes it easy to burn and write. Or for Google's intimate praise, each version of the improvements will make it easier for developers to use.
Careful readers will find that some of the files in the two development image files are different, mainly bootloader and the previous executable code. Interested readers can compare the different places and roles of the bootloader of x86 and arm architectures.
Edision image file in the middle, also includes a file, it seems to be looking back a certain history, if you find out, please leave a message below it.
Burn write image to SD card
The Raspberry Pi external storage device is a MicroSD card, hereinafter referred to as the SD card. Because Linux, Windows, Mac Burn-write tools are not the same, we take Linux as an example of the burning process, write the command as long as the DD, but do not DD to your hard drive up!
The most secure process for burning writes is as follows:
$ df-h command, see what the current device, if the computer does not recognize the SD card, then start the 2nd step, if the computer has recognized the SD card, write down the SD card is which device, you can go 3rd step;
Insert the SD card and repeat the first step;
$ sudo dd bs=4m if=iot_rpi3.img of=/dev/sdx command, determine the device number of your SD card, and then burn the downloaded img file to the SD card, this step requires root permission oh. Here is a reminder that instead of burning a partition on an SD card, burn it to the device on which the SD card resides.
The $ sync command synchronizes the data to the SD card.
Windows system, with the Win32diskimager tool, with administrator rights, burning the IMG file to the SD card.
Under the MAC system is also the command under Linux:
$ sudo dd bs=1m if=image.img of=/dev/rdisk
Start the Development Board
You can start the Development Board by plugging the MCIROSD card that has been written to Android things into the corresponding position of the Raspberry Pi 3.
To start the Development Board, follow these steps:
power supply with MicroUSB;
inserting a network cable;
Insert the HDMI interface.
Probably the first time the system starts up for a minute or two, be patient and wait on the line.
After the system starts, the monitor shows the IP address of the current wired network, and the status of Wi-Fi is not connected. So, we can use the IP of the wired network to connect ADB:
$ adb Connect
Connected to:5555
Since Raspberry Pi is supported for DNS broadcast, if your PC supports MDNS features, run the command:
$ adb Connect android.local
Once the connection is successful, it returns:
Connected to:5555
In this way our ADB is normally connected to the Raspberry Pi 3. With ADB, we can connect to Wi-Fi.
It contains the user name and password, if your password is empty, do not add-e passphrase this parameter.
The next step is to check that Wi-Fi is properly connected:
The message above indicates that Wi-Fi is up and running. Does the DNS pass? Dial the network cable, then ping it and try it out.
Connecting the serial port for debugging
Now, even though the ADB is connected, the Internet has gone through, but things have just begun. In the pre-work, we introduced a more convenient debugging method, that is embedded in the development of the Ashes level debugging mode: Serial debugging:
Right, take the USB to TTL line, find the GPIO pin on the UART TXD and RXD two pins. Then find the ground, connected to the corresponding DuPont line on it. Wait, four pins, why is there a pin not connected it, that is not the power line? Due to the USB to TTL line, the USB port is already powered, so the VCC interface does not need to be connected.
It is important to note that RX and TX are cross-linked, not directly connected. Because the TX on the Development Board is the RX on the USB side. The difference between RS-232 and TTL is skipped here.
Then we will start using the serial debugging software on the PC to connect the USB to the serial port. The tools of the three systems are not quite the same. Windows has putty, SECRUCRT and so on, Linux under the mimicom, Mac has Serial. Choose according to your own operating system. But remember the baud rate is set to 115200, 8N1, and then do not use flow control, whether hard flow control or soft flow control, all of the election. Have seen too much blood in the general lesson, chose the flow control, the result spent a long time tracking, serial port What print also no, but the oscilloscope can see serial data ... This time is not worth it.
Power off the Board and Dial out the SD card. Read the SD card with the PC machine. Then put cmdline.txt this line in this file:
Remove it. But as an embedded developer, who is willing to close the serial port? Are you? Of course, if your development, there are serial devices for other purposes, you can switch off the serial output.
The next step is to start the analysis of the SDK for Android things.
Android things feature 3 development environment building