Scripts for automating Raspberry Pi 4 configuration and MagicMirror² setup on Rpi for creating Smart Mirror touchscreen with face recognition.
I created these scripts since it took me quite a lot of effort to find a relevant documentation of what needs to be setup for complete solution. This is of course spread over many places on the web and includes many manual steps which is time-consuming and error prone. Since I like to keep my infrastructure and software configuration as a code in version control system I ended up with this repo.
This makes also re-installation much easier when you need to start from the scratch and hopefully makes it easier for getting started for new peeps.
This solution is based on fantastic and inspiring work from Eben Kouao which you can read more about at Smart Mirror Touchscreen (with FaceID) Tutorial – Raspberry Pi 4
- Touchscreen interaction (requires hardware, see below)
- Face recognition (requires hardware, see below) with personalised content
- Integration with home automation system Home Assistant, read more at ha_scripts
- MagicMirror² installation
- MagicMirror² module MMM-Face-Multi-User-Recognition-SMAI (forked) installation for multi-user face recognition and personalised content
- MagicMirror² module MMM-Face-Reco-DNN installation with required libs for face recognition with Open CV and Deep Neural Network
- MagicMirror² module MMM-SmartTouch installation for controlling MagicMirror² using a touchscreen
- MagicMirror² module MMM-Spotify installation for controlling Spotify (requires manual configuration after setup)
- MagicMirror² module MMM-GoogleTrafficTimes installation for displaying traffic time between locations (requires manual configuration after setup)
- PM2 installation for auto starting MagicMirror² on boot
- Rpi configuration
- Disable Screen Blanking to avoid screen going black when no interaction
- Setup WiFi (SSID and password)
- Enable Rpi Camera Module
- Enable SSH for easier management of Rpi from other machines
- Set timezone (default to Europe/Oslo)
- Set OS locale (default to Norwegian Bokmål)
- Set Keyboard layout (default to Norwegian)
- Disable boot splash screen at boot
- Set boot to Desktop and auto login
pi
-user
- Create bash aliases to make CLI commands easier in Rpi
- Install vim and xclip packages
I have only tested with following hardware, but it might work with your spec as well.
- Raspberry Pi 4 Model B, 4GB RAM
- Raspberry Pi 4 Power supply
- Raspberry Camera Module v2
- ICY Box including fan and heat sinks
- Micro HDMI cable
- ViewSonic 32" LED VX3276-2K-mhd
- IR Touch Screen, for example this
- Two-way mirror, for example Pilkington MirrorView
- Fresh installation of Raspberry Pi OS with Desktop (Buster or Bullseye) installed (tip: use Raspberry Pi Imager)
- You are logged in as default user
pi
in Rpi - Raspberry Pi Camera Module v2 connected
- Your Rpi is connected to the internet, either through WiFi or wired
- OpenWeather API key in order to use the default modules weather
Open Terminal in Rpi and execute these commands (might take a couple of minutes, be patient)
git clone https://github.com/ismarslomic/rpi4-smai-setup.git /home/pi/rpi4-smai-setup
cd /home/pi/rpi4-smai-setup
./setup.sh
The setup.sh script is suitable for initial setup on fresh Raspberry Pi OS and makes sure to run all necessary scripts (in sub-folders).
If you later want to do the adjustments you should avoid doing those directly in MagicMirror folder or in general on Rpi OS, but rather adjust existing scripts or add new one to make sure that all setup is automated and version controlled.
If you are new to face recognition (I was at least) I recommend that you spend some time learning about it from these two tutorials: Face recognition with OpenCV, Python, and deep learning and Raspberry Pi Face Recognition
With your MagicMirror running via PM2, you have some handy tools at hand:
pm2 restart mm
pm2 reload mm
pm2 stop mm
pm2 logs mm
pm2 monit
hostname -I
You can also just use the Rpi hostname raspberrypi.local
.
ssh pi@<IP address>
- During running
setup.sh
I see errors such asperl: warning: Setting locale failed.
andlocale: Cannot set XX to default locale: No such file or directory
. This will be fixed after reboot, don't worry! - I don't see current and forecast weather modules in Magic Mirror. Check your OpenWeather API key in
/home/pi/MagicMirror/config/config.js
file - MagicMirror doesn't automatically start after reboot. Open terminal, execute command
/home/pi/rpi4-smai-setup/pm2/pm2.sh
and reboot
sudo apt-get update
sudo apt-get upgrade -y
To get latest version of MagicMirror you should follow the Upgrade Guide and also read the Changelog.
cd ~/MagicMirror
git pull && npm install
For each module found in folder ~/MagicMirror/modules
do following:
cd ~/MagicMirror/modules/<module name>
git pull && npm install
The simplest way to change screen orientation is to use the Desktop:
Pi icon => Preferences => Screen configuration => Orientation => normal/right/inverted/left => Save
# Create bash script for setting the IR Frame orientation
vim /home/pi/xin.sh
# Add following content to the file
DISPLAY=:0.0 xinput --set-prop "Multi touch Multi touch overlay device" "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
# Make the file executable
chmod +x /home/pi/xin.sh
# To run the bash script automatically on startup
sudo vim /etc/xdg/lxsession/LXDE-pi/autostart
# Add following command, before @xscreensaver
@/usr/bin/bash /home/pi/xin.sh
@xscreensaver -no-splash