<jupyter_start><jupyter_text>*This notebook contains material from [cbe61622](https://jckantor.github.io/cbe61622);content is available [on Github](https://github.com/jckantor/cbe61622.git).*     7.2 Stepper Motor Control via I2C  7.2.1 Particle CLI  7.2.1.1 Installation<jupyter_code>%%capture
!bash <( curl -sL https://particle.io/install-cli )

# path to the particle cli. May be environment dependent.
particle_cli = "/root/bin/particle"<jupyter_output><empty_output><jupyter_text>7.2.1.2 Utility functions<jupyter_code>import re
import subprocess

# regular expression to strip ansi control characters
ansi = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')

# decode byte string and strip ansi control characters
def decode_bytes(byte_string):
    if isinstance(byte_string, bytes):
        result = byte_string.decode("utf-8")
    return ansi.sub("", result)

# streamline call to the particle-cli
def particle(args):
    process = subprocess.run(["/root/bin/particle"] + args,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
    process.stdout = decode_bytes(process.stdout)
    process.stderr = decode_bytes(process.stderr)
    return process<jupyter_output><empty_output><jupyter_text>7.2.1.3 Login to Particle<jupyter_code>import getpass

# prompt for username and password
username = getpass.getpass(prompt="Username: ")
password = getpass.getpass(prompt="Password: ")

# attempt login
output = particle(["login", "--username", username, "--password", password])

# report results
if output.returncode:
    print(f"Return code = {output.returncode}")
    print(output.stderr)
else:
    print(output.stdout)<jupyter_output>Username: ··········
Password: ··········
> Successfully completed login!<jupyter_text>7.2.1.4 Select a deviceThe following cell downloads a list of all user devices and creates a list of device names. Here we choose the first name in the list for the rest of this notebook. If this is not the device to be used, then modify this cell accordingly.<jupyter_code>devices = [line.split()[0] for line in particle(["list"]).stdout.splitlines()]
device_name = devices[0]
print(particle(["list", device_name]).stdout)<jupyter_output>jck_argon_01 [e00fce68eaceb1faa7cf7193] (Argon) is online<jupyter_text>7.2.2 Project: Motor Control  7.2.2.1 Grove I2C Motor Driver V1.3[SeeedStudio Documentation](https://wiki.seeedstudio.com/Grove-I2C_Motor_Driver_V1.3/)[Github repository](https://github.com/Seeed-Studio/Grove_I2C_Motor_Driver_v1_3)![](https://files.seeedstudio.com/wiki/Grove-I2C_Motor_Driver_V1.3/img/I2CMotorDriver-1.jpg)Note the default address ``0x0f``.** It turns out this motor driver requires a 5 volt logic. The Particle Argon is capable of 3.3v only, thus not electrically compatible. This is confirmed by the absence of a code library supporting this motor driver on Particle Argon.****New motor drivers are on order.**  7.2.3 Prototype  7.2.3.1 Create Project<jupyter_code>print(particle(["project", "create", "--name", "myproject", "."]).stdout)<jupyter_output>Initializing project in directory myproject...
> A new project has been initialized in directory myproject<jupyter_text>7.2.3.2 Change working directoryThe Particle CLI assumes one is working in the top  project directory.<jupyter_code>%cd myproject<jupyter_output>/content/myproject<jupyter_text>7.2.3.3 Add relevant libraries<jupyter_code>print(particle(["library", "search", "motor"]).stdout)
print(particle(["library", "add", "Grove_I2C_Motor_Driver_v1_3"]).stdout)<jupyter_output>Library Grove_I2C_Motor_Driver_v1_3 not found<jupyter_text>7.2.3.4 Create source file<jupyter_code>%%writefile src/myproject.ino<jupyter_output>Overwriting src/myproject.ino<jupyter_text>7.2.3.5 Compiling<jupyter_code>print(particle(["compile", "argon", "--saveTo", "myproject.bin"]).stdout)<jupyter_output>Compiling code for argon

Including:
    src/myproject.ino
    project.properties

attempting to compile firmware
downloading binary from: /v1/binaries/5f91c30f9c09c651a428aa51
saving to: myproject.bin
Memory use:
   text	   data	    bss	    dec	    hex	filename
   6588	    108	   1112	   7808	   1e80	/workspace/target/workspace.elf

Compile succeeded.
Saved firmware to: /content/myproject/myproject.bin<jupyter_text>7.2.3.6 Flash firmware<jupyter_code>print(particle(["flash", device_name, "myproject.bin"]).stdout)<jupyter_output>Including:
    myproject.bin

attempting to flash firmware to your device jck_argon_01
Flash device OK: Update started

Flash success!
{'fraction_non_alphanumeric': 0.12215595316986967, 'fraction_numerical': 0.03313452617627568, 'mean_word_length': 5.185792349726776, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 35, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 11, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '213967', 'license': 'MIT', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1513, 'n_words': 358, 'path': 'docs/07.02-Stepper_Motor_Control_via_I2C.ipynb', 'repo_name': 'jckantor/cbe61622', 'size': '4527'}