PiGlass v2 is a remake of an older project on the Adafruit Learning System. I made v1 back in 2018 and ran into a lot of performance issues, so I couldn't make it do everything I wanted it to.

When I heard that the Pi Zero 2 was coming out, I knew I had to try this again. My experience with v1 greatly assisted me in the process of making v2. I redesigned it completely and created new software.

The Pi is now located on the back strap of a hat. the audio hat has the exact output using a bone conduction transducer and the hat also has 2 mems microphones. I am using the same 5mp Zero spy cam in the same spot. There is an 8BitDo Bluetooth gamepad as the input device. The display is the same as before, a Vufine+ 720p HDMI display.

When assembled and setup, you can watch shows/movies/YouTube, play retro games, livestream, record videos and take different types of pictures. It takes longer to setup the software than it does to build one. At the heart of this project is a button on the audio hat which is at the back of the head. it does 2 things when pushed, it will either:

  1. Start the launcher program
  2. Kill any running programs

The launcher and camera related programs all use the gamepad for input. Kodi and Retropie use the gamepad as well and can be started from the launcher program. The commands are stored in a toml file that you can edit to customize what your PiGlass v2 does.

Angled shot of a Raspberry Pi Zero 2 W.
NOTE: Due to stock limitations we may only be able to offer refunds or store credit for Pis that are defective, damaged or lost in...
Angled shot of Zero Spy Camera for Raspberry Pi Zero connected to a ribbon cable.
Is your house haunted? Or, rather, are you convinced that your house is haunted but have never been able to prove it since you've never had a camera that integrated with your...
Raspberry Pi Zero FPC Camera Cable - 30cm long connected to a Pi zero and Pi camera
This 30cm long camera cable is specifically designed to work with the Raspberry Pi Zero series (including Zero W and Zero WH) Just...
Small Bone Conductor Transducer with Wires
Drown out the voices in your head with a bone conduction transducer! This incredible speaker does not have a moving cone like most speakers you've seen, instead, a small metal rod...
Mini Bluetooth Keyboard – Black colored
Sure, you have a keyboard. Maybe it's wireless. Maybe it's even Bluetooth. But do you have a mini Bluetooth keyboard? Like Halloween candy, this keyboard is...
1 x 40 pin header
header for pi zero
1 x Micro to Micro USB cable
used to power the display
1 x Vufine+
The heads up display
1 x Safety Glasses
glasses with strap
1 x Hat with plastic strap
hat for mounting pi zero
1 x 8Bitdo Zero 2 Gamepad
Bluetooth gamepad
1 x Waveshare WM8960
Audio hat
1 x 15 to 22 pin camera cable joiner
camera cable joiner
1 x Micro to Mini HDMI cable
display cable

Tools

Soldering Iron
Heat gun
Ruler
Scissors
Small flathead screwdriver
Xacto knife

Materials

4x 2.6mm wide - 6 inch long zip ties
2x paper clips (or other clips)
2mm heat shrink (1x 4" piece)
1/4 inch heat shrink (2x 1.25" pieces)
3/4 inch heat shrink (1x 1.25" piece)
Double sided adhesive

Note: You'll want to be careful handling certain parts of the build. The mechanically weak points of the hardware are:

  • The Pi Zero camera cable. The connection to the Pi can pull out when you try it on the first time, and
  • The bone conduction transducer. The heat shrink will move the point of failure from the transducer itself breaking to the wires popping out of the audio hat, which is an easy fix.

First thing: solder your 40 pin header onto your Pi Zero 2.

Bone conduction transducer mounting

Gather the following:

Safety glasses
Bone conduction transducer
1x 4" piece of 2mm heat shrink
2x 1.25" piece of 1/4 inch heat shrink
1x 1.25" piece of 3/4 inch heat shrink

Put the 4 inch piece of 2mm heat shrink on the transducer wires and move it close to the transducer without putting tension on the connections and use a heat gun to snug it up to the wires.

Put one of the 1/4" pieces on heat shrink over the right side of the glasses frame then use the heat gun. This layer will help the others stay in place.

Use the 3/4" heat shrink to attach the transducer to the frame. Place the transducer inside of the heat shrink and slide it onto the frame. The transducer should be oriented with the rectangle facing your head and the transducer on the same side of the frame as your head. This is what it's going to look like after you use the heat gun.

Take the last 1/4" piece of heat shrink and put it over the transducer wires and over the frame. You'll want to push it on the frame until it just reaches inside the 3/4" piece then shrink it with the heat gun.

When you are done, it should look like this. Don't forget to cut a hole on the outside of the frame for the head strap of the glasses, it doesn't have to be perfect, just make sure the strap fits on.

Assembly

Attach the audio hat to the transducer. A small flathead screwdriver will be needed. You will want to put some of the wire casing into the terminal so that it doesn't pull out easily, then attach the audio hat to the Pi.

Attach the camera to the camera cable adapter then zip tie the camera cable adapter to the Vufine. I have made two of these prototypes, one of the cameras had an adhesive backing and one did not, so you may or may not need a little double sided adhesive to mount the camera to the Vufine.

Attach the Vufine mount to the glasses as close to the hinge as possible. This picture shows the maximum distance you want to be from the hinge, closer is better.

Take the glasses under the hat and have the hat right side up. The Pi is mounted to the hat strap with 2 zip ties, the bottom of the Pi goes against the strap of the hat. Make sure it is centered before tightening them.

Take the camera cable and your choice of clips. I used 2 paperclips, but you can use whatever you like.

The camera cable is going to go into the Pi, then 2 clips evenly spaced from the Pi to the start of the brim of the hat.

Take the vufine and attach it to the mount from earlier.

Add a zip tie to secure the vufine to the frame.

You will have to bend your camera cable a little. The first bend is at the paperclip located near the brim, then bend it towards the front again. The cable will look like this.

Attach the camera cable to the camera cable adapter.

Finishing up

Turn the hat/glasses upside down. Attach the micro to micro USB cable and the micro to mini HDMI cable.

The last step is to attach the straps for the glasses, the straps are optional. The straps help with the bone conduction audio. With the straps on, the audio sounds like you have a headphone in your ear. Without the straps it is still pretty good, the sound quality doesn't change, the intensity does.

Flash your sd-card with 2021-05-07-raspios-buster-armhf.zip as this version has been tested with this hardware configuration.

Setup your WiFi connection preferences. My recommendations are you add your home network and your phone's hotspot. You should ssh in from some other device to do the installs, you will need a monitor later on to setup Kodi and RetroPie.

Enable Camera

sudo raspi-config

Install the audio hat driver

The Audio Hat Manual is here. The manual was missing a step, install rpi-source before following the steps, this will take a bit.

sudo apt update
sudo apt install rpi-source
git clone https://github.com/waveshare/WM8960-Audio-HAT
cd WM8960-Audio-HAT
sudo ./install.sh

Reboot.

Check that driver was installed:

cd WM8960-Audio-HAT
sudo dkms status

You should see
wm8960-soundcard, 1.0: added

Pair The Bluetooth Pro Controller then repeat the pairing steps for the keyboard.

bluetoothctl

Type scan on then
pair mac of 'Pro Controller'
trust mac of 'Pro Controller'
connect mac of 'Pro Controller'

Pro Controller UDev rules

sudo nano /etc/udev/rules.d/99-input.rules

Replace the file with:

KERNEL=="event*", SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="event*", ATTRS{name}=="Pro Controller", SYMLINK+="input/by-id/Gamepad"

Edit this file to allow the programs to have access to the xserver:

sudo nano /usr/share/dispsetup.sh

Add the next line above the last line and below the first:

Edit this file to change the default sound card to be the waveshare hat at index 1:

sudo nano /usr/share/alsa/alsa.conf

Look for these lines:
defaults.ctl.card 0
defaults.pcm.card 0
Replace with:

defaults.ctl.card 1
defaults.pcm.card 1

Edit this file to set the default display.

sudo nano /etc/environment

Add:

DISPLAY=:0

Install ttyecho:

git clone https://github.com/osospeed/ttyecho.git
cd ttyecho/
make
sudo make install

Add these lines to /boot/config.txt to set the framebuffer and overclock.

framebuffer_width=640
framebuffer_height=480
over_voltage=4
arm_freq=1300
core_freq=500

Remove the welcome to Raspberry Pi wizard:

sudo rm /etc/xdg/autostart/piwiz.desktop

Lightdm is disabled to save resources, it is not needed for Kodi, RetroPie or the programs.

sudo systemctl disable lightdm.service

The message of the day can be customized, you can make one or you can use mine.

sudo nano /etc/motd
______  _  _____ _                      ___  
|  __ \(_)/ ____| |                    |__ \ 
| |__)  _| |  __| | __ _ ___ ___  __   __ ) |
|  ___/| | | |_ | |/ _` / __/ __| \ \ / // / 
| |    | | |__| | | (_| \__ \__ \  \ V // /_ 
|_|    |_|\_____|_|\__,_|___/___/   \_/|____|
                                                     
Made with love by Matt the Maker

Install Python libraries, this will take a bit:

sudo apt install vlc python3-evdev python3-alsaaudio python3-vlc python3-opencv python3-toml fbi

Clone PiGlass v2 Repo:

git clone https://github.com/matt-desmarais/PiGlassv2.git

Copy service file to the system location and enable:

sudo cp /home/pi/PiGlassv2/button.service /etc/systemd/system/
sudo systemctl enable button.service

The bumpers are volume up/down.
The dpad with up/down will cycle options.
Select will launch the currently selected option.
Press Y to toggle rainbow mode.

Everything the launcher does is controlled by a file called piglasscmds.toml.

The working directory is /home/pi/PiGlassv2.

The format of the launcher's file is:
[Title]        The name of the option you want to display.
color         The color for this item for rainbow mode.
cmd          The command you want to run/shell script/program.
process    The processes to kill related to the command.

[Kodi]
color = "red"
cmd = "sudo ttyecho -n /dev/tty1 kodi"
process = "kodi.bin_v7"

[RetroPie]
color = "green"
cmd = "sudo ttyecho -n /dev/tty1 emulationstation"
process = "retroarch emulationstatio"

["Funny Camera"]
color = "purple"
cmd = "python3 funnycamera.py"
process = "python3"

["Video w/Audio"]
color = "brown"
cmd = "sh videosound.sh"
process = "raspivid ffmpeg"

You can test a command before you add it by using this command followed by yours, if your command is more than one word (has spaces) make sure to put it in quotes

sudo ttyecho -n /dev/tty1 "sudo apt update"

You can play retro games with RetroPie. I have NES and SNES installed and have hundreds of games for them.

After installing RetroPie, you will need to put games into the proper folders in order to play them. Some games load with a black border around the game, you can press the Vufine's button to change the display mode, which will make the game take up the whole display

Mario

RetroPie Manual Install: RetroPie Install Instructions

git clone --depth=1 https://github.com/RetroPie/RetroPie-Setup.git
sudo apt install libegl1-mesa-dev libegl-mesa0 libgbm1 libudev-dev libxkbcommon-dev libsdl2-dev libusb-1.0-0-dev libx11-xcb-dev libgbm-dev libavcodec-dev libavformat-dev libavdevice-dev
cd RetroPie-Setup
chmod +x retropie_setup.sh
sudo ./retropie_setup.sh

Manage packages
Install core packages

Manage main packages
Install SNES (snes9x) NES (nestopia)

You should hook your Pi up to a monitor to setup RetroPie.

Run Emulationstation

emulationstation

Setup controller: Controller Configuration
When you get to the welcome screen, hold a button to start the controller configuration process.

Transfer roms: Transferring Roms
You will need to put the ROMs for the consoles you installed into the proper folders. It is out of the scope of this tutorial on obtaining game ROMs.

If you have any questions, I suggest looking at the RetroPie Docs.

Kodi is a free and open source media player application developed by the Kodi Foundation. It can be used to view all of the images and videos (including launcher footage) recorded by PiGlass, make sure to add /home/pi/Pictures as a picture source and /home/pi/Videos as a video source.

You can install any add-ons that you want. I have YouTube and Netflix, but there are many others available. You can also install the Kore app (Android, iOS) on your smartphone and control Kodi from that.

You should hook your Pi up to a monitor to setup the add-ons you want.

cd RetroPie-Setup
sudo ./retropie_setup.sh

Manage packages
Manage opt packages

Install Kodi #166

Run Kodi:

Because the the controller was setup with RetroPie, the controller will just work when Kodi is installed through RetroPie.

The Vufine has one button. You hold it to turn it on/off. When the Vufine is on, if you press the button it changes the viewing mode. It has 3 modes. If you aren't in the fullscreen mode, then when Kodi loads you will get a black screen, press the button on the Vufine until you can see Kodi.

The Camera program can take pictures/record silent video, Pictures are copied to /home/pi/Pictures, Videos are copied to /home/pi/Videos.

The bumpers are zoom in/out
The dpad will pan up/down/left/right while zoomed
Hold X button: take picture
Hold A button: record silent video
Hold X button: reset zoom

No Zoom

Halfway Zoomed

Fully Zoomed

This camera program called “funny camera” uses OpenCV to overlay images on detected faces. It is also fed by a toml file to make it easy to add your own images and put them where you want on peoples faces.

To add more, you have to upload the .png to the PiGlassv2 directory and add an entry in piglass.toml. When you take a picture and faces are detected, the funny image gets generated and then displayed to the wearer for 4 seconds.

The bumpers are zoom in/out
The dpad will cycle the overlay options with up/down
The dpad left/right will pan left/right when zoomed
Hold X button: take a picture
Hold B button: take funny picture
Hold A button: take random funny picture

Hold Y button: reset zoom

The format of the toml file is:
[Title]               is the name you want to display for this option
display_name is what you would call the item as a plural.
file                   is the name of the .png file you want to overlay
location           is a word representing the general location of the image on the face

Locations include: 
top, center, bottom, top-left, top-right, center-left, center-right, bottom-left, bottom-right

There is also a location called face which is scaled differently to replace a face versus fit on it.

[brainslug]
display_name = "Slugs"
file = "mask2.png"
location = "top-right"
["brain blender"]
display_name = "Blenders"
file = "mask4.png"
location = "top"
["dum sticker"]
display_name = "Dum"
file = "maskdum.png"
location = "center-right"

This video shows the options and what happens when you select one when no faces are found.

There are two commands involved in live streaming: raspivid and ffmpeg. The streams are 720p 25fps 44kb stereo audio, streams are silent for the first 6 seconds

raspivid --timeout 0 --width 1280 --height 720 --rotation 270 --profile high --level 4.1 --bitrate 2250000 --framerate 25.375 --intra 90 --annotate 4 --annotate 8 --output - | ffmpeg -i - -f alsa -channels 2 -sample_rate 22050 -itsoffset 6 -i hw:1 -c:v copy -af "volume=8.0,aresample=async=1" -c:a aac -b:a 48k -map 0:v -map 1:a  -f flv rtmp://URL and KEY go here

YouTube rtmp:// segment, located in youtube.sh

rtmp://a.rtmp.youtube.com/live2/KEY goes here

Add YouTube streaming as an option by editing piglasscmds.toml.

["YouTube Stream"]
color = "orange"
cmd = "sh youtube.sh"
process = "raspivid ffmpeg"

Facebook rtmps:// segment, located in facebook.sh:

rtmps://live-api-s.facebook.com:443/rtmp/Key goes here

Add Facebook streaming as an option by editing piglasscmds.toml:

["Facebook Stream"]
color = "orange"
cmd = "sh facebook.sh"
process = "raspivid ffmpeg"

Twitch rtmp:// segment, located in twitch.sh:

rtmp://live.twitch.tv/app/Key goes here

Add Twitch streaming as an option by editing piglasscmds.toml:

["Twitch Stream"]
color = "orange"
cmd = "sh twitch.sh"
process = "raspivid ffmpeg"

I also setup my own rtmp server and page to view the stream using a VPS.

This part sets up the streaming to the server: Nginx RTMP Streaming setup.

This part is used to make a page that your stream can be viewed from Dash JS.

I am working on voice commands using hotwords and offline sentence recognition. I have had success using the program spchcat. It does offline sentence recognition. I still need to find a way to do hotwords. Hotwords would trigger commands or start spchcat. I want to be able to trigger Picture screenshot combo feature from v1 with a hotword.

I am working on a program called pet camera which like the funny picture program will overlay images on pets faces.

If you make your own PiGlass and make it do something new please tell me about it on GitHub.

This guide was first published on Apr 05, 2022. It was last updated on 2022-04-05 19:10:28 -0400.