Introduction: Button Trigger for Google Assistant on the Raspberry Pi

Picture of Button Trigger for Google Assistant on the Raspberry Pi

On this Instructablel I will be showing you how you can add a button trigget to your Google Assistent, which is running on your Raspberry Pi.

Hope that you like it and thanks

Step 1: Get Everything Ready

For this tutorial you will need:

Step 2: Connect Everything to the Raspberry Pi

Picture of Connect Everything to the Raspberry Pi

Connect the momentary switch to Ground (3rd pin from right to left on the bottom row) and to the GPIO18.

Connect the LED Light to Ground (8th pin from right to left on the bottom row) and to the GPIO23.

Step 3: Download Our Dependencies

Picture of Download Our Dependencies

Get intot he Raspberry Pi with Raspbian on it and open up the Command Prompt.

Type in "source env/bin/activate" and then press "Enter"

Once we are inside our enviroment, type "pip install RPi.GPIO" and press "Enter"

Step 4: Edit the Googlesamples File

Picture of Edit the Googlesamples File

On the Command Prompt, type in "geany env/lib/python3.4/site-packages/googlesamples/assistant/__main__.py"

Once the Geany editor opens, scroll down after the last "import" and create a new line.

Type in ""import RPi.GPIO as GPIO"

Scroll down to the Line 37 and type in "GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN pull_up_down=GPIO.PUD_UP)

GPIO.setup(23, GPIO.OUT)"

Scroll all the way down to the Line 196.

Comment out the code in the Line 196 by adding an "#" to the start of the code.

NOTE: Remember that Python works by tabs, but the file is indented by spaces, so keep in mind, 1 Tab = 4 Spaces

Create a new line over the code you just commented out and type in "input_state = GPIO.input(18)

if input_state == True

GPIO.output(23,False)

continue

else:

GPIO.output(23,True)

pass"

Save the file and close it.

Step 5: Enjoy Your Button Trigger

Picture of Enjoy Your Button Trigger

Go back to the Comand Prompt.

Type in "python -m googlesamples.assistant" and press "Enter"

You can now press your button and talk to your your Google Assistant in a Raspberry Pi.

And that's it, now you can wake up your Google Assistant in the tap of a button, literally.

Comments

RomanK77 (author)2017-05-12

I have problem, when i write this code i have error:

pi@raspberrypi:~ $ source env/bin/activate

(env) pi@raspberrypi:~ $ python -m googlesamples.assistant

Traceback (most recent call last):

File "/usr/lib/python3.4/runpy.py", line 151, in _run_module_as_main

mod_name, mod_spec, code = _get_module_details(mod_name)

File "/usr/lib/python3.4/runpy.py", line 118, in _get_module_details

return _get_module_details(pkg_main_name)

File "/usr/lib/python3.4/runpy.py", line 126, in _get_module_details

code = loader.get_code(mod_name)

File "<frozen importlib._bootstrap>", line 1572, in get_code

File "<frozen importlib._bootstrap>", line 1532, in source_to_code

File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed

File "/home/pi/env/lib/python3.4/site-packages/googlesamples/assistant/__main__.py", line 322

GPIO.output(23,False)

^

IndentationError: expected an indented block

(env) pi@raspberrypi:~ $

About This Instructable

3,037views

46favorites

License:

Bio: Avid Thinker, Computer Programmer, Web evangelist, Hacking / Breaking expert, Problem Solver, Technology Obsessed, Gamer, 3D printing, Coffee lover!
More by novaspirittech:Voice Activated Google Assistant for Raspberry PiGoogle Assistant on a Raspberry PiButton Trigger for Google Assistant on the Raspberry Pi
Add instructable to: