Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Upload Source Code to Arduino from bash?

Right now I am using the standard Arduino IDE 1.0.1.

Yet I find both the IDE itself flunky and myself editing the code in other editors only to have to copy paste it inside the IDE and upload it there to my Arduino.

I really dislike this workflow.

So I am wondering: Is there a different way to deploy an Arduino project at best via commandline? Basically I am looking for a way to run something like arduino deploy /path/to/project /dev/ttyUSB0 from bash.

like image 719
k0pernikus Avatar asked Mar 03 '13 10:03

k0pernikus


2 Answers

You need a program called avrdude to upload the binary onto your target, and modify the parameters according to your setup and target:

mcu=atmega8
f_cpu=16000000
format=ihex
rate=19200
port=/dev/ttyusb0
programmer=stk500
target_file=test.hex

avrdude -F -p $mcu -P $port -c $programmer -b $rate -U flash:w:$target_file

If you're on a Debian or an Ubuntu machine, you should be able to do this to install avrdude:

sudo apt-get install avrdude 

Otherwise you should be able to grab the sources from here and build it yourself.

Also there is a comprehensive Makefile that you could use to build and upload to your Arduino which again uses the similar avrdude commands to upload to the target. After changing the parameters in the Makefile, run make upload to upload the hex file to the target.

NOTE: You need to have gcc-avr and avr-libc packages installed to build the binaries (which from the question looks like you're already doing).

like image 169
Tuxdude Avatar answered Sep 18 '22 05:09

Tuxdude


Following are two options which you can try

Arduino 1.5.x only

If you are using Arduino 1.5.x then you can use the arduino executable can accept commandline parameters.

Note that Arduino 1.5.x is still in beta, so you may face some issues.

Arduino 1.0.x

If you are using Arduino 1.0.x then you can use my makefile for Arduino which can be used to compile and upload Arduino (or plain AVR C) programs to Arduino from the commandline.

Following are some of the important features of this makefile

  • Supports upload via Arduino as ISP or any programmer
  • Communicate with Arduino through serial
  • Supports compiling plain AVR C programs
  • Supports user as well as system libraries.
  • Generate assembly and symbol files
  • Program using alternate Arduino core (like ATtiny or Arduino alternate cores)
like image 26
Sudar Avatar answered Sep 18 '22 05:09

Sudar