Last active
January 15, 2024 05:15
-
-
Save chriscummings/9651c384cc34fe477a15bf2cd46f2b51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import RPi.GPIO as GPIO | |
import subprocess | |
from glob import glob | |
import time | |
path_to_arduino_cli = "/home/chris/bin/arduino-cli" | |
path_to_avrdude = "/home/chris/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" | |
#========================================================= | |
target_path = sys.argv[1] | |
# Configure GPIO pins | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(4, GPIO.OUT) | |
# Delete old compiled sketches | |
subprocess.run(["rm", "-rf", "/tmp/arduino/sketches/*"]) | |
# Find sketch .ino | |
ino_file = glob(os.path.join(target_path, "*.ino"))[0] | |
if not ino_file: | |
raise Exception("No .ino file found in "+target_path) | |
else: | |
print("Found sketch .ino "+ino_file) | |
# Compile sketch to hex | |
subprocess.run([path_to_arduino_cli, "compile", "-b", "arduino:avr:uno", ino_file]) | |
# Locate hex file | |
hex_loc = None | |
compilation_files = glob("/tmp/arduino/sketches/*/*") | |
for f in compilation_files: | |
if ".hex" in f and "bootloader" not in f: | |
hex_loc=f | |
# Bounce Arduino | |
GPIO.output(4, GPIO.LOW) | |
time.sleep(1) | |
GPIO.output(4, GPIO.HIGH) | |
# Flash Arduino | |
subprocess.run([path_to_avrdude, "-c", "arduino", "-p", "m328p", "-C", "/home/chris/avrdude.conf", "-U", "flash:w:"+hex_loc]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment