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