Intro to Programming Database Internet of Things IT Project Management Networking Web Development For Research Students

Introduction

The Raspberry Pi is an example of a second kind of common IoT board, the single-board computer (SBC). SBCs come with an operating system and therefore device drivers. They are able to do complex IoT things like stream camera input over the Internet. However, they are a lot slower and more power hungry than SBMs. It is much harder to do simple things with a SBC.

The exercises here will work on both the Raspberry Pi Model 3B+ and the Raspberry Pi 4

The current contents are:

Any questions or comments should be directed to: The creator's email

Setting Up Your Raspberry Pi

These are instructions for setting up your Raspberry Pi for first time use. I find Raspberry Pi startup costs can be deceptive. While the board itself is relatively cheap, one needs to buy a number of ancillary products to actually get a Raspberry Pi to work. I personally recommend first time buyers buy the Canakit startup kit. After getting some experience, you'll probably feel you overpaid for a Canakit, because there's stuff in there you didn't use. But, buying one reduces the likelihood you forgot to buy something. Note that in addition to buying a Canakit startup kit, you will need a USB keyboard, USB monitor and HDMI cable before you can do anything with your Raspberry Pi. The hyperlink is to Canakit's startup instructions for configuring a Raspberry Pi for firsttime use.

Setting Up Your Raspberry Pi to Connect to iOS

The following sequence of instructions sets up a Raspberry Pi so iOS devices can project information to a Raspberry Pi, and therefore to any device connected to the Raspberry Pi. This is useful, for example, for converting the Raspberry Pi to a home entertainment system, or to an intelligent video projector.

The instructions assume the Raspberry Pi has been set up and contains Raspbian or equivalent OS.

The video shows the result of completing the exercise.


Instructions are below.

Install Shairport

Shairport is a tool for sending music from an Apple-based music player to the Raspberry Pi. The instructions for installing Shairport come from This site.

Step Command What it does
1. sudo apt-get update sudo is the Linux command for running as a superuser. It is equivalent to "Run As Administrator" in Windows.
apt-get update refreshes a Linux OS's knowledge of the libraries it uses across applications. It is common to run this command prior to any new software installation or upgrade.
2. sudo apt-get install autoconf automake avahi-daemon build-essential git libasound2-dev libavahi-client-dev libconfig-dev libdaemon-dev libpopt-dev libssl-dev libtool xmltoman This installs libraries that shairport is dependent on.
3. git clone https://github.com/mikebrady/shairport-sync.git Download shairport from github. If you do not have permissions, put sudo in front.
4. cd shairport-sync Change directory to where shairport is. Note you might have to alter this command depending on where you put shairport.
5. autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata
Sets options for the compiler. If there are permission problems, put sudo in front.
6. make
sudo make install
Compile and create executable for shairport.
7. sudo systemctl enable shairport-sync Sets shairport to automatically start when the Raspberry Pi reboots.
8. Reboot the Raspberry Pi.

If everything worked, you should be able to open Apple Airplay on your iOS device to find the Raspberry Pi Shairport server. You should then be able to stream your Apple Music to the Raspberry Pi.

Install RPIPlay

Shairport only allows you to stream Apple Music through the Raspberry Pi. To share what's on the iOS device's screen, you need RPIPlay. The instructions for installing RPIPlay come from the RPIPlay page on GitHub and these instructions

Step Command What it does
1. sudo apt-get update sudo is the Linux command for running as a superuser. It is equivalent to "Run As Administrator" in Windows.
apt-get update refreshes a Linux OS's knowledge of the libraries it uses across applications. It is common to run this command prior to any new software installation or upgrade.
2. sudo apt-get install cmake libavahi-compat-libdnssd-dev libplist-dev libssl-dev These are various libraries RPIPlay needs.
3. git clone https://github.com/FD-/RPiPlay.git Download RPIPlay
4. cd RPiPlay Go to the directory containing RPIPlay
5. mkdir build Create a directory called build to store the executable.
6. cd build Go to the directory build.
7. cmake ..
make
Compile RPIPlay.
8. Create a text file in /etc/systemd/system/rpiplay.service with the following content:
[Unit]
Description=An open-source AirPlay mirroring server for the Raspberry Pi
Documentation=https://github.com/FD-/RPiPlay
After=network.target

[Service]
Type=simple
Restart=always
Environment=NAME="Raspberry Pi"
Environment=AUDIO=hdmi
Environment=BACKGROUND=auto
ExecStart=/usr/local/bin/rpiplay -b $BACKGROUND -n ${NAME} -a $AUDIO
Set up the RPIPlay service. Once you do this, RPIPlay will start every time the Raspberry Pi reboots.
9. Reboot the Raspberry Pi

The Raspberry Pi as a Bluetooth Slave

It is substantially easier to teach Internet of Things concepts over WiFi than over other kinds of network connections, because the cheapest Internet of Things boards are WiFi-based. However, IoT is done on multiple kinds of network connections. This exercise explores how to program IoT connections in Bluetooth. Bluetooth is especially prevalent in wearable-based IoT. WiFi often requires a commercial provider to work, and isn't very mobile. Bluetooth can be established between devices without the need for a provider, and so is useful when a bunch of IoT devices must interoperate, and must travel together.

This exercise teaches the student how to establish a Bluetooth connection between two IoT devices and send messages across that connection. It requires Python to be available on both the Raspberry Pi (normally comes default) and on the other device (e.g., the student's PC).

Voice Recognition With The Raspberry Pi

The default language for the Raspberry Pi comes with some powerful tools, including voice recognition. This exercise demonstrates the use of voice recognition to turn an Arduino's light on and off.

Note the voice recognizing machine does not have to be a Pi. It can be a PC or other computer with an operating system hooked to a microphone.