Skip to main content
just added in back/forwardslash words and 'upload sketch with arduino IDE'
Source Link

This is essentially the same as @raddevus answer except it is in python code. I am using windows. Set the preferences in the arduino IDE to verbose and upload the sketch you want to upload using the python codearduino IDE. Find the line of code just before it executes the avrdude bit (where it says 'avrdude: Version...'). The python code below is designed to be flexible in that you can create a function that will feed in different hex files and com ports for different arduinos etc. If you have problems, make sure you get all the apostrophes, speech marks and spaces in the right place and change all the backslashes '' in filenames to forwardslash '/'. I used the arduino blink example here to check it worked.

comport is the COM port that your arduino is on

Sketch is the .hex file path that you can find in normally hidden folder Appdata - you can copy this hex file and store it somewhere more convenient.

in1 is the first part of the line of code up until the P of the part where it says '-PCOM4'.

in2 is the bit that comes after the '-PCOM4' until the location of your file.

cmdIn creates one long string that is then passed to os.system to execute.

import os

comport = 'COM4' # enter your comport here
sketch = 'C:/Users/user_name/AppData/Local/Temp/arduino/sketches/290321875103144FE430B0C8E22741C9/Blink.ino.hex'
in1 = 'cmd /C ""C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude.exe" -C"C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v  -patmega328p -carduino -P'
in2 = ' -b115200 -D "-Uflash:w:';
cmdIn = '%s%s%s%s:i' % ( in1, comport, in2, sketch);
os.system(cmdIn)

This is essentially the same as @raddevus answer except it is in python code. I am using windows. Set the preferences in the arduino IDE to verbose and upload the sketch you want to upload using the python code. Find the line of code just before it executes the avrdude bit (where it says 'avrdude: Version...'). The code is designed to be flexible in that you can create a function that will feed in different hex files and com ports for different arduinos etc. If you have problems, make sure you get all the apostrophes, speech marks and spaces in the right place and change all the '' in filenames to '/'. I used the arduino blink example here to check it worked.

comport is the COM port that your arduino is on

Sketch is the .hex file path that you can find in normally hidden folder Appdata - you can copy this hex file and store it somewhere more convenient.

in1 is the first part of the line of code up until the P of the part where it says '-PCOM4'.

in2 is the bit that comes after the '-PCOM4' until the location of your file.

cmdIn creates one long string that is then passed to os.system to execute.

import os

comport = 'COM4' # enter your comport here
sketch = 'C:/Users/user_name/AppData/Local/Temp/arduino/sketches/290321875103144FE430B0C8E22741C9/Blink.ino.hex'
in1 = 'cmd /C ""C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude.exe" -C"C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v  -patmega328p -carduino -P'
in2 = ' -b115200 -D "-Uflash:w:';
cmdIn = '%s%s%s%s:i' % ( in1, comport, in2, sketch);
os.system(cmdIn)

This is essentially the same as @raddevus answer except it is in python code. I am using windows. Set the preferences in the arduino IDE to verbose and upload the sketch you want to upload using the arduino IDE. Find the line of code just before it executes the avrdude bit (where it says 'avrdude: Version...'). The python code below is designed to be flexible in that you can create a function that will feed in different hex files and com ports for different arduinos etc. If you have problems, make sure you get all the apostrophes, speech marks and spaces in the right place and change all the backslashes '' in filenames to forwardslash '/'. I used the arduino blink example here to check it worked.

comport is the COM port that your arduino is on

Sketch is the .hex file path that you can find in normally hidden folder Appdata - you can copy this hex file and store it somewhere more convenient.

in1 is the first part of the line of code up until the P of the part where it says '-PCOM4'.

in2 is the bit that comes after the '-PCOM4' until the location of your file.

cmdIn creates one long string that is then passed to os.system to execute.

import os

comport = 'COM4' # enter your comport here
sketch = 'C:/Users/user_name/AppData/Local/Temp/arduino/sketches/290321875103144FE430B0C8E22741C9/Blink.ino.hex'
in1 = 'cmd /C ""C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude.exe" -C"C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v  -patmega328p -carduino -P'
in2 = ' -b115200 -D "-Uflash:w:';
cmdIn = '%s%s%s%s:i' % ( in1, comport, in2, sketch);
os.system(cmdIn)
Source Link

This is essentially the same as @raddevus answer except it is in python code. I am using windows. Set the preferences in the arduino IDE to verbose and upload the sketch you want to upload using the python code. Find the line of code just before it executes the avrdude bit (where it says 'avrdude: Version...'). The code is designed to be flexible in that you can create a function that will feed in different hex files and com ports for different arduinos etc. If you have problems, make sure you get all the apostrophes, speech marks and spaces in the right place and change all the '' in filenames to '/'. I used the arduino blink example here to check it worked.

comport is the COM port that your arduino is on

Sketch is the .hex file path that you can find in normally hidden folder Appdata - you can copy this hex file and store it somewhere more convenient.

in1 is the first part of the line of code up until the P of the part where it says '-PCOM4'.

in2 is the bit that comes after the '-PCOM4' until the location of your file.

cmdIn creates one long string that is then passed to os.system to execute.

import os

comport = 'COM4' # enter your comport here
sketch = 'C:/Users/user_name/AppData/Local/Temp/arduino/sketches/290321875103144FE430B0C8E22741C9/Blink.ino.hex'
in1 = 'cmd /C ""C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude.exe" -C"C:/Users/user_name/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v  -patmega328p -carduino -P'
in2 = ' -b115200 -D "-Uflash:w:';
cmdIn = '%s%s%s%s:i' % ( in1, comport, in2, sketch);
os.system(cmdIn)