2019 Fall

Raspberry Pi Hardware List

You need the items in one of: Raspberry Pi 3 or Raspberry Pi 4.
You need the items in Common Accessories.

(1) Raspberry Pi 3

This is the cheaper option and will work fine for this class any many other projects.

Raspberry Pi 3 Computer
($34.30)

Raspberry Pi 3 USB Power Cable with Switch
($5.99)

(2) Raspberry Pi 4

This is the more expensive option, but it is the latest version of the Raspberry Pi. It is faster and comes in larger memory sizes.

Raspberry Pi 4 Computer (most basic kit I could find)
($55.99)

Raspberry Pi 4 USB Power Cable with Switch
($6.99)

Common Accessories

USB TTL Serial Cable
($6.99)

USB Ethernet Hub
($13.99)

Ethernet Cable
($4.09)

Micro SD Card 8 GB or more - 16 GB
($5.79)


Optional Accessories

A case is optional but recommended.

Official Raspberry Pi Case (Raspberry Pi 3)
($7.81)

Note if you use the USB TTY Serial Cable you want case that allow you to access the GPIO pins to connect the cable. Some cases do not allow you to do this.

Operating System and Software Installation

Overview

We are going to install Raspbian Buster Lite onto a Micro SD card then we are going to perform some basic configuration. Our main goal is to get your OS configured to connect your RPi to your laptop and to the Internet.

Hardware Setup: Connect Cables

You should have 3 cables: USB TTL Serial cable, USB Power cable with Switch, and an Ethernet cable. You may also have a USB and Ethernet Hub.

To connect the USB TTL Serial Cable see the picture below. Make sure you have the right color wires connected to the correct GPIO pins:



You also need to connect your USB power cable with switch and the Ethernet cable. You should have everything connect to your laptop (perhaps all through the USB Hub with Ethernet port or all directly to your computer).

Laptop/Computer Serial Driver Setup

You will need to do a little bit of software setup on your laptop so that we can access the RPi through the USB Serial cable.

macOS

For macOS you need to install serial communication drivers for the USB TTL cable:


Note the driver is in a ZIP file. You should unzip the file, inside is a .pkg file. You should double click on the .pkg file. You will be prompted to install the driver. During installation you will be asked to allow the Prolific serial driver extension to be installed from System Preferences then Security and Privacy. Select to allow the Prolific driver. After you install the drivers you will be asked to reboot your computer. 

If you skipped over the step in which it asks you to allow the driver access you need to go to System Preferences then Security & Privacy. In the General tab you need to approve the new Prolific driver so that it can be used.

Linux

You do not need to install serial drivers on Linux. Linux comes with driver support for the USB TTL cable.

Windows

You may not need USB TTL Serial drivers for Windows, but if you do, install the following:



Raspbian Buster Lite

This semester we will be using Raspbian Buster Lite. If you want to run a full GUI Desktop on your Raspberry Pi, then you can install Raspbian Buster with Desktop. The Desktop image for the SD Card is bigger and will take longer to download and install compared to Raspbian Buster Lite. That said, the Desktop version should work fine for our work.

You can find Raspbian Buster here:


Download the ZIP version.

Once you have the image you will need to copy the image file to the SD Card. You will need a tool to do this. A very fast and easy to use tool is called BalenaEtcher:


There are versions of BalenaEtcher for macOS, Windows, and Linux. Download the version that matches the OS on your computer.

Once you have imaged the SD card, you will need to edit the config.txt file on the boot partition. You will need mount your SD card onto your computer. It should show up as a volume called "boot." Use an editor to add the following line to the config.txt file in the top level directory of the boot volume:

enable_uart=1

Make sure you have a newline (CR) at the end of this line.

Laptop/Computer Terminal Setup

You will need a program that allows you to connect to the Raspbian serial console via the USB TTL cable.

On macOS and Linux I recommend you use a program called kermit.

On macOS, you can install kermit via Homebrew:

http://brew.sh

 

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:

$ sudo 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
$

(When you see ^D, type the CTRL key and D at the same time, do not type the characters "^D".)

Note on Linux you will use a different device name for the set line. It is often something like /dev/ttyS0.

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.

On Windows you can use the Putty Program:


Also see more information for using Windows and Putty to connect to the serial console on a Raspberry Pi:


Raspbian Configuration

Using your serial connection and kermit or Putty, you can access the Raspbian console.

The default username and password are:

username: pi
password: raspberry

Use these credentials to log in.

Once logged in you should do some basic configuration using the raspi-config program:

$ sudo raspi-config

You should do the following:
  • Change the default password
  • Change the hostname (optional)
  • In Localization Options change the locale (add en_US.UTF-8 UTF-8 and make this your default locale)
  • In Interfacing Options enable SSH
After you make these changes, restart you RPi:

$ sudo shutdown -r now

Networking Configuration

The best way to connect to your RPi is through the Ethernet cable using ssh. You will need to setup Internet Sharing on your laptop to enable this and to allow your RPi to access the Internet. You need your Raspberry Pi to access the internet to update software and to use GitHub.

macOS

I followed the instructions given here:


http://chariotsolutions.com/blog/post/configuring-network-used-by-mac-os-x/


You should setup the Internet Sharing IP range using the following commands in the Terminal:


$ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict-add SharingNetworkNumberStart 192.168.2.0
$ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict-add SharingNetworkNumberEnd 192.168.2.20
$ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict-add SharingNetworkMask 255.255.255.0


Then turn on Internet Sharing in System Preferences under the Sharing option. You will need to enable Internet Sharing on the Ethernet Device you are connecting to. For the USB Hub with Ethernet this will show up as "USB 10/100/1000 LAN" or something similar.

To ensure that you get the same IP address every time you connect your RPi, you should add the following file to your Mac: /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:39:e1:2d 192.168.2.2 boot


Replace the hwaddr with the hwaddr of you Ethernet device on your RPi. To find this, on your RPi, type:

$ ifconfig


Look for the "ether" device. This is the "MAC" address of your ethernet device on the RPi.


enxb827eb39e12d: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.4 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::3edf:94a3:9457:9779 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:39:e1:2d txqueuelen 1000 (Ethernet)
RX packets 661 bytes 100666 (98.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 122 bytes 20203 (19.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

 

My RPi Ethernet Mac address is:

 

b8:27:eb:39:e1:2d 

Linux

For Ubuntu see:

Windows

See:


With Internet Sharing your RPi should be accessible from your laptop and you should be able to access the Internet on your RPi:

For example, on my mac I can type:

$ ssh pi@raspberrypi.local

or 

$ ssh pi@192.168.2.2

Once on your RPi, you can see if you can access the Internet:

$ ping google.com 
PING google.com (216.58.194.206) 56(84) bytes of data. 
64 bytes from sfo03s01-in-f206.1e100.net (216.58.194.206): icmp_seq=1 ttl=52 time=14.1 ms 
64 bytes from sfo03s01-in-f206.1e100.net (216.58.194.206): icmp_seq=2 ttl=52 time=17.1 ms


Command Line Editors

nano (standard)
vi (standard)
vim (optional)
  sudo apt-get install vim
emacs (optional)
  sudo apt-get install emacs
ne (optional)
  sudo apt-get install ne


C Programming

Create the following C program using a console-based editor, then compile and run:

/* hello.c */

int main(int argc, char **argv)
{
    printf("Hello CS 315!\n");
    return 0;
}

$ gcc -o hello hello.c
$./hello


Comments