What are we Making?
Let's get ready to make our very own automated laser pointer (pictured above). This laser pointer can be activated remotely from your computer. In this tutorial, we'll be grabbing the software needed to make this work and installing it on the Raspberry PI and Arduino. We'll also be setting up the IoT service in AWS. The CAD files are also included so you can 3D print the case.
SlidesThe associated slides from my presentation on AWS IoT & Lambda can be found here for reference. They contain additional details about creating a Lambda function and the IoT service.
http://www.slideshare.net/LisaKester/aws-iot-lambda
Getting StartedFirst, gather all the materials. There's a listing of them below.
Steps Overview- Install servo program on Arduino
- Setup Raspberry Pi
- Install ARM 7 libraries
- Install pip
- Install AWS Cli
- Install AWS IoT Node.js SDK
- Create Thing on AWS IoT
- Create policy
- Get certificates
- Create configuration.json file
- 3D print laser device cover and assemble it
- Connect the various devices with the jumper wires
- Run the main program on the Pi
- Send start message with the AWS console
Download the source code and open the Arduino IDE from your computer. Install it if you need to. Connect your Arduino via a USB cable to the computer. Then compile and send the program to your computer.
First, you need to install NodeJS if it isn't already installed. Here's how:
- Go to The NodeJS website and download the ARM 7 binaries for linux
- Remote into the pi via WinSCP and copy the ARM 7 binaries to the root folder on the pi
- Use Putty to terminal into the PI. (You can activate Putty through WinSCP if you point to it in the settings. Then you won't have to setup the login twice).
- Install NodeJS: http://blog.wia.io/installing-node-js-v4-0-0-on-a-raspberry-pi/
- Download the AWS IoT Node.js SDK.
- Set up the SDK using the instructions from GitHub: https://github.com/aws/aws-iot-device-sdk-js#install
- Download the root-CA.crt from the documentation. You'll need it later.
There's also some good documentation about the configuration.json file in the Certificate Configuration section, but I'll give you an example to work with so you don't have to read it all.
Install AWS Clihttp://docs.aws.amazon.com/cli/latest/userguide/installing.html
You may need to install pip before you install the cli. Here's the command for that:
sudo apt-get install python-pip
Install the aws cli:
sudo pip install awscli
Setup Device on AWS IoTCreate a Thing on AWS IoT- Log in to the AWS console
- Go to the IoT service
- Click on "Create Resource"
- Click on "Create a thing"
- Name it "Laser"
Go to "Create a certificate" and use 1 click to certificate.
Download ALL the certificates that were just created. You can't access some of them after this!
Go to create policy and enter in the information below.
Click Add Statement and then click Create.
Example:
{
"host": "A3RFJD6U2VK2IZ.iot.us-east-1.amazonaws.com",
"port": 8883,
"clientId": "Laser",
"thingName": "Laser",
"caCert": "./lib/keys/rootCA.pem",
"clientCert": "./lib/keys/a09a5452f3-certificate.pem.crt",
"privateKey": "./lib/keys/a09a5452f3-private.pem.key"
}
- Replace the host with the information in the IoT console. If you go to your "Thing," some details should show up on the right and your should be able to get the host information from there.
- ClientId and thingName should be the same - the name you used for your "Thing"
- The caCert is something you download from the github page for the JavaScript Node IoT SDK.
- The other two certificates were downloaded when you created your "Thing" earlier.
- You'll need to access this file when you run the main program JavaScript program.
You'll need to 3D print the laser case. The CAD files are in multiple formats so you should be able to print them. There's a number of pieces. You can superglue most of them together. You'll probably need some screws for the servos.
Once you've assembled the case, just snap in the laser. If you want the laser to stay on (and it's like mine), you can hold down the button and rotate it just until the clasp holds the button down.
Connect the Various Devices with Jumper WiresThe Raspberry Pi connects to the Arduino to send the control signals. I used pin 11 on the Raspberry Pi. That hooked up to the Arduino with pin 2. The servos were connected to the Arduino with pins 9 and 10.
If you look up the Arduino uno and Raspberry Pi 2, you should be able to find some images of the pins. Be careful with the Raspberry Pi as you might burn it out if you plug in the wrong wires. The Arduino is more forgiving. Additionally, for the servos, there is a bread board between the laser case and the Arduino. This was used because of the (lack of) available power slots.
Finally, plug the Arduino into the computer via USB (or to a good power source). If you don't have enough power, the device will die when it starts to move the servos.
Run the Main Program on the PINext you need to grab the python script, your certificates, configuration.json file, and the JavaScript program. Put them all on your Raspberry Pi. The easiest place to run them from is the example folder for the AWS IoT SDK, because that has all the dependencies already installed and accessible. Just put them in the same directory as the echo-example.js file.
To run the program, use this command at the command prompt:
sudo node laserListener.js -F ./lib/keys/configuration.json --thing-name Laser
If the paths are all correct in your configuration.json file, this should setup the laser to receive commands.
Login to the AWS IoT console again. Click on your thing, go to the details, and update the state of your thing. You need to set the state to "on" like this:
Comments