Mikagami
Posts: 4
Joined: Wed Nov 25, 2015 5:27 pm

[GUIDE] Android Device as Screen for rPi via USB & VNC

Fri Dec 04, 2015 6:19 pm

My Problem: I like to travel lite when going abroad and a rPi doesn't add much weight. :D but screens or monitors do and I always have my phone or a tablet with me.

Goal: Be able to use my android device as the head of my raspberry pi.

I researched high and low and tried different solutions that have worked for other people but for some reason or another it didn't for me. So after finally finding a solution for my problem I decided to post it in case it helps someone else. Now I used an android device but any device that you can install a VNC client on and connect it to the rPi via USB should work.

Physical Materials I Used:
1: Raspberry Pi B
2: 16GB memory card
3: Android Device (Nexus 5)
4: Standard Cables & Adapters (micro usb, power adapter for pi, hdmi to vga, keyboard & mouse)

Software Used:
1: Raspbian Jessie ver. Nov 2015
2: SD Formatter
3: Win32DiskImager
4: x11vnc (for the Pi)
5: bVNC Free (for the Android Device)

Step 1: Install Raspbian to SD card

The rPi Foundation has already created a great guide to install Raspbian so here are their resources:

Download Raspbian Image: https://www.raspberrypi.org/downloads/raspbian/

Install Image to SD Card: https://www.raspberrypi.org/documentation/installation/

Step 2: Configure Standard Settings on rPi

Once again the rPi Foundation has great documentation for this as well.

Configure rPi: https://www.raspberrypi.org/documentati ... -config.md

*Note that all I did was expand the file system and set the localisation settings, nothing else.

Step 3: Configure USB port with a static IP

This piece of the guide is thanks to Joshua Woehlke's post, with a little change:
http://joshuawoehlke.com/android-raspbe ... -over-usb/

Log into the rPi and get to a terminal window either via SSH if already using the Pi headless, starting the GUI by typing

Code: Select all

startx
, or if you are already at the terminal window then...great.

We will configure a USB interface to have a static IP, which we will later use to connect to the rPi from our android device. To do so type the following and press enter:

Code: Select all

sudo nano /etc/network/interfaces
Add the following code somewhere at the end since you will have interface data there already:

Code: Select all

allow-hotplug usb0
auto usb0
iface usb0 inet static
address 192.168.42.42
netmask 255.255.255.0
network 192.168.42.0
broadcast 192.168.42.255
Once done entering that data press "control+X", on the next prompt press "Y" then finalize saving the data by pressing "Enter".

Step 4: Install x11vnc on the rPi

This piece of the guide is thanks to a post by "emg" in the following thread on the forums:
viewtopic.php?p=108862#p108862

To install x11vnc type the following and press enter:

Code: Select all

sudo apt-get install x11vnc
Next lets set a password that we will need when trying to connect to the rPi with our android device later. Type the following and press enter, you will then be given the option to type your desired password:

Code: Select all

x11vnc -storepasswd
Step 5: Create an autostart entry for x11vnc

This piece of the guide is from the same post referenced in Step 4.

We need to have the vnc server run automatically when we give power to the rPi so that all we really need is to connect our android device. To do so type the following lines of code and press "Enter" after each line.
First Line:

Code: Select all

cd .config
Second Line:

Code: Select all

mkdir autostart
Third Line:

Code: Select all

cd autostart
Fourth Line:

Code: Select all

nano x11vnc.desktop
Now insert the following text:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=X11VNC
Comment=
Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer
StartupNotify=false
Terminal=false
Hidden=false
Once done entering that data press "control+X", on the next prompt press "Y" then finalize saving the data by pressing "Enter".

Step 6: Install VNC client on Android Device

Go to the Play Store and install the free app bVNC:
https://play.google.com/store/apps/deta ... bVNC&hl=en

Shutdown the rPi, DON'T JUST UNPLUG IT, connect your android device to the rPi using a USB cable, make sure no other usb devices are connected to the pi and you can unplug video source (monitor, tv, whatever you were using to configure the Pi).

Power up your rPi and wait about 20-30 seconds for it to boot.

Turn on "USB Tethering" on your Android device. On Android Marshmallow I had to go to "Settings", "More", and "Tethering & portable hotspot" to find the setting.

Open the bVNC app and enter the following IP in the "VNC Server" field:

Code: Select all

192.168.42.42
Enter the password you set back in Step 4 into the "VNC Password" field and click the "Connect" button.

If everything went smoothly then you should now see the GUI interface for Raspbian.

Now you can use your android device to control your rPi!

Seafood
Posts: 15
Joined: Sun Apr 20, 2014 4:25 am
Location: Australia

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Sun Dec 06, 2015 5:41 am

You have no idea how much I needed that

User avatar
karrika
Posts: 1087
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Mon Dec 07, 2015 9:44 am

Thanks for sharing. I have to try this tonight.

Mikagami
Posts: 4
Joined: Wed Nov 25, 2015 5:27 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Mon Feb 22, 2016 8:50 pm

I am glad this has been of help to others.

I really enjoyed this setup since the rPi now gets internet from my phone and I get to control the rPi via a touchscreen, pretty handy. :)

blaablaaguy
Posts: 623
Joined: Sun Sep 27, 2015 3:26 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Sun Feb 28, 2016 7:43 pm

Do you need internet access on the phone/to do this?
This signature intentionally left blank.

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Sun Feb 28, 2016 10:45 pm

blaablaaguy wrote:Do you need internet access on the phone/to do this?
You'll find it hard to install the software without it.

Once installed the pi communicates with the phone by USB so internet isn't necessary.
Doug.
Building Management Systems Engineer.

dosnoventa
Posts: 3
Joined: Sun Mar 13, 2016 10:54 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Sun Mar 13, 2016 11:01 pm

I keep getting an error when trying to connect through the vnc:

"java.net.ConnectException: failed to connect to /192.168.42.42 (port 5901): connect failed: EHOSTUNREACH (no route to host)"

i keep trying to find the source to this issue and i followed every step accurately, i even did it twice and it still wont work

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Mon Mar 14, 2016 10:46 am

Is VNC display :1 (port 5901) running? Is that the right address for your RPi?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Mon Mar 14, 2016 11:32 am

Check it with sudo netstat -tlnp | grep vnc

Please reply on the forum, DO NOT send private messages.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

dosnoventa
Posts: 3
Joined: Sun Mar 13, 2016 10:54 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Mon Mar 14, 2016 11:33 pm

DougieLawson wrote:Check it with sudo netstat -tlnp | grep vnc

Please reply on the forum, DO NOT send private messages.
i checked and the port 5900 is listening, but even if i use that port on the vnc viewer, i still get the error message

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Tue Mar 15, 2016 12:19 am

What task is listening on 5900? What happens if you explicitly start vncserver :1 from a command line (or LXTerminal)?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

dosnoventa
Posts: 3
Joined: Sun Mar 13, 2016 10:54 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Tue Mar 15, 2016 1:37 am

DougieLawson wrote:What task is listening on 5900? What happens if you explicitly start vncserver :1 from a command line (or LXTerminal)?
The task listening on 5900 is x11vnc and i tried starting the vnc server explicitly and nothing happened, unless i missed something, but it shows x11vnc listening on port 5900

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Tue Mar 15, 2016 1:16 pm

Is 192.168.42.42 really the address of your RPi? What's the IP address of your Android tablet? Is it in the same subnet?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Mikagami
Posts: 4
Joined: Wed Nov 25, 2015 5:27 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Thu Mar 31, 2016 8:03 pm

Do you have your device connected to the correct interface? USB0 in the guide. Try a different port if you are unsure.

I apologize if it seems simplistic but just making sure all rocks are being turned. ;)

thintin
Posts: 2
Joined: Thu Oct 13, 2016 9:31 am

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Thu Oct 13, 2016 9:50 am

Hi.

Thanks for this tutorial, it's really easy to follow and was a great help. I am having one problem though...

Image

...any suggestions?

This is the screenshot from my Xperia Z4 tablet which has a 10" 2K screen. I tried using my older Jellybean 7" tablet (which is what I really wanted to use) but USB tethering isn't available on JB unless you have a data connection, and this old tablet only has WiFi!

Meeeric1
Posts: 1
Joined: Wed Jan 11, 2017 10:48 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Wed Jan 11, 2017 10:57 pm

Hello. I have e tried doing this using the first method and did everything, but when I clicked "connect" on the bvnc app, I got an error message saying:
"Connection failed Connection to VNC server failed with reason : Server did not offer supported security type . Please ensure you have picked the right item in Connection Type java.lang.Exception : Server did not offer supported security type Please ensure you have picked the right item in Connection Type . at com .iiordanov . freebvNC.RfbProto.s electSecurityTypeAfbProto.java : 627 at com.iiordanov.freebvNC.RfbProto.n egotiateSecurity ( RfbProtojava : 514 ) com . ii ordanov . freebvN C. RfbProto.i niti alizeAndAuthenticate ( RfbProtoj ava : 382 ) at com . ¡ iordanov . freebVNC . RemoteCa nvasstartVncConnection ( RemoteC anvas - java : 429 )"
What does this mean, and what should I do?

danoz
Posts: 7
Joined: Mon Dec 18, 2017 9:38 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Mon Dec 18, 2017 9:45 pm

works great by now I have a probelm:
the WIFI isn't working...
how can I make the WIFI work while controlling the pi via USB??

thanks

dongleason
Posts: 3
Joined: Thu Dec 21, 2017 5:51 am

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Thu Dec 21, 2017 6:04 am

The tablet wifi or the Pi wifi?


dongleason
Posts: 3
Joined: Thu Dec 21, 2017 5:51 am

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Tue Dec 26, 2017 6:21 am

Go take a look at forum # 168507 (static ip for usb in Raspian Jessie). It solved my problem and hopefully it will fix yours too!

danoz
Posts: 7
Joined: Mon Dec 18, 2017 9:38 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Tue Dec 26, 2017 8:25 am

thnak you :)

so you have the RP's wifi working, while connected to your phone via USB?

danoz
Posts: 7
Joined: Mon Dec 18, 2017 9:38 pm

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Tue Dec 26, 2017 10:44 pm

dongleason wrote:
Tue Dec 26, 2017 6:21 am
Go take a look at forum # 168507 (static ip for usb in Raspian Jessie). It solved my problem and hopefully it will fix yours too!
hi,
tried this but the RP's WIFI is still not working...

AzraelEcho
Posts: 1
Joined: Sun Jan 28, 2018 1:26 am

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Sun Jan 28, 2018 6:48 am

danoz wrote:
Tue Dec 26, 2017 10:44 pm
dongleason wrote:
Tue Dec 26, 2017 6:21 am
Go take a look at forum # 168507 (static ip for usb in Raspian Jessie). It solved my problem and hopefully it will fix yours too!
hi,
tried this but the RP's WIFI is still not working...

Hi,

I met the same problem and solved it. I guessed that the key is how to set the static IP for usb0. As in forum # 168507, there are two ways.

The first one (maybe the popular one) is to amend the sudo nano /etc/network/interfaces file with:
allow-hotplug usb0
iface usb0 inet static
address 192.168.42.42
netmask 255.255.255.0
network 192.168.42.0
broadcast 192.168.42.255
gateway 192.168.42.41

For me, the usb0 works but I met the problem on the usb wifi adaptor. I cannot find the wlan0 and eth0 in ifconfig.

Then I tried the second one, by amending the sudo nano /etc/dhcpcd.conf file with:
interface usb0
static ip_address=192.168.42.42/24 (I used 192.168.42.214 as suggested in https://raspberrypi.stackexchange.com/q ... -a-network)

Both the usb0 and wlan0 work.

Hope it is useful.

P.S: If anyone knows what's the difference between amending /etc/network/interfaces and /etc/dhcpcd.conf, please tell me. Someone suggested not modify the first one (viewtopic.php?t=191453)
Last edited by AzraelEcho on Sun Jan 28, 2018 3:10 pm, edited 1 time in total.

LEDDIM
Posts: 2
Joined: Tue Feb 27, 2018 9:10 am

Re: [GUIDE] Android Device as Screen for rPi via USB & VNC

Sat Mar 31, 2018 2:39 am

If you add your Android phone's hotspot to your Pi's wifi networks you can directly connect your phobe's VNC viewer to the Pi. I use it as a backup, in case I change to another network I can use my phone'sVNC viewer to connect to my Pi and set up a new wifi connection.
You can also connect other devices to your hotspot and use VNC viewer from there.No internet connection (4G) required...

Return to “Other projects”