Smart Vanity Mirror: Part 3, Setting up the Raspberry Pi and the Development Environment

Welcome back! Part three of the Smart Vanity Mirror project is all about setting up the Raspberry Pi 3, attaching the extra components, and setting up the development environment.

There are a few assumptions in this part of the guide.

  1. The development environment is Windows 10.
  2. SD Card reader
  3. The Raspberry Pi is version 3
  4. The Debian OS is Jessie
  5. All the required parts for the Raspberry Pi are nearby:
    1. Raspberry Pi
    2. Micro SD card with at least 8GB
    3. Power cable
    4. HMDI cable
    5. Ethernet cable for the initial setup. We will use the wifi option once it is setup.

Any action that is used through SSH on the pi is the same for any development environment. Alternate setup guides for other development environments can be found HERE.

1 Downloading Rasbian

The first step is to download the Raspbian OS. Download the zip file from https://www.raspberrypi.org/downloads/raspbian/. Once that is finished unzip the file into a temporary directory. The .img file is needed to copy onto SD card.

2 Writing the Image

Follow the next steps to get the image installed on the SD card:

  • Insert the SD card into the SD card reader.
  • Note which drive letter is assigned to the card.
  • Download the Win32DiskImager utility from HERE.
  • Extract the executable from the zip file retrieved from above.
  • Run the Win32DiskImager program, you will need to run the file as an administrator. Right click on the file and select Run as administrator.
  • Select the image file location.
  • Select the drive letter for the SD card.
  • Click Write and wait for the write operation to complete.
  • Exit the imager program and eject the SD card.

3 Setting up the Pi

Insert the SD card into the SD slot on the bottom of the Raspberry Pi.

Sdcard

Next, connect the ethernet cable to a router and then plug it into the Rpi. Access your router’s web-based portal. Different routers have different ways to get to the portal. Check the documentation for your router. Find and write down the IP address associated with your Raspberry Pi.

Using Git Bash for Windows, or any other bash type program that allows one to connect via ssh, connect to the Rpi using the commands below:

ssh pi@xxx.xxx.xxx.xxx

xxx.xxx.xxx.xxx = the IP address to the Rpi. You will be asked for a password for pi which is ‘raspberry’.

Next, type the following to enter the setup menu for the Rpi:

sudo raspi-config

A screen like the image below will be displayed:

raspiconfig

Highlight the first option “Expand Filesystem” and press the enter key. This will expand the OS to use the entire SD card.

After that, highlight “Boot Options” and press enter. Then select  “B4” and press enter. This will automatically log in the user pi and start the desktop GUI.

Next, select “Enable Camera” and hit the enter key. Then select “Yes” and hit enter again. This will enable the use of the camera interface that the RaspiCam uses.

Optionally you can go into the “Advanced Options” and change the hostname of the pi to anything you want.

Finally, select “Finish” and then select “Yes” when asked to reboot.

Wait a few seconds then connect to the Rpi using the ssh command.

4 Updating the Firmware

Once connected back to the Rpi run the following to update the Rpi firmware:

sudo rpi-update

What this does is update the Rpi to a new version than what may have been in the OS image. Quick fixes and patches are updated this way instead of installing a new image for small updates to the OS.

5 Configuring Wifi

Time to configure the wifi so the Rpi can get connected to the mirror and be controlled remotely by the desktop. Write down the SSID from the router the Pi will connect to, it is the name of the router, and the pass key. Next, open the wpa-supplicant file using the command below:

sudo nano /etc/wpa_supplicant.conf

Go to the bottom of this file and enter the following text:

network={
    ssid="The_SSID_to_your_router"
    psk="Your_wifi_password"
}

To save the file press Ctrl+X, then Y, and finally Enter.

Shutdown the Rpi:

sudo shutdown -h now

6 Connecting the Raspberry Pi to the Mirror

Disconnect the ethernet cable from the Raspberry Pi. Now, install the Raspberry Pi inside the mirror and connect to the TV using an HMDI cable as well as connecting the power cable to the power source for the mirror. Below is how I installed the Rpi inside the mirror:

20160904_095406

The breakout board will be used to access the motion sensor, buttons, and other GPIO pins I might need. The white cable is the camera cable that will be connected when I get to the face recognition portion.

7  Updating Aptitude and Installing Basic Packages

Next, update aptitude, which is the package installer for most packages needed. Then, install the basic packages to get started programming the Rpi. Run the following commands in the terminal:

 
sudo aptitude update 
sudo aptitude dist-upgrade
sudo apt-get install openjdk-8-jre openjdk-8-jdk ant 

This will install java and ant which will allow the compiling of the Smart Mirror GUI.

8 Rotating the Display and Setting up Remote Display

When turning on the mirror and the Pi, the display is configured for a 1920 X 1080 resolution. What is needed is a 1080 X 1920, so the mirror can be vertical and the display will match the dimensions. To do this the config.txt file needs to be updated. This is done with the following commands:

sudo nano /boot/config.txt

Find the parameter ‘display_rotate=0’. Change the value to 1 to rotate the display 90 degrees. It should now read ‘display_rotate=1’. If the parameter is not there add it at the bottom.

To save the file press Ctrl+X, then Y, and finally Enter.

Next, install X11VNC. This will allow a remote view of the pi desktop on the development machine. To do this, enter the following commands in the terminal:

sudo apt-get install x11vnc
x11vnc-storepassword

After x11vnc is installed and the password stored, a start-up configuration file is needed. Create the file by entering the command below:

mkdir -p ~/.config/autostart
nano ~/.config/autostart/xterm-autostart.desktop

Inside the file, enter the follow:

[Desktop Entry]
Encoding=UTF-8 
Name=x11vnc autostart 
Comment=Starts the x11vnc server to allow for remote VNC connections. 
Exec=x11vnc –forever -usepw

To save the file press Ctrl+X, then Y, and finally Enter.

Reboot the Rpi once more.

Now, download TightVNC, install, and start it up.

In the ‘Remote Host’ drop-down box, type in the IP to the Rpi followed by ‘:5900’. Then click connect. Enter the password that was provided for the X11VNC setup.

TightVNC

The display to the Rpi should now be visible on the development machine.

RaspDisplay

9 Setting up Remote Shares

Next, it is time to create remote shares on the Raspberry Pi. Remote shares will allow the creation of folders on the Rpi and give access to them over the network. This allows the Windows development machine to access them and edit the files inside. This will be used later when programming on Windows with Netbeans and then building and running the program on the Rpi remotely.

To begin, find the workgroup name that Windows uses on the network. To do this go to Control Panel -> All Control Panel Items -> System. Next to ‘Workgroup’ is the name of the workgroup the computer is under. Change it now if needed, make sure to restart the computer for it to take effect.

System

Write that down for later. Next, jump back over to the terminal connected to the Rpi. Follow the commands below to create a working directory, install Samba, and edit the config file:

mkdir ~/SmartVanityMirror
sudo apt-get install samba samba-common-bin
sudo cp /etc/samba/smb.conf /etc/samba/smbconf.backup
sudo nano /etc/samba/smb.conf

The commands above create a directory to share with windows, installs the samba framework, copies the config file to a backup then opens the config file for editing.

Under the [global] section find ‘workgroup = WORKGROUP’ and change this to match the workgroup of the development machine. Under the workgroup setting add the line:

netbios name = NameOfDevice

Change the NameOfDevice to whatever windows should see. Now, navigate all the way to the bottom of the file to add share definitions so the development machine can find the folders. Enter the following to allow the folder created earlier to be found.

[MirrorBuildFolder]
path = /home/pi/SmartVanityMirror
valid users = pi
read only = no

To save the file press Ctrl+X, then Y, and finally Enter. Now since samba has its own password config run the command below to give the user pi, a password for accessing the folder:

sudo smbpasswd -a pi

Enter a password for the user twice. Now restart the samba service with the following:

sudo service smbd restart

From the development machine type \\IP_OF_PI into an explorer window and the folders that have been shared on the Raspberry Pi should be visible. A username and password of the pi user may be needed to access the folders. If so the username is NameOfDevice\pi and the password is the password provided to Samba earlier. Right click on the folder and map to network drive to have access to the folder without having to type out all the above.

10 Done

That is a wrap for setting up the Raspberry Pi for the basics needed to get up and running. The next part will deal with installing Netbeans, setting up the GUI shell, and displaying a very basic GUI that displays the date and time on the Raspberry Pi. To view the list of all the parts, see the Smart Vanity Mirror Intro.

Resources Used

The following links were used in setting up the Raspberry Pi and development environment:

2 thoughts on “Smart Vanity Mirror: Part 3, Setting up the Raspberry Pi and the Development Environment

Leave a Reply

Your email address will not be published.