Lab 0: Intro To Running Jupyter Notebook On A Raspberry Pi
Lab 0: Intro To Running Jupyter Notebook On A Raspberry Pi
Lab 0: Intro To Running Jupyter Notebook On A Raspberry Pi
on a Raspberry Pi
Li-Hao Yeh, and Michael Chen updated from
previous efforts by Nick Antipa, Jon Tamir, and Frank Ong
January 28, 2019
This lab will walk you through setting up your Raspberry Pi to run a
Jupyter Notebook server. By the end of this lab, you will be able to write
code from a Jupyter Notebook in a browser on your laptop, then execute the
code on the Raspberry Pi.
1 Quick intro
A Raspberry Pi is a tiny, inexpensive computer that uses ARM processors, just like most
smart phones. The Linux-based operating system is installed on a micro SD card. We
have provided SD cards with a functioning operating system, as well as a full installation
of Python 3.5 and Jupyter Notebook. In this lab, we begin by using a USB-to-serial
converter to open a terminal window on your Pi. From that terminal, you will secure your
Pi with private passwords, connect it to WiFi, and establish an adhoc WiFi network.
Once this is complete, you will be able to connect to your Pi wirelessly and write Python
code from your own computer. In future labs, we will connect hardware to the Pi, but
this lab focuses on simply setting up and executing code. Let’s get started.
1
Figure 1: Procedure for assembling Fe-pi sound extension and wiring CP2102 chip to
Raspberry Pi 3
1. Start by downloading and installing the drivers for your appropriate OS from
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers.
∗ Mac users: Remember to allow installation of every part of the driver from System Preferences →
Security & Privacy .
2. Next, assemble the sound extension to the Pi and then use the provided jumper
cables to wire the CP2102 to your pi. Connect RXI to Pi pin 8, TXO to Pi pin
10, and GND to Pi pin 6. See figure 1. Note you may get a different CP2102 chip,
the TXO and RXI pins could be in reverse order as in the Figure. Make sure you
connect them in the specified order.
3. Plug in the CP2102 to your laptop’s USB-A port. Do not power up the Pi yet.
2
3 Open a terminal on the Pi
Next, we will establish a terminal window on the Pi. This will allow you to modify the
settings of the Pi, including securing it with a private password. Do not forget your
system password! If you do, we will have to format your SD card and you will need to
repeat lab0.
2. Use the provided wall-plug power supply to power the Pi with the micro USB port
on the Pi. The Pi will boot, indicated by the blinking green light.
3. After entering the command, press extra return on your keyboard to proceed.
Otherwise, it will get stuck in a empty screen.
You should now be logged into the Pi. If you have to reboot, leave this window open
and it will automatically reconnect. If you close the window and try to connect again
with the same command, it may not work. In that case, try screen -r to reopen the
original session.
3
3.2 Directions for Windows
We will use a free program called PuTTY to open a serial terminal to the Pi.
1. Download and install PuTTY from here, using default options: https://www.chiark.
greenend.org.uk/~sgtatham/putty/latest.html
3. Under Ports (Com & LPT), find the Silicon Labs device and note its number in
the form of COM# (COM3 in this example)
4. Launch PuTTY
5. Select ”Session” in the left panel, and select the ”serial” radio button on the right.
7. Enter 115200 in the ”Speed” box. Your window should look like Figure 3
8. Click ”Open”
9. Once the terminal window opens, press return once on your keyboard
4
Figure 3: PuTTY configuration
11. If you were successful, you should see the command prompt.
5
Important: Always shutdown the pi using the command sudo shutdown -h now
**BEFORE** disconnecting the power. Failure to do so, may corrupt your file system.
3. select ”Expand Filesystem”. It will say ”Root System has been resized”
6. wait until your terminal window returns to the login screen, and enter user name
pi and password EE123Rocks!
Now you have a fully functional Pi! Let’s personalize and secure it in the next section.
1
sudo is a command that gives you admin rights, and raspi-config is an interactive script for
personalizing your Pi.
6
5 Passwords
In this section, you’ll set secure passwords for your Pi as well as the Jupyter Notebook
server running on the Pi.
Your system password is now set. Test it by rebooting and logging in with the same
username as before, but your new password. Do not forget this password! If you
do, your SD card will need to be reformatted!
This is the password you will use to login to Jupyter Notebook from another computer.
7
6 Setting up the network
You won’t be able to use nice features of Jupyter Notebook like plotting over the serial
connection, so in this section, you’ll be guided through various methods for wirelessly
networking with your Pi from another computer.
4. Select Network Options → Wi-Fi . Type the SSID (name) of the network, then
its password, then exit raspi-config.
5. Test that your are online by pinging any website you want ping www.google.com
8
Connecting to Airbears2 is optional. However, if you choose to use it, it will
make it more simple to connect to the Pi and the internet while on campus. The process
is a bit more complicated and requires editing a file that stores your Wi-Fi network
information. This step is optional. Only proceed if you want to get your Pi online while
on Campus.
First, make sure your Pi is in Wi-Fi mode. Your Wi-Fi network info is stored in a
plain text file. The file provided already has a blank spot for Airbears2, and all you need
to do is edit the file. Do this by typing sudo nano /etc/wpa_supplicant/wpa_supplicant.conf .
2 You’ll see a section that looks like Fig. 4. Replace the appropriate text, but do not re-
move the quotes! Exit by pressing ctrl-X . Enter Y when it asks Save modified buffer? ,
then hitting return .
2. After the Pi reboots, open your laptop’s Wi-Fi and look for a network called
EE123YourCustomSSID.
9
4. Save the file (ctrl-X, Y, return)
7. You should now see a WPA-2 securred WiFi network named whatever you named
it. Connect using your super secret password.
10
7 Connecting to the Jupyter Notebook Server
Your Pi is already setup to automatically start a Jupyter Notebook Server when it boots.
In this section, you will see how to connect to this server from your laptop browser.
1. Make sure your Pi is booted into adhoc or managed mode (see 7.1 and 6.4. Connect
your laptop to the ad hoc network. Note: you will lose internet connectivity once
you’ve done this.
3. Your browser will probably tell you this is an unsecure, terribly dangerous thing
to do. But you know better, so tell your browser you know what you’re doing and
proceed.
4. Enter the Jupyter password you set earlier into the prompt that looks like this:
You now have a Jupyter Notebook window on your laptop that can see code in the
directory ~/EE123 on the Pi. It is empty, but you can put any code you want here in
the future. N.B. at this point, you could remove the CP2102 and use ssh to connect to
the Pi by typing ssh [email protected] . We recommend that you create a folder for
each lab, so your notebook and files don’t get messy. In this case, create the directory
Lab0 with mkdir Lab0 under ~/EE123 .
Finally, on your laptop, download the Lab0 notebook file. For Mac, from a terminal
on your laptop, move it to the Pi by typing
Alternatively, from a terminal connected to the pi, you can use the command
wget http://file.url to download the file using the commandline.
11
On Windows, PuTTY comes with a command line program called PSCP From a
command prompt (search “CMD” to start), the syntax is pscp source_file destination .
For example, to move a file from your PC to your Lab0 folder on the Pi in ad hoc mode,
type
pscp [PathToFile] [email protected]:/home/pi/EE123/Lab0
You may also be able to transfer using a USB thumb drive, but we have not tested this
so you’re on your own!
Important: Always shutdown the pi using the command sudo shutdown -h now
**BEFORE** disconnecting the power. Failure to do so, may corrupt your file system.
12
Collections of commands
• screen /dev/cu.SLAB_USBtoUART 115200 : connect to the pi through CP2102
from your laptop
• sudo ~/adhoc YourSSID : switch the Pi to Ad-Hoc mode with SSID of EE123YourSSID
13