Accessing Raspberry Pi From a Smartphone Part 2 – VNC Auto-run

Accessing Raspberry Pi From a Smartphone Part 2 – VNC Auto-run


In the second part of our series on how to control Raspberry Pi using VNC, we’ll set up the auto-run. We will get into the second half of the document from Raspberry Pi’s official website, “Automation and run at boot”.

First, let’s fix the IP address before we mount the auto-run. With a fixed IP, we can connect from the VNC app with one touch!
We re-installed a new Raspbian at start, but the Wi-Fi setting was different from before, so let’s start from there!

Wi-Fi settings

After installing Raspbian (ver.3.1.8) released on 2015-05-05, I can’t seem to find “WIFI Config” where I used to set up the Wi-Fi. It seems that the way to set it up has changed.


Figure 1

I found this mark on the top right of the desktop when I was looking for the network settings!


Figure 2

Click the icon and you will see a list of networks. If you are connected to a Wi-Fi network, a green check mark will appear as seen on the first row.


Figure 3

From the list, select the network you want to connect to, then you will be asked to enter the password.


Figure 4

It may take some time until you get connected, but once the icon looks like figure 4, you’re set! If it doesn’t work, try to unplug and plug the power cord of the Wi-Fi router.


Figure 5

By the way, with a wired connection, the icon will look like figure 5. When connecting, you will see an animation where the two displays are blinking. Once the x mark on the bottom right disappears, you are connected!

Fixing the IP address

Let’s fix the IP address to enable the VNC auto-run.
We’re using a Raspberry Pi 2 model B running Raspbian ver.3.1.8, released on May 5th, 2015. (*Steps may vary depending on the network environment or the OS version)


Figure 6

Figure 6 shows the current network status. It is connected to the network, “wlan0” with the IP address, “”, which is automatically assigned.

The network setting file can be found at “ /etc/network/interfaces”. Back it up before editing to be safe.
Use the “cp” command to copy the file. The 1st argument is the file path that was copied and the 2nd argument is the file path that it as copied to. For instance, if you want to copy it using the name “interfaces_backup” in the same directory, it will look like this.

sudo cp /etc/network/interfaces /etc/network/interfaces_backup

Before we get into the settings, we have to do one more thing. When fixing an IP address, we need a “Subnet mask” and a “Default gateway” value.


Figure 7

We couldn’t acquire it properly on the Raspberry Pi. So this time, we looked it up using a Windows machine in the same network. In figure 7, it shows the “details of network connection” in Windows 8. In this network, the “subnet mask” is “”, and the “default gateway” is “”.
In Windows 7/8, you can check the “details of network connection” screen by going to control panel, “network center”, “local area connection (or Wi-Fi) status”, and clicking on the “detail” button on the bottom right of the pop up.

Now that we have the information, let’s edit the setting file from the Raspberry Pi.

sudo nano /etc/network/interfaces


Figure 8

When we opened the settings file, it looked like figure 8. The contents of the file may differ by the environment, so let’s check them one by one and adjust accordingly. Today, we will set the information of “wlan0” which we looked into earlier.

There are 4 places to fix. In the 11th row where it reads “address”, enter the fixed IP address you want to use. On the 12th and 13th row where it reads “netmastk” and “gateway” accordingly, enter the value we looked up earlier. Set these values according to your environment. Then, change the “manual” on the 9th row to “static”. *When setting a fixed IP, make sure that the IP does not conflict with other devices using the same router.
Reboot Raspberry Pi and if the IP address is enabled, you are done!

ip a


Figure 9

Auto-run settings

Let’s continue looking at the document from Raspberry Pi official website, “Automation and run at boot”. In this article, it shows two ways to launch the server software for VNC. First is a shell script that lets you launch it upon, and the second is a script that automatically starts it when Raspberry Pi boots. Here, we will look at the “auto-run” settings shown in the second item.


Figure 10

There are many lines in the script. So, open a browser document page, align it with LX Terminal, and copy and paste to make things easier.
Create a script file for when the system is up and running.
We will need root permission, so execute the “sudo su” command and move the current directory to /etc/init.d/ which is where we will be creating the new file.

sudo su
cd /etc/init.d/

Next, let’s create the file. You can do this by specifying a path without a file in nano editor. Write the following for the content.

nano vncboot

Copy and paste the code from the official website to complete the file.


Once you have completed the file, let’s move on to access permission settings. “755” is a permission that states “all users can execute and only administrators can write”.

chmod 755 vncboot

That’s it for files! Now, all we need to do is set up the auto-execute, and we’re done!

update-rc.d /etc/init.d/vncboot defaults


Figure 11

We see two lines of results.

update-rc.d: using dependency based boot sequencing

If you see these strings, you did it!

update-rc.d: error: unable to read /etc/init.d//etc/init.d/vncboot

But, if you see this, you have to execute the command once again. So, let’s run the last command.

update-rc.d vncboot defaults

Once you execute this, the same strings from the 1st line in the results screen show up. No error message this time. Now, we are ready! Let’s reboot Raspberry Pi.


Figure 12

Once the auto-run settings is completed successfully, you will see the following message: “New ‘X’ desktop is raspberrypi:0” in the launch screen as seen in figure 12. Using the VNC viewer on the iPhone to access “”. If you can connect, you are good to go!


Figure 13

The display size is specified in the script, so the initial display on iPhone looked like this. Now, if you got all the settings right, you can just have the power cord plugged in and connect, even before logging in. Now, you don’t need to use a display, mouse, or a keyboard to operate Raspberry Pi!


That was a 2-part article on VNC!
By mounting the auto-run, we no longer need to log in. We can now interact with Raspberry Pi much easily. We can see the desktop screen just by powering it on. It really feels like a smartphone app now.
Personally, I used to “ask my boss to come to my seat” when I made something new with Raspberry Pi. But now, I can “run towards the boss’ desk with my smartphone”. It looks like the beginning of my new Raspberry Pi life.
In the next article, we will take a look at this!

I found an interesting document on the Raspberry Pi official website! What are the children in the picture doing? They are accessing WordPress with Raspberry Pi!
In our next article, we will create a blog system that works on Raspberry Pi!