The Gertboard is an I/O expansion board designed for the original Raspberry Pi, providing a wide range of inputs and outputs, and a microcontroller, giving the user a convenient means to interface and experiment with the Pi while adding a layer of hardware protection to the Pi. You may be interested in Farnell Global's video in which Gert van Loo is interview about the Gertboard:
Read on to learn more about the Gertboard and my experience of using it.
I got a Gertboard I/O expansion board in 2024 from eBay for a little over £8 ($10) shipped, considering the board is from 2012 and is now retired it's just as well I didn't pay too much for it as I had some difficulty getting it working, as we'll see later on. The box claims exclusively from element14 and that it was designed by Gert van Loo, hence the board's name (Gertboard). Contained in the box, in addition to the Gertboard, you get a Gertboard Regulatory Compliance and Safety Information leaflet, x8 F-F jump wires, x16 shunts, x6 posts, Welcome to the world of ARM leaflet, and a CooCox CD. On the CD is has written 'Free and open ARM Cortex M development tools', 'CooCox', and 'www.coocox.org'.
The URL is down but an archived version from 2017 can be found at:
https://web.archive.org/web/20171228015754/http://www.coocox.org/
Looks like the site went down in 2018.
CooCox CoIDE can be found mentioned on a STMicroelectronics page:
https://www.st.com/en/development-tools/coide.html
Under Tools & Software it gives the option to download STM32CubeIDE and STM32CubeProg, as if they are replacements.
On the CD there is installation for CooCox CoIDE, and links to various development board accessories and other hardware. While I understand that the CD could be very useful to someone interested in ARM development it would have made more sense to provide Gertboard related software, documentation, etc.
A summary of the Gertboard features is as follows:
Various buttons, LEDs, DAC, ADC, motor controller, Atmel AVR MCU (Microcontroller Unit)
x12 buffered I/O
x3 pushbuttons
x6 open collector drivers 50V 0.5A
48V 4A (first board version)/18V 2A motor controller (second board version)
ATmega MCU ATmega168/328
2 channel 8/10/12 bit DAC
2 channel 10-bit ADC
The manual is well written and goes into a lot of detail how to use the board. There are at least a couple of different versions of the user manual available online, due to there being two main revisions of the Gertboard. Revision 1.0 can be found at:
https://cdn-reichelt.de/documents/datenblatt/A300/DS_USER_MANUAL.pdf
This is for an older version of the Gertboard which came as a kit that had to be assembled (but there are no assembly instructions in the manual), and it connects to the Raspberry Pi's GPIO header with a ribbon cable. As you can see in the photo on page 7 the 12 LEDs are THT (Through-Hole Technology) type whereas the version of the Gertboard I have uses SMD (Surface-Mount Device). Another difference is that all the ICs are socketed but on my Gertboard only the MCU (Microcontroller Unit) is in a socket. This version of the manual has the board schematics in Appendix A, whereas other versions of the manual do not, such as Revision 2.0:
https://www.farnell.com/datasheets/1683444.pdf
In this version the photo on page 5 closely matches the Gertboard I have with the SMD LEDs and only the MCU socketed, likely this version was not available in kit form, and plugs directly into the Pi's GPIO header, and appears to be from 2014. There are some other differences between these two manuals, the first one I linked to has more information in the Overview section at the beginning. The second manual doesn't have the board schematics at the end but otherwise both manuals should be generally adequate for working with either version of the Gertboard.
This video confirms that the original version of the Gertboard was a kit that had to be assembled and the later version was sold already soldered:
It also reveals that the newer version of the Gertboard has a weaker motor controller, looking at the manuals we can see that it was rated for 48V @ 4A in the original and 18V @ 2A in the later version.
While the Gertboard was originally designed for the first Raspberry Pi it should be is compatible with Pi2+, including Pis which have more GPIO header pins, however the extra GPIO pins will be inaccessible if the Gertboard is plugged directly into the Pi. Alternately, you could run wires between the Gertboard and Pi GPIO pins rather than plug straight in, either way, plugging in or removing the Gertboard must only be done with the Pi disconnected from power.
If you have the version of the Gertboard that plugs straight into the Pi's GPIO, look for pin 1 of J1 on the Gertboard, it'll have a square outline. On the Pi, GPIO header pin 1 will have a square solder blob on the PCB on the underside. Line up the female and male connectors and push the Gertboard carefully into the Pi, making sure you don't misalign the pins, if done right the Gertboard will hang off the Pi so-to-speak. If you are using a ribbon cable to connect the Gertboard to the Pi ensure that pin 1 on the Gertboard header matches with pin 1 on the Pi's GPIO header.
For testing I used an original Raspberry Pi as it seemed fitting and I hoped there wouldn't be any issues getting the Gertboard working, which I was proved wrong (as we will see later) - note that I was initially using Raspbian Wheezy. With the Gertboard plugged into the Pi and powered on there were no LEDs lit until I placed a shunt on header J7 (placed toward U1). Powering the Pi from a phone charger I measured 4.65V between 5V (J24, either pin) and GND (example, J28). However, using the official Pi power supply (5.1V, 2.5A) I got 5.02V, which shows how important it is to use a decent power supply. Without the shunt on J7 I measured 0.46V between 3.3V (3V3 header, either pin) and GND, with J7 shunt installed the reading was 3.31V.
To make life a bit easier (or so I thought) with testing the Gertboard I opted to try out the Python test programs, so they will be covered in this section. The manual has information for both the C and Python examples, take note. I will be referring to the Revision 2.0 manual, other versions the page numbers that I mention will be different.
For Python, instructions on installing the test code start on page 13. Use:
wget http://raspi.tv/download/GB_Python.zip
In a terminal window on the Pi to get the example code. You can then do the following:
unzip GB_Python.zip
cd GB_Python
ls
To unzip the downloaded file, move to the directory, and list the extracted files.
The manual instructs to read README.txt to learn how to install required packages. You can do:
nano README.txt to view the file.
The manual explains that there are test programs for WiringPi and RPI.GPIO, since neither has all the features of the other (or at least when the Gertboard was made). So its recommended to install both Wiring and RPI.GPIO. To install WiringPi:
sudo apt-get update
sudo apt-get install python-dev python-pip
sudo pip install wiringpi
The second line didn't work for me, saying it failed to fetch the archives. Looking online, it would appear WiringPi is deprecated but RPI.GPIO should already be included in Linux. To check RPI.GPIO version:
sudo python
import RPi.GPIO as GPIO
GPIO.VERSION
Which returned 0.5.2a for me.
Exit out of Python with CTRL+D.
Going back to the example code, we can run any of the 'rg' versions, which use RPI.GPIO, so that is what I used.
To run the LED test code:
sudo python leds-rg.py
When the program runs it explains how to wire up, and enter is pressed to run the test. Page 20 of the manual goes into more detail about how to wire the 'Testing the LEDs' test and how it works. I found that after installing the required shunts, my fingers getting close to the board caused any of the LEDs that were off to turn on (looking online other people have had the same issue, likely caused by the current in our bodies influencing the GPIO). Nevertheless, when the test program ran it turned the 12 LEDs D1 to D12 on/off in different sequences.
Now I will go through the test examples from the manual that I tried out but there are more covered in the manual.
I also tried Button test on page 17, I ran the Python version using:
sudo python buttons-rg.py
When run, press enter to confirm you have wired the Gertboard correctly, then the initial button state, 111, will be displayed if no buttons are pressed. Pressing S1 will print 011 and D1 will go out, S2 will print 101 and D2 turn off, S3 will print 110 and D3 turn off. I had to be careful as my fingers were causing the LEDs to turn on and some of the other LEDs were on regardless.
Next I tried the ocol (open collector) example on page 24. I sued similar wiring, but I used two green 2V 20mA LEDs in series with limiting resistor 270R, and a 9V battery. Note that they manual says the Python examples are ocol-wp.py and ocol-rp.py but the latter is actually ocol-rg.py. When run the program, have to select the driver number, which should be 1 if the LEDs wired to RLY1 like in the example wiring.
The motor controller is detailed on page 27. I used a small motor and 9V battery for the motor power. Because I'm used RPI.GPIO the PWM is software controlled, as it doesn't support hardware PWM (or at least not when the manual was written). With software PWM the motor may not spin so smoothly, I found at low speed the motor struggled to turn but once the speed was increased enough it ran happily.
The Digital to Analogue Converter (DAC) and Analogue to Digital Converter (ADC) are introduced from page 32. As mentioned, you can check U10 to see what version of MCP48x2 has been fitted, my board has 4802 so it's an 8-bit chip. Testing DAC can be done using dtoa.py for the Python version, as well as fitting the specified jumpers, you need to connect a multimeter to GND, and DA0 for channel 0, or DA1 for channel 1.
Before running the test program, make sure you have SPI (Serial Peripheral Interface) installed, something I neglected to do when reading the readme file. In the readme file it mentions editing raspi-blacklist.conf, then after rebooting installing the Python SPI wrapper:
cd ~
git clone git://github.com/doceme/py-spidev
However, git returned with:
fatal: unable to connect to github.com
Fortunately we should be able to do it another way, first install pip:
sudo apt update
sudo apt install python-pip python3-pip
or
sudo apt-get update
sudo apt-get install python-pip python3-pip
Which is the older way of doing it and the way I had to do it, however, it failed to fetch the archives. This is a similar issue to sudo apt-get install python-dev python-pip failing, likely due to using an older Pi and older operating system.
I did:
sudo apt update
sudo apt upgrade
But I still couldn't install pip.
Going back to original issue of needing to install py-spidev via git clone, I found online it was recommended to replace 'git:' with 'https:' and I found that worked. I used:
git clone https://github.com/doceme/py-spidev
Then followed remaining instructions in the readme file to get SPI working. However this requires sudo apt-get install python-dev which fails. Ultimately issue is Wheezy is out of date and the archives have been moved, I should have used a newer operating system. So I decided to install to the SD card Bookworm, the most recent Pi operating system (at the time), and surprisingly supported by original Pi, although, not surprisingly the performance is very slow.
I then download and extracted the software again and moved on to enabling SPI, which I did through the Raspberry Pi Configuration tool (accessible from the Applications/Preferences menu), by clicking on the Interfaces tab and toggling SPI on, then clicking the OK button.
Trying:
git clone git://github.com/doceme/py-spidev
Resulted in same error as before. So I did:
git clone https://github.com/doceme/py-spidev
Which worked. Then I did:
cd py-spidev/
sudo apt-get install python-dev
The second command resulted in error:
Package python-dev is not available, but is referred to by another package.
This is possibly because Python 3 is installed by default so you need to do:
sudo apt-get install python3-dev
However, when I ran it, it said the newest version (3.11.2-1) was already installed. So I went on to the next step:
sudo python setup.py install
Then I went back to dtoa.py but when I ran it I got error:
SyntaxError: Missing parentheses in call to 'print'.
This is because from Python 3 print became a function. One solution would be to edit dtoa.py, another would be to install an earlier Python version alongside Python 3 (V3 can be removed if you want). Going with the former option, I edited the file:
sudo nano dtoa.py
And added the parentheses. Now when I ran dtoa.py I got an error about spi_bcm2708 not found. I did try restarting the Pi yet I got the same error. The issue seems to be with the way dtoa.py is written, which loads/unloads module bcm2708 (the original 'Pi' chip), rather than bcm2835, which is what the original Pi later used. Running lsmod, I could see bcm2835 is referenced.
I checked raspi-blacklist.conf and it was empty. The recommendation online was to add:
dtparam=spi=on
to:
/boot/config.txt
Opening the file it said to not edit and instead edit /boot/firmware/config.txt. However, dtparam=spi=on was already there, since the Raspberry Pi Configuration app, which I used to enable SPI, already added the line.
I edited dtoa.py and replaced both occurrences of spi_bcm2708 with spi_bcm2835, exited, saved and ran, and there was no SPI error. However, there was another error:
NameError: name ‘raw_input’ is not defined
In Python 3, raw_input() became input(), so once again we could install an older version of Python, or run with Python 3 but change raw_input() to input(), which is what I did. There are four occurrences raw_input() that need to be changed. After editing, dtoa.py now ran, prompting for the DAC channel to test, 0 or 1. The program will go through setting different voltages, which can be read with a voltmeter connected to DA0 and GND for ch. 0, or DA1 and GND for ch. 1. This ran successfully for ch. 0 but when I ran again but specifying ch. 1 I got error:
Modprobe: ERROR: could not insert ‘spi_bcm2835’: Device or resource busy
Run again and specifying ch. 0 I get error:
rmmod: ERROR: Module spi_bcm2835 is not currently loaded.
I restarted the Pi, ran dtoa.py again, selected ch.1 and it worked.
For testing the ADC we can use atod.py with a potentiometer opposite ends connected to 3.3V and GND, wiper to AD0 for channel 0, or AD1 for channel 1, as described on page 34. The shunts that need to be installed are slightly different to dtoa.py, take note. For atod.py to run I had to edit the file just like with dtoa.py; replace all occurrences of spi_bcm2708 with spi_bcm2835, replace all occurrences of raw_input() with input(), but I didn't need to add parentheses for the print statements, however. The print() function in display(), which starts with:
print ('\r',"{0:04d}"
causes an error:
TypeError: can't multiply sequence by non-int of type 'float'
What the code is supposed to do is print a variable number of '#' symbols and spaces depending on the position of the pot wiper so perhaps Python 3 doesn't like a float being used to do that. The fix is to cast reps to int in the while loop. Modify:
reps = adc_value / 16
to:
reps = int(adc_value / 16)
After saving the changes and running atod.py I got error:
FileNotFoundError: [Errno 2] No such file or directory
After multiple restarts I got the program to run but it always displayed '0000' regardless of the position of the pot wiper - I confirmed with a multimeter it was connected correctly.
Ultimately, the test code needs to be rewritten but to confirm whether the ADC chip was at fault I found an alternate means to install WiringPi:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
./build
And confirmed it was successful with:
gpio -v
Then on this page it shows a quick way to test the ADC:
https://forums.raspberrypi.com/viewtopic.php?t=41680
We can run the following from the terminal:
gpio gbw 0 0
gpio gbr 0 # Expect 0
gpio gbw 0 128
gpio gbr 0 # Expect 332
gpio gbw 0 255
gpio gbr 0 # Expect 664.
Make sure you have the shunts installed including the one on CSnA and GP8, and CsnB and GP7 just like in the dad.py example on page 35, also connect a wire between AD0 and DA0. When I ran the above code in the terminal I got zero as expected but for the second test I got 559 instead of 332, and for the third test I got 87 instead of 664. Although the ADC clearly isn't dead the values aren't what was expected.
Save trying to build the C version of atod, I used gpio gbr to test the ADC further without the DAC, with the pot connected to 3.3V/GND, wiper to AD0. With the wiper turned completely one way gpio gbr 0 gave 0, turned slightly the other way I got 110, 867 for roughly half way, 340 turned some more, and 895 for completely turned the other way. I then connected the pot wiper to AD1 and repeated the tests but using gpio gbr 1 to access ch. 1, which gave similar values.
Again, the values weren't what I expected so I decided to further test using an Arduino compatible board running at 3.3V (save using voltage level converters), using a generic 'Blue Pill' STM32 board that has the Arduino bootloader. You can read about the board on my site:
I used the MCP3XXX library, which can be installed through Sketch->Include Library->Manage Libraries... After installing there will be couple of examples under File->Examples->MCP3XXX, I went with the MCP3002 example., since that's what's fitted on the Gertboard.
I connected the Blue Pill to the Gertboard without the Pi as follows:
Gertboard Blue Pill
SCLK B3
MOSI B5
MISO B4
CSnA 15
3V3 3.3
GND G
I removed the shunt from J7 on the Gertboard - probably not necessary since I didn't have a Pi connected and there's no reason why you couldn't have the Pi connected as well and have the Blue Pill connected to the Gertboard without the 3V3 connection.
I had the pot connected to 3V3, AD0 and GND. After uploading to the Blue Pill the MCP3002 example I opened the Serial monitor set to 9600 in the Arduino IDE and I saw both ADC channel values displayed. Adjusting the pot wiper from one end to the other resulted in values ranging from 0 to 1023, which is what we should have seen when using the Pi. I tested both channels were behaving in that way so its odd why I was getting wrong values when using the Pi.
Getting the ATmega microcontroller (MCU) to work was the most difficult of the tests I tried and while I did eventually get it programmed it took a lot of effort, which you'll see shortly. I'm no Linux expert and had to research the issues I faced to find solutions but I've included my attempts to get it working (which was eventually successful) to show what I went through and possibly save people some trouble should they also acquire the Gertboard.
The ATmega Device is covered from page 41 in the manual, which explains that ATmega48A/PA, 88A/PA, 168A/PA or 328/P are supported in the U8 socket, a 168 or 328 will be fitted (328 on mine). The MCU is run at 12MHz, its I/O routed to header J25, header J23 for programming, UART TX and RX are located next to the Pi's UART pins, making it easy to connect the Pi and MCU via UART. The MCU is operated at 3.3V, presumably to make interfacing with the Pi easier (which uses 3.3V logic) and consequently, the MCU runs at only 12MHz (opposed to 16MHz of Arduino Uno, for example, which also uses a 328).
To program the MCU, you need to use a customised version of the Arduino IDE running on the Pi, information available at:
https://projects.drogon.net/raspberry-pi/gertboard/
On the page are links to each step of setting up and programming the MCU, starting with Arduino IDE Installation.
Install Arduino IDE:
sudo apt-get install Arduino
After that you need to install the modified avrdude package, commands are given for Debian Squeeze and Debian Raspbian, with the only difference being the .deb files. Debian Squeeze was the original Pi operating system, so I wasn't know what 'Debian Raspbian' was supposed to mean. Nonetheless I used the 'Debian Raspbian' version commands:
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
However, the http://project-downloads.drogon.net page no longer exists. We can download it using the Wayback Machine:
wget web.archive.org/web/20200720083417/http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armhf.deb
Then I continued with:
sudo dpkg -i avrdude_5.10-4_armhf.deb
But it reported:
dpkg: dependency problems prevent configuration of avrdude:
avrdude depends on libncurses5 (>= 5.5-5~); however:
Package libncurses5 is not installed.
So I tried the 'Debian Squeeze' version:
wget https://web.archive.org/web/20210224134358/http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armel.deb
Followed by:
sudo dpkg -i avrdude_5.10-4_armel.deb
But that complained that the package architecture (armel) doesn't match system (armhf). It turns out armel is for older ARM devices, but at least I confirmed which version to use.
Going back to libncurses5 issue, it can be installed with:
sudo apt-get install libncurses5-dev libncursesw5-dev
But it complained of unmet dependencies. As recommended online:
sudo apt clean
sudo apt autoclean
sudo apt --fix-broken install
The last command detects that libncurses5 is needed and asks if you want to install it, so there was no need for me to try to manually install it. Now I tried again:
sudo dpkg -i avrdude_5.10-4_armhf.deb
Which was successful. Then I could do:
sudo chmod 4755 /usr/bin/avrdude
The xext step wass to get and run a script:
cd /tmp
wget http://project-downloads.drogon.net/gertboard/setup.sh
chmod +x setup.sh
sudo ./setup.sh
But the link was down so I had to use an archived version:
https://web.archive.org/web/20200817180619/http://project-downloads.drogon.net/gertboard/setup.sh
When I ran:
sudo ./setup.sh
I got error:
Arduino IDE: Not installed. Please install it first
Which is odd as I checked the Arduino IDE was accessible from the Linux Apps Programming menu.
If you open up setup.sh you can see that it detects if the Arduino IDE has been installed by looking for the file programmers.txt in /usr/share/arduino/hardware/arduino/. I checked and it doesn't exist at the specified location but it does at /usr/share/arduino/hardware/arduino/avr/. This is likely because the script was written for an older version of the Arduino IDE, so we can modify setup.sh to use the correct path and run again. However, we cannot modify setup.sh in the tmp folder - the point of using tmp is that the contents will be deleted after reboot so it serves as temporary storage place. One solution to allow editing is to do:
sudo chmod -t /tmp
To remove the sticky bit and later use:
sudo chmod +t /tmp
To put it back once we have finished with the tmp folder. Now when I ran setup.sh it identified that the Arduino IDE was installed and fetched files; boards.txt, programmers.txt, and avrsetup. However, when it came to the 'Replacing/updating files' part, mv failed with No such file or directory, along with lots more 'No such file or directory' errors. The actual issue is that wget fails to fetch the files but because quiet mode was specified (-q) we don't see the errors. So we can modify the script again but use an archived version of the url. So in setup.sh replace:
wget -q http://project-downloads.drogon.net/gertboard/$file
With:
wget -q web.archive.org/web/20200817180620/http://project-downloads.drogon.net/gertboard/$file
You may want to leave out the 'q' param to see if there are any further issues when run setup.sh again. Indeed, it couldn't download avrsetup as it hasn't been archived by waybackmachine. It is available, along with the other files at:
https://github.com/DexterInd/AVRDUDE/tree/master/avrdude
We can download just avrdude from terminal using:
wget https://raw.githubusercontent.com/DexterInd/AVRDUDE/master/avrdude/avrsetup
And manually copy avrsetup to /usr/local/bin and run chmod as in the script if there are any issues.
Running setup.sh again I got error:
inittab: cp: cannot stat 'inittab': No such file or directory
And other errors.
According to:
https://www.networkworld.com/article/930604/unix-how-to-the-linux-etc-inittab-file.html
inittab "controls what happens whenever a system is rebooted or forced to change run levels".
There was no such file in /etc which is why I got the error, since it is no longer included in recent Pi distros. In setup.sh it comments out any lines containing 'AMA0' in inittab, which appears to be a TTY interface used on the Pi. We can get the same result by using the Raspberry Pi Configuration tool, on Interfaces tab turn Serial Console off, and click the OK button. It will prompt to reboot, I said no as I'll do that later.
Going back to setup.sh I commented out the code relating to inittab, ran the script again and now there were no errors as such, just saying the backups exist so at this point I rebooted.
After the Pi rebooted I went on to the next step:
https://projects.drogon.net/raspberry-pi/gertboard/initial-setup-of-the-atmega/
You need to wire up GPIO to the ISP header and then run avrsetup, which will ask for the type of ATmega chip, in my case ATmega328p so I entered '1'. But it failed with 'cannot execute: required file not found'.
Trying to use Arduino IDE will have the same issue since it uses avrdude, which is called from avrsetup.
To review, we need to use the modified version of avrdude to program the ATMega over SPI. According to:
https://github.com/arduino/ArduinoCore-avr/issues/282
avrdude (6.3.0-arduino14) includes linuxspi programmer. I tried installing latest version:
sudo apt-get update
sudo apt-get install avrdude
But it reported the newest version (1:5.10-4) was already installed. We can manually install the latest version, however, and by using build.sh included with the newest avrdude it will auto enable linuxspi. We need cmake:
sudo apt-get install cmake
Note: this resulted in Error: Timeout was reached
We also need some other software:
sudo apt-get install flex
sudo apt-get install bison
sudo apt-get install yacc
Next (make sure you are in the Home directory) we manually get new avrdude:
wget https://github.com/avrdudes/avrdude/releases/download/v8.0/avrdude-8.0.tar.gz
tar xvzf avrdude-8.0.tar.gz
cd avrdude-8.0/
bash build.sh
sudo cmake --build build_linux --target install
avrdude should now be installed, running from terminal should output usage and version. If it doesn't run then try restarting the Pi.
Then I ran avrsetup, which now returned with:
Error: cannot find programmer id gpio
We can confirm it's the right avrdude:
avrdude -c ?type
You should see:
linuxspi = SPI using Linux spidev driver
Next, edit avrdude.conf:
sudo nano /etc/avrdude.conf
Add:
programmer
id = "linuxspi";
desc = "Use Linux SPI device in /dev/spidev*";
type = "linuxspi";
reset = 8;
;
To the end of the list of programmers, then save and exit nano. This was taken from:
https://kevincuzner.com/2013/05/27/raspberry-pi-as-an-avr-programmer/
But I set the reset pin to 8 rather than 25 to match the Gertboard manual wiring.
Edit avrsetup:
sudo nano /usr/local/bin/avrsetup
In do328(), on 'avrdude' line:
Add sudo at start of the line.
replace gpio (following -c) with linuxspi.
Before the first '-U' add:
-P /dev/spidev0.0:/dev/gpiochip0
So in full:
sudo avrdude -qq -c linuxspi -p atmega328p -P /dev/spidev0.0:/dev/gpiochip0 -U lock:w:0x3F:m \
It took some Googling to get the correct syntax and sudo might not actually be necessary. However, when I ran avrsetup and selected 1 I got:
Error: AVR device not responding
It turns out the issue was the reset signal, by using 25 for reset in avrdude.conf under linuxspi programmer, avrsetup was successful, and running avrsetup it reported 'Looks all OK - Happy ATmega programming!'. So I dont know why pin 8, which they used in the Gertboard manual, didn't work.
Next I tried the Arduino IDE. On:
https://projects.drogon.net/raspberry-pi/gertboard/using-the-arduino-ide/
They say to select 'Gertboard with ATmega328' from Tools -> Board but I didn't have that option, the page also instructs to select 'Raspberry Pi GPIO' under Tools -> Programmer but I didn't have that as an option. Firstly, the programmer issue, I checked programmers.txt in /usr/share/arduino/hardware/arduino/ and it looked like it was still using the original version so I opened programmers.txt and added at the beginning the Raspberry Pi GPIO definition, modified from project-downloads.drogon.net to use linuxspi:
gpio.name=Raspberry Pi GPIO
gpio.protocol=linuxspi
This will cause 'Raspberry Pi GPIO' to be a selectable option under Tools -> Programmer in the Arduino IDE.
To add 'Gertboard with ATmega328' (I didn't bother with 'Gertboard with ATmega168') I manually added the definition to boards.txt located in /usr/share/arduino/hardware/arduino/ using the information from project-downloads.drogon.net but modified to use linuxspi:
gert328.name=Gertboard with ATmega328 (GPIO)
gert328.upload.using=gpio
gert328.upload.protocol=linuxspi
gert328.upload.maximum_size=32768
gert328.upload.speed=57600
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
I didn't know if 'gert328.upload.using' should be something other than gpio.
Reopening Arduino IDE I saw 'Gertboard with ATmega328 (GPIO)' under Tools->Board'. With the Blink sketch open, 'Raspberry Pi GPIO' and 'Gertboard with ATmega328 (GPIO)' selected I attempted to compile the sketch which resulted in:
Warning: Board Arduino:avr:gert328 doesn't define a 'build.board' preference. Auto-set to: AVR_GERT328. Other than the warning it did compile. When I tried to upload I got:
Error while uploading: missing 'upload.tool' configuration parameter
The issue may have been caused by a using newer version of the Arduino IDE than when the Gertboard originally came out.
I added to boards.txt:
gert328.upload.tool=avrdude
After saving I closed and reopened the Arduino IDE and attempted upload again. Now when I tried to upload I got error:
Cannot run program "/usr/bin/avrdude": error=2, No such file or directory
This is because avrdude is located in /usr/local/bin/
Which we can check with:
which avrdude
So during setup it appears avrdude was put in wrong location? As a quick fix I copied avrdude to /usr/bin":
sudo cp /usr/local/bin/avrdude /usr/bin/
Returning to Arduino IDE, uploading caused:
Error: unknown token [/etc/avrdude.conf:320]
Error: programmer type must be written as "id_type" [/etc/avrdude.conf:320]
Error: unable to process system wide configuration file /etc/avrdude.conf
This can be 'fixed' by putting double quotes around 'arduino' in avrdude.conf line 320 but when I tried to upload there were other errors.
I remembered on:
https://projects.drogon.net/raspberry-pi/gertboard/arduino-ide-installation-isp/
Someone commented you need to use:
File -> Upload using programmer
Which I found under:
Sketch->Upload Using Programmer
For the version of the Arduino IDE I'm using (V1.8.19). When I clicked upload I got:
Error: while uploading: missing 'program.tool' configuration parameter
This is strange as I added gert328.upload.tool=avrdude to boards.txt.
At this point I decided to try to program the MCU directly using avrdude. We need the .hex file for programming, which we should be able to get from the Arduino IDE using: Sketch->Export Compiled Binary but I got error:
Export canceled, changes must first be saved.
Blink is read only, so you have to Save As then you can do Export Compiled Binary. It will compile and place the .hex file in the folder where you saved Blink, for me the file was called Blink.ino.standard.hex.
This is the command I used to write Blink to the MCU:
sudo avrdude -c linuxspi -P /dev/spidev0.0:/dev/gpiochip0 -p ATmega328P -B 125khz -U flash:w:Arduino/Blink.ino.standard.hex:i
This was run from the home directory.
You can specify a different path (-U) if Blink is located elsewhere, and a different speed (-B) will likely also work but I just wanted to play safe. You will then see the program written and then a wire can be connected between PB5 and BUF1, and the LED should be flashing, except it wasn't for me.
Wondering if the issue was LED_BUILTIN, I changed LED_BUILTIN for 13 and exported the .hex file again. But when I tried writing to the MCU with avrdude it complained the device wasn't responding. I removed the wire from PB5 (which seemed to prevent reprogramming, which makes sense since PB5 doubles up as SCK used for SPI), restarted the Pi and ran avrsetup again, which was successful (perhaps the reset wasn't necessary). I then compiled Blink in the Arduino IDE as an Arduino Uno board (since it should essentially be the same and I wondered if changing the board type to something similar may help) but the LED wouldn't flash (I checked all MCU pins just in case there was a pin mapping issue) and I had trouble writing again using avrdude. I think part of the issue is running the MCU at 3.3V at 12MHz, which is above the stated 8MHz for 3.3V, although I don't know if that affects programming or running code only.
I later powered the Gertboard without being connected to the Pi , I did this after testing the ADC using the Blue Pill board - see toward the end of the ADC test section above. With a wire connected between PB5 and BUF1, and power provided the LED was flashing. Possibly, the SPI connections when the Pi was powered where holding the MCU in a halt state although the Gertboard manual implies you can keep the SPI wires connected.
I don't know if the MCU was actually programmed the first time, likely it was and I didn't need to try other settings. With all the effort of trying to get the Arduino IDE working on the Pi, which runs really slow, I could have programmed the MCU using an external board, such as the Blue Pill.
All content of this and related pages is copyright (c) James S. 2024-2025