{ "cells": [ { "cell_type": "markdown", "id": "109c2fa9", "metadata": {}, "source": [ "\n", "*This notebook contains material from [cbe61622](https://jckantor.github.io/cbe61622);\n", "content is available [on Github](https://github.com/jckantor/cbe61622.git).*\n" ] }, { "cell_type": "markdown", "id": "62107a51", "metadata": {}, "source": [ "\n", "< [8.0 Raspberry Pi](https://jckantor.github.io/cbe61622/08.00-Raspberry-Pi.html) | [Contents](toc.html) | [8.2 RPI Library tests](https://jckantor.github.io/cbe61622/08.02-rpi-test-libraries.html) >

\"Open

\"Download\"" ] }, { "cell_type": "markdown", "id": "f7925595-7ce3-4a70-9e29-c381db9a772e", "metadata": { "nbpages": { "level": 1, "link": "[8.1 Setting up the Raspberry Pi for Lab Use](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1-Setting-up-the-Raspberry-Pi-for-Lab-Use)", "section": "8.1 Setting up the Raspberry Pi for Lab Use" }, "tags": [] }, "source": [ "# 8.1 Setting up the Raspberry Pi for Lab Use" ] }, { "cell_type": "markdown", "id": "bf946a96-00b8-4811-8862-b748f55ba2a6", "metadata": { "nbpages": { "level": 2, "link": "[8.1.1 Setup Procedures](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.1-Setup-Procedures)", "section": "8.1.1 Setup Procedures" }, "tags": [] }, "source": [ "## 8.1.1 Setup Procedures" ] }, { "cell_type": "markdown", "id": "38ee8d24-fe5c-4905-a533-a82fa2da8227", "metadata": { "nbpages": { "level": 3, "link": "[8.1.1.1 Step 0. Learn some Simple Linux Commands](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.1.1-Step-0.-Learn-some-Simple-Linux-Commands)", "section": "8.1.1.1 Step 0. Learn some Simple Linux Commands" } }, "source": [ "### 8.1.1.1 Step 0. Learn some Simple Linux Commands\n", "\n", "The Raspberry Pi OS is a version of Linux maintained by the Raspberry Pi Foundation for use on the systems they produce. [Linux](https://en.wikipedia.org/wiki/Linux) is open-source family of Unix-like operating systems that has been ported to a wide variety of systems, ranging from Android phones, personal computers, on up to large server clusters. \n", "\n", "Linux systems share a common set of simple commands that can be run from a terminal window. While these commands may seem terse and cryptic at first, if you learn to use them you will find them to be quick, powerful productivity tools. The following steps, for example, make use of these commands to set up a Raspberry Pi for use. If you are not already familiar the basic Linux commands, a short summary of the most useful commands is [Basic Linux Commands for Beginners](https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners)." ] }, { "cell_type": "markdown", "id": "314bf134-3311-402b-ae7b-67a10392e510", "metadata": { "nbpages": { "level": 3, "link": "[8.1.1.2 Step 1. Create an OS Image](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.1.2-Step-1.-Create-an-OS-Image)", "section": "8.1.1.2 Step 1. Create an OS Image" } }, "source": [ "### 8.1.1.2 Step 1. Create an OS Image\n", "\n", "The download and imaging of the microSD card takes a while, up to an hour or two. So start this step and let it proceed while you move on to other things.\n", "\n", "1. Download and install [Raspberry Pi Imager](https://www.raspberrypi.com/software/) on your laptop.\n", "2. Mount the microSD card onto your laptop (typically using a USB microSD card reader).\n", "3. Select a Raspberry Pi OS and write the image to the microSD card. " ] }, { "cell_type": "markdown", "id": "77946e71-e90d-4dd3-a31c-30a407ad23d7", "metadata": { "nbpages": { "level": 3, "link": "[8.1.1.3 Step 2. Assemble Case Hardware](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.1.3-Step-2.-Assemble-Case-Hardware)", "section": "8.1.1.3 Step 2. Assemble Case Hardware" } }, "source": [ "### 8.1.1.3 Step 2. Assemble Case Hardware" ] }, { "cell_type": "markdown", "id": "1dc33589-a359-45ad-8495-9baeffb4f570", "metadata": { "nbpages": { "level": 3, "link": "[8.1.1.4 Step 3. Initial Configuration](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.1.4-Step-3.-Initial-Configuration)", "section": "8.1.1.4 Step 3. Initial Configuration" } }, "source": [ "### 8.1.1.4 Step 3. Initial Configuration\n", "\n", "The initial bootup sequence will include a number of configuration steps. You will need to attach a USB keyboard and mouse to complete these steps.\n", "\n", "* Country: United States\n", "* Language: American English\n", "* Timezone: Eastern\n", "* Check \"Use English Language\"\n", "* Check \"Use US keyboard\"\n", "\n", "The default user is \"pi\". We will provide you with a class specific password to use with these devices.\n", "\n", "If the setup process doesn't successfully connect to the local wifi, skip those steps. After the boot process is complete, you can try to connect to wifi again through the taskbar." ] }, { "cell_type": "markdown", "id": "e28d00aa-3a27-47cc-81ee-233bdc16165c", "metadata": { "nbpages": { "level": 3, "link": "[8.1.1.5 Step 4. Update Installed Packages](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.1.5-Step-4.-Update-Installed-Packages)", "section": "8.1.1.5 Step 4. Update Installed Packages" } }, "source": [ "### 8.1.1.5 Step 4. Update Installed Packages\n", "\n", "It's important to keep your device updated with the latest release of software updates. Open a terminal window and update all installed packages.\n", "\n", " sudo apt update\n", " sudo apt full-upgrade\n", " sudo reboot\n", " sudo apt autoremove\n", " sudo apt clean\n", " \n", " " ] }, { "cell_type": "markdown", "id": "ced4b0fa-18f4-41af-9687-940492221f56", "metadata": { "nbpages": { "level": 2, "link": "[8.1.2 Step 5. Configure Options](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2-Step-5.-Configure-Options)", "section": "8.1.2 Step 5. Configure Options" } }, "source": [ "## 8.1.2 Step 5. Configure Options\n", "\n", "In a terminal window, run the command\n", "\n", " sudo raspi-config\n", " \n", "Options to change:\n", "\n", "* Display Options\n", " * D5: Set VNC resolution to 1024x768 or higher\n", "* Interface Options\n", " * P1: Enable RPI camera\n", " * P2: Enable SSH\n", " * P3: Enable VNC\n", " * Consider enabling other options as needed for laboratory interfacing\n", "* Performance Options\n", " * P2: Increase GPU memory to 256 MB\n", " \n", "Reboot when finished." ] }, { "cell_type": "markdown", "id": "0624c71d-b770-4fad-b182-5c96b8910516", "metadata": { "nbpages": { "level": 3, "link": "[8.1.2.1 Step 6. SSH Connectivity](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.1-Step-6.-SSH-Connectivity)", "section": "8.1.2.1 Step 6. SSH Connectivity" } }, "source": [ "### 8.1.2.1 Step 6. SSH Connectivity\n", "\n", "Remote connection from your laptop to a Raspberry Pi if often useful. To proceed you will need to be on the same network, and need the IP address of the Raspberry Pi. You can find the IP address from the VNC icon on the task bar, or typing ``hostname -I`` in a terminal window, or by executing ``ping -c 1 raspberrypi`` on the remote device.\n", "\n", "For SSH connection, open a terminal window on your laptop and use the following command\n", "\n", " ssh pi@xxx.xxx.xxx.xxx\n", " \n", "This should open a terminal window to your Raspberry Pi. " ] }, { "cell_type": "markdown", "id": "fbb37cee-60aa-43ce-99f4-83876f033126", "metadata": { "nbpages": { "level": 3, "link": "[8.1.2.2 Step 7. VNC Connectivity](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.2-Step-7.-VNC-Connectivity)", "section": "8.1.2.2 Step 7. VNC Connectivity" } }, "source": [ "### 8.1.2.2 Step 7. VNC Connectivity\n", "\n", "VNC provides remote access to the full desktop of the Raspberry Pi. If you haven't already done so, install [RealVNC Viewer](https://www.realvnc.com/en/connect/download/viewer/) on your laptop. \n", "\n", "You will need to know the IP address for the Raspberry Pi. This available by opening the VNC Viewer on the Raspberry Pi, or by executing ``hostname -I`` in a terminal window on the Raspberry Pi, or by executing ``ping -c 1 raspberrypi`` on the remote device.\n", "\n", "Then open a terminal window and setup an additional vncserver with the command\n", "\n", " vncserver -geometry 1600x900\n", " \n", "using whatever resolution may be appropriate for your laptop. The command will return a new IP/port address you can use to open an additional desktop window to the Raspberry Pi.\n", "\n", "At this stage you may find it convenient to operate the Raspberry Pi in `headless' mode." ] }, { "cell_type": "markdown", "id": "bf703336-2113-43d6-a681-379dbc9933e2", "metadata": { "nbpages": { "level": 3, "link": "[8.1.2.3 Step 8. Other Software Installations](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.3-Step-8.-Other-Software-Installations)", "section": "8.1.2.3 Step 8. Other Software Installations" } }, "source": [ "### 8.1.2.3 Step 8. Other Software Installations" ] }, { "cell_type": "markdown", "id": "68f63208-4f8e-4e0a-b389-61e406622690", "metadata": { "nbpages": { "level": 4, "link": "[8.1.2.3.1 WaveForms (Digilent)](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.3.1-WaveForms-(Digilent))", "section": "8.1.2.3.1 WaveForms (Digilent)" } }, "source": [ "#### 8.1.2.3.1 WaveForms (Digilent)\n", "\n", "Use the Raspberry Pi web browser to download and install the ADEPT runtime and WaveForms application." ] }, { "cell_type": "markdown", "id": "0595ee2b-b52a-4397-896e-e53ef25efd7c", "metadata": { "nbpages": { "level": 4, "link": "[8.1.2.3.2 Python Libraries](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.3.2-Python-Libraries)", "section": "8.1.2.3.2 Python Libraries" } }, "source": [ "#### 8.1.2.3.2 Python Libraries\n", "\n", "The default distribution of Raspberry Pi OS includes the core Python libraries that are used for many routine calculations, including Numpy, SciPy, and Matplotlib. These libraries, however, do not take full advantage of the Raspberry Pi's multiple cores or the [NEON SIMD unit](https://tttapa.github.io/Pages/Raspberry-Pi/NEON/index.html) incorporated into modern versions of the device. The following installs remove the default libraries, installs a modern BLAS to use the available hardware, and reinstalls core libraries with versions that can use the BLAS.\n", "\n", " sudo apt remove python3-numpy\n", " sudo apt-get install libopenblas-dev\n", " sudo apt-get install python3-numpy\n", " sudo apt-get install python3-matplotlib\n", " sudo apt-get install python3-scipy\n", " \n", "Image processing\n", "\n", " sudo apt-get install python3-opencv\n", " \n", "Qt Windowing\n", " \n", " sudo apt-get install python3-pyqt5\n", " " ] }, { "cell_type": "markdown", "id": "c4ec91c8-0716-4ab6-8b6c-34edd99b0434", "metadata": { "nbpages": { "level": 4, "link": "[8.1.2.3.3 [ImageJ](https://imagej.net/platforms/pi) (Not working!)](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.3.3-[ImageJ](https://imagej.net/platforms/pi)-(Not-working!))", "section": "8.1.2.3.3 [ImageJ](https://imagej.net/platforms/pi) (Not working!)" } }, "source": [ "#### 8.1.2.3.3 [ImageJ](https://imagej.net/platforms/pi) (Not working!)\n", "\n", "The following commands were an attempt to install ImageJ. Unfortunately, the resulting application is, at best, unresponsive and difficult to use. More work will be needed to produce a useable installation.\n", " \n", " sudo apt-get install openjdk-8-jre\n", " sudo update-alternatives --config java\n", " java -version\n", " cd Downloads\n", " wget downloads.imagej.net/fiji/latest/fiji-nojre.zip\n", " unzip fiji-nojre.zip\n", " wget raw.githubusercontent.com/imagej/imagej2/master/bin/ImageJ.sh" ] }, { "cell_type": "markdown", "id": "0e2792cc-bc8f-4bb5-a7b7-7594e4749815", "metadata": { "nbpages": { "level": 3, "link": "[8.1.2.4 JupyterHub and JupyterLab](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.4-JupyterHub-and-JupyterLab)", "section": "8.1.2.4 JupyterHub and JupyterLab" } }, "source": [ "### 8.1.2.4 JupyterHub and JupyterLab\n", "\n", "JupyterHub provides a JupyterLab environment that can be accessed locally or remotely through a web browswer. JupyterHub provides a notebook server for every user, a IPython console, and a terminal window. JupyterLab adds additional functionality corresponding to the latest notebook IDE. Together, these package provide a remarkably useful tool for accessing Raspberry Pi devices.\n", "\n", "The following installation instructions are adapted from https://towardsdatascience.com/setup-your-home-jupyterhub-on-a-raspberry-pi-7ad32e20eed for the latest version of Raspberry Pi OS (Bulleye).\n", "\n", "\n", "#### Step 1. Verify Python 3 is the default version Python.\n", "\n", "Verify that you have Python 3 installed as the default version of Python\n", "\n", " python --version\n", " \n", "If this is reporting a version earlier than Python 3, then go no further without first upgrading the OS to the current version of Raspberry Pi OS, Bullseye or later.\n", "\n", "#### Step 2. Install packages\n", "\n", "The next three commands install the services necessary to provide the JupyterHub service, and jupyterhub itself.\n", "\n", " sudo apt-get install npm \n", " sudo npm install -g configurable-http-proxy\n", " sudo -H pip3 install notebook jupyterhub\n", " \n", "#### Step 3. Setup the configuration file for JupyterHub\n", "\n", "JupyterHub requires a configuration file. This step creates a configuration file, makes changes to the file, then moves the file to the root directory so that it can be accessed by all users. First, be sure we're working in our own home directory.\n", "\n", " cd ~\n", " \n", "Next, create the configuration file ``jupyterhub_config.py`` in the home directory.\n", "\n", " jupyterhub --generate-config\n", " \n", "Two changes to this file will adapt its use for the Raspberry Pi. The first is to change the default port from 8000 to 8888 which is more commmonly used for JupyterHub services. Open the file ``jupyterhub_config.py`` using a text editor of your choice (for example, Thonny or nano on the Raspberry Pi). \n", "\n", " nano jupyterhub_config.py\n", " \n", "Search for a comment line containing ``# c.JupyterHub.bind_url = 'http://:8000'``. Change the line to read\n", "\n", " c.JupyterHub.bind_url = 'http://:8888'\n", " \n", "to enable use of the port 8888. To support JupyterLab, search for a comment line containing ``# c.Spawner.default_url = '/user/:username/lab'``. Change the line to read\n", "\n", " c.Spawner.default_url = '/lab'\n", "\n", "then save the file. Next, move the file to the root directory\n", "\n", " sudo mv jupyter_config.py /root\n", " \n", "That completes setup and installation of the JupyterHub configuration file.\n", " \n", "#### Step 4. Setup and start JupyterHub as a service.\n", "\n", "Create the jupyterhub.service file, and open for editing\n", "\n", " sudo touch /lib/systemd/system/jupyterhub.service\n", " sudo nano /lib/systemd/system/jupyterhub.service\n", "\n", "Add the following lines, write, and close the file.\n", "\n", " [Unit] \n", " Description=JupyterHub Service \n", " After=multi-user.target\n", " \n", " [Service] \n", " User=root \n", " ExecStart=/usr/local/bin/jupyterhub --config=/root/jupyterhub_config.py \n", " Restart=on-failure\n", " \n", " [Install] \n", " WantedBy=multi-user.target\n", "\n", "Next start the service and setup to restart on reboot\n", "\n", " sudo systemctl daemon-reload \n", " sudo systemctl start jupyterhub \n", " sudo systemctl enable jupyterhub \n", " \n", "Confirm the JupyterHub service is active\n", "\n", " sudo systemctl status jupyterhub.service\n", "\n", "\n", "#### Step 5. Setup JupyterLab\n", "\n", " sudo -H pip3 install jupyterlab \n", " sudo jupyter serverextension enable --py jupyterlab --system\n", " \n", " \n", "#### Step 6. Test\n", "\n", "On Chromium browswer on Raspberry Pi, start a JupyterLab session with the link\n", "\n", "``http://localhost:8888``\n", "\n", "From a remote web server, first verify that the Raspberry Pi can be located on the same network. In a terminal window, ``ping -c 1 raspberrypi`` to locate the IP address. Given the IP address, start a JupyterLab session ``http://xxx.xxx.xxx.xxx:8888``.\n", "\n", "Alternatively, a remote session can be started in a VNC session, then executing\n", "\n", " jupyter lab\n", " \n", "in a terminal window." ] }, { "cell_type": "code", "execution_count": null, "id": "ba326a6f-5f5c-4305-bf43-d57658faab62", "metadata": { "nbpages": { "level": 3, "link": "[8.1.2.4 JupyterHub and JupyterLab](https://jckantor.github.io/cbe61622/08.01-Raspberry-Pi-Setup.html#8.1.2.4-JupyterHub-and-JupyterLab)", "section": "8.1.2.4 JupyterHub and JupyterLab" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "ba0dc365", "metadata": {}, "source": [ "\n", "< [8.0 Raspberry Pi](https://jckantor.github.io/cbe61622/08.00-Raspberry-Pi.html) | [Contents](toc.html) | [8.2 RPI Library tests](https://jckantor.github.io/cbe61622/08.02-rpi-test-libraries.html) >

\"Open

\"Download\"" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.12" } }, "nbformat": 4, "nbformat_minor": 5 }