In this article, the wizard will tell us how to make a “smart mirror”. A smart mirror is a device with a mirrored surface behind which the monitor is located. The monitor is located close to the mirror surface and all the data that is displayed on it (weather, news, mail, etc.) are visible through a special mirror.
This mirror has two more functions – voice control and wireless charging of devices.
Tools and materials:
– 15.6-inch LCD panel;
– 40-pin display control board;
-Raspberry Pi 3;
-USB-microphone; -Speaker with AUX; -LEDs; -Stencil sheets; -Wire;
-DC 12 power adapter;
-DC power splitter; -Voltage regulator; -Wireless charger;
-Magnets; -HDMI cable; -Laser cutter; -3D-printer; -Caliper;
-Rule; < br>-Glue gun;
Step one: Raspberry Pi setup – VNC software
Assumes user has a Raspbian operating system formatted with Raspberry Pi, and the computer is ready to go.
1: Boot the Raspberry Pi and open a terminal
Click the terminal icon on the top bar of the application to open a terminal window.
2: Install VNC on your Raspberry Pi
Enter the following command in a terminal to install RealVNC on your Raspberry Pi.
sudo apt-get install realvnc-vnc-viewer
3. Open the Raspberry Pi configurator to enable VNC.
Enter the following command in a terminal to open the settings.
Then go to “ Communication Options “and” Enable “the” VNC “option. Click “Apply” to return to the terminal panel.
4. Reboot your Raspberry Pi.
Enter the following command to reboot your Raspberry Pi for the changes to take effect.
5. Install VNC on your computer
Now on your personal laptop/computer (not your Raspberry Pi) go to the RealVNC website to download the “VNC Viewer” for your operating system (works on almost any OS including Mac, Windows and Linux ).
Complete the installation process and create an account when prompted (alternatively, you can use VNC as a guest).
6: Go back to your Raspberry Pi. Once downloaded, go to the top bar and click on the “VNC” icon, which should now be activated. Click on it to view your IP address and password.
On your laptop or computer, enter this information to connect to your Raspberry Pi remotely. If everything went right, the user will be able to see the Raspberry Pi and control it using a personal computer.
Step Two: Configuring the Raspberry Pi – Magic Mirror Software
1: Open a Terminal on the Raspberry Pi
The first thing we need to do is install a package called “npm” that will help download the Magic Mirror program.
sudo apt-get install npm
2: Use the Sdetweil script to download and install Magic Mirror
& lt; pre & gt; bash -c & # 34; $ (curl -sL & lt; a href = & # 34; https & # 58; //raw.githubusercontent.com/sdetweil/MagicMirror_scripts/master/raspberry.sh" rel = & # 34; nofollow & # 34; & gt; & lt; a href = & # 34; https & # 58; //raw.githubusercontent.com/sdetweil/MagicM..."> https & # 58; //raw.githubusercontent.com/sdetweil/MagicM...>>)"
3: Then you need to configure some things on the Raspberry Pi to make it work as a Smart Mirror. We need to turn off sleep mode, otherwise Smart Mirror will keep turning off. You also need to make sure the Magic Mirror software automatically starts every time you boot your Raspberry Pi.
To disable the splash screen, run the script:
& lt; pre & gt; bash -c & # 34; $ (curl -sL & lt; a href = & # 34; https & # 58; //raw.githubusercontent.com/sdetweil/MagicMirror_scripts/master/screensaveroff.sh" rel = & # 34; nofollow & # 34; & gt; & lt; a href = & # 34; https & # 58; //raw.githubusercontent.com/sdetweil/MagicM..."> https & # 58; //raw.githubusercontent.com/sdetweil/MagicM...> & gt;) & # 34;
To set the program to start automatically, run the following:
bash -c & # 34; $ (curl -sL & lt; a href = & # 34; https & # 58; //raw.githubusercontent.com/sdetweil/MagicM ... & # 34; rel = & # 34; nofollow & # 34; & gt; & lt; a href = & # 34; https & # 58; //raw.githubusercontent.com/sdetweil/MagicM...< ;/a & # 34; & gt; https & # 58; //raw.githubusercontent.com/sdetweil/MagicM...>>
4: By now, Magic Mirror should have already loaded and the user should see a window similar to the Smart Mirror user interface. If this window does not appear, run this code:
pm2 start Magic Mirror
5: Configuring Magic Mirror
Next, you need to customize the widgets. To do this, you need to create an account on OpenWeatherMap (it's free and fast). By registering, Magic Mirror software can take advantage of the OpenWeatherMap API, which is required to obtain weather data. After you create your account on the home page, go to the API Keys tab. Create or rename an API key as needed (it looks like a long string of alphanumeric characters). Copy your API key.
Then on your Raspberry Pi, open the Files app, navigate to the MagicMirror folder (which loads into the/home/pi directory), click the config folder, and finally double-click the config button. config.js is a text file. The user should see a list of modules that are currently running on Magic Mirror. You can edit this folder to change widgets, widget layout, etc. For now, let's move on to the module called “currentweather”.
Where it says: 'appid: “YOUR API KEY HERE”', paste the API key you copied earlier. Two lines above, there is a city indication “location: New York”. You need to edit the field and enter the city in which you live. Finally, you need to edit the 'LocationID. Each city has a unique identifier that tells OpenWeatherMap which city to display Weather Commented out right next to this line of code, you should see a URL where you can download a complete list of cities and their respective codes.
Then you need to customize the messages. This can be done by going back to the “home/pi/MagicMirror/modules/default/compliments” folder via the file manager. Open the .json file and now you can change the lists you see to display whatever message you want, depending on the time of day. Make sure you add/edit strings using the same format you see, such as “quotes” and commas separating each unique message.
6: Magic Mirror Add-ons
Many Magic Widgets can be added in this configuration step Mirror. From tracking FedEx shipments to watching live broadcasts of Earth from space, there are widgets for just about everything.
Here is a complete list of modules for Magic Mirror, as well as documentation on what they are and how to install them. For demonstration, the wizard installs the “MMM-Screencast” widget. This widget allows any device connected to the same internet network as Smart Mirror to stream Youtube videos directly to the Mirror.
To install the widget, first open a terminal on your Raspberry Pi and navigate to the MagicMirror/modules directory (stored here all modules). You need to go here so that when you download “MMM-Screencast” it is automatically saved in the correct place. To change directories, enter the command cd:
cd/MagicMirror/modules & lt; br & gt;
Then clone the MMM-Screencast module from GitHub:
git clone & lt; a href = & # 34 ; https & # 58; //github.com/kevinatown/MMM-Screencast.git" rel = & # 34; nofollow & # 34; & gt; & lt; a href = & # 34; https & # 58; //github.com/kevinatown/MMM-Screencast.git<..."> https & # 58; //github.com/kevinatown/MMM-Screencast.git<...>><br>
After successful installation, enter the module “MMM-Screencast “Using the” cd “command again:
cd MMM-Screencast & lt; br & gt;
Now install the dependencies (other tools/packages required to run this module):
npm install < br> In the modules section, add the following code immediately after the line of code that says "modules: ["
& lt; pre & gt; & # 123; module & # 58; & # 39; MMM-Screencast & # 39 ;, position & # 58; & # 39; bottom_right & # 39 ;, config & # 58; & # 123; position & # 58; & # 39; bottomRight & # 39 ;, height & # 58; 500, width & # 58; 800, castName & # 58; & # 39; ANYTHING YOU WANT & # 39;},
Note that there is a comma at the end of the parenthesis. All modules in the modules section of the config.js file must be separated by commas. It is important that the above code is inserted immediately after "modules: [" because this ensures that it is the first module in the list.
The castName parameter: Shows how Smart Mirror looks to other devices when they want to stream YouTube videos to it. You can change it.
Next save this file and reboot your Raspberry Pi by running the code below in a terminal:
Test the Screencast module by clicking the broadcast button in the YouTube app on your mobile device.
In the "Configure Magic Mirror" step, you may have problems getting the location ID. But there is a simple solution.
First go to OpenWeatherMap. There is a search bar in the upper left corner of the site, find the city in which you live and click on it. You will be redirected to a page with the current weather for that city, and the URL "shortcut" is your location ID. For example, the weather page for San Francisco, California is at https://openweathermap.org/city/5391959.'and 5391959 is its locationID.
Step Three: Configuring Raspberry Pi - Google Assistant Software
Next in this project, the wizard is going to integrate Google Voice Assistant into Smart Mirror. Using a Raspberry Pi, USB microphone and speaker, this Google Assistant will run in parallel with Magic Mirror. The result is a smart mirror that you can ask questions by saying "Hey Google.".
1. Create a new project on Google Cloud Platform
On your Raspberry Pi, you need to set up a Google Cloud Platform account to integrate Google Assistant into your project.
Follow this link to create an account and start a new project.
Now go to APIs and Services and then to OAuth Agreement Page. There you need to fill out a form. Once that is done, click the tab directly above the OAuth agreement page called Credentials.
Click the Create Credentials button and select OAuth Client ID. In the Application Type field, select Desktop, and in the Name field, enter something like [YOUR NAME] smartmirror.
Once your credentials are created, click the download button.
2. Next, you need to connect a microphone and speaker to the Raspberry Pi. First, connect a USB microphone to the Raspberry Pi and use the AUX cable to connect the speaker to the audio jack on the Raspberry Pi.
Open a terminal on the Raspberry Pi and run this command:
An example should look something like this if the USB microphone is working correctly:
**** List of CAPTURE Hardware Devices **** card 2 & # 58; Device & # 91; USB PnP Sound Device & # 93 ;, device 0 & # 58; USB Audio & # 91; USB Audio & # 93; Subdevices & # 58; 1/1 Subdevice # 0 & # 58; subdevice # 0
sudo nano /etc/asound.conf
Copy and Paste into this text file the following code:
pcm.! default & # 123; type asym capture.pcm & # 34; mic & # 34; playback.pcm & # 34; speaker & # 34; } pcm.mic & # 123; type plug slave & # 123; pcm & # 34; hw & # 58; 2.0 & # 34; }} pcm.speaker & # 123; type hw card 0} ctl.! default & # 123; type hw card 0}
Note: On line # 9 pcm “hw: 2.0”, replace “2” with whatever mic card number you found earlier. If you had a microphone register on card 2, then nothing needs to be changed. However, if it says "map 1", change that line to: pcm "hw: 1.0".
To exit the text editor, hold Control + X, enter Y to save and Enter to confirm.
Then run the following command to create another text file:
sudo nano .asoundrc.
In this text file, copy and paste the same configuration items that you saved in the '/etc/asound.conf' file, remember to change line 9 to be your specific USB microphone card number. Save and exit this file (Control + X, type Y to save and Enter).
To set up a speaker via AUX, you need to tell the Raspberry Pi that the sound should go to the speaker and not elsewhere. To do this, run the following code in a terminal:
This action opens a menu similar to the settings on a Raspberry Pi device. Go to System Settings (press Enter to select) and Audio (use up/down keys to navigate). Go to AUX or headphones as audio output and enter to confirm. Then press the right arrow button and press Enter to exit the raspi-config menu.
Next, restart your Raspberry Pi. Once the device boots up, open the terminal again.
Now you need to check that the speaker and microphone settings are working.
Run the command:
speaker-test -t wav & lt; br & gt;
If you hear, when your speaker says something like "Right, Left ...", it means that the speakers are configured correctly.
To test the microphone, you need to record something and play it through the speaker.
Run the command:
arecord --format = S16_LE --duration = 10 --rate = 16000 --file-type = raw audiotest.wav
This command records a 10 second file through a USB microphone and saves it to a file called audiotest.wav. Those. you need to say something for 10 seconds.
Then, to play this audio file on the connected speakers, run:
aplay --format = S16_LE --rate = 16000 audiotest.wav & lt; br & gt ;
Your voice should be heard from the speaker.
3. The next step is to install important packages to enable Google Assistant on our Pi.
You need to update your device first.
sudo apt-get update & lt; br & gt;
Then run the following command to install the package that will control the LEDs:
pip install RPi.GPIO
Now you need to install Python 3:
sudo apt-get install python3-dev python3-venv & lt; br & gt;
Run the command to activate the package:
python3 -m venv env & lt; br & gt;
Install all dependencies.
env/bin/python -m pip install --upgrade pip setuptools & lt; br & gt;
To fully activate your Python 3 environment, run the activation command:
source env/bin/activate & lt; br & gt;
Next, you need to install the Google Assistant library, which actually provides the voice assistant:
python -m pip install - -upgrade google-assistant-library & lt; br & gt;
Next, you need to authenticate the Raspberry Pi with the Google Cloud developer account. First, you need to install Google's dedicated authentication tool:
python -m pip install --upgrade google-auth-oauthlib & # 91; tool & # 93; & lt; br & gt;
Go to the File Explorer app on the Raspberry Pi. There we should see the downloaded .json file, the name of which should start with client_secret. Right-click this file and hit the Copy button.
Go back to Terminal on your Raspberry Pi and run this code:
google-oauthlib-tool --scope & lt; a href = & # 34; https & # 58; //www.googleapis.com/auth/assistant-sdk-prototype"> & lt; a href = & # 34; https & # 58; //www.googleapis.com/auth/assistant-sdk-pro...</a" ;> & lt; a href = & # 34; https & # 58; //www.googleapis.com/auth/assistant-sdk-pro...</a" ;> https & # 58; //www.googleapis.com/auth/assistant-sdk-pro...>>> --save --headless --client-secrets & # 91; PASTE YOUR PATH HERE & # 93;
If the command completes successfully, the URL will be displayed. Click on the link and log into your Google account. After logging in, copy the provided code and paste this code into the terminal prompt where it says:
Enter the authorization code & # 58;
4.In the terminal window Raspberry Pi run this command:
cd/home/pi & lt; br & gt;
Create a Python text file named 'main' by running this code:
sudo nano main.py & lt; br & gt;
After opening your text editor, copy and paste this code:
#!/usr/bin/env python from __future__ import print_function import argparse import os.path import json import google.oauth2.credentials import RPi.GPIO as GPIO from google.assistant.library import Assistant from google.assistant.library.event import EventType from google.assistant.library.file_helpers import existing_file GPIO.setmode (GPIO.BCM) GPIO.setup (25, GPIO.OUT) def process_event (event) & # 58; if event.type == EventType.ON_CONVERSATION_TURN_STARTED & # 58; print () #m = alsaaudio.Mixer (& # 39; PCM & # 39;) # m.setvolume (100) GPIO.output (25, True) print (& # 34; hit the lights & # 34;) print (event ) if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and event.args and not event.args & # 91; & # 39; with_follow_on_turn & # 39; & # 93;) & # 58; print () #m = alsaaudio.Mixer (& # 39; PCM & # 39;) # m.setvolume (0) GPIO.output (25, False) print (& # 34; lights out & # 34;) def main () & # 58; parser = argparse.ArgumentParser (formatter_class = argparse.RawTextHelpFormatter) parser.add_argument (& # 39; - credentials & # 39 ;, type = existing_file, metavar = & # 39; OAUTH2_CREDENTIALS_FILE (os. 39.join os.path.expanduser (& # 39; /home/pi/.config'), & # 39; google-oauthlib-tool & # 39 ;, & # 39; credentials.json & # 39;), help = & # 39; Path to store and read OAuth2 credentials & # 39;) args = parser.parse_args () with open (args.credentials, & # 39; r & # 39;) as f & # 58; credentials = google.oauth2.credentials.Credentials (token = None, ** json.load (f)) with Assistant (credentials, & # 34; & # 91; YOUR SMART MIRROR NAME & # 93; & # 34;) as assistant & # 58; for event in assistant.start () & # 58; process_event (event) if __name__ == & # 39; __ main __ & # 39; & # 58; main ()
The only text that needs to be edited in this code is in the penultimate paragraph where it says "[NAME OF YOUR SMART MIRROR]". Remember when we created the OAuth Client ID on the Google Cloud Platform and I told you to name your project something like [YOUR NAME] smartmirror. Get this name and replace it with [YOUR SMART MIRROR NAME] "(smart mirror name).
Once done press Control + X, type Y and press Enter to save and exit this text editor .
Finally, go to the Files app on your Raspberry Pi and find the previously used client_secrets .json file (it should be in/home/pi/Downloads). Right-click it and select Copy. Then go to the directory “/home/pi” and paste it there by right-clicking and choosing “Paste.”
5. Automating the Boot Process
The final step in making Google Assistant work is to create a shell script that points to the main code and runs it. This will make it easier for this shell script to run on boot, so every time the Raspberry Pi reboots, Google Assistant will automatically initialize and run.
To create a shell script named google-assistant-init.sh, run the following command:
sudo nano google-assistant-init.sh & lt; br & gt;
Once inside the text editor, copy and paste this code:
#!/bin/sh & lt; br & gt;/home/pi/env/bin/python3 -u /home/pi/main.py
Click Command + X, type Y and press Enter to save and close the text editor ... Then we Next enter the following command:
chmod + x google-assistant-init.sh
Now open the Folders app on your Raspberry Pi. Go to "/home/pi" and right click on an empty space. Click the Show Hidden Files button. Find and open a text file called ".bashrc". This is the file that starts when booting to the Raspberry Pi.
Paste the code below at the very bottom:
echo Running at boot
Save this file and reboot your Raspberry Pi. The voice assistant is ready.
Step four: laser cutting
Next, the master prepares the parts for the body. Some parts will be cut on a laser cutter.
The second part will be 3D printed.
You can learn more about the design project here.
Step five: electronics
After cutting and printing the parts, the wizard proceeds to the assembly of the project.
First, the master prepares the LEDs. On a previously cut strip of plywood, he glues an acrylic diffuser.
Then, on the breadboard, he checks the operation of the LEDs (connects them to pin 25 of the GPIO). Then you need to say "OK, Google" and the LED will light up.
After checking, glues them to the frame and connects them in parallel.
Now you need to adjust the voltage regulator. To do this, connect it to a 12V power source. After turning on the regulator, the small LED panel should light up and show the output voltage.
To change the output voltage, turn the left screw on the board counterclockwise (to decrease the voltage). The voltage must be set from 5.0 to 5.1 V.
< img class = "aligncenter" alt = "" Smart mirror "with Google Assistant and wireless charging" src = "https://usamodelkina.ru/uploads/posts/2021-05/1620465095_1-50.jpg"/> Then you need to check everything. Connect the Raspberry Pi and speaker to the positive and negative output terminals on the voltage regulator (5V current) and connect the LCD controller board to 12V. From the controller board comes a 40-pin wire that connects to the back of the LCD panel. Plug in this 40-pin connector. Also connect HDMI cable from Raspberry Pi to LCD controller board.
Connect 12V power cable and test device operation.
Step six: assembly
Next, the wizard starts assembling the device. Assembles the bottom, back and side. Sets the speaker.
Installs and connects electronics. Glues the screen to the front panel frame.
Installs the LED bar at the bottom of the device body.
Installs the panel together with the screen into the case.
To access the electronics, the master made the top panel removable. It is fastened with magnets installed in holders.
Now you need to remove the protective film from the mirror and use hot glue or double-sided tape fasten to the front panel (on the display).
Step seven: wireless charging
To make the device more functional master decided to install a wireless charging module.
The module itself must be disassembled, and the board must be fixed under the top cover. Then you need to connect the power and replace the cover.
< a href = "https://usamodelkina.ru/uploads/posts/2021-05/1620465114_1-86.jpg" rel = "prettyPhoto"> Everything is ready.