Introduction: DIY Amazon Alexa

The Amazon Alexa is a marvelous piece of technology. It has revolutionized how we interact with our environment using technology and how we receive information.

Getting into the IoT category is hard if you are trying to not buy something pre-built. There are many solutions that offer it in a simpler way but why not do it the nitty gritty way and do it yourself!

It is not as hard as you think to do something like this. There isn't even any soldering required!

Here is what you will need:

  • A Raspberry Pi (Zero W preferably or 3 B - Either work)
  • Micro SD card (At least 8GB)
  • A micro USB cable (I had a micro USB adapter that would plug into the wall directly)
  • A charging brick (If you do not have an all in one adapter)
  • A USB microphone (You can pick up a PS Eye or use any other USB microphone)
  • Speaker (3.5mm or bluetooth - 3.5 preferably)
  • Internet connection

Step 1: Setting Up the Pi

I used Raspbian for my Raspberry Pi. You can use NOOBS but I would say that Raspbian works better for this purpose.

Windows:

  1. Download Raspbian and insert your Micro SD card (adapter may be needed)
  2. Download Win32diskimager
  3. Open Win32diskimager
  4. Browse to Raspbian .img
  5. Write to disk MAKE SURE YOU SELECT THE RIGHT DISK
  6. Eject disk

MacOS:

  1. Download Raspian and insert your Micro SD card (adapter may be needed)
  2. Download Etcher
  3. Open Etcher
  4. Browse to Raspbian .img
  5. Write to disk MAKE SURE YOU SELECT THE RIGHT DISK
  6. Eject disk

If you are planning on using SSH instead of a display with keyboard and mouse follow these steps below:

  1. Insert the Micro SD card again (adapter may be needed)
  2. Open the SD card files
  3. Create a BLANK file (you can copy and paste config.txt, rename, and remove all contents)
  4. Name it SSH
  5. Eject disk

Next:

  1. Put Micro SD in the Pi
  2. Connect ethernet to Pi
  3. Connect power to Pi

Give the Pi a couple of seconds to boot up then open terminal.

If you are using SSH:

  1. Download Fing or some other network IP scanner
  2. Scan your network (same one Pi is connected to)
  3. Find IP of "raspberry pi"
  4. Ex: 192.168.x.x
  5. If on Mac: Open terminal; type "ssh pi@192.168.x.x(The IP you JUST got from fing)"; password is "raspberry"
  6. If on Windows: Download Putty; type "pi@192.168.x.x(The IP you JUST got from fing)"; password is "raspberry"
  7. You should be in!

Step 2: Getting Your Amazon Account Ready.

  1. Login at https://developer.amazon.com and go to ALEXA, then Alexa Voice Service.
  2. Register a Product Type > Device.
  3. You are at Device Type Info left tab.
    1. For the Device Type ID and Display Name use something like AlexaPi or whatever you want.
  4. You are at Security Profile left tab.
    1. From the drop-down menu choose Create a new profile.
    2. Choose whatever for Security Profile Name and Security Profile Description.
    3. Hit Next.Under Web Settings horizontal tab hit Edit and:
      1. Allowed Origins put
      2. http://localhost:5050 and http://ALEXA.DEVICE.IP.ADDRESS:5050
      3. replace ALEXA.DEVICE.IP.ADDRESS with the IP that you got from fing. This is especially necessary when you are installing from another computer than your Pi is going to run on.
      4. Allowed Return URLs put
      5. http://localhost:5050/code and http://ALEXA.DEVICE.IP.ADDRESS:5050/code
      6. replace ALEXA.DEVICE.IP.ADDRESS with the IP that you got from fing. This is especially necessary when you are installing from another computer than your Pi is going to run on.
    4. Fill in the rest (if there is anything to fill out)

Credit to AlexaPi github repository for some content above.

Step 3: Installing AlexaPi

Enter sudo by entering:

sudo su

Navigate to /opt:

cd /opt

Update and install git:

apt-get update && apt-get upgrade
apt-get -y install git nano

Clone the AlexaPi repo:

git clone <a href="https://github.com/alexa-pi/AlexaPi.git" rel="nofollow"> https://github.com/alexa-pi/AlexaPi.git</a><br>

Start the setup script:

sudo ./AlexaPi/src/scripts/setup.sh

Follow the instructions and copy and paste information from Amazon's Developer site

Credit to AlexaPi github repository for some content above.

Step 4: Post-installation

To run AlexaPi reboot or run:
sudo systemctl start AlexaPi.service

Check status of AlexaPi:

<p>sudo systemctl status AlexaPi.service</p>

Now you want to create the AlexaPi user:

<p>chown -R alexapi:alexapi /var/lib/AlexaPi/<br>usermod --home /var/lib/AlexaPi alexapi</p>

Next:

<p>sudo adduser pulse audio</p><p>sudo adduser pi pulse-access</p><p></p><p>sudo adduser alexapi pulse-access</p>

Now you need to edit a file, open:

<p>sudo nano /etc/systemd/system/pulseaudio.service</p>

In the new blank file write:

<p>[Unit]<br>Description=PulseAudio Daemon</p><p>[Install]
WantedBy=multi-user.target</p><p>[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit</p>

Save by entering "[ctrl] + x & y & [enter]"

Now run the following command to ensure that pulse runs:

<p>sudo systemctl enable pulseaudio.service</p>

Lastly we need to edit the config file for AlexaPi:

nano /etc/opt/AlexaPi/config.yaml

In the sound section change the following values:

<p>input_device: "pulse"<br>output: "pulse"
output_device: ""</p>

I would recommend installing VLC:

<p>apt-get -y install vlc</p>

and finally:

reboot

Credit to AlexaPi github repository for some content above.

Step 5: The Working Alexa

By now, the Alexa should have rebooted and said "Hello".

Now you say, "Alexa", it will respond with "Yes" and you are good to go!

Step 6: Additional Step: Wifi

Use this tutorial offered by the documentation of the Raspberry Pi. Then reboot!

Internet of Things Contest 2017

Runner Up in the
Internet of Things Contest 2017