Project01 - Raspberry Pi Setup

Due Date
In Lab on Week 2 (Wed 8/26 for sections 1 and 2, Thu 8/27 for section 3)
Instructor/TA will check: ssh onto your pi, clone a git repo from github.com (must show Internet access)

What To Buy

  1. Raspberry Pi

    1. If you don't have one, you should get a Raspberry Pi Zero W. They're cheap and suitable for our projects.

    2. Acceptable models: Zero, Zero W, 3b, 3b+, 4. Unacceptable models: 1, 2

  2. USB On-the-Go (OTG) cable suitable for your Pi (Micro USB for the Zero W) and your laptop's USB port

  3. Micro SD cards and suitable adapters for your laptop's USB port

    1. If your laptop has an SD slot, many Micro SD cards come with an SD adapter in the packaging

    2. You can use a multi-port USB dock suitable for your laptop if it has an SD slot

    3. We recommend 16GB Micro SD cards

    4. We recommend buying at least two Micro SD cards in case you break or lose one. It happens, and you'll need them to work for project grading.

  4. You may want to use a case to protect your Pi

    1. For the Pi Zero W, we use this one, which is easily assembled and powers the Pi using your laptop's USB port (potentially with a USB adapter) without a separate AC adapter.

Install Raspberry Pi OS (Linux)

    1. Go to https://www.raspberrypi.org/downloads/

    2. Download the Imager for your laptop's OS, and install it

      1. The imager allows you to "burn" or "flash" the OS image onto the Micro SD card

    3. Under Choose OS, we recommend selecting Raspberry Pi OS (other) and then Raspberry Pi OS Lite (32 bit).

      1. If you want to install one of the desktop GUI builds and plug your Pi into a keyboard, mouse, and monitor, that's fine. Lite is a smaller download and adequate for our projects

    4. Insert your Micro SD card or adapter into your laptop or hub. Your laptop may mount the SD card.

    5. Under Choose SD Card, select your card, and click the Write button

    6. The imager leaves the boot volume unmounted. We need to mount it again to edit come configuration files. You can do that by removing and reinserting the card/adapter.

Option 1: Sharing Your Computer's Wi-Fi

  1. The advantage of using your computer's Wi-Fi is that you don't have to enter network names and passwords on your Pi. USF Wireless is especially inconvenient. Instead, you can share your laptop's Wi-Fi connection to your Pi, using the Pi as an Ethernet Gadget using the RNDIS network protocol.

  2. Open your Terminal app and $ cd /Volumes/boot

  3. Edit config.txt and add this line to the bottom of the file, ensuring that there is a newline afterwards:
    dtoverlay=dwc2

  4. Edit cmdline.txt and insert this into the line, right after rootwait, ensuring that there is a single space on each side of what you add:
    modules-load=dwc2,g_ether

  5. $ touch ssh so that Raspberry Pi OS will start the SSH server when it boots

  6. $ cd ~ so you can Eject the SD card, remove it, and insert the Micro SD card into your Pi

  7. On your laptop, enable Internet sharing:

    1. On macOS: Go to System Preferences | Sharing. Check Internet Sharing. Share your connection from Wi-Fi to computers using RNDIS/Ethernet Gadget

    2. On Windows: TBA

    3. On Linux: download TBA

  8. Plug your Pi into your laptop to power it up. After about 30 seconds (first boot takes longer), you can ssh onto your Pi:
    $ ssh pi@raspberrypi.local

  9. The default password is raspberry. You should change that immediately using the command:
    $ passwd

  10. RNDIS will make up new MAC addresses every time we connect, but we want to have constant MAC addresses, so we will set them into the rndis.conf file like this:

    1. $ dmesg | grep usb0 should produce something like:
      [ 6.315112] usb0: HOST MAC 07:17:57:07:1e:ab
      [ 6.318300] usb0: MAC 5a:50:5e:5e:5f:5b

    2. Put those addresses into rndis.conf like this:
      $ sudo bash
      $ cd /etc/modprobe.d
      $ cat > rndis.conf
      options g_ether host_addr=07:17:57:07:1e:ab dev_addr=5a:50:5e:5e:5f:5b
      ^D
      (that's CTRL-D)

  11. $ sudo reboot for the MAC address changes to take effect

Option 2: Connect your Pi to Wi-Fi Directly

  1. The Pi hardware has its own Wi-Fi interface you can use if you like. To do that, you must provide the Wi-Fi SSID and password before you boot it, so the Pi will be on your network when you ssh to it. This may be helpful if you're using a Pi 3b+ or later, which can draw more power than USB can provide.

  2. Picking up where the Install Raspberry Pi instructions left off, open a Terminal window and cd into the boot volume of the SD card you just burned

  3. Create a file called wpa_supplicant.conf on the boot volume and add your Wi-Fi network(s) using the template below. You can have multiple network blocks if needed
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1

    country=US
    network={
    ssid="CSLabs"
    psk="1kudlick"
    }
    This approach does not work with USF Wireless

  4. $ touch ssh so that Raspberry Pi OS will start the SSH server when it boots

  5. $ cd ~ so you can Eject the SD card, remove it, and insert the Micro SD card into your Pi

  6. Plug your Pi into your laptop to power it up. After about 30 seconds (first boot takes longer), you can ssh onto your Pi:
    $ ssh pi@raspberrypi.local

  7. The default password is raspberry. You should change that immediately using the command:
    $ passwd

  8. In order to avoid hostname conflicts on the Wi-Fi network, change the hostname of your Pi by editing the following files:
    $ cd /etc
    $ sudo nano hosts
    $ sudo nano hostname

    changing raspberrypi in each of those files to your unique hostname. I use my USF login ID to ensure uniqueness.

  9. $ sudo reboot for the hostname changes to take effect. Now you can $ ssh pi@jsmith32.local, for example

Install Software

  1. At this point, your Pi should be able to connect to Internet sites, either using Internet Sharing, or directly on Wi-Fi. Check this using the command:
    $ ping usfca.edu and see that you get ICMP timings back. CTRL-C to stop ping

  2. You should install any updates to the Raspberry Pi OS using these commands:
    $ sudo apt-get update
    $ sudo apt-get upgrade

    and reboot your Pi using the command:
    $ sudo reboot

  3. Raspberry Pi OS Lite does not come with a git client. You should install it using the command:
    $ sudo apt-get install git

  4. Raspberry Pi OS comes with the text editors vi and vim. If you prefer to use emacs (Greg's preference) or micro (Phil's preference) you may install those. Cyberduck and similar are not recommended.

Powering your Pi Safely

  1. Since Raspberry Pis have no battery, disconnecting power while the OS is running can lose your changes, or even corrupt the filesystem, rendering the OS unbootable.

  2. Always use $ sudo shutdown now to power down the board when you're not using it.

  3. If you're powering a larger Pi (model 3b+ or 4) using USB, and you get low voltage warnings on the terminal, you may need a separate AC adapter