Arduino Module

This module provides several functions to download the arduino-cli and install firmware on an Arduino board.

automationshield.arduino.LEONARDO: str = 'arduino:avr:leonardo'

FQBN for Arduino Leonardo.

automationshield.arduino.UNO: str = 'arduino:avr:uno'

FQBN for Arduino UNO.

automationshield.arduino.MEGA: str = 'arduino:avr:mega'

FQBN for Arduino MEGA and MEGA 2560.

automationshield.arduino.src_dir: Path

Path to the automationshield src directory on the system.

automationshield.arduino.script_dir: Path

Path to the directory containing the Arduino script directories.

automationshield.arduino.out_dir: Path

Path to the directory containing the .hex files.

automationshield.arduino.cli_dir: Path

Path to the directory containing the arduino-cli.

automationshield.arduino.cli_path: Path

Path to the arduino-cli executable.

automationshield.arduino.download_cli(system: str)[source]

Download the arduino-cli for the appropriate system. The executable is placed in cli_dir.

Parameters:

system (str) – Name of operating system. Result of calling platform.system().

automationshield.arduino.setup_cli()[source]

Run setup for arduino-cli. This function calls the following methods of the arduino-cli:

1arduino-cli core update-index
2arduino-cli core install arduino:avr

These respectively update the index of cores to the latest version and downloads the core for AVR boards, which includes a.o. the Arduino UNO, Mega (2560) and Leonardo.

automationshield.arduino.compile_script(device: str, script: str)[source]

Compile an Arduino script for a specific Arduino board and Automationshield.

1arduino-cli compile
2    --fqbn {device}
3    --clean
4    --libraries {arduino.script_dir}/lib
5    --export-binaries
6    {arduino.script_dir}/{script}
Parameters:
  • device (str) – FQBN of Arduino board.

  • script (str) – Directory name of the Arduino code to be installed. Script directory are provided as a property of the shield classes, e.g.: automationshield.AeroShield.script.

automationshield.arduino.upload_script(device: str, script: str, port: str, hex: str | None = None)[source]

Upload compiled script onto Arduino board.

1arduino-cli upload
2    --input-file {file}
3    --fqbn {device}
4    --port {port}
5    {arduino.script_dir}/{script}

In the command, the file argument points to the appropriate .hex file in arduino.out_dir. This can be overridden by providing the hex argument.

Parameters:
  • device (str) – FQBN of Arduino board.

  • script (str) – Directory name of the Arduino code to be installed. Script directory are provided as a property of the shield classes, e.g.: automationshield.AeroShield.script.

  • port (str) – Port where the Arduino board is connected. Shield classes provide a port attribute that can be used.

  • hex (str | None) – .hex file to upload. Optional, defaults to the appropriate file in out_dir.