A while ago I backed the kickstarter campaign for Particle (formerly Spark)’s Electron board, a IOT (internet of things) with a built in 3G modem (2G are available) with global data coverage, recently they shipped,

Setup was as easy as getting it out the box, wiring it up and following the instructions on setup.particle.io (mine is set up using my awsome Mondo card) it offered me the name “nimble-aardvark”.

Once the board is powered up and connected, you get navigated to build.particle.io where you are prompted to start a new project (there is an IDE available on the at Dev Site, but no way as far as I can see of using the Arduino IDE), It is also worth checking out spark.github.io for additional things.

I have downloaded the Local Dev App (still requires web access to do compilation of code), it appears to be a customised version of the Atom text editor.

Particle Dev

Particle Dev

Using the Small bag of parts provided, and the sheet on the solderless breadboard (read the pin assignment as the holes don’t match up) I have wired it up as specified.

Wired up and Powered on

Wired up and Powered on

I loaded up the web IDE (and pulled up the docs) and flashed the example “Blink an LED” to the Particle Electron, the example as provided lists the second LED as on Pin0 when its acctuly on Pin6, so replace line 28:

int led1 = D0; // Instead of writing D0 over and over again, we'll write led1

with

int led1 = D6; // Instead of writing D6 over and over again, we'll write led1

Then click on the button to Flash the code to the device

Options to flash over USB or via 3G

Options to flash over USB or via 3G

Which is all very good, but I can do this with an Arduino… so moving quickly on to using the backhaul for something exciting (I mean I may want to flash an LED in a different country where there is no access to WiFi).

So for turning an LED on and Off over the internet we use this example code:

// -----------------------------------
// Controlling LEDs over the Internet
// -----------------------------------

/* First, let's create our "shorthand" for the pins
Same as in the Blink an LED example:
led1 is D6, led2 is D7 */

int led1 = D6;
int led2 = D7;

// Last time, we only needed to declare pins in the setup function.
// This time, we are also going to register our Particle function

void setup()
{

   // Here's the pin configuration, same as last time
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);

   // We are also going to declare a Particle.function so that we can turn the LED on and off from the cloud.
   Particle.function("led",ledToggle);
   // This is saying that when we ask the cloud for the function "led", it will employ the function ledToggle() from this app.

   // For good measure, let's also make sure both LEDs are off when we start:
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);

}


/* Last time, we wanted to continuously blink the LED on and off
Since we're waiting for input through the cloud this time,
we don't actually need to put anything in the loop */

void loop()
{
   // Nothing to do here
}

// We're going to have a super cool function now that gets called when a matching API request is sent
// This is the ledToggle function we registered to the "led" Particle.function earlier.

int ledToggle(String command) {
    /* Particle.functions always take a string as an argument and return an integer.
    Since we can pass a string, it means that we can give the program commands on how the function should be used.
    In this case, telling the function "on" will turn the LED on and telling it "off" will turn the LED off.
    Then, the function returns a value to us to let us know what happened.
    In this case, it will return 1 for the LEDs turning on, 0 for the LEDs turning off,
    and -1 if we received a totally bogus command that didn't do anything to the LEDs.
    */

    if (command=="on") {
        digitalWrite(led1,HIGH);
        digitalWrite(led2,HIGH);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(led1,LOW);
        digitalWrite(led2,LOW);
        return 0;
    }
    else {
        return -1;
    }
}

I have put the following HTML code at Skippy.org.uk/led.html:

<html>
<head>
<title>Skippy's LED</title>
</head>
<body>
<center>
<br>
<br>
<br>
<form action="https://api.particle.io/v1/devices/nimble-aardvark/led?access_token=lalala" method="POST">
Tell my LED what to do!<br>
<br>
<input type="radio" name="args" value="on">Turn the LED on.
<br>
<input type="radio" name="args" value="off">Turn the LED off.
<br>
<br>
<input type="submit" value="Do it!">
</form>
</center>
</body>
</html>

I will have a further play, as I have five of these in total.