Skip to content

Instantly share code, notes, and snippets.

@jossef
Last active August 29, 2015 14:12
Show Gist options
  • Save jossef/218bffcaa4bd181114ce to your computer and use it in GitHub Desktop.
Save jossef/218bffcaa4bd181114ce to your computer and use it in GitHub Desktop.
Arduino firmware upload script using `Eclipse Arduino IDE` and `inotool`
#!/usr/bin/python
import os
import shutil
import subprocess
import tempfile
def get_hex_files():
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
if file.lower().endswith('.hex'):
yield os.path.join(root, file)
def main():
if os.getuid() != 0:
raise Exception('this must be run as root')
hex_files = [file for file in get_hex_files()]
if len(hex_files) > 1:
raise Exception('to many hex files. clean your project and proceed')
if not len(hex_files):
raise Exception('hex file are missing. build and run again')
hex_file_path = hex_files[0]
if not os.path.isfile(hex_file_path):
raise Exception('hex file {0} not found'.format(hex_file_path))
temp_dir_path = tempfile.mkdtemp()
os.makedirs(os.path.join(temp_dir_path, 'src'))
leonardo_build_path = os.path.join(temp_dir_path, '.build', 'leonardo')
os.makedirs(leonardo_build_path)
shutil.copy2(hex_file_path, os.path.join(leonardo_build_path, 'firmware.hex'))
os.chdir(temp_dir_path)
subprocess.call(['ino', 'upload', '--board', 'leonardo'])
shutil.rmtree(temp_dir_path)
if __name__ == '__main__':
try:
main()
except Exception as ex:
print ex
@jossef
Copy link
Author

jossef commented Dec 31, 2014

place it in /opt/arduino-upload/upload.py

add execution permissions

sudo chmod +x /opt/arduino-upload/upload.py

create a symlink to run from everywhere

sudo ln -s /opt/arduino-upload/upload.py /usr/local/bin/arduino-upload

build your eclipse project using Eclipse Arduino IDE

image

cd to your eclipse project dir and run sudo arduino-upload

cd ~/workspace/blinker/
sudo arduino-upload 

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment