Taking The Raspberry Pi Further

Programming on the Raspberry Pi is one of my favorite activities, but I understand that not everyone is as passionate about code as I am. There are many different directions you can take with the Raspberry Pi that have nothing to do with code. This section is full of projects, solutions, and resources to use the Raspberry Pi in creative ways.

Projects

Raspberry Pirate Radio

Have you ever wanted to run your own radio station? You can turn your Raspberry Pi into an FM radio transmitter using one wire and a Python script.

Notice: If the project was left running in the United States, the FCC could track you down for using improper signals. The problem is that depending on the frequency you use, you could be interfering with frequencies used by emergency services. The reason for this is the makeshift antenna and program sends out block shaped radio waves instead of sine waves. This spills over to other frequencies unintended by the program.

http://www.instructables.com/id/Raspberry-Pirate-Radio/

http://makezine.com/projects/raspberry-pirate-radio/

http://lifehacker.com/start-a-pirate-radio-station-with-a-raspberry-pi-and-a-1538837219

http://myhowtosandprojects.blogspot.com/2014/04/raspberry-pi-make-your-own-pirate-radio.html

Build a robot

If you can power a light with GPIO pins, you can just as easily connect it to a motor. Add more motors and you have a robot.

http://diyhacking.com/raspberry-pi-robot/

Book - Make a Raspberry Pi-Controlled Robot: Building a Rover with Python, Linux, Motors, and Sensors By Wolfram Donat

Create your own web server

What better way to learn web design than creating your own web server? You can turn a Raspberry Pi into an entire web stack. ‘‘LAMP’’ stacks are very popular among the industry (GNU/Linux + Apache + MySQL + PHP). I prefer using smaller programs to accomplish nearly the same thing. I use GNU/Linux + Nginx + SQLite

  • PHP (LNSP) when using a web stack on the Raspberry Pi. These can also interact with Python.

https://wiki.archlinux.org/index.php/Nginx

Create your own Baby Monitor

Most of the “smart” baby monitors on the market are always on devices connected to the Internet that you do not control. I built my own with PiCam. It can record to a file or stream on your local area network (LAN).

# If you have not enabled camera, enable it with raspi-config then reboot
sudo raspi-config

# Install dependencies
sudo apt-get update
sudo apt-get install -y libharfbuzz0b
sudo apt-get install -y libfontconfig1

# Create directories and symbolic links
cat > make_dirs.sh <<'EOF'
DEST_DIR=~/picam
SHM_DIR=/run/shm
mkdir -p $SHM_DIR/rec
mkdir -p $SHM_DIR/hooks
mkdir -p $SHM_DIR/state
mkdir -p $DEST_DIR/archive
ln -sfn $DEST_DIR/archive $SHM_DIR/rec/archive
ln -sfn $SHM_DIR/rec $DEST_DIR/rec
ln -sfn $SHM_DIR/hooks $DEST_DIR/hooks
ln -sfn $SHM_DIR/state $DEST_DIR/state
EOF
chmod +x make_dirs.sh
./make_dirs.sh

# Optionally, increase microphone volume with alsamixer
#alsamixer

# Install picam binary
wget https://github.com/iizukanao/picam/releases/download/v1.4.6/picam-1.4.6-binary.tar.xz
tar xvf picam-1.4.6-binary.tar.xz
cp picam-1.4.6-binary/picam ~/picam/

# Run picam
#cd ~/picam
#./picam --alsadev hw:1,0

# Install nginx
sudo apt-get install -y nginx

# Edit nginx configuration
echo "Within the server { ... } block add these lines:"
echo "	location /hls/ {"
echo "		root /run/shm;"
echo "	}"

#	location /hls/ {
#		root /run/shm;
#	}
sudo nano /etc/nginx/sites-available/default

# Set Picam to start automatically
echo "Before exit 0, add this line:
echo "/home/pi/picam-1.4.6-binary/picam -o /run/shm/hls --alsadev hw:1,0"

# /home/pi/picam-1.4.6-binary/picam -o /run/shm/hls --alsadev hw:1,0

sudo nano /etc/rc.local

echo "Find your local IP address."
ip a

sudo reboot

On another machine, test your stream.

VLC can open video streams. Kodi can open streams with the surveillance camera add-on.

My address was: http://192.168.1.208/hls/index.m3u8

https://github.com/iizukanao/picam

Universal Translator

This project allows you to convert speech from one spoken language to another. Record audio of talking, convert the audio to text, translate the text to another language, and have it read back to you in another language.

http://www.daveconroy.com/turn-raspberry-pi-translator-speech-recognition-playback-60-languages/

https://github.com/dconroy/PiTranslate

Connect Raspberry Pis to automate your home

The ‘‘Internet of Things’’ (IoT) is a way to connect everything together through the Internet. Purchasing IoT devices and appliances can be COSTLY unless you do it yourself. A single board computer and a little bit of Python knowledge can start you on the path to creating your own IoT devices. Slap a Raspberry Pi onto a garage door, program it to listen for your phone to connect to the network, and you have an automated garage door. There are unlimited possibilities now with single board computers.

http://www.informationweek.com/software/enterprise-applications/10-raspberry-pi-projects-for-learning-iot/d/d-id/1320757

https://www.raspberrypi.org/blog/tag/internet-of-things/

Build your own camera

The Raspberry Pi foundation has designed two camera modules that can be easily connected to the Raspberry Pi. They are the camera and the infrared modules.

RPi Camera Module

RPi Infrared Camera Module

RPi Camera help

  • Emulating a Raspberry Pi on your Computer with QEMU and Windows

Emulating a Raspberry Pi on your Computer with QEMU and Windows

I confirm that it works and covers all pitfalls. It feels very slow to use because it is limited by 256mb of allocated RAM. The advantage of emulating the Pi on a computer is that the img file can be modified directly. A custom img with updated software and all of your programs can then be copied to your SD card.

Build a Retro Game system

The RetroPie project aims to turn a Raspberry Pi into a game system. It includes an interface called emulationstation and can emulate many of the game consoles from 1977 to 1998.

To install RetroPie on top of default Raspbian run these commands:

sudo apt-get update
    
git clone git://github.com/petrockblog/RetroPie-Setup
    
cd RetroPie-Setup
    
sudo ./setup.sh

or download setup.sh

The games will need to be copied into the appropriate folder before the console will appear in the menu. Logout to the terminal and run this command:

emulationstation

A popular alternative to this project is to build a RetroPie into a handheld case using 3D printed cases and a tiny screen.

Official RetroPie Website

3D printing project for a GameBoy style case

Micro Arcade Cabinet

Build your own ‘‘cloud’’ server

The term cloud has been confusing the majority of computer users since its creation. It simply means you are putting your private data on someone else’s server. Since you cannot verify that their interests are in your best interest, the majority of cloud based services cannot be trusted. You could build your own cloud! I will suggest Freedom Box. It acts as a cloud and more.

FreedomBox Foundation

Talk with all of your friends at once

You can run a server on your Raspberry Pi called mumble that will allow your friends to all connect and talk to each other at once.

Mumble Server forum post

Design your own case

If you have access to a 3D printer or some spare legos, you can make your own cases. You can use any 3D modeling software to design your own 3D shapes to protect your Raspberry Pi. Here are some examples of cases that others have made:

8 Interesting DIY RPi Case Ideas

Thingiverse 3D models Raspberry Pi Results

Try a program out in space

The AstroPi project put some Raspberry Pi computers on the International Space Station. You can build a duplicated device using a 3D printer, a Raspberry Pi, and a Sense Hat. There are programming competitions regularly that you can enter. Your Python experiment can be carried out in space. The Raspberry Pis in space even have their own twitter accounts that you can browse.

https://astro-pi.org/

https://www.raspberrypi.org/blog/astro-pi/

https://twitter.com/astro_pi_ir

https://twitter.com/astro_pi_vis

https://vimeo.com/157627149

Control your stereo over wifi

How cool would it be to use your phone to control the stereo? You can do that with the Raspberry Pi. Put all of your music on a storage device. Connect your music collection to your Pi. Install and configure mpd (Music Player Daemon) on your Pi. Connect your Pi to the stereo. Connect your phone to your Pi through an MPD app such as MPoD or MPDroid.

# Update software repositories, remove unnecessary software, and install mpd.

sudo apt-get update

sudo apt-get remove -y pulseaudio wolfram-engine wolframscript scratch # Removing pulseaudio fixes the volume control problem.  Removing wolfram and scratch speeds up upgrade time.

sudo apt-get upgrade -y

sudo apt-get install -y mpd mpc

# Change ownership of mpd folders to user mpd and group audio.

sudo chown mpd:audio -R /var/lib/mpd

sudo chown mpd:audio -R /var/log/mpd

# Change the settings for mpd.

sudo nano /etc/mpd.conf

# Add a drive formatted with ext4 containing music files.

# Symlink the music drive to the mpd directory.

sudo ln -s /mnt/music1/Audio /var/lib/mpd/music/

# Change the ownership properties of the mounted drive.

sudo chown mpd:audio -R /mnt/music1

# Restart mpd

sudo service mpd restart

# Update mpd database

mpc update --wait

# Check the progress of the database or look for errors.

tail -n 30 /var/log/mpd/mpd.log

http://elinux.org/Rpi_Music_Player_Daemon

Build a media center

Kodi is a powerful media center that can be installed on your Raspberry Pi. You can view your video files from a hard drive or stream files from the web. I have had the most success with OSMC which can be installed directly from NOOBS with an Internet connection.

OSMC

Build your own tablet

The Raspberry Pi has released a 7 inch touch screen. Connect the cables to the Pi, add power, and you have a tablet.

https://www.raspberrypi.org/products/raspberry-pi-touch-display/

Virtual Network Computing (VNC)

VNC can be used with nearly all computer systems including GNU/Linux, iOS, Mac, and Windows. It is a way to share control of a computer across a network or the Internet. Today, it is most commonly used for tech support from remote sites. VNC software can be installed with these commands:

sudo apt-get install tightvncserver xtightvncviewer

A VNC server can be started with this command:

vncserver :1 -geometry 1920x1080 -depth 24

Other computers or phones on your network can connect to your Raspberry Pi with the proper credentials using your local IP address. IPv4 addresses are four sets of numbers separated by periods. An example of an IP address is 192.168.1.58. Your local IP address can be found using the command:

ifconfig | grep inet

https://www.raspberrypi.org/documentation/remote-access/vnc/

Build a surveillance system

Build your own motion detection cameras and have them email you when someone walks near your car. Create a camera that emails you a picture of your desk every hour. The possibilities are endless.

What should I wear today?

Create a system to check the temperature and humidity outside. Based on that information, the Raspberry Pi could email you what you should wear to stay warm throughout the year.

Create interactive installation art

Many artists have included Raspberry Pis into their work. One of the most tranquil of such projects is called ‘‘Lichen Ohms Seriatim’’ located in Cambridge, United Kingdom. Participants carry around a Raspberry Pi with a screen, bluetooth adapter, headphones, and a battery in a clear plastic container. The sounds change as they approach bluetooth beacons referred to as ‘‘lichens.’’ This creates an immersive audio/video experience.

https://www.raspberrypi.org/blog/lichen-beacons/

http://www.ludions.com/projects/lichens/

Build a supercomputer

You can create a beowulf system by connecting a bunch of computers together using network cables, GNU/Linux, and software to make them act as one.

http://www.zdnet.com/article/build-your-own-supercomputer-out-of-raspberry-pi-boards/

33 Raspberry Pi Cluster

64 Raspberry Pi Cluster

GCHQ’s 66 Raspberry Pi Cluster

Pi Zero OTG Cluster

Dramble is a 5 RPi Drupal cluster that can be used to teach ansible.

Participate with an open source project

Another great way to get more experience is to find a python script on github, make a github account, and fork the project. To fork a project, you can take someone else’s program, make changes, and make it your own; or you can make a change, and submit the change back to the original project. Even changing a simple grammar mistake is a great first move.

Problems and Solutions That Worked for Me

This section is not a comprehensive troubleshooter for a Raspberry Pi, but it gives some examples of the problem solving skills that will be beneficial to your journey into microcomputers. When I bought my model B, a lot of problems had not been worked out. Compromises, workarounds, and hacks had to be implemented to accomplish some goals. Many of these problems have been solved with the new line of Raspberry Pis including the A+, B+, 2 B, Zero, and 3 B.

No monitor

If you have a Raspberry Pi and do not have a monitor there is a way! Maybe you went on vacation and could not fit a monitor in your luggage. Maybe you ordered some cables and are waiting for them to arrive. Maybe you are working on a project that will never use a traditional monitor. Do not fear! There is a way!

I am using a Debian based GNU/Linux machine for this section. If you are using another operating system, the process will be different.

I flashed the Raspberry Pi OS onto a MicroSD card for the RPi. My sd card is sdc. Your device might be different.

dd if=2021-03-04-raspios-buster-armhf.img of=/dev/sdc bs=4096 status=progress

I need to add wireless info and enabled ssh before first boot.

Mount the boot/ partition. My device is sdc.

sudo mount /dev/sdc1 /mnt

Add a blank file titled ssh to enable ssh.

sudo touch /mnt/ssh

Build an encrypted wpa_supplicant file. Replace Netgear with your network name.

wpa_passphrase Netgear

Enter the network password and press the Enter key.

The wpa_supplicant with encryption will appear. Copy the contents into your wpa_supplicant.conf file and place it in the boot/ directory of the mounted Raspberry Pi disk. Remove the commented out line that includes the unencrypted password.

sudo nano /mnt/boot/wpa_supplicant.conf

Unmount boot/.

sudo umount /mnt

Sync.

sync

Eject.

sudo eject /dev/sdc

Place the sd card into the RPi.

Scan the network before plugging the Raspberry Pi in. For this step, I am using nmap. Replace 192.168.0.0 with your local IP address. Replace the number after the last period . with 0.

nmap -sn 192.168.0.0/24

Scan again a few minutes after plugging in the RPi.

nmap -sn 192.168.0.0/24

Note: If you do not have a laptop with GNU/Linux, you can scan the network with your phone. If you have administrator access to the router, you can also use the admin interface to look for differences in connected devices.

The difference is your RPi’s local IP address. Connect to it using ssh. Replace 192.168.0.??? with the IP address of the Raspberry Pi.

Note: If you do not have GNU/Linux, you can use ConnectBot from F-Droid on Android based mobile devices.

Default password is raspberry.

Change the password.

passwd

Now, you can do just about any command line work with the Raspberry Pi without a monitor.

Low resolution video

This happens with kids ofen. The quick solution is to reboot. Click on the menu in the top left > Logout > Reboot.

This happens when you first plug in the Raspberry Pi with the power before the HDMI. If you change the order of operations to HDMI and then power, the boot process will automatically identify the video source and give provide optimal resolution.

Wireless Drivers

Wireless adapters do not always work. This is because the hardware manufacturer has closed source, proprietary drivers. Some brands work very well and others require extra work to use them. After doing too much of the extra work, I always look up the chipset of compatible wireless cards BEFORE I buy a new one. Atheros chipsets are nearly always compatible. The packaging rarely says the name of the chipset so you always have to look it up.

Peripheral power / Powered USB Hub

The B has two USB ports. I need to plug in a keyboard, a mouse, and a wifi adapter. I could plug in the keyboard and mouse at the same time and use it perfectly with a wired ethernet connection. I could unplug the keyboard, plug in the wifi, search for networks. To enter in a password, I would have to unplug the mouse, plug the keyboard in, type the password, and then plug in the mouse. Just after I got a valid IP address, the wifi adpater would lose power. It would start up again, connect, and lose power. This loop would continue until I unplugged it. I ordered a powered USB hub off amazon. Once that arrived, I could plug in a keyboard, mouse, wifi adapter, and two storage devices. The best part about the powered USB hub is that you can power the Raspberry Pi with a MicroUSB to USB cable. The drawback after this is that I was using much more power then before. I was very surprised when I tried the B+ with four USB slots. On the B+, I plugged in keyboard, mouse, and wifi directly in and it worked perfectly.

Corrupted SD Cards

The operating system traditionally uses either a SD card or a microSD card. The firmware of the first production run ruined many SD cards. The firmware can be updated and it eventually got better. I had been running various GNU/Linux operating systems off of 16GB flash drives for many years at this point. After corrupting the same SD card many times, I gave up on the SD card. I had to use it to boot from, but I did not have to run the system off of it. Default Raspbian has two partitions in its .img file. One is a boot and the other is the root. I modified the boot configuration to boot from /dev/sdb2 instead of /dev/sda2. I then used dd to copy the Raspbian img to a flash drive. That one still works.

Audio pops

One of the projects I made turned my Raspberry Pi model B into an mp3 player for my hi-fi stereo. I could control it with my iPhone over the network. Everything talked perfectly together. The only problem I had was that there would be a loud pop between each track. Not only is this annoying, but it could damage my speakers. The problem was well known on the Internet and by the developers. The problem was that the power would turn off when not in use and then turn back on. The power could not be left on using ALSA the default audio interface on Raspbian. I solved this problem by installing PulseAudio. I configured pulse to remain always on. This solved my problem. The Raspberry Pi B+ and 2 B fixed this problem.

No HDMI Video Output

I did a programming workshop using my model B. I introduced what we were doing on a TV with the Pi. Later that day, I took it back out and I could not get any output from the HDMI. After troubleshooting a few things, it went back in the bag. I later give it to my tech team to try to solve the problem. They researched ways to troubleshoot the HDMI, they took off the case, and got it to work. This was reproducible. That official case has since been replaced with legos.

No hardware clock

Desktop computers typically have a coin sized battery attached to the motherboard to keep the clock running on the BIOS. When the Rapsberry Pi gets turned off, it loses track of time. When connected to the Internet, this should not matter as it will get the correct time from a server. For offline projects, you must keep this in mind if your program uses specified times. As a work around, I boot up the system, set the time manually, reboot, and then the clock is correct. An example of this code is:

sudo date -s "14 APR 2053 15:34:00"

Language defaults

When installing from NOOBS and even if the language is correctly set at the bottom, sometimes the language and keyboard is still incorrect with Raspbian. There is a GUI tool that can help configure this at the Raspberry Pi menu > Preferences > Raspberry Pi Configuration > Localisation. I use Set Locale, Set Timezone, and Set Keyboard in that menu.

To check localization settings, open a terminal and run this command:

locale

If settings are not correct, you can run this command (my preferences are English United States UTF-8):

sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

journalctl reads a problem with mtp-probe

journalctl -xb -p 5 reads systemd-udevd[208]: failed to execute '/lib/udev/mtp-probe' 'mtp-probe /sys/devices/platform/soc/

Install libmtp-runtime.

sudo apt install -y libmtp-runtime

From by The Good Doctor at https://crunchbang.org/forums/viewtopic.php?id=25200

Raspberry Pi Giveaway

During a live presentation of this content, I like to give away a Raspberry Pi setup.

We will pick an almost random number using Python. Everyone gets a number 0 through n minus 1. n being the total number of people present. n-1 because 0 is a number.

Make a text file.

nano rpidrawing.py

Add this text to the file and modify as necessary.

from random import randrange

n = 30 # Total number of participants

print(randrange(0, int(n)))

Run the script.

python3 rpidrawing.py

The winner gets a Raspberry Pi!

If you did not win, you can buy the one I did this presentation with at cost.

Encode QR Code

We can encode a QR code offline on the Raspberry Pi using qrencode.

To install qrencode on the pi run this command:

sudo apt-get update && sudo apt-get install -y qrencode

We will encode a QR code of this website to a PNG and then display the QR code with these two commands:

qrencode -o qrcode.png 'https://github.com/TechnologyClassroom/RaspberryPiProgrammingWorkshop'

feh -F qrcode.png 

For more ideas on using qrencode, check out this Linux Magazine link.


Licenses and Attributions


Speak Your Mind

-->