
C H A P T E R 1 4
T H E G P I O P O R T
223
I
2
C Bus
As the name suggests, the
Inter-Integrated Circuit (I²C) bus
is designed to provide communica-
tions between multiple
integrated circuits (ICs)
. In the case of the Pi, one of those integrated
circuits is the Broadcom BCM2835 SoC processor at the heart of the system. These pins
include access to
pull-up resistors
located on the Pi, meaning no external resistors are required
to access the I
2
C functionality.
The I
2
C bus can be accessed on Pins 3 and 5, with Pin 3 providing the
Serial Data Line (SDA)
signal and Pin 5 providing the
Serial Clock (SCL)
signal. The I
2
C bus available on these pins is
actually only one of two provided by the BCM2835 chip itself, and is known as I
2
C0. The
second, I
2
C1, is terminated at resistors on the Raspberry Pi circuit board itself and is not
available for general-purpose use.
SPI Bus
The
Serial Peripheral Interface (SPI) bus
is a synchronous serial bus designed primarily for
in-
system programming (ISP)
of microcontrollers and other devices. Unlike the UART and I²C
buses, it’s a four-wire bus with multiple
Chip Select
lines, which allow it to communicate with
more than one target device.
The Pi’s SPI bus is available on Pins 19, 21 and 23, with a pair of Chip Select lines on Pin 24
and Pin 26. Pin 19 provides the
SPI Master Output, Slave Input (MOSI)
signal; Pin 21 provides
the
SPI Master Input, Slave Output (MISO)
signal; Pin 23 provides the
Serial Clock (SLCK)
used
to synchronise communication; and Pins 24 and 26 provide the
Chip Select
signals for up to
two independent slave devices.
Although additional buses are present in the Raspberry Pi’s BCM2835 SoC processor, they
are not brought out to the GPIO port and are thus unavailable for use.
Using the GPIO Port in Python
With the theory out of the way, it’s time to get practical. In this section, you’ll l learn how to
construct and program two simple electronic circuits that demonstrate how to use the GPIO
port for input and output.
As you saw in Chapter 12, “An Introduction to Python”, Python is a friendly yet powerful
programming language. It’s not, however, the perfect choice for every scenario. Although it
works fine for the simple circuits you’ll be creating in this chapter, it does not offer what is
known as
deterministic real-time operation.
For the majority of users, this doesn’t matter; if
you’re planning on using the Pi at the heart of a nuclear reactor or a complex robotics plat-
form, however, you may want to investigate a lower-level language such as
C++
or even
assembler
running on a dedicated real-time microcontroller
.
Summary of Contents for A
Page 1: ......
Page 2: ......
Page 3: ...Raspberry Pi User Guide 2nd Edition...
Page 4: ......
Page 5: ...Raspberry Pi User Guide 2nd Edition Eben Upton and Gareth Halfacree...
Page 10: ......
Page 26: ...R A S P B E R R Y P I U S E R G U I D E S E C O N D E D I T I O N 10...
Page 28: ......
Page 29: ...Chapter 1 Meet the Raspberry Pi...
Page 37: ...Chapter 2 Getting Started with the Raspberry Pi...
Page 56: ......
Page 57: ...Chapter 3 Linux System Administration...
Page 79: ...Chapter 4 Troubleshooting...
Page 89: ...Chapter 5 Network Configuration...
Page 109: ...Chapter 6 The Raspberry Pi Software Configuration Tool...
Page 122: ......
Page 123: ...Chapter 7 Advanced Raspberry Pi Configuration...
Page 140: ......
Page 141: ...Chapter 8 The Pi as a Home Theatre PC...
Page 151: ...Chapter 9 The Pi as a Productivity Machine...
Page 160: ......
Page 161: ...Chapter 10 The Pi as a Web Server...
Page 172: ......
Page 173: ...Chapter 11 An Introduction to Scratch...
Page 189: ...Chapter 12 An Introduction to Python...
Page 216: ......
Page 218: ......
Page 219: ...Chapter 13 Learning to Hack Hardware...
Page 234: ......
Page 235: ...Chapter 14 The GPIO Port...
Page 249: ...Chapter 15 The Raspberry Pi Camera Module...
Page 265: ...Chapter 16 Add on Boards...
Page 280: ......
Page 281: ...Appendix A Python Recipes...
Page 287: ...Appendix B Raspberry Pi Camera Module Quick Reference...
Page 293: ...Appendix C HDMI Display Modes...