raspberrypi.org/magpi The Official Raspberry Pi Projects Book 117
Tutorial
raspberrypi.org/magpi The Official Raspberry Pi Projects Book 117
There are a few tutorials on how to turn your
Raspberry Pi into an Amazon Echo using Amazon
Alexa. However, AlexaPi (magpi.cc/2kiyOxO) is the
easiest way to get Amazon Alexa on your Raspberry
Pi. The project has prepared everything to set up
Alexa Voice Services on your Pi in a streamlined
and simple manner. The hardest part is setting up
your Amazon Developer account and gathering your
credentials (and really, that’s not that hard!).
At this point, with your speaker and your
microphone plugged into your Pi, you should be able
to run Alexa on your GoPiGo, just as you would on
an Amazon Echo. Ask it for a news update: “Alexa,
what’s the news?”
ALEXA POWERED ROBOT
from flask import Flask
import gopigo
import time
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello world'
@app.route('/forward')
def forward():
print("Forward!")
gopigo.fwd() # Send the GoPiGo Forward
time.sleep( 1 ) # for 1 second
gopigo.stop() # then stop the GoPiGo
return 'Alexabot moved forward!'
@app.route('/backward')
def backward():
print("Backward!")
gopigo.bwd() # Send the GoPiGo Backward
time.sleep( 1 ) # for 1 second
gopigo.stop() # then stop the GoPiGo.
return 'Backward!'
@app.route('/left')
def left():
print("Left!")
gopigo.left()
time.sleep( 1 )
gopigo.stop()
return 'Left!'
@app.route('/right')
def right():
print("Right!")
gopigo.right()
time.sleep( 1 )
gopigo.stop()
return 'Right!'
@app.route('/dance')
def dance():
print("Dance!")
for each in range( 0 , 5 ):
gopigo.right()
time.sleep(0.25)
gopigo.left()
time.sleep(0.25)
gopigo.bwd()
time.sleep(0.25)
gopigo.stop()
return 'Dance!'
@app.route('/coffee')
def coffee():
print("Coffee!")
return 'coffee!'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Alexabot.py
Language
>PYTHON
DOWNLOAD:
magpi.cc/2kiFlZz
Figure 1 An example of how to build your own command