Code, robots and stuff

This is sort of a howto on how I do my development with Arduinos, while there is nothing wrong with the IDE, it's sort of in the way most of the time to me. I prefer using my favourite editor(Vi IMproved of course) and make.
This is kind of tricky, since I'm not that certain as to what the IDE does when it compiles the source in to a hex-file. Luckily, I found a make file that works with Arduino 1.0.

But let's not get ahead of ourselves! First thing we have to do is setup our editor.
The Arduino IDE uses .pde as it's file format of choice. For fancy syntax highlighting we need to add a Syntax file for vim.
First thing that we need to do is create a directory to hold our syntax file.

$ mkdir -p ~/.vim/syntax


Next step is to download the syntax file and put it in the directory.

$ wget http://www.vim.org/scripts/download_script.php?src_id=17108 -O ~/.vim/syntax/arduino.pde

--2012-01-04 01:11:30--  http://www.vim.org/scripts/download_script.php?src_id=17108

Resolving www.vim.org... 216.34.181.97

Connecting to www.vim.org|216.34.181.97|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 2258 (2,2K) [application/octetstream]

Saving to: `/home/gabriel/.vim/syntax/arduino.pde'



100%[=======================================================================================>] 2 258       --.-K/s   in 0s      



2012-01-04 01:11:30 (324 MB/s) - `/home/gabriel/.vim/syntax/arduino.pde' saved [2258/2258]



$


Next, we need to add a line to our ~/.vimrc so that vim will recognize .pde-files as arduino files.

" For arduino syntax

autocmd! BufNewFile,BufRead *.pde setlocal ft=arduino


Now vim should recognize .pde-files as arduino-files and you will have wonderous colours flying over your screen in formations of joy.
Next step is creating a directory for your project, let's call it Super ninja robot master control beaver.

$ mkdir -p ~/development/arduino/super_ninja_robot_master_control_beaver

Not that hard, huh?
Next step is downloading a suitable Makefile, I've used a modified version of one I found in this post on the Arduino forum. You can find it here.

$ cd ~/development/arduino/super_ninja_robot_master_control_beaver

$ wget http://hax0r.se/files/Arduino-1.0_Makefile -O Makefile

--2012-01-04 01:23:02--  http://hax0r.se/files/Arduino-1.0_Makefile

Resolving hax0r.se... 62.109.46.153

Connecting to hax0r.se|62.109.46.153|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 11782 (12K) [text/plain]

Saving to: `Makefile'



100%[=======================================================================================>] 11 782      --.-K/s   in 0,004s  



2012-01-04 01:23:02 (3,10 MB/s) - `Makefile' saved [11782/11782]



$ 

Now that we have a makefile that will work with the Arduino 1.0 IDE, we need some other things too. We need the binaries and libraries from the IDE itself.
We also need stty, avrdude and avr-gcc, install these with your distributions package manager.

$ cd ~/

$ mkdir .arduino/

$ cd arduino/

$ $ I use a 64-bit system, if you have a 32-bit install, use that file instead

$ wget http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz

--2012-01-04 01:24:50--

http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz

Resolving arduino.googlecode.com... 209.85.173.82

Connecting to arduino.googlecode.com|209.85.173.82|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 4351508 (4,1M) [application/x-gzip]

Saving to: `arduino-1.0-linux64.tgz'



100%[=======================================================================================>]

4 351 508   1,24M/s   in 3,3s    



2012-01-04 01:24:54 (1,24 MB/s) - `arduino-1.0-linux64.tgz' saved

[4351508/4351508]



$ tar xf arduino-1.0-linux64.tgz

$ 

We're almost done. We just need to modify the makefile to suit our enviroment.
On line 54 of the makefile there should be a line like this
ARDUINO_DIR = /home/gabriel/.arduino/arduino-1.0/
Change that gabriel(Hey! That's me :) to your username. We need to do one more change before we're done though. On line 44 there is a line that looks like this:
 TARGET = sketch
That will have to be changed for every new project you make, unless you want to call the main file sketch everytime.
Now cd to your super ninja robot master control beaver directory and get coding, I'll wait.
Done? Good. Now type make to compile the source code you just created.

$ make 

[ interesting but very long compiling things ]

  text	   data	    bss	    dec	    hex	filename

      0	   1498	      0	   1498	    5da	applet/sketch.hex

$ 

Well woud you look at that, you compiled it, all by yourself, good for you!
Now we need to upload the code to our Arduino, connect it to your usb-port and make sure you've got the right permissions set up.

$ make upload

stty -F /dev/ttyACM* hupcl

/home/gabriel/.arduino/arduino-1.0//hardware/tools/avrdude -V -F -C /home/gabriel/.arduino/arduino-1.0//hardware/tools/avrdude.conf -p atmega2560 -P /dev/ttyACM* -c stk500v2 -b 115200 -U flash:w:applet/sketch.hex



avrdude: AVR device initialized and ready to accept instructions



Reading | ################################################## | 100% 0.01s



avrdude: Device signature = 0x1e9801

avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.

avrdude: erasing chip

avrdude: reading input file "applet/sketch.hex"

avrdude: input file applet/sketch.hex auto detected as Intel Hex

avrdude: writing flash (1388 bytes):



Writing | ################################################## | 100% 0.22s



avrdude: 1388 bytes of flash written



avrdude: safemode: Fuses OK



avrdude done.  Thank you.



$

That's it. You have now uploaded a bunch of stuff to your arduino(I do not take any responsibiliy, what so ever as to what happens to your hardware or anything else if you follow this guide)