36
3
Gertboard Overview ................................................................................................................................ 5
Labels and Diagrams ........................................................................................................................... 7
Power on the Gertboard ....................................................................................................................... 9
GPIO Pins .......................................................................................................................................... 10
Schematics ......................................................................................................................................... 11
Test Programs Overview ....................................................................................................................... 11
C Code Overview .............................................................................................................................. 11
Macros ........................................................................................................................................... 12
Python Code Overview ...................................................................................................................... 13
Downloading the Software ............................................................................................................ 13
Why Different Program Versions? ................................................................................................ 14
Buffered I/O, LEDs, and Pushbuttons ................................................................................................... 14
Pushbuttons ........................................................................................................................................ 15
Locating the I/O Ports on the Gertboard ............................................................................................ 16
Testing the Pushbuttons ..................................................................................................................... 17
Buttons Test in C ........................................................................................................................... 19
Buttons Test in Python ................................................................................................................... 19
Testing the LEDs ............................................................................................................................... 20
LEDs Test in C .............................................................................................................................. 21
LEDs Test in Python ...................................................................................................................... 22
Testing I/O ......................................................................................................................................... 23
Butled Test in C ............................................................................................................................. 24
Butled Test in Python .................................................................................................................... 24
Open Collector Driver ........................................................................................................................... 24
Testing the Open Collector Drivers ................................................................................................... 25
Open Collector Test in C ............................................................................................................... 26
Open Collector Test in Python ...................................................................................................... 26
Motor Controller .................................................................................................................................... 27
Testing the Motor Controller ............................................................................................................. 28
Motor Test in C .............................................................................................................................. 29
Motor Tests in Python ................................................................................................................... 30
Digital to Analogue and Analogue to Digital Converters ..................................................................... 32
Digital to Analogue Converter ........................................................................................................... 32
Analogue to Digital Converter ........................................................................................................... 33
Testing the D/A and A/D ................................................................................................................... 33
22
4
D/A and A/D tests in C .................................................................................................................. 35
D/A and A/D tests in Python ......................................................................................................... 36
Combined Tests ..................................................................................................................................... 38
A/D and Motor Controller ................................................................................................................. 38
Potmot Test in C ............................................................................................................................ 39
Potmot test in Python ..................................................................................................................... 39
Decoder .............................................................................................................................................. 40
Decoder Test in C .......................................................................................................................... 40
ATmega Device ..................................................................................................................................... 41
Programming the ATmega ................................................................................................................ 41
Arduino Pins on the Gertboard ...................................................................................................... 42
A Few Sketches to Get You Going .................................................................................................... 42
Uploading Sketches using the SPI Bus .......................................................................................... 43
Blink Sketch ................................................................................................................................... 43
Button Sketch ................................................................................................................................. 44
AnalogInput Sketch ....................................................................................................................... 46
AnalogReadSerial Sketch Using Minicom .................................................................................... 47
LEDmeter Sketch ........................................................................................................................... 48
Going Forward ............................................................................................................................... 50
For More Information ............................................................................................................................ 50
Appendix A: Schematics ....................................................................................................................... 50
19
5
Figure 1: Gertboard and Raspberry Pi
The Gertboard is an input/output (I/O) extension board for the Raspberry Pi computer. It fits onto the
GPIO (general purpose I/O) pins of the Raspberry Pi (the double row of pins on the upper left corner)
via a socket on the back of the Gertboard. A bit of care is required when putting the two devices
together. It is easy to insert just one row of pins into the socket, but all of the pins need to be
connected. The Gertboard gets its power from those GPIO pins, so you will need a power supply for
the Raspberry Pi (RPi) that is capable of supplying a current of at least 1A.
The Gertboard has collection of functional blocks (the major capabilities of the board) which can be
connected together in a myriad of ways using header pins. The functional blocks are:
• 12x buffered I/O
• 3x pushbuttons
• 6x open collector drivers (50V, 0.5A)
• 18V, 2A motor controller
• 28-pin dual in line ATmega microcontroller
• 2-channel 8, 10, or 12 bit Digital to Analogue converter
• 2-channel 10 bit Analogue to Digital converter
The location of these blocks on the Gertboard is shown in Figure 2.
13
6
Figure 2: Functional blocks diagram: the key blocks are identified by coloured boundary marking. Please note that
the appearance of some components can vary.
This annotated photo of a populated (fully assembled) Gertboard shows where the functional blocks
are located. Some of the blocks have two areas marked. For example, the turquoise lines showing the
Atmel ATmega chip not only surround the chip itself and the header pins next to it (on the lower left)
but also surround two header pins near the bottom of the board, in the middle. These two pins are
connected to the Atmel chip and provide an easy way to interface the GPIO signals from the
Raspberry Pi (which are in the black box) with the Atmel chip.
There is no connection (other than power and ground) between the different functional blocks on the
Gertboard. The many headers (the rows of pins sticking up from the board) allow you to make these
connections, using straps and jumpers. See Figure 11 on page 18 for an example of how these are
used to connect the various blocks together.
9
7
Figure 3: Photograph showing straps (the coloured wires) above, and jumpers below. Straps connect two parts of
Gertboard together, whilst jumpers conveniently connect two adjacent pins together.
Labels and Diagrams
As you get to know the Gertboard and make connections between the various blocks, you will be
guided extensively by the white labels on the circuit board. At this point, we would like to introduce
the diagram, shown in Figure 5, which we will use to show you how to wire up your Gertboard for the
test programs.
Figure 4: Photograph of the Gertboard
24
8
Figure 5: Diagram representing a bare Gertboard circuit board. The blue elements correspond to the white lines and
text, and the gray elements correspond to the silver coloured pads.
The diagram in Figure 5 is created from the files that were used to design the Gertboard circuit board.
The blue in the diagram is generated from the silkscreen file, which indicates where the white text and
lines on the circuit board will be. The grey in the diagram is generated from the solder mask file,
which roughly corresponds to where the silver conductive areas on the top of the circuit board will be.
We will be using this blue and grey diagram as a basis for our wiring diagrams, which show you the
pins that need to be connected together for each of the test programs. We use these diagrams because
they are much clearer than a photo of the fully assembled board.
Have a close look at the white text on the photo of the Gertboard in Figure 4 (or the white text on your
own board or the blue text in the diagram in Figure 5). These labels provide information that is
required in order to connect together the various blocks of the Gertboard. Almost all of the
components have labels, and more importantly, the pins in the headers have labels. It isn’t necessary
to be too concerned about many of the components, such as resistors and capacitors (labelled with Rn
and Cn, where n is some number). However the labels for headers, integrated circuits, diodes, and
switches are important.
Diodes are labelled Dn. The ones that you will be interested in are D1 through D12, the LEDs (light
emitting diodes). The LEDs are near the top of the board, on the left. The labels for them are a bit
crowded. Each LED has a resistor next to it and thus each label Dn has an Rm next to it. The LEDs
are easy to find when you have the board powered up, as they are a row of bright red lights. See
below, in the section Power on the GertboardPower (page 9) for information on how to provide
power to the Gertboard.
Pushbutton switches are labelled S1, S2, and S3 (they are located just beneath the LEDs).
57
9
Figure 6: Two examples of ICs – an 8-pin and a 20-pin dual-inline package (DIP). In this package style, pin 1 is always
identified as the first pin anticlockwise from the package notch marking.
Integrated circuits (also known as ICs or chips), are marked Un. For example the I/O buffer chips are
U3, U4, and U5 (these are near the middle of the board), while the Atmel microcontroller is U8 (this
is below and to the left of U3 to U5). It is important to understand IC pin numbering. If the chip is
orientated so that the end with the semi-circle notch is to the left, then pin 1 is the leftmost pin in the
bottom row. Pin numbers increase in an anti-clockwise direction from there, as shown in Figure 6.
Knowing this means that the schematics in Appendix A can always be related to the pins on the ICs
on the Gertboard.
Headers (the rows of pins sticking up from the board) will be a frequently used component on the
Gertboard. They are labelled Jn. For example, there is a collection of headers along the left edge of
the board. They allow you to access the three chips on the left side of the board: J28 on top for the
analogue to digital chip, J29 below that for the digital to analogue chip, and J25 below that for the
Atmel microcontroller. It is a bit difficult to see the boundary between these headers on a fully
assembled board; it’s much clearer on the blue and grey diagram in Figure 5. On the Gertboard circuit
board, each header with more than two pins has pin 1 marked with a square around it and a dot next to
it. The dot is most useful on the assembled board, but these dots don’t appear in the blue and grey
diagram, so you can use the squares to find pin 1 there.
Not everything labelled Jn is a collection of pins. J1, at the bottom of the board, is the location of the
socket that connects the Gertboard to the Raspberry Pi. J19, at the top of the board (right of centre) is
a block of screw terminals that allow you to easily connect wires from a power supply and a motor.
Power on the Gertboard
Power pins are marked with their voltage, e.g. 5V or 3V3 (this means 3.3V). A 5V power supply
comes onto the board from the Raspberry Pi, and if you need this voltage it can be accessed from the
lower pin (marked 5V) on header J24 on the lower right-hand corner of the board. Ground is marked
with GND or a symbol.
The supply voltage (the voltage that acts as high or logical 1 on the board) is 3.3V. This is generated
from the 5V power pin in the J1 header by the components in the lower right corner of the board. To
send the 3.3V power supply to the components on the Gertboard, you need to install a jumper over the
top two pins of the header J7. It is near the lower right corner of the board; see the photo and diagram
in Figure 7. The open collector and motor controllers can handle higher voltages and have points to
attach external power supplies.
1
2
3 4
5
6
7
8
1
2
4
3
5
8
6
7
20 19 18
9 10
11
12
13
14
15
16
17
35
10
Figure 7: Power jumper installed in header J7: photo on left, diagram on right
The diagram on the right of Figure 7 above is our first example of a wiring diagram based on the blue
and grey circuit board diagram. These diagrams indicate pins via black circles around the locations of
pins on the board, and show connections as black lines between the circles. The diagram does not
indicate directly whether the two pins should be joined by straps (wires) or jumpers. Generally, if the
two pins are right next to each other, use a jumper, and if they are further apart, use a strap.
GPIO Pins
The header J2, to the right of the text ‘Raspberry Pi Gertboard’ on the board, provides access to all the
I/O pins on the GPIO header. There are 26 pins in J1 (the socket which connects the Gertboard to the
Raspberry Pi) but only 17 pins in J2: 3 of the pins in J1 are power (3.3V and 5V) and ground, and 6
are DNC (do not connect). The labels on these pins, GP0, GP1, GP4, GP7, etc, may initially seem a
little arbitrary, as there are some obvious gaps, and the numbers do not correspond with the pin
numbers on the GPIO header J1. These labels are important however: they correspond with the signal
names used by the BCM2835, the processor on the Raspberry Pi (RPi). Signal GPIOn on the
BCM2835 datasheet corresponds to the pin labelled GPn on header J2. At least, this was true of the
first version of the Raspberry Pi (“rev1”). Starting in September 2012, revision 2 Raspberry Pis
(“rev2”) were starting to be shipped. On the rev2 RPis, some of the GPIO pins have been changed.
The GPIO port that used to be controlled by GPIO21 is now controlled by GPIO27, and the ports that
used to be controlled by GPIO0 and GPIO1 are now controlled by GPIO2 and GPIO3. The rest have
remained the same. The first three columns of Table 1 below summarize the current situation.
Some of the GPIO pins have an alternate function that are made use of in some of the test programs.
These are also shown in Table 1, in the last two columns. The ports that have nothing in the “Alt
function” column are only used as general purpose input/output in the code. In the C test programs,
we use macros to gain access to the alternative functions of the GPIO ports. This is explained in the
section on analogue to digital and digital to analogue converts (D/A and A/D tests in C, page 35). In
Python, we use packages to provide access to the alternative functions.
We mention the I
2
C bus use of GPIO0 and GPIO1 (or GPIO2 and GPIO3 for rev2 RPis) in Table 1
not because the I
2
C bus is used in the test programs, but because each of them has a 1800Ω pull-up
resistor on the Raspberry Pi, and this prevents them from being used with the pushbuttons (see the
section on Buffered I/O, LEDs, and Pushbuttons for more information).
95
11
Label on GB Port on RPi1 Port on RPi2 Alt function (which alt)
Purpose
GP0
GPIO0
GPIO2
SDA
I
2
C bus
GP1
GPIO1
GPIO3
SCL
GP4
GPIO4
GPIO4
GP7
GPIO7
GPIO7
SPI_CE1_N (alt 0)
SPI bus
GP8
GPIO8
GPIO8
SPI_CE0_N (alt 0)
GP9
GPIO9
GPIO9
SPI_MISO (alt 0)
GP10
GPIO10
GPIO10
SPI_MOSI (alt 0)
GP11
GPIO11
GPIO11
SPI_SCLK (alt 0)
GP14
GPIO14
GPIO14
TXD0 (alt 0)
UART
GP15
GPIO15
GPIO15
RXD0 (alt 0)
GP17
GPIO17
GPIO17
GP18
GPIO18
GPIO18
PWM0 (alt 5)
pulse width modulation
GP21
GPIO21
GPIO27
GP22
GPIO22
GPIO22
GP23
GPIO23
GPIO23
GP24
GPIO24
GPIO24
GP25
GPIO25
GPIO25
Table 1: GPIO ports corresponding to “GP” labels, and alternative functions of GPIO ports
(GB means Gertboard, RPi1 means Raspberry Pi rev1, RPi2 means Raspberry Pi rev2)
Schematics
Whilst there are some circuit diagrams, or schematics, in the main body of the manual for some of the
functional blocks of the board, they are simplifications of the actual circuits. While these simplified
diagrams and the explanations in the text will be good enough for most uses of the Gertboard, there
will occasionally be questions that can only answered by knowing exactly what is on the board. Thus
we have attached the full schematics at the end of this manual as Appendix A. These pages are in
landscape format. The page numbers A-1, A-2, etc, are in the lower left corner of the pages (if you
hold them so that the writing is the right way up).
There are test programs for the Gertboard written in C and in Python. C provides the most direct
access to the Gertboard functionality, but it is not a language that is very accessible to the beginner
programmer. Several packages have been written to allow Python code to access the Raspberry Pi
GPIO pins and alternative functions of these pins such as Serial Peripheral Interface (SPI) bus and
pulse width modulation (PWM). Using these packages, you can access most of the functionality of the
Gertboard with Python. At the time of writing, the only major functional block that (to our
knowledge) cannot be programmed with Python is the Atmel microcontroller.
C Code Overview
To download the Gertboard C software, go to http://www.element14.com and search for
“Gertboard” using the box at the top of the screen. The link you want will probably be called
something like “Application Library for Gertboard”. From there you can download the file containing
the C code; it will have a name like gertboard_sw_20120725.zip. As you can tell by the file
extension .zip, this is a zip file, which means that it is a compressed collection of different files, all
packed together into a single file.
Documents you may be interested
Documents you may be interested