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.
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.
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:
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:
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.