• Hardware
  • [Debian] Compiling your arduino code without the IDE

If you've written just two lines or arduino code, you know how annoying it is to use the IDE the SDK comes with. Since we've recently been using arduino quite a lot in the workshop, I figured I'll prepare my system for a more comfortable (relative) environment.

Arduino IDE Cons

Poor text editing
Slow startup
Slow compilation/verification

Let's solve this. I'm using a debian based system, so if you're not on one. Tough Luck! You'll need to do some research :-(

Grab the dependencies:
sudo apt-get install gcc-avr avr-libc avrdude
Grab the Makefile

Makefile: (This is a newer version than the old one linked in arduino's playground)

-

Create your project directory, create your arduino project file, copy the makefile:
$ mkdir helloworld
$ cd helloworld
$ touch hello.ino
$ cp /path/to/Makefile .
All thats left to do is to modify the Makefile.

Here are the steps I used:

1- Open the Makefile and change the TARGET to hello
2- Modify the ARDUINO_DIR to the point to your arduino installation
3- Modify the ARDUINO_MODEL based on the model you have.
4- You may or may not need to check the PORT, that really depends on the operating system you're on.
5- Replace all instances of .pde in the Makefile to .ino (Processing and Arduino used the same extension before .pde, but now arduino switched to ino, so this accomodates that change)

Now let's add some simple code to test, open your hello.ino file and add the following:
void setup(){
    Serial.begin(9600);
}

void loop(){
    Serial.println("Does it work?");
    delay(1000);
}
Save your code and run the following to compile/verify:
$ make
If all goes well, you are now ready to upload your code:
$ make upload
If all goes well, the MCU is now sending "Does it work?" to your serial port on baud 9600, so let's read that!
$ cat /dev/ttyACM0
Does it work?
Does it work?
Does it work?
Does it work?
Does it work?
Enjoy.
a month later
For those that are interested, I'm no longer using the method described above. I'm currently using inotool instead. Here's a video i created that shows it in action.
Really cool vid xterm!

Did you have to configure anything for ino to detect your Arduino board? If not, can it handle multiple Arduinos plugged in simultaneously?
Thanks,

In terms of configuration, all you need are the arduino libs from the official site, inotool tries to guess which board and port you're using, unless specified.

You can specify the board model and port using -m and -p respectively, example:
~ $ ino build -m mega2560
~ $ ino upload -m mega2560 -p /dev/ttyACM1
That also answers your second question; Yes you can target multiple arduinos on the same machine since each one of them has its own port.