Here is an example using AVRDUDE, based on the way Arduino IDE flashes after compilation.
Save the script to flash.sh, run chmod +x flash.sh, then call it like ./flash.sh firmware.hex. If avr is not installed, first install it with brew tap osx-cross/avr and brew install avr-gcc. Make sure to close uArmStudio and ArduinoIDE as they might interfere with the connection while flashing is in progress.
#!/bin/bash# default location from `brew tap osx-cross/avr` and `brew install avr-gcc`export AVR_PATH=/Applications/Arduino.app/Contents/Java/hardware/tools/avr/
export PROGRAM="$1"# search for connected deviceforiin$(seq 1 10);doexport DEVICE_ID=$(ls /dev/tty.usb*2>&1| grep -v "No such")if [ -z"$DEVICE_ID" ];thenecho -ne "[$i of 10] Looking for device, connect USB and double tap the button to put it in flash mode \033[0K\r"
sleep 1.5
elseecho"Found device, flashing ${PROGRAM} to ${DEVICE_ID}"# flash the hex program to the device$AVR_PATH/bin/avrdude \
-C$AVR_PATH/etc/avrdude.conf \
-v \
-patmega2560 \
-cwiring \
-P${DEVICE_ID} \
-b115200 \
-D \
-Uflash:w:${PROGRAM}:i
breakfidone
Here is an example using AVRDUDE, based on the way Arduino IDE flashes after compilation.
Save the script to
flash.sh, runchmod +x flash.sh, then call it like./flash.sh firmware.hex. Ifavris not installed, first install it withbrew tap osx-cross/avrandbrew install avr-gcc. Make sure to close uArmStudio and ArduinoIDE as they might interfere with the connection while flashing is in progress.