The Adruino Diecimila board supposedly has circuit protection to ensure that one doesn’t fry their computer accidentally, but just in case, I figured it might be better to use a spare machine for my Arduino hacking. I happened to have an older PowerBook that fits the bill perfectly; however, I run Ubuntu PPC on it, and it didn’t take long for me to realize that neither the Arduino OS X or Linux builds would work on it.
Not to be discouraged, some quick googling led to the instructions on patching up the OS X release for Ubuntu PPC. However, a little more googling dug up something much more interesting: Arduino from the Command Line.
It’s not obvious while using the Arduino/Wiring IDE, but you’re really just writing C without includes and prototypes. When you save, the IDE patches up your code, then passes it to gcc-avr for compiling and avrdude for flashing. Therefore, if you’re so inclined (or happen to prefer vi and be on a non-supported platform), one can simply add the extra C++ manually and build/flash yourself.
The docs on this (linked above) tell the story, but they’re a little out of date (since they reference release 0007.) You still need to “sudo apt-get install gcc-avr avr-libc avrdude”, but after that, download the “Arduino 0009 installer for Linux” [the newest at the time of writing] instead, uncompress it, and look in “lib/targets/arduino/” for the Makefile and libraries you need. Read the comments in the Makefile — they explain it all quite well.
Once you stash the libraries somewhere handy, starting a new project goes like this:
It’s not as simple as the IDE, but it works, it lets you use any text editor you want, and gets you a little closer to whats going on behind the scenes.
For those curious, I’ve included an example of how the supplied “Blink” sample looks once modified for command-line building. It’s a bit longer… but still manageable:
/*
* Blink (modified for command-line building)
*
* The basic Arduino example. Turns on an LED on for one second,
* then off for one second, and so on... We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
#include <WProgram.h>
void setup();
void loop();
int main();
int ledPin = 13; // LED connected to digital pin 13
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
int main() {
init();
setup();
for (;;)
loop();
return 0;
}
September 3rd, 2007 at 10:38 am
“but you’re really just writing C++ without includes and prototypes.”
I had absolutely not realised that. Goodness!
December 16th, 2007 at 4:32 pm
I’ve got a problem, this is what I get:
make
avr-gcc -c -mmcu=atmega168 -I. -gstabs -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os -Wall -Wstrict-prototypes -std=gnu99 /home/skormel/programacion/arduino/arduino_libs/pins_arduino.c -o /home/skormel/programacion/arduino/arduino_libs/pins_arduino.o
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/wiring_private.h:30,
de /home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:26:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/signal.h:36:2: aviso: #warning “This header file is obsolete. Use .”
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/wiring_private.h:31,
de /home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:26:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/delay.h:36:2: aviso: #warning “This file has been moved to .”
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:65: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:66: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:67: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:73: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:74: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:75: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:81: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:82: aviso: la inicialización crea un entero desde un puntero sin una conversión
/home/skormel/programacion/arduino/arduino_libs/pins_arduino.c:83: aviso: la inicialización crea un entero desde un puntero sin una conversión
avr-gcc -c -mmcu=atmega168 -I. -gstabs -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os -Wall -Wstrict-prototypes -std=gnu99 /home/skormel/programacion/arduino/arduino_libs/wiring.c -o /home/skormel/programacion/arduino/arduino_libs/wiring.o
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/wiring_private.h:30,
de /home/skormel/programacion/arduino/arduino_libs/wiring.c:25:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/signal.h:36:2: aviso: #warning “This header file is obsolete. Use .”
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/wiring_private.h:31,
de /home/skormel/programacion/arduino/arduino_libs/wiring.c:25:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/delay.h:36:2: aviso: #warning “This file has been moved to .”
/home/skormel/programacion/arduino/arduino_libs/wiring.c:196:2: aviso: no hay caractér de fin de línea al final del fichero
avr-gcc -c -mmcu=atmega168 -I. -gstabs -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os -Wall -Wstrict-prototypes -std=gnu99 /home/skormel/programacion/arduino/arduino_libs/WInterrupts.c -o /home/skormel/programacion/arduino/arduino_libs/WInterrupts.o
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/WInterrupts.c:29:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/signal.h:36:2: aviso: #warning “This header file is obsolete. Use .”
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/wiring_private.h:31,
de /home/skormel/programacion/arduino/arduino_libs/WInterrupts.c:34:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/delay.h:36:2: aviso: #warning “This file has been moved to .”
/home/skormel/programacion/arduino/arduino_libs/WInterrupts.c:40:1: aviso: se redefinió “MCUCR”
En el fichero incluído de /usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/iom168.h:36,
de /usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/io.h:278,
de /home/skormel/programacion/arduino/arduino_libs/WInterrupts.c:27:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/iomx8.h:297:1: aviso: esta es la ubicación de la definición previa
avr-g++ -c -mmcu=atmega168 -I. -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os led.cpp -o led.o
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/WProgram.h:6,
de led.cpp:12:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/avr/signal.h:36:2: aviso: #warning “This header file is obsolete. Use .”
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/WProgram.h:8,
de led.cpp:12:
/home/skormel/programacion/arduino/arduino_libs/wiring.h:60:1: aviso: se redefinió “abs”
En el fichero incluído de /home/skormel/programacion/arduino/arduino_libs/WProgram.h:1,
de led.cpp:12:
/usr/lib/gcc/avr/4.2.2/../../../../avr/include/stdlib.h:118:1: aviso: esta es la ubicación de la definición previa
avr-g++ -c -mmcu=atmega168 -I. -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.cpp -o /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o
avr-g++ -c -mmcu=atmega168 -I. -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os /home/skormel/programacion/arduino/arduino_libs/WRandom.cpp -o /home/skormel/programacion/arduino/arduino_libs/WRandom.o
avr-gcc -mmcu=atmega168 -I. -gstabs -DF_CPU=16000000 -I/home/skormel/programacion/arduino/arduino_libs -Os -Wall -Wstrict-prototypes -std=gnu99 /home/skormel/programacion/arduino/arduino_libs/pins_arduino.o /home/skormel/programacion/arduino/arduino_libs/wiring.o /home/skormel/programacion/arduino/arduino_libs/WInterrupts.o led.o /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o /home/skormel/programacion/arduino/arduino_libs/WRandom.o –output led.elf
led.o: In function `loop’:
led.cpp:(.text+0×6): undefined reference to `digitalWrite’
led.cpp:(.text+0×1c): undefined reference to `digitalWrite’
led.o: In function `setup’:
led.cpp:(.text+0×34): undefined reference to `pinMode’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::printNumber(unsigned long, unsigned char)’:
HardwareSerial.cpp:(.text+0xe): undefined reference to `printIntegerInBase’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::print(unsigned char)’:
HardwareSerial.cpp:(.text+0×2a): undefined reference to `printByte’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::print(char)’:
HardwareSerial.cpp:(.text+0×32): undefined reference to `printByte’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::print(char const*)’:
HardwareSerial.cpp:(.text+0×14e): undefined reference to `printString’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::flush()’:
HardwareSerial.cpp:(.text+0×16a): undefined reference to `serialFlush’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::read()’:
HardwareSerial.cpp:(.text+0×170): undefined reference to `serialRead’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::available()’:
HardwareSerial.cpp:(.text+0×176): undefined reference to `serialAvailable’
/home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::begin(long)’:
HardwareSerial.cpp:(.text+0×182): undefined reference to `beginSerial’
make: *** [led.elf] Error 1
December 16th, 2007 at 4:33 pm
What can I do?? It seens like a linker error, isn’t it?
December 17th, 2007 at 10:22 am
Yikes. The bits to look at first are the “This header file is obsolete”, “This file has been moved to…”, and “undefined reference to…” warnings. When I first started playing with Arduino from the command line, the key bits were to (1) ensure that I had the latest libraries; (2) ensure that I was building for the right processor (ie., building for the atmega168 since I have a Diecimila); and (3) ensure that the compiler could find the Arduino libraries.
February 3rd, 2008 at 10:18 pm
I installed the SimpleMessageSystem and it works, sort of. I can run ’screen’ and get AD
values. I prefer connected mode, for Data Acquisition. I get data using ’screen’ as shown
in the ‘Linux TTY’ page at arduino.cc. But I have no luck w/bash:
stty {all those parms}
echo “d a” > /dev/ttyUSB0;read < /dev/ttyUSB0;echo $reply
Then I could convert to CommaSeparatedValues for import to your_fave_spreadsheet.
When I bot this unit I thought the point was Data Acq/Control. No, it’s apparently
a toy for programmers. Still trying. Anyone got pointers? Thanks.
February 11th, 2008 at 1:44 pm
I have developed a method to communicate with the SimpleMessageSystem on my Diecimila,
under linux using shell scripts. It isn’t polished, but it is functional, and I would
appreciate comments. Try it! wget http://207.14.167.161/SMS1.tgz . The scripts look odd
because they contain ^Ms. Use vi to examine the files.