Using the Arduino IDE with the Gertboard

If you are familiar with the Arduno IDE on any other platform, then there should not be any surprises using it on the Raspberry Pi with the Gertboard.

There is one notable thing you need to do to make it work though, and that is to select the correct programmer and device before you upload a sketch to the ATmega.

To do this, launch the Arduino IDE and select:

Tools -> Board

and select either the Gertboard with ATmega328, or the Gertboard with ATmega168 options.

Next select:

Tools -> Programmer

and select the Raspberry Pi GPIO option. You should be ready to go after that.

Load up the

Examples -> Basics -> Blink

sketch and upload it to the ATmega. To actually see it doing something, you’ll need to connect a jumper wire from pin 13 on the ATmega (That’s PB5 on the Gertboard) to one of the buffered drivers set to output mode.

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)

Serial console access

To access the serial console on the ATmega it’s probably easier to use a separate program to the Arduino IDE, and minicom is recommended.

sudo apt-get install minicom
cd /etc/minicom
sudo wget

then you can simply type (in a terminal window)

minicom ama0

to open up the serial port. It’s defaulted to 9600 baud, but that should be fine for most of the demo sketches.

Note: You may need to add the ‘pi‘ user into the ‘tty‘ group to be able to access the on-board serial port. If you get a permissions denied type of error, then run this command:

sudo adduser pi tty

for other Linux distributions you may need to check the permissions and ownership of the /dev/ttyAMA0 device and adjust accordingly.


Using the Arduino IDE with the Gertboard — 51 Comments

  1. Hi, can I double check that the following line is actually correct :
    cd /etc/minirc

    after installing minicom I don’t seem to have a minirc folder, instead I have a minicom folder.
    should the line not be :
    cd /etc/minirc ?

    Thanks !

  2. Hi Gordon
    Forgive me for being daft, but how do I launch the Arduino IDE? I have got as far as here:

    Using the Arduino IDE with the Gertboard
    If you are familiar with the Arduno IDE on any other platform, then there should not be any surprises using it on the Raspberry Pi with the Gertboard.

    There is one notable thing you need to do to make it work though, and that is to select the correct programmer and device before you upload a sketch to the ATmega.

    To do this, launch the Arduino IDE and select:

    Tools -> Board

    • If you’re running the LXDE (or other windowing environment), then there is usually a menu item – somewhere. If not, then start up a terminal and just type:


      which should then start it going.


  3. Hi, I’ve followed this guide all the way to testing the board using the basic Blink example, however after I choose “File -> Upload using programmer”, I get this error:
    avrdude: verification error, first mismatch at byte 0x0000
    0x0c != 0x00
    avrdude: verification error; content mismatch

    I’ve tried searching around for some answers however there doesn’t seem to be any information on Gertboards except for your guide here. Has anyone else experienced this or have any suggestions?

    • Regarding my post, all I was missing was the jumper on the 3v3 in J7! As the the Gertboard manual says:

      “There is one jumper that should be in place at all times on the board: the one connecting pins 1 and 2
      in header J7. This is the jumper that connects power from the power input pins to the rest of the board.”

  4. Hi Gordon – I’m trying to run Adafruit’s raw IR decoder sketch (it’s at with a Pi, Gertboard, IR sensor connected to PD2, and remote IR controller. The sketch uses Serial.*** statements, and is supposed to open up a COM console on a PC. As I’m using the Pi, I have run your instructions for minicom, but nothing seems to happen when I point the IR controller at the the IR sensor on the breadboard. I know the IR sensor is working, because I have an LED flashing when I press a button on the IR controller. Have you any suggestions?

    • I don’t know too much about IR, but I think if you’re connecting that directly into the serial line it won’t work – that chip/sensor decodes the IR – which is a 38KHz carrier – pulsed for each bit sent, so you might need to further decode the serial data stream coming off the sensor – which I’m not sure is rs232 format… I’d need to do more reading to work out the actual protocol, but have you seen the LIRC modules for Linux?


  5. Thanks Gordon – my query was more about getting a COM or other console to open up, hopefully with the aid of minicom.

    Your help as usual is appreciated, as novices like me can simply hit a brick wall without help.


    • The Pi’s serial device is /dev/ttyAMA0 – so enter that into minicom. The issue might be the baud rate – I’ve no idea what that might be – start with 9600 and go down from there – it probably won’t be higher as there just isn’t enough bandwidth in 38KHz to send any more data down.

      Are you use the softwares that use the COM port under Windows aren’t polling the DCD/DTR lines rather than reading the serial data directly?


  6. Hi Gordon
    The sketch I want to get working is supposed to open up a window as follows:
    But unfortunately no window is opened up on the Pi. That’s my problem.
    The sketch is reproduced below:
    /* Raw IR decoder sketch!
    This sketch/program uses the Arduno and a PNA4602 to
    decode IR received. This can be used to make a IR receiver
    (by looking for a particular code)
    or transmitter (by pulsing an IR LED at ~38KHz for the
    durations detected
    Code is public domain, check out and
    for more tutorials!

    // We need to use the ‘raw’ pin reading methods
    // because timing is very important here and the digitalRead()
    // procedure is slower!
    //uint8_t IRpin = 2;
    // Digital pin #2 is the same as Pin D2 see
    // for the ‘raw’ pin mapping
    #define IRpin_PIN PIND
    #define IRpin 2

    // the maximum pulse we’ll listen for – 65 milliseconds is a long time
    #define MAXPULSE 65000

    // what our timing resolution should be, larger is better
    // as its more ‘precise’ – but too large and you wont get
    // accurate timing
    #define RESOLUTION 20

    // we will store up to 100 pulse pairs (this is -a lot-)
    uint16_t pulses[100][2]; // pair is high and low pulse
    uint8_t currentpulse = 0; // index for pulses we’re storing

    void setup(void) {
    Serial.println(“Ready to decode IR!”);

    void loop(void) {
    uint16_t highpulse, lowpulse; // temporary storage timing
    highpulse = lowpulse = 0; // start out with no pulse length

    // while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 <= MAXPULSE) && (currentpulse != 0)) {
    // we didn’t time out so lets stash the reading
    pulses[currentpulse][0] = highpulse;

    // same as above
    while (! (IRpin_PIN & _BV(IRpin))) {
    // pin is still LOW
    if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
    pulses[currentpulse][1] = lowpulse;

    // we read one high-low pulse successfully, continue!

    void printpulses(void) {
    Serial.println(“\n\r\n\rReceived: \n\rOFF \tON”);
    for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");

    // print it in a 'array' format
    Serial.println("int IRsignal[] = {");
    Serial.println("// ON, OFF (in 10's of microseconds)");
    for (uint8_t i = 0; i < currentpulse-1; i++) {
    Serial.print("\t"); // tab
    Serial.print(pulses[i][1] * RESOLUTION / 10, DEC);
    Serial.print(", ");
    Serial.print(pulses[i+1][0] * RESOLUTION / 10, DEC);
    Serial.print("\t"); // tab
    Serial.print(pulses[currentpulse-1][1] * RESOLUTION / 10, DEC);
    Serial.print(", 0};");
    If you run this while pointing a Sony IR remote and pressing the ON button you will get the following…

    • OK. So are you actually using an arduino? I was under the impression that you’d connected this sensor directly to the Pi… (via the Gertboard)

      From what I can gather, that script is designed to run on an arduino, and decodes the pulses coming off that sensor and presents them as human readable to the serial port – connected to a Win PC running some terminal program…

      If you have connected it to the Pi, then you’re going to have to translate that program into something that will run on the Pi… And here you’ll have a problem as despite its speed, the Pi won’t have as accurate timing as an Arduino (in user land anyway), so for good results, it needs a kernel level driver. (Google LIRC) You may get away with it 9 times out of 10 though.


  7. Yes Gordon – I have it connected to the Gertboard’s PD2 – the Gertboard’s Arduino pin 2. Do you think there’s any way I could get this to work with the Gertboard and Pi?

    • OK. I’d go back to basics. Upload a test sketch to the ATmega that just prints “Hello world” in a loop. Then see if you get that going on the Pi.

      Then you can re-upload the IR sensor one and see if you can make that print anything…


  8. Thanks Gordon – I tried the following sketch using the Arduino 1.0.1 program. I don’t know if you’re familiar with this software, but it allows a user-friendly version of C to be used. The relevant connections for programming the ATmega are made, and the sketch does upload, but it doesn’t work!! :

    Test sketch to print “Hello World” using Gertboard & RasPi
    (when using this with a Windows PC you would expect a COM
    window to open and display the Serial.println string)

    // the setup routine:
    void setup() {
    // initialize serial communication at 9600 bits per second:

    // the loop routine runs over and over again forever:
    void loop() {
    printf(“Hello World”); //doesn’t do anything !
    Serial.println(“Hello World”);

    • Remove the programing wires and try again. Or run this after programming:

      gpio unexportall

      and see what happens. Some boards seem seneitive to having the wires connected after programming.


  9. Hi Gordon,

    Between your excellent tutorial and Gert’s documents, I’ve got the ATmega running like a charm and I’m having a ball making it play with the Pi.

    This is really a neat way to work with cooperative electronics/computing!

    Thanks for all of your work and guidance!

  10. Hi,

    I used your excellent guide about month ago to get my gertboard and ATmega running straight away. I have since been testing and running a number of sketches with no issue until today when I start getting verification errors on upload and I am stumped.

    avrdude: verification error, first mismatch at byte 0×0002
    0x52 != 0×40
    avrdude: verification error; content mismatch

    It first happened when I attempted to upload a sketch with some slight modifications to one that was currently running on the ATMega and runing with no issue. I have since checked all the connections and removed connections not required for upload but still no joy.

    What else can I try and is it possible that the ATMega is blown?

    Thanks in advance,


    • I think it’s unlikely it’s ‘blown’ (I’ve not managed to do that in several years of tinkering!) However, I’m wondering about other things – like a Raspberry Pi upgrade (apt-get update/upgrade ?) That might have pulled in a newer version of the atmega utilities which will overwrite the config files.

      Have a look at:/usr/share/arduino/hardware/arduino/boards.txt and /usr/share/arduino/hardware/arduino/programmers.txt to see if they still have the definitions in them.

      If they have, then plan B might be to check for the presence of the SPI driver in the Pi – make sure it’s not loaded and any other programs that may have used the GPIO pins.

      Also try running

      gpio unexportall

      before programming too…


      • I have the same verification problems…

        Some time ago I did my first experiments with uploading sketches. Blink worked fine. Made some changes, uploaded and got the verification error.
        No result with ‘gpio unexportall’ and gave up for a while.

        I now popped in a new 328P, re-ran avrsetup.
        First tried my modified blink sketch and all went well.
        Then tried to run ‘blink’ and the verification error was back.
        Tried all the checks and potential remedies (checked board & programmer settings, deactivated SPI driver and ran ‘gpio unexportall’) without result…

        Any ideas?

        • Going to have to do more tests myself on this. Avrdude doesn’t touch any of the setup fuses, just the flash protection bits, so I’m not convinced that the chip is “bricked”. It is possible it’s something to do with the GPIO pins on the Pi being left set as outputs though – but I’ll need to do more tests myself.


          • Update: Doing “File -> Upload using programmer” instead of just “upload” fixed my verification problem. I dont know why upload stopped working in the same dev session with no other pi “activity” such as upgrades.

          • Clive’s solution (using ‘upload using programmer’) also works for me.

            I did a bit of testing and found out that ‘normal’ upload *does* work after I erase the chip using ‘avrdude -p atmega328p -c gpio -e’.

          • It seems that (not) erasing before uploading is indeed the problem here. The Arduino IDE generates a different command line for ‘upload’ and ‘upload using programmer’: the latter has the erase option (-D) and the former does not.

    • Removing the B1 jumper stopped my upload verification problems with the blink sketch. But why? I understand that the Buf1 LED (when connected to PB5) will not blink with the B1 jumper in place because of voltage conflicts but not why it stops the sketch being loaded.

      • PB5 on the ATmega is the SPI SCKL signal from the Pi into the ATmega – used during programming. So if you have jumpered PB5 to B1 then it might be interfering with the clock from the Pi to the ATmega.


  11. Hi Gordon,
    have just purchased the Pre-Assembled Gertboard and having fun with that. I have done some Arduino programming before so was excited to try with the built in chip. With your excellent site I managed to get it up and running without too much trouble, so thank you.

    Everything seems fine so far except …. The delay(1000) is giving me a 10 second delay (or there abouts) not 1 second. I checked the boards.txt file and the clock seems to be OK 12000000L.

    Any other thoughts?

    at the moment I just changed the sketch to be delay(100) but I’d rather know what I was doing wrong.

    Thanks again


    • It sounds like the fuses have not been programmed correctly and the ATmega is running at 1MHz. (Internal 8MHz RC oscillator divided by 8 is the default) Did you run avrsetup on it?


  12. I have my self-assembled Gertboard up and running with many of the tests completed including the ATmega and the Adiuno IDE. Thank you for your first class tutorial and taking the time. Thanks to you it’s all looking Blinking Good!


  13. Gordon,

    First off, thanks for all the hard work on this! Much appreciated. 😀

    Now, for my question… I’m having an issue compiling a program with this setup. I’ve got a cheap OLED module here, which came with an Arduino library:

    The GraphicLCDAdapterDemo compiles just fine on my Mac with 1.0.4, but I can’t get it to compile with the Linux IDE on my RPi. It doesn’t seem to want to accept prog_uchar as a valid type. (GraphicLCDAdapterDemo.cpp:23:1 error: ‘prog_uchar’ does not name a type)

    I’m thinking it might be a compatibility issue with the version of avr-libc or one of the other libs. Any ideas?


  14. Hi Gordon,

    Thanks for these great setup guides! I Got Blink example working with gertboard + Atmega328, but the IDE will only upload if I start arduino IDE as root (i.e. sudo arduino &). Otherwise it complains about permissions on the GPIO port (” gpio/export: Permission denied”)

    Is there any way to set that up so I can run it as ‘ordinary’ user ? (I logged in as ‘pi’ on the latest raspbian distribution) Did I miss a step somewhere ? I don’t see any references to this fault from other users…

    Many thanks, Frank.

    • Sorry I fixed this now – seems I missed out the step ‘sudo chmod 4755 avrdude’ ! This fixes the permissions.

  15. Gordon,

    I have followed your instructions and successfully loaded up the Arduino IDE onto the Raspberry PI to support the Gert board.

    Is the IDE extendable to support additional programming languages rather than Sketch?

    Alternatively can the uploader be used to upload code produced elsewhere onto the AVR on the Gert board?



    • You can program the ATmega directoy in C or C++ if you like. There are online tutorials if you search. Personally, I never use the IDE myself (well, vary rarely), but I’ve not had time to publish my own systems.

      You can drive avrdude manually (or in a makefile) if needed. You just need the .hex file, then something like:

      avrdude -p atmega328p -V -B 50 -c gpio -U flash:w:filename.hex:i


  16. Thanks for this tutorial. Really easy to follow. Up and blinking in a very short time. Like the poster David, I forgot to put the jumper on J7. But that was my only problem

  17. Can you try uploading the following Arduino sketch code in the Raspberry Pi Arduino IDE and observe the compile erros that I am experiencing. The same code compiles without error on the PC version of the Arduino IDE. The two SoftwareSerial examples will not compile either.


    SoftwareSerial BTSerial(10, 11); // RX | TX

    void setup()
    pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
    digitalWrite(9, HIGH);
    Serial.println(“Enter AT commands:”);
    BTSerial.begin(38400); // HC-05 default speed in AT command more

    void loop()

    // Keep reading from HC-05 and send to Arduino Serial Monitor
    if (BTSerial.available())

    // Keep reading from Arduino Serial Monitor and send to HC-05
    if (Serial.available())

    Kind regards


    • I don’t use the Arduino IDE or use “sketches”, sorry.

      Maybe if you actually listed the compiler errors I might be able to help though. They’re usually quite informative.

      It’s possible that the Debian version of the Arduino IDE doesn’t support software serial though. I remember having to poke about with this for some other project before I decided to never use the Arduino IDE ever again.


      • This is the output after compiling the sketch.
        avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=12000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/SoftwareSerial /tmp/build7622045544577904400.tmp/SoftwareSerialExample.cpp -o /tmp/build7622045544577904400.tmp/SoftwareSerialExample.cpp.o
        avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=12000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/SoftwareSerial -I/usr/share/arduino/libraries/SoftwareSerial/utility /usr/share/arduino/libraries/SoftwareSerial/SoftwareSerial.cpp -o /tmp/build7622045544577904400.tmp/SoftwareSerial/SoftwareSerial.cpp.o
        /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

        I am trying to use the sketch at to talk to a Bluetooth Module. Perhaps you may have other suggestions.

        • I presume you saw the error about the softtwareSErial only supporting 20, 16 and 8 MHz processors? On the Gertboard at 12MHz it’s a no-go…


  18. Thank you for the wonderful tutorials – they’ve been very helpful.

    When I upload a sketch to the ATMega from the RPi it seems that I get one shot. Any other attempts to upload a sketch will seem to work, but the sketch doesn’t seem to execute unless I reboot the RPi (which must send a reset of some kind to the ATMega).

    Has anyone else experienced this behavior? I’m using Debian Wheezy, the latest full image as of 12/2013, all packages up to date AFAIK.


  19. I am trying to access the serial monitor with Gertboard/Pi combination and to write to the monitor but I get a COM1 error and suggestion that I look in Arduino IDE Tools/Serial Port menu but is is grayed out. How can I get access to the Serial Port menu item please? Regards