The Adruino Diecimila board supposedly h…

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 [Update 10/08/17: Build Process.]

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 code 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:

  1. Create a new directory to work in
  2. Write your Arduino code as a *.cpp instead of a *.pde file
  3. Copy and modify the Makefile for your project
  4. Run ‘make’ to compile it
  5. Run ‘make upload’ to flash your code to the Arduino

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;
}

13 thoughts on “The Adruino Diecimila board supposedly h…”

  1. 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+0x6): undefined reference to `digitalWrite’
    led.cpp:(.text+0x1c): undefined reference to `digitalWrite’
    led.o: In function `setup':
    led.cpp:(.text+0x34): 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+0x2a): undefined reference to `printByte’
    /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::print(char)':
    HardwareSerial.cpp:(.text+0x32): undefined reference to `printByte’
    /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::print(char const*)':
    HardwareSerial.cpp:(.text+0x14e): undefined reference to `printString’
    /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::flush()':
    HardwareSerial.cpp:(.text+0x16a): undefined reference to `serialFlush’
    /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::read()':
    HardwareSerial.cpp:(.text+0x170): undefined reference to `serialRead’
    /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::available()':
    HardwareSerial.cpp:(.text+0x176): undefined reference to `serialAvailable’
    /home/skormel/programacion/arduino/arduino_libs/HardwareSerial.o: In function `HardwareSerial::begin(long)':
    HardwareSerial.cpp:(.text+0x182): undefined reference to `beginSerial’
    make: *** [led.elf] Error 1

  2. 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.

  3. 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.

  4. 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.

  5. Hi
    I’m running Ubuntu for PPC on an old G4 i-book, bit slow but very light machine. Sun Java is unavailable for this architecture, Open-JDK works good for some apps like Eclipse IDE but does not manage to get Arduino going, soooo,
    trying to get Arduino command line working, then i can use text pad and terminal.
    I have looked at your instructions which are very helpful but what i actually did was too.
    > created a working directory in my home folder.
    > copied blink.pde there
    > copied Makefile there from arduino/hardware/cores/arduino
    > edited Makefile with correct settings for serial port, arduino install location, and locations for avr-gcc etc which are /usr/bin/
    > open terminal in working directory and run ‘make’
    > makes fine, creates hex, outputs following ->

    # Here is the “preprocessing”.
    # It creates a .cpp file based with the same name as the .pde file.
    # On top of the new .cpp file comes the WProgram.h header.
    # At the end there is a generic main() function attached.
    # Then the .cpp file will be compiled. Errors during compile will
    # refer to this new, automatically generated, file.
    # Not the original .pde file you actually edit…
    test -d applet || mkdir applet
    echo ‘#include “WProgram.h”‘ > applet/test.cpp
    cat test.pde >> applet/test.cpp
    cat /home/jowan/MyBin/arduino/hardware/cores/arduino/main.cxx >> applet/test.cpp

    text data bss dec hex filename
    0 1104 0 1104 450 applet/test.hex

    > all good so far but ..
    > run ‘make upload’ and get the following error !! ..

    # make upload
    /home/jowan/MyBin/arduino/hardware/tools/avrdude -V -F -C /usr/bin/avrdude.conf -p atmega168 -P /dev/ttyUSB0 -c stk500v1 -b 19200 -U flash:w:applet/test.hex
    /home/jowan/MyBin/arduino/hardware/tools/avrdude: 1: Syntax error: “(” unexpected
    make: *** [upload] Error 2

    > the usb settings are correct, confirmed from dev folder
    > also i am linking against the avrdude and avrdude.conf that are in my arduino install directory
    > can anyone help please

    cheerio

    Jowan

  6. I have updated my package of shell scripts (mentioned above, Feb.11) to use with Diecimila and Simple Message System. Now with a GUI via the Xdialog program. Available 24/7: run ‘wget http://user.cavenet.com/rolandl/SMS1.tgz
    Full IO & PWM control. AD is scaled to milliVolts and formatted for import to most spreadsheets.

  7. Jowan:

    It looks like avrdude is trying to read some text file for configuration information, and has found an error. As far as I know, the files that avrdude looks at are .avrduderc and avrdude.conf.

    .avrduderc is a place for you to record your default preferences. According to the avrdude man page, the options you can set in it are the default programmer and the default serial port.

    If you have an .avrduderc file, it will be hidden in your home directory. (The ‘.’ at the start of the filename marks it as hidden.) Its contents should look something like this:

    default_programmer = “skt500v1″;
    default_serial = “/dev/ttyUSB0″;

    Note the semicolon at the end of each line. That confused me.

    I’m also having trouble with avrdude. When I run it there is a short pause, and then I get the message:

    avrdude: stk500_recv(): programmer is not responding

    Then there’s another short pause, and the same message again:

    avrdude: stk500_recv(): programmer is not responding

    And then it gives up. I *can* upload to my Arduino with the Java IDE.

  8. Oh! I fixed it.

    I have to press and release the reset button at about the same time as I run avrdude. avrdude also needs the -F option to be set.

  9. Hi there,

    Just in case. I’m starting with this but I have found that using the arduino editor and compile code from there, the resulting binary files are located in the /tmp directory. When reading this I took the Blink example and I build it. I searched for it and then I found that all the build in this case was located in /tmp/build17280.tmp/. The Blink.hex file is the one you’re gonna use so, the only thing left is to use avrdude. The makefile uses the stk500. I made an stk200 like programmer as you may read here (http://labombiya.com.ar/2009/01/04/programming-avrs) so I would use avrdude as:

    $ avrdude -t m168 -c stk200 -e -U flash:w:Blink.hex

    Of course you can made a script for this. I still didn’t programmed the freeduino but I think it’s easier using this interface so you forget about what to include and what to override. You just compile. Then, using your fav programmer you flash the binary in the temp directory using avrdude command-line or you made yourself a Makefile.

    Good post!
    Regards,
    Sebastián Treu

Comments are closed.