This book – with a glowing endorsement by Eben Upton on the front cover – promises a lot. Can it deliver?
When we hear ‘Embedded Linux’ we normally think of some sort of appliance – a router, maybe – that runs some custom application on a trimmed-down Linux distro from ROM. The Raspberry Pi is most emphatically not an embedded system, in that sense, but rather a fully-featured computer running (typically, but not necessarily) a full desktop Linux distro. The book’s sub-title therefore led me, initially, to fear the worst.
The book’s 700-odd pages are divided between sixteen chapters organized in three sections. Each chapter is well-organized, in most cases beginning with a preamble and a list of any hardware parts required to complete any exercises in the chapter, and ending with a summary and in some cases a ‘Further Reading’ section listing both online and hard-copy resources. Photographs, diagrams, and code samples are plentiful, and are used effectively.
The first section is entitled ‘Raspberry Pi Basics’. The first couple of chapters describe the basic hardware and software environment provided by a Raspberry Pi running the default Raspbian (Debian-derived) Linux distribution. The availability of other Linux and non-Linux operating software is mentioned in passing, but the emphasis is (quite rightly, in my view) on Raspbian. OS installation and set-up are discussed, as is headless use (over a network or a serial connection). Chapters 2 and 3 contain as good a short introduction to using the Linux command line as I can remember seeing, together with a quick introduction to git (which is important as many Raspberry Pi code samples and Open Source libraries are available from github).
The second section of the book is entitled ‘Interfacing, Controlling, and Communicating’. Chapter 8 describes the Pi’s GPIO bus and gives examples of input and output using the
filesystem, using memory-mapped i/o via
, and using the WiringPi C library. The examples here all use the Linux command line or programs in C or C++.
Chapter 7 describes development of Pi software on another (Linux) computer. This leads to a discussion of cross-compilation and remote debugging using Eclipse, and finishes with cross-compiling a custom Linux kernel for the Pi.
The next three chapters deal with communication between the Raspberry Pi and other devices – such as sensors, motors, and displays – using the Pi’s GPIO pins as serial, I2C, and SPI buses. The techniques are all well explained and example code (most of it in ‘C++ as a better C’) is given. The last chapter of the second section discusses using an Arduino computer as a slave to the Pi, communicating over I2C – because there are some things a dedicated microcontroller can do better than a general-purpose computer running a multi-tasking OS!
The final section of the book is entitled ‘Advanced Interfacing and Interaction’. Chapter 12 describes web client and server software on the Pi and using the Pi as an IoT device. Chapter 13 adds handling of wireless interfaces and interfacing to XBee devices, as well as Bluetooth and NFC communications. Chapter 14 discusses programming a GUI on the Pi itself, using Qt, and chapter 15 adds images, sound, and video to this and discusses the Raspberry Pi camera interface.
Finally Chapter 16 discusses Linux kernel programming and Pi-specific device drivers written as loadable kernel modules.
That’s a lot of material! If the coverage of some of it is a little light that’s understandable. Some authors might have not have chosen to include some of the more advanced and less Raspberry-Pi-specific topics, but I would say that one of the strengths of this book is the breadth of its coverage. The reader may need to look further to learn how to use some of the techniques presented to best effect, but the coverage does at least illustrate what can be done and suggest avenues for further reading. It may not contain all the answers, but it does at least help in concocting good internet search terms!
Two things niggled. One is to do with software, and concerns the author’s tendency to blur the distinction between C and C++. One might also hope that a book published in 2016 and claiming to use C++11 would use more modern features and idioms.
The other niggle concerns hardware. Everything else I’ve read that describes controlling an LED with a Raspberry Pi uses a simple circuit in which a current-limiting resistor and an LED are connected in series between one of the Pi’s GPIO pins and GND, but here it is stated that the Pi’s GPIO lines can provide only 2-3mA of current – not enough to drive an LED – and will be damaged by any attempt to draw more. The author suggests using a transistor to switch a circuit drawing current from another source instead – and, indeed, all the examples in the book that use LEDs driven by the Pi employ such a technique. That surprised me – were all those other books, articles, and websites wrong? Was I in danger of blowing up my Pi?
No. The book is misleading, here, because it perpetuates an early misconception that seems to arise from the fact that the original Raspberry Pi had only about 50mA of power available in total for its 17 GPIO pins, and so just under 3mA per pin. Later Raspberry Pi models – including those current when the book was published – have more power available, and the actual limit per GPIO pin is 16mA (a limitation of the Broadcom BCM2835 system-on-a-chip family, versions of which are used by all models of Raspberry Pi). 16mA is plenty to drive typical LED with (say) a 260 Ohm current limiting resistor in series. I’ve had 26 LEDs running simultaneously using all 26 GPIO pins of a Raspberry Pi Zero-W in this way.
There is some discussion of this on the book’s support website. It seems that the author was unable to find authoritative data on the BCM2835 when writing the book, and based his advice on the total current limit for the original Pi. This doesn’t make the book wrong; it just means that some of the example circuits in the book could have been made simpler. The use of a transistor to switch a circuit is a valid technique, and is necessary for circuits whose current requirements really do exceed the capability of the GPIO bus.
I found this an interesting and surprisingly exhaustive book that does, indeed, live up to its hype. As a programmer I found it to be a good guide to the Raspberry Pi, its capabilities, and all the things you can do with it – as well as a useful course in digital electronics. The old C++ style in the examples was disappointing, but this book is more about hardware than software, so perhaps I’m being unfairly critical in this regard.
For experienced programmers who are looking specifically for information on Raspberry Pi hardware and interfacing, and who will not be led astray by any deficiencies in the sample code, I’d give this a ‘Highly Recommended’ rating, for everyone else I’d give it ‘Recommended’.