My Android Things

Android Things Tutorials (IoT)

Tutorial 5 : Setting up Network/Wifi on Raspberry PI with ADB commands

To connect to Raspberry PI we need it to be connected over same network that our computer (Running Android Studio) is. We can connect Raspberry PI to network via LAN or wifi. Here we will learn both ways:


Connecting via LAN:

Step 1 : Disconnect the Pi from your power supply to power it down, and connect the Ethernet cable on it.


Step 2 : Now power it up again, and you should see that this time when it powers up it’s assigned an IP Address. Note down the given IP. Note: If you don't have HDMI display, you can move to next step in this process directly.


Step 3 : Now open your Android Studio with our empty project, and click on "Terminal" Tab from the bottom bar of Android Studio:



Step 4 : Now a terminal window will open at the bottom of Android Studio Like this:



Step 5 : Now to connect to raspberry pi, type following command in Terminal Window:

adb connect <ip-address>

Here replace <ip-address> with the ip-address shown at your HDMI screen and hit ENTER, You will get output like:


If you don't have an HDMI cable, so don't know your Raspberry PI IP address; No worries. The Raspberry PI Automatically broadcasts "Android.local" name and it should resolve to the IP address assigned to your Pi on port 5555. Running the following:

adb connect Android.local

The command above is effectively the same as running:

adb connect <ip-address>


Now, we can give any adb command via Terminal Window to Raspberry PI.


Connecting via WiFi:

If you hate working with Network Cable, you can now connect your Raspberry PI via WiFi connection. So everytime your Raspberry PI get started; It will automatically connected to your provided Wifi Connection. To connect WiFi run following command [replace the network ssid & password].

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


Press enter and restart your Raspberry PI without LAN cable. Now, you will see one IP address has been assigned to your raspberry PI over WiFi.



Now from your Android Studio's Terminal Window fire following command:

adb connect <new-ip-address>

Congrats now your little Pi is connected to WiFi yay!

Now from your Android Studio's Terminal Window fire following command:

adb devices 

command you should see your Pi attached.