Slide 1

Slide 1 text

getting started with the spark core 1

Slide 2

Slide 2 text

2

Slide 3

Slide 3 text

hardware • 72MHz ARM Cortex M3 • TI CC3000 WiFi • 7 analog IO (pwm out), 7 digital IO • ~ S$ 55 • coming soon: Photon, 120MHz, Broadcom Wifi, half the price 3

Slide 4

Slide 4 text

setup, the easy and unreliable way • install smartphone app • power up spark • use smartphone app to create cloud account and register the core 4

Slide 5

Slide 5 text

setup, the better way (USB) npm install spark-cli spark setup 5

Slide 6

Slide 6 text

ready? • your spark core should have a name and be breathing cyan by now 6

Slide 7

Slide 7 text

the tinker firmware • default firmware of spark core • allows access to all inputs/outputs 7

Slide 8

Slide 8 text

let’s ask the cloud export SPARK_CORE_ID=53ff71065075535128311587
 export SPARK_ACCESS_TOKEN=[get this from https://spark.io/ build or “spark login”] 8

Slide 9

Slide 9 text

let’s ask the cloud curl -H "Authorization: Bearer $SPARK_ACCESS_TOKEN” https:// api.spark.io/v1/devices/$SPARK_CORE_ID/
 
 Alternatively include the token in the URL:
 
 https://api.spark.io/v1/devices/$SPARK_CORE_ID/?access_token= $SPARK_ACCESS_TOKEN 9

Slide 10

Slide 10 text

output { "id": "53ff71065075535128311587", "name": "schnitzel", "connected": true, "variables": {}, "functions": [ "digitalread", "digitalwrite", "analogread", "analogwrite" ], "cc3000_patch_version": "1.29" 10

Slide 11

Slide 11 text

using functions curl https://api.spark.io/v1/devices/$SPARK_CORE_ID/ digitalwrite?access_token=$SPARK_ACCESS_TOKEN -d params=D7,LOW or include access_token in POST data: curl https://api.spark.io/v1/devices/$SPARK_CORE_ID/ digitalwrite -d access_token=$SPARK_ACCESS_TOKEN -d params=D7,LOW 11

Slide 12

Slide 12 text

response { "id": "53ff71065075535128311587", "name": "schnitzel", "last_app": null, "connected": true, "return_value": 1 } 12

Slide 13

Slide 13 text

the cloud API • events, functions, variables • http://docs.spark.io/api/ 13

Slide 14

Slide 14 text

the javascript API • runs in browser and in nodejs • (npm|bower) install spark • http://docs.spark.io/javascript/ 14

Slide 15

Slide 15 text

voodoospark • alternative firmware • faster communication through local TCP connection • npm client module • still uses cloud for facilitating local connection 15

Slide 16

Slide 16 text

DIY, noob mode 16

Slide 17

Slide 17 text

DIY, noob mode #2 17

Slide 18

Slide 18 text

DIY spark compile myapp.ino spark flash firmware_1421160254713.bin 18

Slide 19

Slide 19 text

DIY, hardcore mode brew tap PX4/homebrew-px4 brew update brew install gcc-arm-none-eabi-48 brew install dfu-util
 git clone https://github.com/spark/core-firmware.git git clone https://github.com/spark/core-common-lib.git git clone https://github.com/spark/core-communication-lib.git 19

Slide 20

Slide 20 text

DIY, hardcore mode 20

Slide 21

Slide 21 text

DIY, hardcore mode cd core-firmware/build make 21

Slide 22

Slide 22 text

flash via USB • press&hold mode button, tap and release RST button until LED flashes yellow • spark core is now in DFU mode 22

Slide 23

Slide 23 text

flash via USB make program-dfu 23

Slide 24

Slide 24 text

flash via cloud make program-cloud 24

Slide 25

Slide 25 text

create your own app mkdir core-firmware/applications/myapp vim core-firmware/applications/myapp/application.cpp cd core-firmware/build make APP=myapp make APP=myapp program-dfu # or program-cloud 25

Slide 26

Slide 26 text

app structure #include "application.h"
 int example(String command); void setup(){ // set up cloud functions & variables, IO pin modes Spark.function("example", example); pinMode(D7, OUTPUT); } void loop(){ // called continuously } int example(String command){ digitalWrite(D7, HIGH); delay(2000); digitalWrite(D7, LOW); return 1; } 26

Slide 27

Slide 27 text

app structure { "id": "53ff71065075535128311587", "name": "schnitzel", "connected": true, "variables": {}, "functions": [ "example" ], "cc3000_patch_version": "1.29" 27

Slide 28

Slide 28 text

documentation • http://docs.spark.io/firmware/ 28

Slide 29

Slide 29 text

my current project 29

Slide 30

Slide 30 text

my current project • websockets • static site hosted on S3 • direct connection from browser to spark • https://github.com/ponyfleisch/cloudlamp 30