Part 2: Install the OS, Setup WiFi, and Run Headless with Tight VNC Server


Install Raspbian wheezy OS to SD Card:

  1. Download Raspberry Pi Raspbian “wheezy” OS image at: http://www.raspberrypi.org/downloads. You can also download the copy I used here.
  2. OS X: Install Raspbian “wheezy” image to SD card – run RPi-sd card builder v1.2 or click here to use my copy -> select .img file -> select SD card to install to -> provide password to proceed -> watch gear rotate in taskbar at top and wait for dialog box to open when done -> stick the card in the Raspberry Pi and boot up

    Windows: Install Raspbian “wheezy” image to SD card – run(may need to run as Administrator) Win32 Disk Imager or click here to use my copy -> select .img file -> select SD card to install to -> wait until finished -> stick the card in the Raspberry Pi and boot up.

  3. Raspberry Pi “wheezy” OS image configuration

    Raspberry Pi “wheezy” OS image configuration

  4. Upon first boot the following is how I configured my OS(FYI, I live on the east coast of the US): expand_rootfs; configure_keyboard => generic 101 PC => Other => English(US) => English(US) => default layout => no compose key => no; change_password => set your own password; set_locale => en_US.UTF-8; change_timezone => US => eastern; ssh => enable; boot_behavior => boot straight to desktop; finish.

Setup Wired and Wireless interfaces with a static IP address:

  1. I typed sudo nano /etc/network/interfaces and made it look like the below text, which sets the wired(eth0) IP address, as well as the wireless IP addresses.  You will need to determine what you want your static IP address, netmask and gateway addresses to be. Instead of typing the below text you can also download, if you already have connectivity, and modify the file by typing: cd /etc/network/ then sudo wget https://dl.dropbox.com/u/8170542/interfaces then sudo chmod 644 interfaces to set the correct permissions
  2. auto lo
    
    iface lo inet loopback
    iface eth0 inet static
    address 192.168.0.14
    netmask 255.255.255.0
    gateway 192.168.0.1
    
    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    
    iface default inet static
    address 192.168.0.14
    netmask 255.255.255.0
    gateway 192.168.0.1
    
  3. Next, I typed sudo nano /etc/wpa_supplicant/wpa_supplicant.conf to make it look like the below text, which sets your WiFi network’s SSID name and PSK password. You can also download, if you already have connectivity, and modify the file by typing cd /etc/wpa_supplicant/ then sudo wget https://dl.dropbox.com/u/8170542/wpa_supplicant.conf then sudo chmod 600 wpa_supplicant.conf to set the correct permissions. If all else fails use the GUI WiFi Config utility, click Manage Networks Tab => Enabled => Scan for your network.
  4. ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
            ssid="YOUR SSID"
            psk="YOUR PSK PASSWORD"
            proto=RSN
            key_mgmt=WPA-PSK
            pairwise=CCMP
            auth_alg=OPEN
            id_str="default"
    }
    
  5. Once you have made the changes reboot the Raspberry Pi by typing sudo reboot and check that the settings have stuck. In my case I’m using the Edimax 7811U USB WiFi, so there is no need to install any drivers. Everything just works out of the box after a restart.

Setup Raspberry Pi VNC server for headless operation:

  1. Login to your Raspberry Pi and install the Tight VNC package by typing sudo apt-get install tightvncserver
  2. Next Run TightVNC Server by typing vncserver. This will prompt you to enter a Password and an optional View Only Password(respond with No). When you do this you will see something like “New ‘X’ desktop is raspberrypi:1” The 1 corresponds to the number of the desktop session created
  3. Screenshot

    VNC Viewer Headless Display

  4. Once that is done you can start a VNC server from the shell prompt by typing vncserver :0 -geometry 1920×1080 -depth 24 This example starts a session on VNC display zero (:0) with full HD resolution.
  5. You can test the server by using a VNC client, on your desktop or notebook, like VNC Viewer or use my copy here. On the desktop/notebook side you will need to enter the ip address of your Raspberry Pi and the VNC desktop session number. For example, for the VNC Server your would type something like, 192.168.1.5:1 and then you will be prompted for the VNC Password you typed earlier.
  6. To make the server startup automatically on boot type sudo nano /etc/init.d/vncboot and make it look like the below text, or you can download and modify the file by typing cd /etc/init.d/ then sudo wget https://dl.dropbox.com/u/8170542/vncboot then sudo chmod 755 vncboot to set the correct permissions
  7. ### BEGIN INIT INFO
    # Provides: vncboot
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start VNC Server at boot time
    # Description: Start VNC Server at boot time.
    ### END INIT INFO
    
    #! /bin/sh
    # /etc/init.d/vncboot
    # First configure the user you want to run this under - this will generally be pi, unless you've created your own users
    export USER='pi'
    
    eval cd ~$USER
    
    # Check the state of the command - this'll either be start or stop 
    case "$1" in
      start)
        # if it's start, then start vncserver using the details below
        su $USER -c '/usr/bin/vncserver :1 -geometry 1280x960 -depth 16 -pixelformat rgb565'
        echo "Starting vncserver for $USER "
        ;;
      stop)
        # if it's stop, then just kill the process
        pkill Xtightvnc
        echo "vncserver stopped"
        ;;
      *)
        echo "Usage: /etc/init.d/vncserver {start|stop}"
        exit 1
        ;;
    esac
    exit 0
    
  8. We can now start or stop the service manually by typing: sudo /etc/init.d/vncboot start or sudo /etc/init.d/vncboot stop to make sure everything is working.
  9. To make the Tight VNC Server start every time the Raspberry Pi boots up type: cd /etc/init.d/ then sudo update-rc.d vncboot defaults
  10. Reboot your Raspberry Pi and startup your VNC client on your Desktop/Notebook and enter the Raspberry Pi’s IP address:1 ,or whatever desktop number you want, and your password. **NOTE** Wait for the the Raspberry Pi to finish booting before trying the Tight VNC Server, otherwise you’ll get connection errors. For me the trickiest part of this project was getting the WiFi setup and the VNC server. I seemed to have a spotty success rate, which were caused by typos most of the time. Don’t give up and keep trying until it works.
  11. References and more information:

Enable Tight VNC copy and paste to/from your desktop or notebook

  1. It’s much easier to copy and paste text to and from the Raspberry Pi by installing autocutsel. To do this type sudo apt-get install autocutsel
  2. To enable copy and paste type sudo nano /home/pi/.vnc/xstartup and make it look like the below text, or you can download and modify the file by typing cd /home/pi/.vnc/ then sudo rm xstartup then sudo wget https://dl.dropbox.com/u/8170542/xstartup then sudo chmod 755 xstartup to set the correct permissions then sudo reboot to reboot and try out the Raspberry Pi as a headless server
  3. #!/bin/sh
    
    xrdb $HOME/.Xresources
    xsetroot -solid grey
    autocutsel -fork
    #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    #x-window-manager &
    # Fix to make GNOME work
    export XKL_XMODMAP_DISABLE=1
    /etc/X11/Xsession
    
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s