Skip to content

Instantly share code, notes, and snippets.

@pastacolsugo
Created May 2, 2019 22:33
Show Gist options
  • Save pastacolsugo/bdf2b76a55dafee410605858a1f08ddd to your computer and use it in GitHub Desktop.
Save pastacolsugo/bdf2b76a55dafee410605858a1f08ddd to your computer and use it in GitHub Desktop.
Arduino Leonardo reset-search-upload
From:
https://github.com/gibatronic/sesame
found on StackOverflow @ https://stackoverflow.com/questions/43016993/how-can-i-force-a-leonardo-to-reset-with-avrdude
#!/bin/bash
ARDUINO_JAVA='/Applications/Arduino.app/Contents/Java'
ARDUINO_BUILD_MCU='atmega32u4'
ARDUINO_BUILD_VARIANT='leonardo'
ARDUINO_UPLOAD_PORT="$(find /dev/cu.usbmodem* | head -n 1)"
ARDUINO_UPLOAD_PROTOCOL='avr109'
ARDUINO_UPLOAD_SPEED='57600'
main() {
local OPTIONS=(
-p "${ARDUINO_BUILD_MCU}"
-b "${ARDUINO_UPLOAD_SPEED}"
-c "${ARDUINO_UPLOAD_PROTOCOL}"
-C "${ARDUINO_JAVA}/hardware/tools/avr/etc/avrdude.conf"
-D
-P "${ARDUINO_UPLOAD_PORT}"
-q
-q
-U "flash:w:/Users/sugo/git/qmk_firmware/flash_sugo_firmware/converter_usb_usb_hasu_sugo.hex:i"
)
# reset the Arduino
stty -f "${ARDUINO_UPLOAD_PORT}" 1200
# wait for it...
while :; do
sleep 0.5
[ -c "${ARDUINO_UPLOAD_PORT}" ] && break
done
# ...upload!
"${ARDUINO_JAVA}/hardware/tools/avr/bin/avrdude" "${OPTIONS[@]}"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment