Tuesday, November 4, 2014

Getting started with a Raspberry Pi




This article walks through some basic tips to get up and running with Raspbian on your Raspberry Pi. It assumes you have at bare minimum the following, and that they have been wired up.

  • A Raspberry Pi (preferably B+)
  • SD card with Noobs
  • Power cable for the Pi
  • An output device (Monitor/TV)
  • A cable to connect to the output device (HDMI/3.5mm Composite for B+ or RCA for older models)
  • A keyboard and mouse or Ethernet cable 


NOOBS

The Pi doesnt have a power switch - it just starts up when you plug in the power cable. The first time you do this it will boot into the NOOBS (New Out Of Box Software) installer menu which contains a list of customized Linux distros that you can select for installation. You may install multiple of them in one go here but you will be limited by the size of your card. If you change your mind later you can always get to this menu (by pressing shift) before the OS loads up and install a different OS, but beware - this will wipe your previous installations.

From the NOOBS menu, you can install Raspbian (a flavor of Debian tuned to run on the Pi) or other distros including Rasbmc, which is XBMC for the Pi. (an open source media center now known as Kodi). Here we will mostly focus on the configuration of Raspbian.

Raspbian

The first time Raspbian loads up it will start Raspi-config where you can change some of the basic settings for the Pi. This includes changing the password of the default user (reccomended). It may also give you the option to configure the keyboard but this wasn't available for me and I had to use the command dpkg-reconfigure keyboard-configuration as sudo to configure that later on. Btw, you can always get back the the config simply with the following command at any later time.
 $ sudo raspi-config

Setting up Wi-Fi

The Pi doesn't come with Wi-Fi, but you can use a dongle to remedy that. However beware that it's known to have problems with some Wi-Fi dongles, so if you are buying one make sure it's been tried and tested and is guaranteed to be compatible. I tried the Edimax EW-7811Un  and it works well. The B+ comes with 4 USB ports so there is plenty of spares to plug in a mouse and keyboard if required, but if you have Wi-Fi you can always SSH to it from your machine using Putty or even phone if you have a SSH client app for your phone. (I'm and Android user and I used ConnectBot along with Hacker's Keyboard) Note that you will need to do some configuration to enable the Wi-Fi dongle on Raspbian. This is a good tutorial on how to do it.

Creating a new login

The default logon credentials for Raspbian is pi/raspberry. (it is the same for Raspbmc as well if you want to log on to it's shell). However, you can add a new user using the following commands
 $ sudo useradd <newusername>

Then add the new user to usergroups. Might as well to all the usergroups that the default user is part of:
 $ sudo <newusername> <usergroup>

The groups on user pi is on can be checked with
 $ groups pi

Finally you will need to set a password for the new user
 $ sudo passwd <newusername>

Now you should be able to log back in as your new user. And your Pi is ready as a lightweight Linux machine to do what you wish.

You can switch to the UI with the following command
 $ startx


Playing movies off a network share

Let me start by stating that if your primary intent of the Pi is to use it as a media center, you should be using an XBMC distro such as RaspBMC or OpenELEC instead of Raspbian. However that doesn't mean you cant watch movies on Raspbian if you wanted to.
In order to access the data/movies on a machine on another machine you will need to create a network share. Instructions for doing this on Windows 8 can be found here.

Next you will need to create that share to mount the network share to
 $ mkdir /mnt/win

Then mount the share
 $ sudo mount -t cifs -o username=<yourwindowsusername>,password=<yourwindowspassword> //<windows machine name or ip>/<share name> /mnt/win

If you don't want the hassle of mounting this every time your pi restarts, you can automate it by adding an entry to the /etc/fstab file with the share info and credentials as described here.
Assuming it mounted successfully you should be able to play stuff off it using a player.
Unfortunately VLC doesn'tsupport hardware acceleration on the Pi, however Raspbian does come bundled with an alternative - Omxplayer.
You can simply pass the file to Omxplayer as follows
 $ omxplayer /mnt/win/<rest of the path to the video>

A list of shortcuts for Omxplayer are available here.
If you are adamant to get VLC working on the Pi apparently it is now possible with a bit of pain according to this.