How to Add Siri Control to Your Raspberry Pi Project

How to Add Siri Control to Your Raspberry Pi Project

1. Purpose
The purpose of this tutorial is to teach you how to use the SiriControl open-source Python framework to add Siri functionality and control to RaspberryPi Projects.

2. Overview

In this tutorial, I go over how to set up and use the SiriControl Python framework. I use the SiriControl module with a Raspberry Pi 3 to flash an LED on and off. After the tutorial, you will be able to use SiriControl to add Siri voice commands to any Raspberry Pi project. Before continuing, make sure you have the following equipment and materials and that your RaspberryPi is set up and running.

3. Equipment

  1. Raspberry Pi 3Link for Raspberry Pi
  2. HDMI Cable Link for HDMI Cable
  3. LEDLink for LEDs from Adafruit
  4. Mouse + KeyboardAmazon Link for Keyboard/Mouse
  5. Monitor/TV – Any TV or monitor with HDMI
  6. Jumper WiresAmazon Link for Jumper Wires
  7. Micro USB CableAmazon Link for Micro USB Cable
  8. BreadboardAmazon Link for Breadboard

4. Table of Contents

  1. Setting up a Gmail Account for SiriControl
  2. iOS Device Setup
  3. SiriControl
    1. Setting Up SiriControl
    2. Create Your Own Module
  4. Wiring the Circuit
  5. Uploading and Running the Code

Procedure

1.0 Setting up a Gmail Account for SiriControl

The SiriControl module requires a Gmail account to work. I set up a new Gmail account just for use with SiriControl and suggest doing the same. This is a good idea because the Python script will have the username and password for this account in it.

Once an account is created I allow less secure apps access to Gmail. This is because the Gmail server views the Python script as a less secure app. I do this under the Sign-in & Security section for my account.

Figure 1: App. Access (Off)

Figure 2: App. Access (On)

The last step of setting up your Gmail account is to enable IMAP protocol. This can be done under Gmail->Settings->Gear Part->Settings->Forwarding and POP/IMAP->IMAP Access.

Figure 3: IMAP (Disabled)

Figure 4: IMAP (Enabled)

2.0 IOS Device Setup

Connect “Notes” on your iOS device to the Gmail account set up to be used with SiriControl. I go to Settings->Accounts & Passwords->Add Account and add the Gmail account I just set up. After adding that account, I select it and enable notes (Figure 6: Notes Under Gmail Account). Next, I go to Settings->Notes and enable “On My iPhone” Account. I then change my Default Account to the Gmail Account. My iOS device is now set up.

Figure 5: Account & Passwords

Figure 6: Notes Under Gmail Account

Figure 7: Default Account – Notes

3.0 Siri Control

3.1 Setting Up SiriControl

To use SiriControl I clone the repository for the module to my RaspberryPi. To do this I open the terminal window and enter the following commands:

1. sudo apt-get update
2. sudo apt-get install git-core
3. git clone https://github.com/theraspberryguy/SiriControl-System

Figure 8: Cloning Repository

After cloning the repository, I open the script: siricontrol.py. Inside the script I entered my Gmail account username and password and save the script.

3.2 Create Your Own Module

Siricontrol.py works by loading module scripts from the modules folder. It is important to follow the template when writing new module scripts to perform different tasks. Because I am controlling an LED, I write one script to turn the LED on (LED_on.py) and one script to turn the LED off (LED_off.py).

To make your own module, follow the steps below within a template script:

1. Name the module in “moduleName”
2. Give the module “commandWords” that you need to give to Siri to execute a command.
3. Write the function you want executed under execute(command) function.
4. Make sure you save your script in the modules folder.

4.0 Wiring the Circuit

The circuit I set up SiriControl to command is a simple LED circuit. I always like to make a wiring diagram () using Fritzing, an open-source schematic capture and PCB routing software. You can download Fritzing using the following link (optional): http://fritzing.org/home/

Figure 9: Raspberry Pi LED Schematic

The LED and resistor should be connected in series between Pin 11 (GPIO17) and Pin 25 (Ground). The resistor is there to limit current through the LED and should be sized accordingly depending on your LED to prevent burning it out. Remember the longer lead on the LED is positive and should be connected to Pin 11.

5.0 Uploading and Running the Code

After completing all the steps, I run the SiriControl script with the following command:

python siricontrol.py

The script starts running and should initialize with all the modules in the module folder.

Figure 10: LED On Executing

Figure 11: LED Off Executing

Now I command Siri, “Note: Turn on LED,” and my LED turns on while the script tells me it executed the command and is listening for another. I now say, “Note: Turn off LED,” and the LED is turned off. The script will execute the commands I give to Siri from anywhere in the world as long as:

1. The script is running on the Raspberry Pi.
2. The Raspberry Pi is connected to the Internet so that it can poll the Gmail account.

You can now add any modules you want to add SiriControl to any Raspberry Pi projects. Although I used a Pi for this project, this should work on other Linux Development boards with Python installed.

6.0 Appendix: Scripts

6.1 Siricontrol.py

6.2 Led_on.py

#You can import any modules required here
import RPi.GPIO as GPIO #import GPIO module
import time

#This is name of the module – it can be anything you want
moduleName = “LED_on”

#These are the words you must say for this module to be executed
commandWords = [“turn”, “on”, “led”]

#This is the main function which will be execute when the above command words are said
def execute(command):
LED = 11 # Set LED pin to pin 11

GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT) #configure LED as an output

print(“\n”)
print(“LED is On.”)

6.3 Led_off.py

#You can import any modules required here
import RPi.GPIO as GPIO #import GPIO module
import time

#This is name of the module – it can be anything you want
moduleName = “LED_off”

#These are the words you must say for this module to be executed
commandWords = [“turn”, “off”, “led”]

#This is the main function which will be execute when the above command words are said
def execute(command):
LED = 11 # Set LED pin to pin 11

GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT) #configure LED as an output

print(“\n”)
print(“LED is off.”)
GPIO.output(LED, GPIO.LOW) #turn LED on