Upload
sl2square
View
582
Download
1
Embed Size (px)
DESCRIPTION
These slides were presented at the #startathon2.0 pre-workshop on 20 September covering technology topics. For more information, please contact [email protected].
Citation preview
Spark Core
Spark Core?
Spark Core
• What is it?
• Why is it special?
• How is it implemented?
WiFi on the front ARM on the back
For more info visit https://www.spark.io/dev-kits
Specs
• 8 digital, 8 analog I/O pins• PWM, UART, SPI, I2C, and JTAG • Programmed wirelessly
(through Spark Cloud), via USB or JTAG.
• 3.3V DC supply voltage (on board power regulator), USB Mini A powered.
• Low power consumption (300 mA).
Comparison between
Setup Requirement
USB
Examples
Examples
Youtube Examples
• Wolowitz Lamp - http://www.youtube.com/watch?v=BW9FbjjkKo4
• RC Car- http://www.youtube.com/watch?v=D6k7bMYXRiU
• Snake game - http://www.youtube.com/watch?v=7EJ-d9rizAE
• RFID Locker - http://www.youtube.com/watch?v=BLVLL3qkTlU
Web IDE -Arduino-ish Programming
Before starting
• Visit http://docs.spark.io/start/to setup your Spark Core for the first time.
Web IDE
• Go to: https://www.spark.io/build or https://www.spark.io/login
• For more info visit http://docs.spark.io/build/
Arduino basics
• See examples at http://docs.spark.io/examples/
• Breadboard connection in RED
Arduino coding
• Input - pinmode(#,INPUT);
– digitalRead();
– analogRead();
• Output - pinmode(#,OUTPUT);
– digitalWrite();
– analogWrite();
• Variable (data types)
– Container for data
– int, float, char, string
• Function
– void setup() {...}
– int digitalRead() {...}
To learn more about coding in arduino, visit
http://www.arduino.cc
Wireless Communication
Communicating with your Spark Core
• What medium and protocol?
• Why communications protocols?
• How to use protocols?
Internet & HTTPProtocol system of digital rules
for data exchange
Is a technical standard, a common language
HTTP GET & POST methods
• HTTP = Hyper Text Transfer Protocol
– Enables communication between client and server
– A request-response protocol
• HTTP requests
– GET = request data from resource
– POST = request to send data to resource
Default action of the address bar in
browser
Requirement for remote Spark Core
• Expose internal variables or function to cloud• Spark.variabe(“*exposed name+”, &*internal variable+,*data type+);
• Spark.function(“*exposed name+”, [internal function]);
• A tool or user interface to remotely interact with Spark Core
• jFlasher for spark core, http://jflasher.github.io/spark-helper/
• Spark App on mobile device
One question...
• What do you need to know before creating your own user interface or tool to remotely control and monitor your Spark Core?
How to use HTTP GET – The Easy Way
• Easy way
– Open browser
– Type in address bar (be sure to include https://) : https://www.google.com
• Accessing Spark Core status:– https://api.spark.io/v1/devices/?access_token=[Your Access Token]
How to use HTTP GET – The Cool Way
• Cool way ( The Pro’s Way)
– For Google Chrome browser (recommended): google search for “advanced rest client” and click the “+Free” button
How to use HTTP GET – The Cool Way (Cont.)
• How to use GET to check Spark Core Connection?
– Type in browser address bar:
https://api.spark.io/v1/devices/[Device ID]/?access_token=[Access Token]
e.g. https://api.spark.io/v1/devices/4...7/?access_token=5...5
– You can do the same in the REST client with Get checked.
Get Variables on Spark Core
• Easiest way to obtain variables on the Spark Core is to:
1. Expose the variable to the cloud
2. Use the HTTP Get method to request for variable
Get Variables on Spark Core (Cont.)
Inputs: external variable name,
variable address, data type
Don’t forget to Flash Device!
• How to get variable?
– Same as before, type in browser or REST Client: https://api.spark.io/v1/devices/[Device ID]/[External Variable]?access_token=[Access Token]
e.g. https://api.spark.io/v1/devices/4...7/exposed_dly?access_token=5...5
Get Variables on Spark Core (Cont.)
How to use HTTP POST
• Can you POST through address bar in browser?
– Query strings ≠ POST variables
• When to use POST method?
– Sending parameters e.g. params=“Hello World”
– Sending large chunks of data e.g. files, webpages, etc...
• Example of using POST Method
How to use HTTP POST (Example)
• Open Advance REST client
– Type: https://www.posttestserver.com/post.php
– In payload text box, type: params=“Hello my name is...”
Don’t forget to check
POST
Call Function on Spark Core
• Calling functions on the Spark Core requires POST method:
1. Expose the function to the cloud
2. Use the HTTP Post method to call the function
Same Example
Call Function on Spark Core (Cont.)
• Calling the function through the internet
– In REST Client, type: https://api.spark.io/v1/devices/[Device ID]/[Exposed Function name]?access_token=[Access Token]
e.g. https://api.spark.io/v1/devices/4...7/chgDlyFunc?access_token=5...5
– In the Payload field, type:
params=[An integer value]
e.g. params=200
Call function on Spark Core (Cont.)
So now what?
• On Chip
– Learn to use Web IDE
– Flash the core with an Arduino Sketch
– Read sensors and activate actuators
• Off Chip
– Ask for an exposed variable
– Run a function remotely
• What about a UI (User Interface)?
UI for the Spark Core -Ideas for making a front end
jFlasher
• http://jflasher.github.io/spark-helper/
Spark Mobile App
• Android/IPhone user:
– Download from Google Play/App Store – Spark Core App by Spark Labs
– Make sure Thinker is flashed into Spark Core using app
MIT App Inventor
• http://appinventor.mit.edu/explore/
Thank you!
Here’s how you can get connected:
1 Facebook page: www.facebook.com/sl2square
“Maker Circle” Facebook group
Email Farah at [email protected]
2
3
Q & A or Start playing with your Spark Core!
Important Points (Summary)• Tutorials, examples, help, and get started:
– https://docs.spark.io/
• The web IDE:– https://www.spark.io/build
• Spark API:– http://docs.spark.io/api/
• Request list of available cores:• GET https://api.spark.io/v1/devices/?access_token=[Your Access Token]
• Request status of core:• GET https://api.spark.io/v1/devices/[Device ID]/?access_token=[Access Token]
• Request variable of core:• GET https://api.spark.io/v1/devices/[Device ID]/[Exposed Variable]?access_token=[Access Token]
• Activate function in core:• POST https://api.spark.io/v1/devices/[Device ID]/[Exposed Function]?access_token=[Access Token]
• Payload: params=*value or “string”+