LED Light Strip with Pi Zero

Raspberry Pi Zero controlling a LED strip, with a hardwired clear button.

I wanted to set up a small (20 LEDs) light strip using a Raspberry Pi Zero, so students could learn how to remotely log in to a device, work with the Linux command line, run python programs, and get visible, real feedback on their progress.

Instructions and code are in the Github rpi-led-strip repository.

Web control for the LED strip.

The repository also has instructions and code for setting up a local server on the Pi so you can control the LED strip via a webpage. Students working on their own LED projects in the Makerspace will appreciate this.

The main idea here was to make the project as simple as possible. The web page is basic with minimal styling, so it should be easy to edit, but I do test out some of the newer HTML input elements, like the color picker. The README in the repository also includes instructions on how to, step by step, add components to the webpage to control the Pi: the “Blue” button is used as the example (it sets the entire strip to blue).

With only 20 LEDs you don’t need an external power supply so everything can be run through the Pi.

Adafruit’s CircuitPython NeoPixel library makes controlling the lights really easy. There are a few example programs in the rpi-led-strip/pyLED/ directory of the repository.

The full strip.

I’ve also included a physical button (it’s optional) that I’m using right now to just clear the LED strip. I may change it to just reboot the Pi, because I anticipate that things will get interesting when I have an entire class trying to connect to one or two devices. So far, I’ve had a small group of four students try this with some success.

Making Animations with HTML Canvas

Based off of Mozilla’s nice introduction to basic animations on the web, I made as simple of an animation as I could using the Canvas element in HTML. It just contains a static, red rectangle, and a green sphere that slowly moves across the canvas. This should serve as a simple introduction for my students who want to make online games.

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>

  <body>
    <div id="gameBoard"></div>

  </body>

  <script type="text/javascript">

    canvas_width = 400;
    canvas_height = 300;

    //create canvas
    cvs = document.createElement("CANVAS");
    cvs.height = canvas_height;
    cvs.width = canvas_width;
    document.getElementById("gameBoard").append(cvs);
    ctx = cvs.getContext("2d");
    cx = 10;
    cy = 20;

    window.requestAnimationFrame(animate);

    function animate(){
      //clear the canvas
      ctx.clearRect(0, 0, canvas_width, canvas_height); // clear canvas

      //set location of the circle
      cx += .2;
      cy += .1;
      
      //recreate the canvas (every time)
      ctx.fillStyle = '#ff0000';
      rect = ctx.fillRect(0, 0, 20, 100);

      ctx.beginPath();
      circ = ctx.arc(cx, cy, 10, 0, 2 * Math.PI);
      //ctx.stroke();
      ctx.fillStyle = '#00ff00';
      ctx.fill();

      window.requestAnimationFrame(animate);

    }

  </script>
</html>

This uses plain HTML and Javascript, with no additional libraries.

Linux Laptops

We had a couple laptops recently donated to the Makerspace (thanks Ms. A) and I’ve installed Ubuntu’s Linux (20.04 LTS) to see if I could get them to be useful for my students. I particularly wanted to see how hard they’d be to set up for programming (especially given the issues I’ve had with python). They’re working quite well so far, and this is my record of what I’ve done to set them up.

Installing Ubuntu

Ubuntu makes it really easy to install their operating system; it’s the main reason it’s one of the more popular flavors of Linux. You can download the ISO and get instructions on how to create a USB installation stick on their page.

Getting System Information

inix is a nice tool to for finding information about your computer (which you sort-of need when you’re dealing with donated machines): what type of cpu, how much RAM, size of the hard drive and things like that. Install with:

sudo apt-get install inxi

and to get the full set of information, run:

inxi -F

Extremely useful, but I did not really need this to tell me that I needed to upgrade the hard drive. Swapping the hard disk drive (HDD) for a solid state drive (SSD) is one of the quickest and cheapest ways to upgrade an older system. I picked up a 120 Gb SSD for less than $20 and the computer is now an order of magnitude faster (though I’m down from 500 Gb).

Upgrading

The final step after installing the operating system is to update the software. Ubuntu runs an automatic update on your first boot. However, since I’ll be doing most of my installations from the command line, I run the update commands (just in case):

sudo apt update
sudo apt upgrade

Setting up Python

Python 3.8.5 was installed by default, but I need the python package installer (pip) to install the modules I’ll need:

sudo apt install python3-pip

Now I can install numpy (-U option to upgrade) for numerical stuff:

pip3 install -U numpy

as well as, matplotlib:

pip3 install -U matplotlib

and vpython

pip3 install vpython

and for virtual environments (venv):

pip3 install virtualenv

and the IDLE editor for python

sudo apt-get install idle3

also the Thonny editor that makes using Raspberry Pi Picos much easier (especially for the pico LED strips)

sudo apt install thonny

Now we should be good to go.

git, github, and vs code

git: I’ve been using github.com for keeping my programming projects and GitHub Classroom for my programming class. The GitHub Desktop program is great for Windows and OSX, but does not exist for linux at the moment. So I needed to install git:

sudo apt install git-all

VS Code is a pretty popular IDE for coding that I’ve been using for my computer programming class. It’s a Microsoft product that is designed to work closely with github repositories. You can download the .deb from

It’s usually saved in the ~/Downloads folder, so to install this should work:

sudo apt install ./Downloads/code*.deb

I usually test the VS Code installation with my ledPixelsPico repository because I want to make sure I can operate my Raspberry Pi Pico LED strips.

To get VS Code to be able to make commits and sync with the repository (you’ll have to test this with a repository of your own–or that you have permission to sync with) you’ll need to run the ‘git config –global user.email “you@example.com”‘ and ‘git config –global user.name “Your Name”‘ commands in the VS Code Terminal.

LaTeX

For typesetting beautiful documents (mainly for the equations) I use LaTeX.

Since I don’t want to worry about downloading LaTeX packages when I need something esoteric I install the full Tex Live distribution (Note: for texlive on Fedora use ‘texlive-scheme-full‘).

sudo apt-get install texlive-full

Editor: To use LaTeX we need an editor. I prefer TeXstudio:

sudo apt-get install texstudio
  • Folder with all files needed to test the typical things I do with LaTeX in a chapter format: LaTeX Demo Report.

NOTE: if you’re low on memory, you can install something like Miktex instead of Tex Live because it installs packages only when you need them. Also, some of my students who use Apple computers seem to find TexShop easier to set up than TexStudio.

Installing Additional Software

The basic Ubuntu installation comes with a lot of the free software I use, but, using the command line:

sudo apt install ...

or the Ubuntu (or other package manager) Software tool, I added:

  • [Atom] [depreciated]: text editor for coding (being depreciated unfortunately, I’ve been forced to use VS Code instead: see above, or Thonny: see below and above).
  • Thonny: Coding editor for working with Raspberry Pi Picos in particular (may already be installed from the python section above).
  • GIMP: for image editing
  • Inkscape: for vector graphics
  • OpenScad: for 3d Modeling (for printing)
  • Shotcut: for video editing (it’s multi-platform). I’m trying this one for extracting time information from experiments (like ball drops). Can install with ‘sudo apt-get install shotcut’

UxPlay [Optional]: A crucial piece of software for online teaching that I had to install via the command line was, UxPlay, and you can see my variant of the installation instructions here. This program allows me to mirror my iPad to the computer.

The Rest

The rest is mostly tweaking the settings to your specifications (there’s even a program called Tweak you can install for extra settings).

Tweaks

I use this to enable hot-corners and customize the desktop interface.

sudo apt install gnome-tweak-tool
sudo apt install gnome-shell-extensions
Fonts

Added the student fonts following LinuxConfig’s instructions, specifically the section on “Manual system-wide font installation”, which just meant copying the folder with all the fonts to the “/usr/local/share/fonts/” directory.

php

I use php a lot so I’ve set it up so I can run php off the command line (I haven’t figured out how to use url parameters this way though).

sudo apt install php libapache2-mod-php
sudo apt install php-cli
gdebi

gdebi is a little application for installing .deb software. I’ve had enough hiccups with the Ubuntu Software tool, to find it useful to right click a downloaded .deb file and install it using gdebi. To install:

sudo apt install gdebi
Imager

The first thing I used gdebi to install was Imager, which is used to write the Raspberry Pi operating system to USB’s or SD cards. Download the imager .deb, right click and install using gdebi.

nmap

nmap maps your local network, which is useful if you have a bunch of Raspberry Pi’s around and need to figure out their IP addresses.

sudo apt-get install nmap

To use nmap to find all the raspberry pi’s on the local network use something like this, where you change the IP address (192.168.4.0) to whichever IP your computer is on, but switch the last number for 0:

sudo nmap -sP 192.168.4.0/24 | grep -in -B 2 'pi'

UxPlay: Sharing iPad Screen on Linux (Ubuntu)

My setup for teaching online and in school students simultaneously requires me to mirror/share my iPad screen, which I’m using as a whiteboard, with a computer that’s doing video-conferencing for the online students and is hooked up to a projector for the in-class students.

I’ve been using X-Mirage on a Windows computer, but this week my Windows desktop started having trouble connecting to the internet in the middle of classes, and I’ve not been able to debug. Fortunately, I’d been setting up a donated laptop with Ubuntu Linux, mainly to use as a machine for programming, but a quick internet search lead me to Rodrigo Ribeiro’s UxPlay that allowed me to switch over to the Linux laptop for the last two days.

The installation instructions are straightforward, but I wanted to make a note to myself for future reference, because I did this on two different laptops and both times I had to run one of the commands I found in the comments.

So, to install run:

sudo apt-get install cmake
sudo apt-get install libssl-dev libavahi-compat-libdnssd-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-libav
sudo apt-get install gstreamer1.0-vaapi

The last command was redundant on at least one of the computers, but didn’t seem to hurt.

You then download the UxPlay program from his webpage, and follow his instructions to unzip the file, cd into the directory, make a ./build folder, cd into that, and then run the commands:

cmake ..
make

At this point you may be able to run the program, but I was not able to connect my iPad until I ran:

sudo apt-get install gstreamer1.0-plugins-bad

Then I could launch the program (while still in that build directory) with:

./uxplay
Screen mirrored using UxPlay showing my Jamboard notes that were written on the iPad.

Now, I just need to figure out the best way of streamlining the use of the program.

Update: I copied the “uxplay” executable into the “/usr/local/bin” folder so it’s now accessible from everywhere, and available to all users on the laptop.

The Technology I Use for Teaching in Person and Online at the Same Time

This year we’ve been doing a hybrid system with most students at school and a few, who’re more sensitive to the COVID risk, at home. Setting up the technology to accomplish this has been quite tricky, but we’ve settled on a system the works reasonably well.

Hardware

The standard system involves:

  1. iPad: for notes that will normally be written on the board,
  2. Computer: the iPad screen is mirrored on the computer and then,
  3. Projector: to project what’s on the computer/iPad the kids in the classroom.

In practice it looks like this.

The iPad is mirrored to the computer which connects to the project and shares the screen with the kids at home.

If it looks a bit messy, that’s because it is.

Software

Video Conferencing

We’re using Google Meet for our video conferencing software, pretty much because we’re using Google Classroom for our classes and it’s built in. However, all you need is something that can share the computer screen with the kids at home, so Zoom, which we used in the spring, would probably work as well. One advantage of Meet is that it’s easy to set up a meeting for the class and the link is posted at the top of the page every time you log into Google Classroom.

Jamboard as a Whiteboard app.

After trying a few programs we’re using Google’s Jamboard as a whiteboard program for the iPad. Jamboards are shared documents, just like another Google Doc or Sheet, so in theory, if I shared the specific Jamboard document with them (which I do) the students at home could just follow along in the same document in real-time. In practice Jamboard can be extremely laggy, so I’ve given up on that approach and now I just share my entire computer screen over the video conferencing program.

One nice thing about Jamboard is that they are files, so the whiteboard notes can be saved and cataloged with other materials for a particular lesson or assignment. It’s also probably a good thing that you’re restricted to 20 slides otherwise I’d end up with some really large documents.

The ability to save them as files with all the other google documents, and the fact that it’s free, are the main reasons I prefer Jamboard to the other whiteboard options I’ve tried.

Mirroring the iPad (X-Mirage and UxPlay)

Mirroring the iPad to the computer turned out to be quite tricky. Since we’ve been working primarily with Windows PC’s, I ended up going with X-Mirage. I’ve set it up so X-Mirage automatically launches when you start up the computer, but it’s another piece of software to pay attention to. This program has a mac version as well. On the downside it costs about $14 for each computer it’s on.

I recently got my hands on a couple old (donated) laptops, and installed Linux (Ubuntu) on them for the operating system. In the few days I’ve been testing them they seem to work very well. For these I’ve used UxPlay as mirroring software, which has slotted into the system very, very well. Because it’s a command line program, setting up can be a little tricky.

In Summary

In summary, I have a system, and it works well enough that all of the other teachers have adopted it for their classes as well. This works for us because we can mostly use the hardware we have (we did have to buy iPads for the teachers who did not have them), and the software is fairly cheap. The kids at home appreciate it because it allows them to see and hear what’s going on in the classroom, especially what’s written on the board, pretty clearly. I’ve not heard many complaints from the kids at school.

As for the future, I am somewhat excited that I can effectively use the Linux computer now, and I’m always looking for ways to streamline.

Introduction to Pi’s (Raspberry Pi)

The family of Raspberry Pi’s are just really small computers. You can plug a monitor, keyboard, and mouse into one and it will not look too different from your desktop. They are small and cheap, but what makes them really useful is that they have little slots (called GPIO’s) that you can stick wires into that allow you to build circuits that can get information from sensors and control devices like LED lights or motors.

This is a quick introduction about how to set one up. You’ll find lots of great tutorials on the internet. This one is specific to my needs: it’s an introduction to the Pi’s for students who are new to them; I’m setting it up with a web server so we can control the devices through a webpage; and I’m setting it up so you can control the Pi “headlessly”, which means you don’t need the keyboard, mouse, etc..

Installing the Operating System

Downloading the OS

Download: The operating system files can be downloaded from the Raspberry Pi website. We’re going to use the Raspbian Desktop version with the recommended software.

Your typical computer has a built in hard drive that stores the data you save, the programs/apps you install, and the operating system (OS) that runs it all. When you start the computer the first thing it does is read the files that make up the operating system from the hard drive and set them up in the active, processing memory (RAM). Then when you interact with the computer (type on the keyboard, click the mouse etc.) you’re interacting with the operating system: you tell the operating system what to do, like start up a web browser (Firefox, Chrome, Safari, Explorer, Opera etc.), and it does it. And when your apps want to do something, like save a file, they have to ask the operating system to do it.

On the Raspberry Pi the data for the operating system is not stored on a built in hard drive, but on an SD card (or microSD), which means that you’re going to have to install the operating system yourself to get your Pi running. You can find the operating system at the Raspberry Pi website’s download page.

Installing

As of this writing, I’ve been using balenaEtcher to install the operating system on the SD Card.

balenaEtcher is free and pretty easy to use. Hopefully, your computer has an SD card port, if not you’re going to have to find an adapter. Just plug your SD card into your computer and run Etcher, it will ask you to:

  • Select Image: Which is the Raspbian file you downloaded
  • Select Drive: Which should default to the SD card you plugged in (check the size of the drive to make sure)
  • Flash: Which writes the Operating System files to the SD card, making sure everything is in the right place.

You may see some warnings pop up about Unrecognized Files Systems or similar. You can just close those windows.

When the flashing is done, don’t take the SD card out of your computer (or put it back in if you have) just quite yet. We’re going to set it up so the Pi can automatically connect to the WiFi, which will make it easier to talk to.

Setting Up WiFi

You’re going to have to edit some files on the SD card to give the Pi the information about the WiFi situation so that it can automatically connect. This is most useful if you’re not going to plug in a keyboard and monitor and just want to control the Pi from your computer (more on how to do this later). If you do want to go the keyboard and mouse route, you can just plug the SD card into the Pi, power it up, and set up the WiFi like you would normally do on your laptop.

To edit the files I use Atom on Windows or TextEdit which is built in on Mac. These programs should allow you to easily save files as plain text, without any of the fancy styling that will create errors when the Pi operating system tries to get the information from the files.

WiFi

Create a new file called: “wpa_supplicant.conf” (based on these notes) containing:

ctrl_interface=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
 ssid="networkID"
 psk="password"
}

But you have to change:

  • networkID to the name of the WiFi network you’re trying to connect to
  • password to the password for the network

If you need to connect to multiple networks (home and school for example) you can add another network command on a new line after the first one:


network={
 ssid="otherNetwork"
 psk="otherPassword"
}

Save this file to the boot directory of the SD card.

ssh

ssh allows you to remotely connect to your Pi’s operating system. This means that you can use your laptop to control the Pi (however you’ll be using command line commands).

Create an empty file named “ssh” and save it to the boot directory of your SD card.

USB connection

You should be able to find your Pi on the network (I use an app on my phone called Fing) and ssh in. However, to do most of the setup, especially if the Pi has trouble connecting to the WiFi (or you can’t find it on the network), you’ll probably want to set up your pi so you can plug it into your computer’s USB port and control it from the computer. Based on the notes from Adafruit, do this:

Open the file “config.txt” which is in the SD card’s boot directory, and add this as the last line in the file:

dtoverlay=dwc2

Save the file then:

Open the file “cmdline.txt”, find the word “rootwait” and, after it, insert the phrase:

 modules-load=dwc2,g_ether

You should end up with something that looks like “…=yes rootwait modules-load=dwc2,g_ether quiet…”:

Connecting to your Pi

To talk to your Pi’s Operating System you should be able to connect your Pi’s USB port to your computer’s or connect over WiFi. Either way you’ll need to use an ‘ssh’ program.

  • Windows: I use putty. Install the program and run it. Then you’ll need to enter:
    • Host Name: raspberrypi.local
    • Password: raspberry
  • Mac: I use the built-in Terminal (In your Applications->Utilities folder). Type in the command (don’t type in the “>”):
    • > ssh raspberrypi.local
    • Use the password: raspberry

If you go the WiFi route, you’ll need to find your Pi’s IP address and use that as the Host Name.

Update and Upgrade

Once you’re ssh’d in, and are connected the internet, you can update and upgrade the operating system. Type in the commands (without the “>”).

> sudo apt-get update
> sudo apt-get upgrade

The “sudo” means you’re giving yourself permission to run commands that could potentially mess up your system. The program you’re running is called “apt-get” which connects to the internet repositories with the latest updates and upgrades to your operating system and programs, and then downloads and installs them. The options “update” and “upgrade” specifically tells the “apt-get” program what you want it to do. Downloading and upgrading may take a while.

Enable Interfaces

You’ll also want to check that the interfaces to the GPIO pins are enabled, so you can build circuits and control them. Notes on this are here.

First check that your tools are installed and updated with the commands:

> sudo pip3 install --upgrade setuptools
> sudo apt-get install -y python-smbus
> sudo apt-get install -y i2c-tools

Then Activate the Interfaces. You’ll run the command “raspi-config” and then use your keyboard to tab through the windows to activate the I2C and SPI interfaces. These are just two different ways for the Pi to talk to the devices you plug into it.

> sudo raspi-config
---- Interfacing Options
-------- I2C
------------ Yes
---- Interfacing Options
-------- SPI
------------ Yes

To get this all up an running you need to reboot the Pi:

> sudo reboot now

For the OLED displays

To control the little OLED displays we have, install the adafruit-blinka, and OLED libraries:

> sudo pip3 install adafruit-blinka
> sudo pip3 install adafruit-circuitpython-ssd1306

Tornado Server

The tornado server allows us to create webpages on the Pi that we can connect to over WiFi that can be used to control devices connected to the Pi. Install tornado using:

> sudo pip3 install tornado

Now restart everything and we can get to work.

> sudo reboot now

Preparing Students for a Technological Future

I’m currently preparing a proposal to create a laboratory of digital fabrication machines–a CNC, a laser, and a vinyl cutter–and one of the questions I’m answering is about how the proposed project would prepare students for a technology-rich future. What you see below is my first response to this prompt. It’s a bit longer than I have space for in the proposal, and probably a bit too philosophical, but before I cut it down I wanted to post this draft because it does a reasonable job of encapsulating my philosophy when it comes to teaching technology:

Preparation for a technology rich future is less about preparing for specific technologies and more about getting students to have a growth mindset with respect to technology. We are living in a truly wonderful moment in history. Technological tools are rapidly expanding what we as individuals can accomplish. They are allowing us to see farther (think about remote sensing like lidar and tomography), collate more information (especially with more and more data becoming publicly available), and create things that push the limits of our imaginations. Indeed, to paraphrase a former student, we are already living in the future.

To prepare students to live and thrive in this ever-evolving present we need to demystify technology and give students the intellectual tools to deal with the rapid change. We can start by letting them peek into the black boxes that our technological devices are rapidly becoming.

We request electronics stations and tool kits not just to build things, but to be able to take them apart and look inside. Students greatly enjoy dissassembling and reassambling computers, for example, which provides younger students a good conceptual understanding of how most modern devices work. This foundation helps when they start building circuits of their own and realize what they really want to do is to control them–making lights blink and turning motors for example–and this is when they will start working with Raspberry Pi computers, Arduino microcontrollers and programming.

As students start to build (and even before really), they naturally start thinking about design. We all have an affinity for the aesthetic. If you’ve ever had the opportunity to see a laser in action, you’ll remember your sense of fascination the first time you saw someone’s design emerging from the raw material right before your eyes. Thus we get into graphic design, computer aided design (CAD) and computer aided manufacturing (CAM) and the digital fabrication machines we propose.

By the time they’re done with this curriculum, we intend that students will have developed an intimate familiarity with the technological world–including the ability to create and design their own, which prepares them for the technological future.