spark core – a diy guide for kingmakers spark core development is arduino-like (gotcha is: most...
TRANSCRIPT
![Page 1: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/1.jpg)
SPARK CORE – A DIY guide for KingMakers
http://www.spark.io
KANDARP JANI ([email protected])
DAN TEBBS
![Page 2: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/2.jpg)
What is the Spark Core?
A Wi-Fi based module for connecting sensors, controllers and other gizmos to the Internet.
The Core includes the powerful STM32F103CB ARM 32-bit Cortex™-M3 CPU Core 72Mhz operating frequency, 1.25 DMIPS/MHz (Dhrystone 2.1) 128KB of Flash memory 20KB of SRAM 12 bit ADC USB 2.0 full-speed interface USART, SPI and I2C interfaces JTAG Debug mode
Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting)o Small, low-cost, low-power computer that can run a single application.o Has a set of "pins" GPIO (General Purpose Input and Output) pins, both digital and analog.
D0 to D7 A0 to A7
o Supports Serial (also called UART), SPI, or I2C (also called Wire).
![Page 3: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/3.jpg)
Has a Wi-Fi module, Uses “SmartConfig” to receive SSID & Password from the Spark Core Phone App
Connects it to your local Wi-Fi network using the SSID/Password
Establishes a connection to the Spark Cloud. (REST API)
![Page 4: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/4.jpg)
Buttons
The RESET button
- Put the Core in a hard reset, effectively powering down and then re-powering the micro-controller
The MODE Button
- Smart Config mode
- Clear the Wifi-Network’s from Core’s memory
- Bootloader mode for flashing new firmware via USB
- Factory reset mode for bringing the core to original firmware
![Page 5: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/5.jpg)
LEDs- The small blue LED is the user LED. It is connected to D7.
- The larger LED in the middle is a full-color RGB LED which always shows the status of the Core's Wi-Fi / internet connection.
The RGB LED states:
Flashing blue Listening mode, waiting for network information.
Solid blue Smart Config complete, network information found.
Flashing green Connecting to local Wi-Fi network.
Flashing cyan Connecting to Spark Cloud.
High-speed flashing cyan Spark Cloud handshake.
Slow breathing cyan Successfully connected to Spark Cloud.
Flashing magenta Updating firmware.
![Page 6: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/6.jpg)
Pins
![Page 7: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/7.jpg)
SETUP - Step 1 - Phone or Tablet
Setting up Spark on Phone
1. Go to the Google Play Store or iPhone apps
2. Search for “Spark Core”
a. https://play.google.com/store/apps/details?id=io.spark.core.android
3. Install the app.
4. Sign up for an account simply using an email address.
![Page 8: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/8.jpg)
SETUP - Step 2 - Core1. Power the Core
2. Make sure it is blinking blue.a. If not - Hold down the MODE button until it starts blinking blue, then continue.
![Page 9: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/9.jpg)
SETUP - Step 3 – WIFI / CLAIMING1. Make sure your phone is connected to the WiFi you want to use
2. Click on the wifi button in the app
3. SSID of the phone should show up on the app
4. Enter your password and
5. click CONNECT!
6. Be PATIENT , Observe the RGB LED on your core
7. If this works, you have now “claimed” this core and only your account has access to it.
This may take a little while- but be patient. It should go through the following colors:
![Page 10: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/10.jpg)
The RGB LED states:
Flashing blue Listening mode, waiting for network information.
Solid blue Smart Config complete, network information found.
Flashing green Connecting to local Wi-Fi network.
Flashing cyan Connecting to Spark Cloud.
High-speed flashing cyan Spark Cloud handshake.
Slow breathing cyan Successfully connected to Spark Cloud.
Flashing magenta Updating firmware.
![Page 11: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/11.jpg)
SETUP - Step 4 - The Tinker Screen
![Page 12: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/12.jpg)
LETS TINKER
Blink an LED with Tinker
1. Tap D7
2. Then digitalWrite in the popup.
3. Then tap the D7 circle
The tiny blue LED should turn off and on.
![Page 13: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/13.jpg)
SETUP - Step 5 - Web IDE
Go to Spark.io/build1. Sign in using the same user name ID (email) you used earlier.
![Page 14: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/14.jpg)
See Your Core Via The Web
1. CLICK on the on the bottom left
2. CLICK on the > (GREATER THAN ICON)
3. Device ID: identifies the device uniquely
![Page 15: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/15.jpg)
![Page 16: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/16.jpg)
Blink Your LED via THE WEB
1. Click on the “CODE” ICON
2. Click "BLINK AN LED" under the Example apps title.
3. Brings up the familiar Arduino IDE like Code environment.
![Page 17: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/17.jpg)
4. Click FORK THIS SAMPLE
![Page 18: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/18.jpg)
FLASH THE FIRMWARE FROM THE CLOUD 1. Click on verify if you want to verify that the code compile s
2. Click on the flash button
3. Spark Cores should start flashing magenta, then more magenta, then green, then cyan (fast), then cyan (breathing)
![Page 19: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/19.jpg)
Cloud Functions
REST API (Cloud API ) 1. Allows reading the value of a variable exposed in the spark firmware via the Cloud using
“HTTP GET”
GET /v1/devices/{DEVICE_ID}/{VARIABLE}.
2. Allows calling a function that you implement in the spark firmware via the Cloud using
“HTTP POST”
POST /v1/devices/{DEVICE_ID}/{FUNCTION}
![Page 20: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/20.jpg)
Reading a variable from Spark Core via the Cloud
Step 1: Expose the Variable via Spark.variable()
Expose a variable through the Spark Cloud so that it can be called with:
// EXAMPLE USAGE
int analogvalue = 0;
double tempC = 0;
char *message = "my name is spark";
void setup()
{
// variable name max length is 12 characters long
Spark.variable("analogvalue", &analogvalue, INT);
Spark.variable("temp", &tempC, DOUBLE);
Spark.variable("mess", message, STRING);
pinMode(A0, INPUT);
}
void loop()
![Page 21: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/21.jpg)
{
// Read the analog value of the sensor (TMP36)
analogvalue = analogRead(A0);
//Convert the reading into degree celcius
tempC = (((analogvalue * 3.3)/4095) - 0.5) * 100;
delay(200);
}
![Page 22: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/22.jpg)
STEP 2: Get your API TOKEN.
![Page 23: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/23.jpg)
STEP 3: Read from the Cloud OPTION 1: http://jflasher.github.io/spark-helper/
1. Enter your CORE ID
2. Enter your API Token
![Page 24: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/24.jpg)
STEP 3: Read from the Cloud with CURL
OPTION 2: USE CURL
1. Download : http://curl.haxx.se/dlwiz/
2. Open cmd.exe on windows and run the following commands
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl "https://api.spark.io/v1/devices/0123456789abcdef/analogvalue?access_token=123412341234"
curl "https://api.spark.io/v1/devices/0123456789abcdef/temp?access_token=123412341234"
curl "https://api.spark.io/v1/devices/0123456789abcdef/mess?access_token=123412341234"
# In return you'll get something like this:
960
27.44322344322344
my name is spark
![Page 25: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/25.jpg)
Calling a function on Spark Core via the Cloud
Spark.function()
Expose a function through the Spark Cloud so that it can be called with POST device/{FUNCTION}.
int brewCoffee(String command);
void setup()
{
// register the Spark function
Spark.function("brew", brewCoffee);
}
void loop()
{
// this loops forever
}
// this function automagically gets called upon a matching POST request
![Page 26: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/26.jpg)
int brewCoffee(String command)
{
// look for the matching argument "coffee" <-- max of 64 characters long
if(command == "coffee")
{
// do something here
activateWaterHeater();
activateWaterPump();
return 1;
}
else return -1;
}
COMPLEMENTARY API CALL
POST /v1/devices/{DEVICE_ID}/{FUNCTION}
# EXAMPLE REQUEST
curl https://api.spark.io/v1/devices/0123456789abcdef/brew \
-d access_token=123412341234 \
-d "args=coffee"
![Page 27: SPARK CORE – A DIY guide for KingMakers Spark Core Development is Arduino-like (gotcha is: most libs won't work without porting) o Small, low-cost, low-power computer that can run](https://reader030.vdocument.in/reader030/viewer/2022040820/5e68e232a3f8b7621b64b855/html5/thumbnails/27.jpg)
Appendix – TroubleshootingWi-Fi Setup -
It needs to be blinking blue before attempting setup, but it is green or cyan:
Hold down the Mode Button for 10 sec.
The LED will change to blue.
The LED will do several quick flashes.
At this point it is ready for a Wi-Fi Setup attempt.
The core never progresses past the blinking green stage:
Did you select the right Wi-Fi network SSID?
Did you use the correct password for that network?
Is your phone/tablet device already connected to that network?
Claiming the Core -
The core is slow blinking cyan, but still doesn't show in the app:
This can happen if the core is already claimed on someone else's account.
Have that person sign in to the app, and release that core.
Then try again to claim the core from your own app and account.