Coding for Particle
Contents
Coding for Particle#
Installation of the Particle command line interface#
%%capture
!bash <( curl -sL https://particle.io/install-cli )
Login to Particle#
import getpass
import subprocess
particle_cli = "/root/bin/particle"
username = getpass.getpass(prompt="Username: ")
password = getpass.getpass(prompt="Password: ")
process = subprocess.run([particle_cli, "login",
"--username", username,
"--password", password],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if process.stderr.decode("utf-8"):
print(process.stderr.decode("utf-8"))
else:
print(f"Successfully logged in to Particle Device Cloud as {username}")
process = subprocess.run([particle_cli, "list"], stdout=subprocess.PIPE)
print(process.stdout.decode("utf-8"))
Username: ··········
Password: ··········
Successfully logged in to Particle Device Cloud as kantor.1@nd.edu
jck_argon_01 [e00fce68eaceb1faa7cf7193] (Argon) is online
device_name = "jck_argon_01"
Blinking LED Demo#
Blinking LED Code#
%%writefile blink.ino
int led = D7;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(800);
}
Overwriting blink.ino
Compiling#
process = subprocess.run([particle_cli, "compile", "argon", "blink.ino", "--saveTo", "blink.bin"],
stdout=subprocess.PIPE)
print(process.stdout.decode("utf-8"))
Compiling code for argon
Including:
blink.ino
attempting to compile firmware
downloading binary from: /v1/binaries/5f8e4e0fbbdad933df7dedb8
saving to: blink.bin
Memory use:
text data bss dec hex filename
5708 112 1060 6880 1ae0 /workspace/target/workspace.elf
Compile succeeded.
Saved firmware to: /content/blink.bin
Flashing binary to device#
process = subprocess.run([particle_cli, "flash", device_name, "blink.bin"], stdout=subprocess.PIPE)
print(process.stdout.decode("utf-8"))
Including:
blink.bin
attempting to flash firmware to your device jck_argon_01
Flash device OK: Update started
Flash success!