Arduino IDE Installation

The In System Programming (ISP) method is the one I recommend to use with the Raspberry Pi and the Gertboard. The down-side is that during program development of the code you are running in the ATmega, you need to use 4 GPIO pins on the Pi. You can pick (almost) any 4, but I suggest you use 4 of the 5 pins dedicated to the SPI interface.

To use the Arduino IDE with the Raspberry Pi and the Gertboard, you will need to make some small changes to both the Pi’s and the Arduino’s configuration files. However, the first step is to install the IDE, cross compilers, etc. To use the ISP programming method (which is recommended), you need a modified version of the avrdude program.

First start by installing the standard Arduino IDE:

sudo apt-get install arduino

This will pull in several packages including the required C compilers and Java based IDE.

Now fetch and install the modified avrdude package:

Standard Debian Squeeze:

cd /tmp
wget http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armel.deb
sudo dpkg -i avrdude_5.10-4_armel.deb
sudo chmod 4755 /usr/bin/avrdude

Debian Raspbian:

cd /tmp
wget http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armhf.deb
sudo dpkg -i avrdude_5.10-4_armhf.deb
sudo chmod 4755 /usr/bin/avrdude

This will install the modified version of avrdude. The chmod command will let avrdude use the GPIO pins without using sudo. (which is needed to run it inside the IDE) It does carry a slight security risk, but shouldn’t really be an issue here.

If using Arch or another Linux distribution then the sources are there, as well as some binaries, just check the

http://project-downloads.drogon.net/gertboard/

location and get in-touch if needed.

We still need to do a few more things to fully integrate the Arduino IDE system with the Gertboard.

There are several steps involved, so what I’ve done is to put together a script that automates most of it for you. Get and run this script as follows:

cd /tmp
wget http://project-downloads.drogon.net/gertboard/setup.sh
chmod +x setup.sh
sudo ./setup.sh

This script will fetch and overwrite some system files (keeping backups first) If you’re not sure about this, then do inspect the script and run it line by line if you want to.

Now, initialise your ATmega processor

Or, read below for a full description of what the script is doing:

  • Disable Linux Serial Console:

To use the serial port that connects the ATmega with the Raspberry Pi, we need to make 2 small changes to the system to make sure nothing else will interfere with the serial port. The first is to stop Linux outputting debug and console messages to the serial line:

sudo nano /boot/cmdline.txt

and you need to remove the references to console and ttyAMA0. References similar to these below need to be removed:

  • console=ttyAMA0,115200
  • kgdboc=ttyAMA0,115200
  • console=tty1

but if manually editing the file then do double check before you write it out and make sure the resulting data is all on one line only. (This is quite important!)

The above setup.sh script edits these out of /boot/cmdline.txt file.

Next we need to disable Linux serial console login by stopping the getty process starting at boot time:

sudo nano /etc/inittab

and scroll down to near the bottom where you’ll see a line like:

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Comment this line out by putting a # symbol at the start of it. The setup.sh script adds this comment in for you.

Add Gertboard definitions into the Arduino IDE:

The next thing we need to do is tell the Arduino IDE about the processor on the Gertboard.

This is a bit more complicated, so it’s probably easier to simply fetch my files and use them directly, however if you have added your own board into an Arduino IDE before, then fetch my file and merge the changes in.

cd /tmp
wget http://project-downloads.drogon.net/gertboard/boards.txt
wget http://project-downloads.drogon.net/gertboard/programmers.txt
cd /usr/share/arduino/hardware/arduino
sudo mv boards.txt board.txt.bak
sudo mv /tmp/boards.txt .
sudo mv programmers.txt programmers.txt.bak
sudo mv /tmp/programmers.txt .

If you run then examine boards.txt and programmers.txt then you’ll see new additions at the top for the two different processor types that the Gertboard supports. This operation is performed by the setup.sh script above.

Download/install the avrsetup script

The script downloads a shell-script avrsetup and places it in /usr/local/bin. You need to use this script to initialise the ATmega processor the very first time you use it.. See the next page here for details. (Although you need to reboot the Pi to make the serial port settings take effect).

Comments

Arduino IDE Installation — 59 Comments

  1. Thanks for the great directions, I am setting up an ATMega328 on a breadboard since my Gertboard is backordered for another month. I got everything working, but I am using a 10 MHz crystal instead of 12, where would I configure that? Right now my delay calls are 20% too short

    • A-Ha..

      What you need to do is create a new board definition for the Arduino IDE and tell it that F_CPU is 10MHz.

      So edit the file: /usr/share/arduino/hardware/arduino/boards.txt and either add in a new entry, or change one of the existing ones to set the CPU frequency to 10000000L

      You’ll need to compile everything again, and your delays might still be a bit off, but it should be much better.

      -Gordon

  2. I am seeing this message 9/10 if I try to upload a sketch

    avrdude: verification error, first mismatch at byte 0x0006
    0x79 !=0x01
    avrdude: verification error content mismatch.

    I have successfully run “blink” but “knob” Failed.
    “blink” then failed with the same error.
    some time later I tried again after messing about and checking connections.
    and “blink” ran OK but “sweep” failed.
    I have searched for the error and there seem to be conflicting answers on-line.
    I thought perhaps you may have an idea where to start.
    I have ordered another chip from Tandy Just in case.

  3. Last comment
    “Think we’re got this sorted on the forums!”
    What forum and where is it? Please
    Sorry I’m not good at this

    • Er.. Not sure – it was weeks ago/months? – but I suspect I replied to you on the forums as well as replying here (guessing). I’d need to go back through several months of replies on this site which isn’t easy – it’s not at all threaded sensibly – the joys of using wordpress )-:

      -Gordon

  4. I have had exactly the same problem with uploading sketches to the Atmega. Uploaded “blink” and it worked fine but the next sketch I tried to upload failed with “verification error, first mismatch at byte 0x0002”. I also tried uploading “blink” again but got the same error. I got this error for all every sketch I tried to upload. Just like the previous post I tinkered about for a bit pulling connectors on and off, re-running the avrsetup script etc and it seamed to fix the problem. I once again downloaded the “blink” sketch and it started to work but as soon as I attempted to download another sketch I got the “verification error, first mismatch at byte 0x0002” error once again.

    I have tried to find an answer to this on web and have tried to find anything on the element 14 community. You mentioned that this had come up on the forum but I also don’t know where that is. I would really appreciate your help in pointing me to the relevant post on this problem.

    -Alan

  5. Gordon.
    Checking out the pi fporum I managed to find your answer to my question “verification error, first mismatch at byte 0×0002”.
    Just reproducing it here for others to find.

    Note: to upload you must use the

    File -> Upload using programmer

    Method if the normal method doesn’t appear to work for you. (The standard method seems to assume it’s using a serial port and sometimes gets confused, so use this method, or type the Ctrl+Shift+U shortcut rather than the normal Ctrl+U.

  6. Gordon,

    I was wondering how I could use this technique to program ATTiny84 on a breadboard. Can I connect the GPIO connections to the relevant pins of the ATTiny on the breadboard, and program from the Raspberry Pi in the same way as documented above? ie Using the Raspberry Pi as a ISP Programmer?

    I assume I would need to upload new board definitions for this, but use the same programmer config?

    Thanks

    Ian

    • You should be able to – make sure both sides are at 3.3v though. Check the boards.txt file for the right parameters and /etc/avrdude.conf for the pin definitions for the ICSP interface. If you need to set the fuses, then you’ll need to read the right document from atmel to work these out.

      -Gordon

  7. Hello Gordon

    I am working on Arch Linux….

    Is it possible to get programming of the atmega328p up and running?

    • Well the easiest way woul be to install Raspbian 😉

      However other than that I don’t really know. You could get the sources to avrdude and apply the patch that I did though, them compile and install it yourself – along with the modified boards.txt and processors.txt files. You’ll find all the sources that I worked from here: http://project-downloads.drogon.net/files/

      -Gordon

      • I have tried to apply the patch found here:
        http://project-downloads.drogon.net/gertboard/avrdude-5.10-bb-gpio.patch

        to the source code from here:
        http://download.savannah.gnu.org/releases/avrdude/avrdude-5.10.tar.gz

        ./configure goes fine, but make throws an error:

        .a -lusb -lm -lreadline -lncurses
        ./libavrdude.a(libavrdude_a-config_gram.o): In function `yyparse’:
        /root/avrdude-5.10-gpio/config_gram.y:445: undefined reference to `gpio_initpgm’
        collect2: error: ld returned 1 exit status
        make[2]: *** [avrdude] Error 1
        make[2]: Leaving directory `/root/avrdude-5.10-gpio’
        make[1]: *** [all-recursive] Error 1
        make[1]: Leaving directory `/root/avrdude-5.10-gpio’
        make: *** [all] Error 2

        [root@alarmpi avrdude-5.10-gpio]#

        Something you have seen before or can help me resolve?

        Is it possible to get your patched sources for avrdude? The once i find on your site is deb packages…?

        -Ronnie

        • I started from the .deb sources – applied that patch, then re-made the .deb’s. What’s on my downloads site is what I worked from…

          I’m guessing you’re not making this on a Raspbian machine?

          If not, then won’t the binary work for you?

          -Gordon

      • I have tried to apply the patch found here:
        http://project-downloads.drogon.net/gertboard/avrdude-5.10-bb-gpio.patch

        to the source code from here:
        http://download.savannah.gnu.org/releases/avrdude/avrdude-5.10.tar.gz

        ./configure goes fine, but make throws an error:

        .a -lusb -lm -lreadline -lncurses
        ./libavrdude.a(libavrdude_a-config_gram.o): In function `yyparse’:
        /root/avrdude-5.10-gpio/config_gram.y:445: undefined reference to `gpio_initpgm’
        collect2: error: ld returned 1 exit status
        make[2]: *** [avrdude] Error 1
        make[2]: Leaving directory `/root/avrdude-5.10-gpio’
        make[1]: *** [all-recursive] Error 1
        make[1]: Leaving directory `/root/avrdude-5.10-gpio’
        make: *** [all] Error 2

        [root@alarmpi avrdude-5.10-gpio]#

        Something you have seen before or can help me resolve?

        Is it possible to get your patched sources for avrdude? The once i find on your site is deb packages…?

        -Ronnie

  8. Hello,

    I made myself an expansion board for the Raspberry Pi, with an
    ATMega16 AVR microcontroller.
    To program the AVR directly from the RPi, I want to use your modified
    version of Avrdude.
    In my circuit, I am using a NPN transistor to pull the AVR’s reset-pin to ground (as a level converter 3,3–>5V).
    So the RPi has to pull the base of the transistor to high in order to
    program it.
    But in the patched Avrdude, the GPIO pin is pulled to ground.

    Is there a way to tell Avrdude to pull it to high, instead?

    regards,
    Daniel

  9. Something tells me this is a stupid question but, is there any way to do this with purely the RPi? Meaning without the gertboard?

      • Oops, sorry, I thought I was on a different page. I wanted to have a setup with purely my RPi so that I could burn the atmega chips without any other hardware.

        • Right! No problems there – just make sure you’re powering the ATmegas at 3.3v.

          (Personally, I use a USB programmer though)

          -Gordon

          • Dayum, I wasn’t expecting it to be that easy! Do I just run the avrsetup as normal like on the initial setup page?

          • Yes and no…. Avrsetup is designed to setup the ATmega on the Gertboard – which runs at 12MHz, so you need to check the fuse values for your own ATmega projects – e.g. use the internal 8 MHz oscillator or not…

            -Gordon

  10. First of all, great thanks for all the tools and info. I’m enjoying the Pi and the Gertboard to bits.

    My question is this: I understand that the modified avrdude programs the flash on the AVR via SPI. If I happen to write a program for the AVR that uses the SPI interface and flash that program using SPI, will I be able to flash the device via SPI again or will my program be in the way?

    The Gertboard IS my AVR programmer right now so I don’t want to block myself.

    • You won’t have a problem using the ATmegas SPI interface – you will need to unplug the 4 wires going to the Pi though, then connect up your own hardware – then swap the connections back if you need to re-program.

      I am going to publish a method of programming it via the serial port shortly though – I used both methods when I was testing it all out and thought the ICSP method would be easier, but I’m not so sure now… The big issue is that you must use the ICSP method to program the serial bootloader and it’s a modified one to work at 12MHz…

      -Gordon

    • And here I answer my own stupid question. The answer was a simple google search away and I found it here:

      http://www.atmel.com/images/doc0943.pdf

      For other newbs like me – the secret lies in the Reset line. When the Reset line is activated (active low), the target AVR is reset and in programmable mode.

      Short answer: RTFM 😉

      • You beat me to my reply! Thanks for the quick response.

        I plan to use the AVRs SPI interface with the Pi, so fortunately I can keep them wires in place all the time.

        • Remember the Pi can only be an SPI master, and you will need to disconnect the reset wire – that’s the yellow one on my diagram – remove it from the ICSP header and connect it to the ATmegas PB2 pin. (/SS) Otherwise the ATmega will be reset the first time the Pi tries to send anything via SPI…

          -Gordon

          • Thanks Gordon.

            I interpreted your advise and applied it to my scenario. I’m testing SPI on the Pi via the spidev kernel module. Since the Pi has 2 chip select lines, I kept the chip select A of the Pi connected to the AVRs reset line, and wired chip select B of the Pi to /SS on the AVR. The spidev module creates a /dev/spidev0.0 and /dev/spidev0.1 character device node which can be used by the example in the kernel sources at Documentation/spi/spedev_test.c (modified the device line to “/dev/spidev0.1”)

            There was one obstacle that I only figured out after a while: the spidev module and the accompanying spi_bcm2708 modules needs to be unloaded before flashing the AVR using avrdude – else the Pi’s SPI seems to go into a bad state and SPI won’t work as expected. After flashing the AVR with avrdude you can load said modules again and everything works great. And you need not move wires around all the time.

          • Sounds good.

            If you have wiringPi installed, then you can use it to load the modules (but not unload)

            gpio load spi

            will do the trick, and a side-effect is that it changes the ownership to the calling user, so you shouldn’t need to use sudo on programs using SPI.

            -Gordon

  11. Is it also possible to transmit a programm with avrdude over UART to an atmega328 with bootloader?

    • Yes. If it’s using a USB serial, then there is no issue – if using the on-board serial, then make sure they are all at 3.3v or that you are using a level shifter to get to the 5v of the ATmega. The only real issue using the on-board serial is resetting the ATmega at the right time. Might need to type the avrdud command, push the reset button on the ATmega, then push enter on the Pi’s avrdude command.

      -gordon

      • So it needs to be reset just before pressing enter.
        I’m using a Atmega328P @ 3,3V so i don’t need any TTL-Logic converters

  12. Gordon,
    I have not yet installed the modified IDE. Does it add one more “serial port like” to the IDE, or replace the existing ones ? -ie- could I both program the gertboard AVR and a arduino board within the same (modified) IDE ?
    (hope to be clear…)
    Congratulations and thanks a lot for your work, and your answer.

    • It adds a ‘gpio’ programming device – you can still program an ATmega via (e.g.) USB serial with it. (which is what I do)

      -Gordon

  13. I have since changed this line:
    gpio328.bootloader.high_fuses=0xDA to
    gpio328.bootloader.high_fuses=0xD9

    Also I believe the verification error was likely due the the breadboard connection rather than any brownout settings.

    • AIUI – the high fuse at 0xD9 tells the ATmega to reserve 2KB for the bootloader – we’re not using a bootlaoder here, so I’m not sure what your intention is…

      -Gordon

      • My intention has been to be able to program the ATmega on a breadboard using the Raspberry PI.

        I was suffering from doing too many new things at once and not 100% understanding what was going on.

        It’s all working fine – I now believe the content verification errors were related to an alternate use for the digital pin 13 which was being used to send clocked communication in addition to being used for the programmer. I think I have previously had to burn the bootloader to erase the running program so as stop the serial comms from that pin. Moving the the clocked comms to another pin has resulted in being able to upload a new program without having to burn a the bootloader every time.

        All fun and games!

        • I’m looking at a serial bootloader for the Gertboard ATmega – the big issue is pretting the reset button, so use single gpio for that.

          -Gordon

  14. Hello Sir,
    I followed every single instruction of tutorial but, when I fire ‘sudo ./setup.sh’ command
    it shows
    Checking …
    Avrdude: OK
    Arduino IDE: Not installed. Please install it first

      • I am having the same issue “Arduino IDE: Not installed. Please install it first”. the Arduino IDE is installed. I have even uninstalled it and reinstalled it.

  15. Hello Gordon, I downloaded the newest OS for raspberry, but it seems to not be a compatible with the new OS. I get the error: –control returned error exit status 2, that says: avrdude_5.10-4_armel.deb is not a debian format archive. Any idea or solution? thanks in advance 🙂

  16. Good day – thanks for the tutorials. I’m discovering that I’m failing during the installing avrdude – apparently my raspbian install is 64 bit?

    sudo dpkg -i avrdude_5.10-4_armhf.deb
    dpkg: error processing avrdude_5.10-4_armhf.deb (–install):
    package architecture (armhf) does not match system (amd64)
    Errors were encountered while processing:
    avrdude_5.10-4_armhf.deb

    Also I already had avrdude installed but it is version 5.11. I’m going to try to download and compile 5.11 and apply the patch but I was curious if anyone else had encountered these problems.

    • There is no 64-bit Pi software – are you suer you’re running the dpkg command on a Pi?

      I have some new avrdude software though that’s much faster – hoping to post it in the next few days.

      -Gordon

  17. Having a 404 error when i try to install arduino:
    “sudo apt-get install arduino”

    I see 3 cases of 404 not found…
    …/t/tzdata/tzdata-java_2013b-2_all.deb
    …/i/icedtea-web/icedtea-netx-common_1.3.2-1_all.deb
    …/i/icedtea-web/icedtea-netx_1.3.2-1_armhf.deb

    –fix-missing pulls up the same error.

  18. im stuck with the arduino-gertboard software setup I get the project avrdude ok but when I try the line
    sudo dpkg -i avrdude_5.10-4_armhf.deb

    I get the error message
    error processing avrdude_5.10-4_armhf is not a debian format archive
    error processing avrdude_5.10-4_armf.deb(–install)
    subprocess dpkg.deb–control returned error exit status2
    I have typed and retyped the sudo code so many times I hope you can help

  19. i have a problem. i folowed the tutorial step by step. and have the latest raspian installed but when i try to use the command : sudo dpkg -i avrdude_5.10-4_armhf.deb my pi sais ” 5.10-4.armhf.deb is not a debian format archive” and also the files for installing arduino (sudo apt-get install arduino) most of them are unreacheble from the 170mb it should be downloading it gets under 20. sorry if is a bad question, im a beginer with pi and gertboard

  20. The compile errors previously reported in SerialSoftware.cpp

    /usr/share/arduino/libraries/SoftwareSerial/SoftwareSerial.cpp:128:2: error: #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
    /usr/share/arduino/libraries/SoftwareSerial/SoftwareSerial.cpp: In member function ‘void SoftwareSerial::begin(long int)’:
    /usr/share/arduino/libraries/SoftwareSerial/SoftwareSerial.cpp:383:31: error: ‘table’ was not declared in this scope
    /usr/share/arduino/libraries/SoftwareSerial/SoftwareSerial.cpp: In member function ‘virtual size_t SoftwareSerial::write(uint8_t)’:
    /usr/share/arduino/libraries/SoftwareSerial/SoftwareSerial.cpp:458:26: error: ‘XMIT_START_ADJUSTMENT’ was not declared in this scope

    appear to be due to the 12Mhz speed of the ATMEGA328P and the support for only 20,16,or 8 meg processors in the SoftwareSerial.cpp file.
    #error “This version of SoftwareSerial supports only 20, 16 and 8MHz processors”

    This is a major issue for those wishing to run Arduino sketches using the Debian Arduino IDE. Can anyone help with the appropriate code to include in this file where e.g. for 8 Meg the entries are:
    #elif F_CPU == 8000000

    static const DELAY_TABLE table[] PROGMEM =
    {
    // baud rxcenter rxintra rxstop tx
    { 115200, 1, 5, 5, 3, },
    { 57600, 1, 15, 15, 13, },
    { 38400, 2, 25, 26, 23, },
    { 31250, 7, 32, 33, 29, },
    { 28800, 11, 35, 35, 32, },
    { 19200, 20, 55, 55, 52, },
    { 14400, 30, 75, 75, 72, },
    { 9600, 50, 114, 114, 112, },
    { 4800, 110, 233, 233, 230, },
    { 2400, 229, 472, 472, 469, },
    { 1200, 467, 948, 948, 945, },
    { 600, 948, 1895, 1895, 1890, },
    { 300, 1895, 3805, 3805, 3802, },
    };

    const int XMIT_START_ADJUSTMENT = 4;

    Any help would be much appreciated, would doubtless help others and should be on the Arduino Forum.