39

#startathon2.0 - Spark Core

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

Page 1: #startathon2.0 - Spark Core
Page 2: #startathon2.0 - Spark Core

Spark Core

Page 3: #startathon2.0 - Spark Core

Spark Core?

Page 4: #startathon2.0 - 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

Page 5: #startathon2.0 - Spark Core

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).

Page 6: #startathon2.0 - Spark Core

Comparison between

Page 7: #startathon2.0 - Spark Core

Setup Requirement

USB

Page 8: #startathon2.0 - Spark Core

Examples

Page 9: #startathon2.0 - Spark Core

Examples

Page 11: #startathon2.0 - Spark Core

Web IDE -Arduino-ish Programming

Page 12: #startathon2.0 - Spark Core

Before starting

• Visit http://docs.spark.io/start/to setup your Spark Core for the first time.

Page 13: #startathon2.0 - Spark Core

Web IDE

• Go to: https://www.spark.io/build or https://www.spark.io/login

• For more info visit http://docs.spark.io/build/

Page 14: #startathon2.0 - Spark Core

Arduino basics

• See examples at http://docs.spark.io/examples/

• Breadboard connection in RED

Page 15: #startathon2.0 - Spark Core

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

Page 16: #startathon2.0 - Spark Core

Wireless Communication

Page 17: #startathon2.0 - Spark Core

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

Page 18: #startathon2.0 - Spark Core

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

Page 19: #startathon2.0 - Spark Core

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

Page 20: #startathon2.0 - Spark Core

One question...

• What do you need to know before creating your own user interface or tool to remotely control and monitor your Spark Core?

Page 21: #startathon2.0 - 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]

Page 22: #startathon2.0 - Spark Core

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

Page 23: #startathon2.0 - Spark Core

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.

Page 24: #startathon2.0 - Spark Core

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

Page 25: #startathon2.0 - Spark Core

Get Variables on Spark Core (Cont.)

Inputs: external variable name,

variable address, data type

Don’t forget to Flash Device!

Page 26: #startathon2.0 - Spark Core

• 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.)

Page 27: #startathon2.0 - Spark Core

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

Page 28: #startathon2.0 - Spark Core

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

Page 29: #startathon2.0 - Spark Core

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

Page 30: #startathon2.0 - Spark Core

Call Function on Spark Core (Cont.)

Page 31: #startathon2.0 - Spark Core

• 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.)

Page 32: #startathon2.0 - Spark Core

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)?

Page 33: #startathon2.0 - Spark Core

UI for the Spark Core -Ideas for making a front end

Page 34: #startathon2.0 - Spark Core

Spark-CLI

• http://docs.spark.io/cli/

Page 36: #startathon2.0 - Spark Core

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

Page 37: #startathon2.0 - Spark Core

MIT App Inventor

• http://appinventor.mit.edu/explore/

Page 38: #startathon2.0 - Spark Core

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!

Page 39: #startathon2.0 - 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”+