Programming the Gertboard using Another Computer

The title of this page may seem a little counter-intuitive – why would you want to use another computer to program something that can easily be done from the RPi?
I have already written a guide to programming the ATMEGA328p from the command line; however, at the end of that page I mentioned the fact that the process ties up the SPI pins on the RPi which can mean constant unplugging/plugging of jumpers and wires. The answer to avoiding this issue is to program the chip using another computer.

What you will need:
Essential:

    A Raspberry Pi connected to a Gertboard
    Another computer with the Arduino IDE installed
    Another Arduino board (I have used a Pro Mini w/ ATmega328p clone costing £1.99 with an FTDI cable (see below for details))
    A 4 Channel Logic Level Converter
    Connecting wires

Optional:

    Some LEDs + protective resistors

Here are a couple of pictures of my setup, I will explain the details as we go along.

Top View
Top View

Side View
Side View

There is a lot of stuff in these pictures that’s not relevant to this tutorial, the main bit to focus on is the stuff on the left hand side of the breadboard. Here is a Fritzing Schematic of the setup.

Gertboard ISP_bb

In the left is the FTDI USB To RS232 TTL PL2303HX Auto Converter Module (they go for about £1.00 on ebay). This connects to an Arduino Pro Mini (£2.00 on ebay), I have the 5V version as I use it for other applications. Then I have the logic level converter (£2.50 from ebay); however, you could just use some resistors as a potential divider if you want to save a bit of cash. The LEDs (with 220 Ω protective resistors) are indicators showing the progress of the programmer.
The wiring is as follows:
Indicators
Pin 7 -> Yellow LED – Communication in progress
Pin 8 -> Red LED – Error
Pin 9 -> Heartbeat – Indicates programmer is running
SPI
Pin 10 -> Slave Reset 5V -> Slave Reset 3V3 -> Gertboard J23 Pin 5
Pin 11 -> MOSI 5V -> MOSI 3V3 -> Gertboard J23 Pin 4
Pin 12 -> MISO 5V -> MISO 3V3 -> Gertboard J23 Pin 1
Pin 13 -> SCK 5V -> SCK 3V3 -> Gertboard J23 Pin 3
The level converter also needs 5V and 3V3 and GND.

Once it’s all wired up you need to make the Pro Mini into a programmer. Fire up the Arduino IDE on the external PC and open the ArduinoISP sketch from the examples. Upload this onto the Pro Mini, there’s no reset pin on my FTDI converter so I have to manually press the reset on the Pro Mini as soon as the compilation finishes. I all goes well the LEDs will flash in the order Y, R, G and the Green will remain pulsing.

Now we have to tell the Arduino IDE about the ATMEGA328p on the gertboard. Open up your boards.txt in the Arduino installation directory on your computer (/usr/share/arduino/hardware/arduino/boards.txt on linux) and add the following lines to the top:

##############################################################

gert328.name=Gertboard with ATmega328 (w/ Arduino as ISP)
gert328.upload.using=arduino:arduinoisp
gert328.upload.protocol=arduino
gert328.upload.maximum_size=32768
gert328.upload.speed=19200
gert328.upload.disable_flushing=true

gert328.bootloader.low_fuses=0xE7
gert328.bootloader.high_fuses=0xDA
gert328.bootloader.extended_fuses=0x07
gert328.bootloader.path=atmega
gert328.bootloader.file=ATmegaBOOT_168_gert328.hex
gert328.bootloader.unlock_bits=0x3F
gert328.bootloader.lock_bits=0x0F

gert328.build.mcu=atmega328p
gert328.build.f_cpu=12000000L
gert328.build.core=arduino
gert328.build.variant=standard

Restart the Arduino IDE and check that the board definition is at the top of the boards list (Tools->Board) and select it. Next you must select “Arduino as ISP” from the Programmer options (Tools->Programmer). Now open up a sketch to upload to the Gertboard (Blink is a good first test) and hit Ctrl-Shift-U to upload using programmer. If all goes well the yellow LED will flash rapidly and then go out – that’s it…! Wire up an LED from the PB5 pin on the Gertboard and it should blink. You can now upload code to your Gertboard without using the RPi.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s