Lab 1


Set up your Raspberry Pi starting with a preinstalled NOOBS SD card

Steps (from http://www.raspberrypi.org/help/noobs-setup/, http://www.raspberrypi.org/help/quick-start-guide/, and Chapter 1 of your textbook):
  1. Use a permanent marker to identify your Raspberry Pi (e.g., write your initials on the flat metal side of the Ethernet port), your Pi plastic enclosure, etc.

  2. Insert SD card into your Raspberry Pi.

  3. Plug in your keyboard and mouse into the Raspberry Pi's USB A ports and the monitor cable to the Raspberry Pi's HDMI port. DO NOT plug in the Raspberry Pi power supply yet.

  4. Now plug in the USB power cable to your Pi's micro-B USB port. Your Raspberry Pi will boot, and a window will appear with a list of different operating systems that you can install.

  5. Tick the box next to Raspbian, switch Language from English (UK) to English (US) at the bottom of the screen, and then click on Install. Raspbian will then run through its installation process. This takes about 10 minutes or so.

  6. When the install process has completed, the Raspberry Pi will boot the Raspbian operating system. When done, click on the Terminal icon (on the upper left) and type the following at the command line:

     $ sudo raspi-config

    (Do not type the '$' symbol, it represents the command line prompt.) For more info on the terminal app, see
    http://www.raspberrypi.org/documentation/usage/terminal/README.md

  7. Your command opened up the Raspberry Pi command line configuration utility. You navigate it using arrow keys, the tab key, and the Enter/Return key on your keyboard. More info is at http://www.raspberrypi.org/documentation/configuration/raspi-config.md. At this point you should:
  1. Use the internationalization options to set your locale (using the Space key, uncheck en_GB.UTF-8 UTF-8 first and then check en_US.UTF-8 UTF-8), timezone (choose US and then Central), keyboard layout (Generic 104-key PC and choose defaults) and Wi-fi country (US United States).
  2. Enable the Raspberry Pi camera board.
  3. Under Advanced Options:
    1. change the hostname/network name of your Pi. Please use your first inital + last name as the network name. For example John Smith would use set the network name to jsmith.
    2. Enable SSH.
    3. Enable SPI.
    4. Enable I2C.
    5. Enable Serial.
  4. I recommend you do not change the user password unless you are sure you are going to remember it.
When done (i.e., you entered "Finish"), reboot your system. If the reboot option is not offered to you, just type
$ sudo reboot
at the command line (that appeared after entering "Finish") to reboot the operating system. Now browse through the recipes in Chapter 1 of the textbook.


Set up your Raspberry Pi starting with an SD card without preinstalled NOOBS

Using a computer with an SD card reader, start with the instructions at http://www.raspberrypi.org/help/noobs-setup/ and then switch to the above instructions.


Connect the Pi to a WiFi network and updating the system software

First browse through recipes 2.0 through 2.5 of the textbook. Then set up the wireless networking on your Pi as follows:
1. You will edit the file with pathname /etc/wpa_supplicant/wpa_supplicant.conf using the nano editor. To open the file using nano, type:
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
You will edit the file so it contains the following (use your campusconnect user ID and password where specified):
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
        ssid="depaulsecure"
        proto=RSN
        key_mgmt=WPA-EAP
        pairwise=CCMP
        auth_alg=OPEN
        eap=PEAP
        identity="your campusconnect user id"
        password="your campusconnect password"
}
Note that tabs are used in the lines below "network={" and above "}". When done, reboot your Pi by typing:
$ sudo reboot
After rebooting, your Pi should be connected to the depaulsecure wifi network.

3. Now that you are connected to the Internet, you can update your OS. You will update the apt-get package manager using the following commands:

    sudo apt-get update
    sudo apt-get upgrade

This takes about 10 minutes or so.


Controlling the Pi remotely from your laptop

The most convenient way to control your Pi is by remotely logging into it using a laptop. That way, you will not need a monitor, keyboard, mouse, and all the associated cables.
1. First, at the command line prompt in LXTerminal, find your Pi's IP address using
hostname -I
or
ifconfig
2. To connect to your Pi via SSH follow recipe 2.7. Windows user will need to install the Windows SSH client from http://www.cdm.depaul.edu/Current%20Students/Pages/Software.aspx; alternatively, you may choose Putty.

3. To connect to your Pi via VNC remote desktop, follow recipe 2.8 including the steps described in the discussion. I recommend you choose the same password for vncserver as for your pi (default: raspberry) and do not choose a view only password.

4. If you power up you Pi without a monitor/keayboard/mouse attached, you somehow need to learn the IP address assigned to it by depaulsecure. The following will set up your Pi so it emails you, to your gmail account email, the IP address every time it boots up. First you need to install additional sendmail utilities:

    sudo apt-get install ssmtp
    sudo apt-get install mailutils

Then open the configuration file /etc/ssmtp/ssmtp.conf using the nano editor:

    sudo nano /etc/ssmtp/ssmtp.conf

and edit the file so that it contains
root=postmaster
mailhub=smtp.gmail.com:587
hostname=yourPiHostname
FromLineOverride=YES
AuthUser=YouGmailUserName@gmail.com
AuthPass=YourGmailPassword
UseSTARTTLS=YES
NOTE: You will need to modify the above so it has your Pi's hostname (which you have set up), your gmail address (get one if you do not already have one), and your gmail password. It is a good idea to create a new gmail account just for this class, by the way.

All this enables you to send emails from your Pi. Try it:
echo "Body of email." | mail -s "Email subject" YourGmailUserName@gmail.com
In order for Gmail to be able to send the email, you will need to enable less secure Gmail sign in technology temporarily using
https://www.google.com/settings/security/lesssecureapps
Now that you have sendmail set up, you need to write a script that emails you the IP address of your Pi  when it boots up. Open file /etc/rc.local for editing:
sudo nano /etc/rc.local
and comment out all the code; you do this by adding a # symbol at the beginning of every line that does not already start with the # symbol. Then add the following code at the end of the file (while making sure that you change the Gmail user name to yours)
_IP=$(hostname -I) || true
COUNTER=0
while [ ! "$_IP"  -a $COUNTER -lt 10 ]; do
  sleep 10
  COUNTER=`expr $COUNTER + 1`
  _IP=$(hostname -I) || true
done

echo "" | mail -s "$_IP" YourGmailUserName@gmail.com
printf "My IP address is %s\n" "$_IP"

exit 0

This code will repeatedly query for the IP address until one is obtained or 10 failed queries were made.

5. Now reboot and verify that the ip address assigned to your pi by depaulsecure is emailed to your gmail account.

6. As mentioned above, you can set up your Pi to connect to your home network as well. To make it even easier to remotely login to your Pi on a local network such as a home network, you should do the following. In the command line shell, type the following to install the necessary system software that assigns the .local domain to your pi:

    sudo apt-get install avahi-daemon

This step will make it possible to remotely access you pi using its network name (e.g., lperkovic.local) rather than a dynamically allocated IP address that may change every time you connect. More info at http://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/


Use the Pi's Linux operating system

For an introductory tutorial on the Linux operating system use http://www.ee.surrey.ac.uk/Teaching/Unix/index.html. Tutorials 1-5 are relevant to this course and you should read them.

Recipes in Chapter 3 in your textbook describe how to do common operating system tasks. Depending on your experience with Linux, read carefully or browse through them.

We will often use the nano editor. Documentation is available at http://www.nano-editor.org/docs.php.


Use the Pi's software

Browse through the recipes in Chapter 4 to get sample of available apps for your Pi. Note: Recipe 4.1 requires an additional SD card. Do not overwrite the SD card containing Raspbian with the XBMC app!!


Program Raspberry Pi using Python

We will use Python to program the Raspberry Pi. Python 2 and 3 are both already installed. To open a Python 3 IDLE session, click on Menu, then Programming, and then just double click on the IDLE 3 icon. Depending on your level of experience with Python, read carefully or browse through the recipes in Chapters 5, 6, and 7.

If you have not programmed in Python before, go through the Python tutorial at https://docs.python.org/3/tutorial/.


Homework

If you are new to Linux/Unix or to Python, go through the tutorials listed above.

There will be a short quiz next week based on all these tutorials.