Notes on Setting up Raspbian for USF Systems ClassesHere are some notes on the steps needed to setup a Raspberry Pi 3 Model and Raspbian for use in CS 315, CS 326, can CS 631 at USF. Terminology
Raspbian InstallationDownload Raspbian Jessie Lite (or regular Jessie with Pixel if you want the GUI desktop) from You will download a zip file that contains the file 2017-01-11-raspbian-jessie-lite.img You will need to copy the img file to an SD Card. You will want to use at least an 8 GB SD Card. To copy the img file to the SD card you can use the UNIX dd command. You can find install instructions for different operating systems here: For Mac OS X, you can use a program called Pi Filler, which can be downloaded here: The Pi Filler application (actually it is an Apple Script program) will walk you through the steps of putting a Raspbian image (or any Raspbery Pi OS image) onto an SD Card. I've found this to be quite a bit faster than using dd directly. It takes about 30 seconds to copy the Jessie Lite image to an SD Card (Sandisk Extreme Pro). There are some other useful Mac OS X utilities for the Raspberry Pi on the same page as Pi Filler. After you have installed the img file onto your SD Card, you need to put the card into the Micro SD slot on the RPi. Before turning on the RPi follow the next section to setup a serial communication link between your RPi and your laptop or desktop computer. After putting the img file onto the SD Card you need to edit config.txt on the SD Card: You need to add the following line: enable_uart=1 (no spaces and make sure there is newline at the end) This allows the UART to work on the RPi3. Now that you have an SD Card with Raspbian installed you need to boot into Raspbian. However, we need a way to connect to the Raspberry Pi. You can hook up a Raspberry Pi to an HDMI display, a USB keyboard, and a USB mouse. Raspbian will recognized these devices and allow you to interact via a console. You can also start up a graphical desktop. However, this is not very convenient if you carry your Raspberry Pi around with you. An alternative way to connect with the Raspberry Pi is to use a USB Serial Cable that connects to the Raspberry Pi UART port available on the GPIO pins. This allows for a simple console interface to the Raspberry Pi and Raspbian. As we will see we can also build bare metal kernels that directly use the UART device to display text and get user input. You need to buy a USB to UART RS232 cable: The Linux kernel comes with the PL2303 TTL serial driver, so you do not need to install a drive. This is true if you have Linux running directly on your computer or if you are running Linux inside a virtual machine. On a Mac you will need to install a USB serial driver in order to connect to the Raspberry UART TTL: The USB serial cable does provide power to the Raspberry Pi and in principle you do not need to use a separate Micro USB power adaptor. This was generally true for the Raspberry Pi B+ (RPi1), but it seems that some laptops do not provide enough power through a single USB port in order to power a Raspberry Pi 3 Model B (RPi3, the one we are using in class). So, in order to power a RPi3 you will need a separate USB to Micro USB cable to connect to a separate USB port on your laptop or desktop. Since we are going to reboot (power cycle) the RPi3 often, it is best to get a cable that has a on/off switch: Here is a picture of how the cables should be connected: Once you have the cables sorted out and connected you will need a way to interact with the RPi and Raspbian via the serial cable from your computer. To do this you will need to run a terminal program that can interact with the serial device. On a UNIX-based OS (e.g., Mac OS X or Linux) you can use a program called kemit from a Terminal window. You will need to install this on macOS and Linux: On a Mac you can install kermit using Homebrew (which allows you to install a whole bunch of standard UNIX programs):
Follow the homebrew install instructions.
Once installed you can type:
$ brew install c-kermit
On Ubuntu Linux you can use apt-get to install c-kermit:
$ apt-get install ckermit
Once installed, create a .kermrc file in your home directory (on your host computer/laptop):
$ cd $ cat > .kermrc set line /dev/cu.usbserial set speed 115200 set carrier-watch off connect ^D $
Now you can use kermit to connect to your RPi via the USB Serial cable.
Type:
$ kermit
Now turn on your RPi.
You should see the boot squence.
To exit kermit, type
CTRL-\ then q
You can start and stop kermit multiple times with out the terminal hanging. Windows In order to connect to the RPi via the USB serial cable on Windows, you can use the Putty program. See the information in the following page for details (search for Putty). Now that you have a power connection and a serial connection to your RPi and you have an SD Card with Rasbian installed, you can power up your RPi and login via a console (screen or Putty). When you first boot up, you will see several Linux boot messages, and then finally you will see something like: Raspbian GNU/Linux 7 raspberrypi ttyAMA0\ raspberrypi login: Use the following credentials to log in: username: pi password: raspberry Then you will see: The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config' pi@raspberrypi:~$ One of the first things you will need to do is resize the Linux partition on the SD Card. The Jessie Lite img file defaults to a 3 GB partition, but this is much smaller than the full 8 GB (or 16 GB) available on the SD Card. To resize, type: $ sudo raspi-config Using the menu select the first option "1 Expand Filesystem". You need to reboot to see the changes. When you exit raspi-config, it will ask you if you wan to reboot. You should select "yes". Changing the Default PasswordEventually we will configure Raspbian so that we can connect to it via ssh over the network (hardwired or WiFi). When we put the Raspberry Pi on the network, others will potentially be able to login. Because everyone knows the default Raspberry Pi password, it is a good idea to change it now. Once you are logged in again, you can type: pi@raspberrypi:~$ passwd Changing password for pi. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully pi@raspberrypi:~$ Pick a new password you can remember. Resizing the Terminal WindowWhen connecting to the RPi via a Terminal window it is useful be able to "resize" the window so that Raspbian understand the number of rows and columns in the Terminal. This allows programs such as vi, emacs, pico, and nano to utilize the entire window and not just the default size of 80x24. Create a directory called 'bin' in your home directory: Then add the following to $HOME/.profile $ cd$ cat >> .profile # Resize the terminal python $HOME/bin/resize.py ^D $ This will be invoke resize.py automatically each time you log in. You can manually resize the terminal by typing: $ python ~/bin/resize.py Shutting Down RaspbianWhen you are done working in Raspbian, you should shutdown Linux properly before turning off the RPi. You can shutdown Raspbian by typing: $ sudo shutdown -h now Wati for the final "Power down" message for turning off the power. pi@raspberrypi:~$ sudo shutdown -h now The system is going down for system halt NOW!MA0) (Thu May 7 01:19:16 2015): [ 953.595652] reboot: Power down You can make this an alias: $ cd $ cat >> .bash_aliases alias pidown='sudo shutdown -h now' ^D $ After you login in again, you can shutdown your RPi2 with: $ pidown You still need to wait for the final "Power down" message. Setting up NetworkingWhile you can get by interacting with Raspbian via screen or Putty, the Terminal support is still limited and you only have one console available. By setting up networking on in Raspbian, you can ssh into your RPi and you can also download additional packages for Rasbian. In addition you can connect to Github to get source code and access your project repositories. You have different options to connect the RPi2 to the network:
Internet Sharing on a Mac I followed the instructions given here: http://chariotsolutions.com/blog/post/configuring-network-used-by-mac-os-x/
My RPi Ethernet Mac address is:
b8:27:eb:82:1e:fa
You will need to find your Mac address on your RPi using the ifconfig command:
$ ifconfig eth0 eth0 Link encap:Ethernet HWaddr b8:27:eb:82:1e:fa inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0 inet6 addr: fe80::a9c4:4df2:407d:84cd/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:414 errors:0 dropped:0 overruns:0 frame:0 TX packets:248 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:58170 (56.8 KiB) TX bytes:33998 (33.2 KiB)
Your mac address is the one after HWaddr.
You need to create a /etc/bootptab file with your mac address.
See below:
$ cat /etc/bootptab # Bootptab file # Section 1 -- ignored %% # Section 2 -- used # Hardware types: 1=Ethernet, 6=Wireless # See http://www.ietf.org/rfc/rfc1700.txt # # machine entries have the following format: # # hostname hwtype hwaddr ipaddr bootfile rpi 1 b8:27:eb:82:1e:fa 192.168.2.2 boot WiFi network={ ssid="CSLabs" psk="<ask_for_password>" } You will need to edit as root: $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf You can put multiple network entries in the wpa_supplicant.conf file. This way you can have Rasbian automatically connect to different networks depending on your location. Then type: $ sudo ifdown wlan0 $ sudo ifup wlan0 After a few seconds a connection should be made. You check if you have been assigned an IP address by typing $ ifconfig wlan0 If you have a valid IP address you will see it next to "inet addr". Once you see an IP address you can test connectivity by typing: $ ping google.com You should see something like: PING google.com (216.58.192.14) 56(84) bytes of data. 64 bytes from nuq04s29-in-f14.1e100.net (216.58.192.14): icmp_req=1 ttl=53 time=22.2 ms 64 bytes from nuq04s29-in-f14.1e100.net (216.58.192.14): icmp_req=2 ttl=53 time=20.1 ms 64 bytes from nuq04s29-in-f14.1e100.net (216.58.192.14): icmp_req=3 ttl=53 time=18.6 ms ^C --- google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 18.682/20.353/22.205/1.443 ms pi@raspberrypi:~$ Type CTRL-C to exit, otherwise it will go on forever. Once you find the IP address using ifconfig, you can then ssh into your RPi2: pi@raspberrypi:~$ ifconfig wlan0 wlan0 Link encap:Ethernet HWaddr 74:da:38:0a:1d:f2 inet addr:192.168.2.22 Bcast:192.168.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:612 errors:0 dropped:84 overruns:0 frame:0 TX packets:263 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:156849 (153.1 KiB) TX bytes:47152 (46.0 KiB) |