Headless start with the Raspberry Pi

Hi! Some time ago I made two posts about the the Raspberry Pi (Raspberry Pi has Arrived and First Impressions on the Raspberry Pi) and unfortunately since then it has been closed inside its box. I really wanted to do something with it but other projects always got in the way. Finally I'm doing a project where I'll use the Raspberry Pi and I hope to make some posts about Raspberry Pi stuff while I work on it. To begin I'll show you how to start playing with your Raspberry Pi without having to connect it to an external HDMI monitor or screen with RCA connector and using Ubuntu on your computer.

(Click the photo for better resolution in Picasa Photostream)
The first thing to do is get yourself a 4GB (or greater) class 4 SD card. Branded cards are usually better and more trustful. If you have one, then its time to prepare the card to be used in the Raspberry Pi.
First you should format it to FAT32 to clear whatever the manufacturer stuffed inside it. To do that you can use Gparted. After formatting you should go to the Downloads section in the Raspberry Pi website and download the latest Rasbian "Wheezy" image. After downloading the image follow the the process described below:
  1. Verify if the the hash key of the zip file is the same as shown on the downloads page (optional). Assuming that you put the zip file in your home directory (~/), in the terminal run:
    • sha1sum ~/2012-12-16-wheezy-raspbian.zip
    • This will print out a long hex number which should match the "SHA-1" line for the SD image you have downloaded
  2. Extract the image, with
    • unzip ~/2012-12-16-wheezy-raspbian.zip
  3. Run df to see what devices are currently mounted
  4. Connect the SD card reader with the SD card inside
  5. Run df again. The device that wasn't there last time is your SD card. The left column gives the device name of your SD card. It will be listed as something like "/dev/mmcblk0p1" or "/dev/sdb1". The last part ("p1" or "1" respectively) is the partition number, but you want to write to the whole SD card, not just one partition, so you need to remove that part from the name (getting for example "/dev/mmcblk0" or "/dev/sdb") as the device for the whole SD card. Note that the SD card can show up more than once in the output of df: in fact it will if you have previously written a Raspberry Pi image to this SD card, because the RPi SD images have more than one partition.
  6. Now that you've noted what the device name is, you need to unmount it so that files can't be read or written to the SD card while you are copying over the SD image. So run the command below, replacing "/dev/sdb1" with whatever your SD card's device name is (including the partition number)
    • umount /dev/sdb1
    • If your SD card shows up more than once in the output of df due to having multiple partitions on the SD card, you should unmount all of these partitions.
  7. In the terminal write the image to the card with this command, making sure you replace the input file if= argument with the path to your .img file, and the "/dev/sdb" in the output file of= argument with the right device name (this is very important: you can trash the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, sdb, not sdbs1 or sdbp1, or mmcblk0 not mmcblk0p1)
    • dd bs=1M if=~/2012-12-16-wheezy-raspbian/2012-12-16-wheezy-raspbian.img of=/dev/sdb
    • Note that if you are not logged in as root you will need to prefix this with sudo
  8. Remove SD card from card reader and insert it in the Raspberry Pi's SD card slot.
Get an ethernet cable and connect one end to the Raspberry Pi and the other to your router. Finally, get a 5V micro USB power supply that can provide at least 0.7A (maybe your phone charger will have such specs) and plug it in the Raspberry Pi power supply socket. Now you should see some LEDs blinking on the board that mean that its booting :). Wait about one or two minutes for it to boot. Then access your router and in the local network section of the router's configuration interface you should be able to find out which IP has been assigned to your Raspberry Pi. If your router shows several devices without showing their names, you'll have to try all of them. Another way is to check the assigned IPs before connecting the Pi to the network and then checking again after connecting the Pi. The new IP will be the one you're looking for :).
Since the Raspbian image comes with SSH enabled you'll be able to SSH into your Pi using the following command (replace 192.168.0.13 with the IP address of your Raspberry Pi):
ssh pi@192.168.0.13
It will probably ask you for some kind of authorization. Type "yes" and then the Raspberry Pi will prompt you for the password for user "pi". The default password is "raspberry".
Now you're finally using your Pi via SSH! :) However you might want to use the Pi in graphical mode. 
To do that there are essentially two ways: the first is to use X11 forwarding over SSH so that everytime you open a program with GUI, it will open on your computer screen; the other way is using VNC, that will show you the entire workspace of the Pi. If you can easily get your way around with the terminal I advise you to use the SSH option. On the other hand, if you find it more comfortable to use the graphical interface, then VNC is for you.
To use the X11 forwarding over SSH you just have to enter the parameter "-Y" when you establish the connection:
ssh -Y pi@192.168.0.13
From the moment you initiate the sessions with the "-Y" parameter, every program with GUI will open on your computer.
To use the VNC it takes a few more steps but its also easy. First you must login into your Pi with SSH as described and then you'll have to install a VNC server:
sudo apt-get install tightvncserver
After installing you'll have to start the server:
vncserver :1 -geometry 1024x600 -depth 16 -pixelformat rgb565
The first time you start the server you will be prompted to choose a password. Do it. Finally you will have to start a VNC client on your computer to access the server that you have just started. Ubuntu 12.04 comes with a VNC client named Vinagre. Launch it, click on "Connect", choose  VNC in the "Protocol" drop-down list and enter the following in the "Server" field: "192.168.0.13:5901" (replace address with the address of your Raspberry Pi). When it prompts you for a password, enter the one you have just chosen and you'll see the Raspberry Pi desktop appearing on your screen! :)
And we've come to the end of this short tutorial on starting with the Raspberry Pi headless mode. I hope it was useful for you and hope to post some more stuff regarding the Raspberry Pi soon! :)

Take care! :)



Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! :)

Donate

0 Comments:

top