When I first saw the hackster.io Star Wars themed contest I knew I had to submit an entry. As a long time Star Wars fan and maker, it seemed like a great opportunity and a chance to get my hands on a Particle Photon.
A few years back I had made a paper mache stormtrooper helmet, which is where the original idea came from. The concept was to upgrade the helmet and connect it to an AWS Alexa Skill/Echo to remotely issue commands. With this concept, I was lucky enough to receive a Photon! While considering how to actually implement the solution, I decided instead of a helmet, a blaster would be much more fun and provide for a few different interactions.
The Particle application is pretty simple and I was surprised at how easy it is to setup the particle to receive command from the Alexa Lambda function. Basically an IoT device receiving values on different threads. For now on the blaster/particle side, the device accepts commands to play different audio clips via a serial connection to the MP3 trigger and via a command can change the clip that plays when you hit the trigger (stun or normal). Note, I struggled for a long time on the serial connection between the Photon and the MP3 board, be sure to include: #include "application.h" in the .ino file and be sure to connect the GND between the two boards.
In the future, I'm planning on including a temperature probe that can be queried and keeping a counter of trigger pulls that will be updated on a web GUI.
On the Amazon Echo side, I built an Alexa Skill to interact with the blaster. This again was surprisingly easy to setup, one note is you really only need to change a few things in the index.js file, otherwise don't touch the alexaskill.js file. Also, you'll need to zip the index, alexaskill, node_modules folder, and package.json files together and upload as a set to an AWS Lambda function. Its kind of a pain during troubleshooting, but works well again after you get the hang of it.
Sample Statements:User: Stormtrooper, power up your blaster BLASTER: Power up effect
User: Stormtrooper, set your blaster to stun BLASTER: 'Set for stun'
User: Stormtrooper, stand guard BLASTER: 'You stand guard'
User: Stormtrooper, who is your daddy? BLASTER: 'I am your father'
To create a new Alexa Skill Set, you will need to create
- Service that will process the voice input (AWS Lambda with NodeJS)
- Intent Schema that defines the actions for the voice input
- Sample Utterance file that contains all the possible voice inputs and its corresponding intent.
Below are the sample utterance, intent schema, and slots of the application:
BlasterCommand Power {on|onoff} your blaster
BlasterCommand Power {on|onoff}
BlasterCommand Begin power {on|onoff}
BlasterCommand Power {up|onoff} your blaster
BlasterCommand Power {up|onoff}
BlasterCommand Begin power {up|onoff}
BlasterCommand Power {off|onoff} your blaster
BlasterCommand Power {off|onoff}
BlasterCommand Begin power {off|onoff}
BlasterCommand Power {down|onoff} your blaster
BlasterCommand Power {down|onoff}
BlasterCommand Begin power {down|onoff}
BlasterCommand Set your blaster to {stun|strength}
BlasterCommand All blasters set to {stun|strength}
BlasterCommand Set to {stun|strength}
BlasterCommand Set your blaster to {normal|strength}
BlasterCommand All blasters set to {normal|strength}
BlasterCommand Set to {normal|strength}
BlasterCommand Don't {fail|motivation} me again
BlasterCommand Stand {guard|motivation}
BlasterCommand Who is your {daddy|father}
BlasterCommand Tell me about your {daddy|father}
BlasterCommand Who is your {dad|father}
BlasterCommand Who is {father|father}
HelpIntent help
HelpIntent help me
HelpIntent what can I ask you
HelpIntent get help
HelpIntent to help
HelpIntent to help me
HelpIntent what can you do
HelpIntent what do you do
HelpIntent how do I use you
HelpIntent how can I use you
HelpIntent what can you tell me
{
"intents": [
{
"intent": "BlasterCommand",
"slots": [
{
"name": "onoff",
"type": "LITERAL"
},
{
"name" :"strength",
"type": "LITERAL"
},
{
"name": "motivation",
"type": "LITERAL"
},
{
"name": "father",
"type": "LITERAL"
}
]
},
{
"intent": "HelpIntent",
"slots" : []
}
]
}
As you can see from the above, the application has two intents BlasterCommand and HelpIntent. BlasterCommand is invoked when you tell the Alexa (or Stromtrooper/blaster) to do any of the commands. HelpIntent is invoked when you ask for help.
In the intent schema, you can see slots section. These are the parameters passed to the AWS Lambda function. The values of these parameters are defined in the utterance file. Here you can see these include {stun|strength}, {daddy|father}, etc...
When the Alexa processes your voice input, it invokes AWS skill for all slot specified. The Node.js application is then uses a hosted AWS Lambda functions. You can see each of these files and the Node.js application in the GitHub Repository linked below.
InstallationThese installation steps are taken from one of the Alexa Skill Set sample.
AWS Lambda Setup
- Go to the AWS Console and click on the Lambda link. Note: ensure you are in us-east or you won't be able to use Alexa with Lambda.
- Click on the Create a Lambda Function or Get Started Now button.
- Name the Lambda Function "Stormtrooper_Blaster".
- Go to the the src directory, select all files and then create a zip file, make sure the zip file does not contain the src directory itself, otherwise the Lambda function will not work.
- Upload the .zip file to the Lambda
- Keep the Handler as index.handler (this refers to the main js file in the zip).
- Create a basic execution role and click create.
- Return to the main Lambda page, and click on "Actions" -> "Add Event Source"
- Choose Alexa Skills Kit and click submit.
- Click on your Lambda function name and copy the ARN to be used later in the Alexa Skill Setup
Alexa Skill Setup
- Go to the Alexa Console (https://developer.amazon.com/edw/home.html) and click Add a New Skill.
- Set "Stormtrooper_Blaster" as the skill name and "storm trooper" as the invocation name, this is what is used to activate your skill. For example you would say: "Alexa, tell storm trooper to turn on stand guard"
- Select the Lambda ARN for the skill Endpoint and paste the ARN copied from above. Click Next.
- Copy the Intent Schema from the included IntentSchema.json.
- Copy the Sample Utterances from the included SampleUtterances.txt. Click Next.
- [optional] go back to the skill Information tab and copy the appId. Paste the appId into the index.js file for the variable APP_ID, then update the lambda source zip file with this change and upload to lambda again, this step makes sure the lambda function only serves request from authorized source.
- You are now able to start testing your sample skill! You should be able to go to the Echo webpage (http://echo.amazon.com/#skills) and see your skill enabled.
- In order to test it, try to say some of the Sample Utterances from the Examples section below.
- Your skill is now saved and once you are finished testing you can continue to publish your skill.
Demo
With the time extension for the submissions, I added in one neat feature. I've included an IR LED on the tip of the blaster and wired it to the circuit/logic controlled by the trigger of the blaster. This allows the blaster to 'shoot' at an Arduino powered Stormtrooper as well as power on/off a TV. It's especially useful if someone is watching a show you're not a fan of (see demo's above)...
Comments