This is a quick tutorial on adding button trigger for google assistant on raspberry pi, this tutorial was very straight forward and should take that much time to perform to add this action.
○○○ Parts ○○○
Momentary Switch ► http://amzn.to/2qUoGf2
LED ► http://amzn.to/2qkgBnP
resistor 220 ohm ► http://amzn.to/2pfiAto
USB Microphone ► http://amzn.to/2qCx4zY
Raspberry Pi 3 ► http://amzn.to/2oquADd
Installing the RPi.GPIO
pip install RPi.GPIO
edit google samples assistant main.py file
nano /home/pi/env/lib/python3.4/site-packages/googlesamples/assistant/__main__.py
on the top of the file we need to import gpio
import RPi.GPIO as GPIO
now we have to setup our pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.OUT)
now we need to add the trigger to our code at line 197
comment out with #click.pause…..
input_state = GPIO.input(18)
if input_state == True:
GPIO.output(18,False)
continue
else:
GPIO.output(18,True)
pass
remember to double check the indents, google likes to use 4 spaces in place of tab spacing.
if you want more details about this project, consider checking out one of my previous post about installing google assistant on raspberry pi
View Comments (16)
***error in code on blog.
Shouldn't the GPIO.output pin # be 23? On your blog you have it listed as 18 but the video has it as correct as 23. Just a heads up:
input_state = GPIO.input(18)
if input_state == True:
GPIO.output(18,False)
continue
else:
GPIO.output(18,True)
pass
In the python 3.5 the __main__.py code is completelly different.
Would you please update your post with Python 3.5? Although it is a good post, it is pretty outdated.
555
555
555
Aa16EGcf
if(now()=sysdate(),sleep(12),0)
0"XOR(if(now()=sysdate(),sleep(12),0))XOR"Z
-1; waitfor delay '0:0:12' --