Exploring Raspberry Pi - Derek Molloy - E-Book

Exploring Raspberry Pi E-Book

Derek Molloy

4,9
24,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Expand Raspberry Pi capabilities with fundamental engineering principles Exploring Raspberry Pi is the innovators guide to bringing Raspberry Pi to life. This book favors engineering principles over a 'recipe' approach to give you the skills you need to design and build your own projects. You'll understand the fundamental principles in a way that transfers to any type of electronics, electronic modules, or external peripherals, using a "learning by doing" approach that caters to both beginners and experts. The book begins with basic Linux and programming skills, and helps you stock your inventory with common parts and supplies. Next, you'll learn how to make parts work together to achieve the goals of your project, no matter what type of components you use. The companion website provides a full repository that structures all of the code and scripts, along with links to video tutorials and supplementary content that takes you deeper into your project. The Raspberry Pi's most famous feature is its adaptability. It can be used for thousands of electronic applications, and using the Linux OS expands the functionality even more. This book helps you get the most from your Raspberry Pi, but it also gives you the fundamental engineering skills you need to incorporate any electronics into any project. * Develop the Linux and programming skills you need to build basic applications * Build your inventory of parts so you can always "make it work" * Understand interfacing, controlling, and communicating with almost any component * Explore advanced applications with video, audio, real-world interactions, and more Be free to adapt and create with Exploring Raspberry Pi.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 1104

Bewertungen
4,9 (18 Bewertungen)
16
2
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Title Page

Introduction

How This Book Is Structured

Conventions Used in This Book

What You'll Need

Errata

Digital Content and Source Code

Part I: Raspberry Pi Basics

Chapter 1: Raspberry Pi Hardware

Introduction to the Platform

RPi Documentation

The RPi Hardware

Raspberry Pi Accessories

HATs

How to Destroy Your RPi!

Summary

Support

Chapter 2: Raspberry Pi Software

Linux on the Raspberry Pi

Connecting to a Network

Communicating with the RPi

Controlling the Raspberry Pi

Configuring the Raspberry Pi

Interacting with the Onboard LEDs

Shutdown and Reboot

Summary

Chapter 3: Exploring Embedded Linux Systems

Introducing Embedded Linux

Managing Linux Systems

Using Git for Version Control

Using Desktop Virtualization

Code for This Book

Summary

Further Reading

Bibliography

Chapter 4: Interfacing Electronics

Analyzing Your Circuits

Basic Circuit Principles

Discrete Components

Logic Gates

Analog-to-Digital Conversion

Concluding Advice

Summary

Further Reading

Chapter 5: Programming on the Raspberry Pi

Introduction

Scripting Languages

Dynamically Compiled Languages

C and C++ on the RPi

Overview of Object-Oriented Programming

Interfacing to the Linux OS

Improving the Performance of Python

Summary

Further Reading

Bibliography

Part II: Interfacing, Controlling, and Communicating

Chapter 6: Interfacing to the Raspberry Pi Input/Outputs

Introduction

General-Purpose Input/Outputs

C++ Control of GPIOs Using sysfs

Memory-Based GPIO Control

WiringPi

GPIOs and Permissions

Summary

Chapter 7: Cross-Compilation and the Eclipse IDE

Setting Up a Cross-Compilation Toolchain

Cross-Compilation Using Eclipse

Building Linux

Summary

Further Reading

Chapter 8: Interfacing to the Raspberry Pi Buses

Introduction to Bus Communication

I

2

C

SPI

UART

Logic-Level Translation

Summary

Further Reading

Chapter 9: Enhancing the Input/Output Interfaces on the RPi

Introduction

Analog-to-Digital Conversion

Digital-to-Analog Conversion

Adding PWM Outputs to the RPi

Extending the RPi GPIOs

Adding UARTs to the RPi

Summary

Chapter 10: Interacting with the Physical Environment

Interfacing to Actuators

Interfacing to Analog Sensors

Interfacing to Local Displays

Building C/C++ Libraries

Summary

Chapter 11: Real-Time Interfacing Using the Arduino

The Arduino

An Arduino Serial Slave

An Arduino I

2

C Slave

An Arduino SPI Slave

Programming the Arduino from the RPi Command Line

Summary

Part III: Advanced Interfacing and Interaction

Chapter 12: The Internet of Things

The Internet of Things (IoT)

The RPi as an IoT Sensor

The RPi as a Sensor Web Server

A C/C++ Web Client

The RPi as a “Thing”

Large-Scale IoT Frameworks

The C++ Client/Server

IoT Device Management

Summary

Chapter 13: Wireless Communication and Control

Introduction to Wireless Communications

Bluetooth Communications

Wi-Fi Communications

ZigBee Communications

Near Field Communication

Summary

Chapter 14: Raspberry Pi with a Rich User Interface

Rich UI RPi Architectures

Rich UI Application Development

Qt Primer

Remote UI Application Development

Summary

Further Reading

Chapter 15: Images, Video, and Audio

Capturing Images and Video

Streaming Video

Image Processing and Computer Vision

Raspberry Pi Audio

Summary

Further Reading

Chapter 16: Kernel Programming

Introduction

A First LKM Example

An Embedded LKM Example

Enhanced Button GPIO Driver LKM

Enhanced LED GPIO Driver LKM

Conclusions

Summary

End User License Agreement

Pages

ii

iii

iv

v

vi

vii

viii

xix

xx

xxi

xxii

xxiii

xxiv

xxv

1

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

481

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

Guide

Cover

Table of Contents

Begin Reading

List of Illustrations

Chapter 1: Raspberry Pi Hardware

Figure 1.1 Raspberry Pi platform board examples (to relative scale)

Figure 1.2 A summary comparison of commonly available RPi models

Figure 1.3 The inputs/outputs and subsystems on two RPi models (to relative scale): (a) The RPi Zero; and (b) The RPi 3

Figure 1.4 Table of general RPi subsystems and connectors

Figure 1.5 A power/reset button for the RPi: (a) A PC power/reset button; (b) A two-pin male header that is soldered to the board; and (c) Attachment of the PC power/reset button

Figure 1.6 (a) Testing that the RPi supply voltage level is in the range 4.75 V to 5.25 V (i.e., 5 V ± 5%); (b) The RPi Zero and its associated connectors

Figure 1.7 (a) The USB-to-TTL 3.3 V serial cable and, (b) its connection to the RPi

Figure 1.8 USB adapters: (a) Wi-Fi adapters; (b) Memory card reader/writer; and (c) A low-cost USB current and voltage monitor

Figure 1.9 (a) RPi NoIR Camera, (b) RPi Camera bracket, and (c) Logitech C920 USB webcam

Figure 1.10 RPi Accessories: (a) An example case; (b) The Sense HAT; (c) The T-Cobbler board; and (d) A prototyping HAT

Chapter 2: Raspberry Pi Software

Figure 2.1 (a) Zenmap scan of the network to locate the RPi; (b) A ping test from the desktop machine

Figure 2.2 An Ethernet crossover cable configuration example

Figure 2.3 (a) Windows Device Manager device identification; (b) a PuTTY serial connection configuration; and (c) a low-cost USB-to-TTL adapter

Figure 2.4 PuTTY SSH Configuration settings beside an open SSH terminal connection window

Figure 2.5 The SSH Chrome App

Figure 2.6 The GNU nano editor being used to edit an example file in a PuTTY Linux terminal window

Figure 2.7 : The raspi-conFigure tool

Figure 2.8 The raspi-conFigure tool Advanced Options menu

Figure 2.9 The RPi onboard power and activity LEDs

Chapter 3: Exploring Embedded Linux Systems

Figure 3.1 The full boot sequence on the RPi

Figure 3.2 The Linux user space and kernel space architectures

Figure 3.3 Linux directory listing and file permissions

Figure 3.4 The basic Git workflow

Figure 3.5 VirtualBox running Debian (Jessie) as a guest OS on a Windows host machine

Chapter 4: Interfacing Electronics

Figure 4.1 The Waveforms application generating a signal and displaying the response from the physical circuit

Figure 4.2 (a) Ohm's law circuit example, and (b) a voltage divider example

Figure 4.3 (a) Potentiometers and using a variable voltage supply, and (b) a current divider example

Figure 4.4 The breadboard with an RPi GPIO extension board and a 7408 IC (quad two-input AND gates)

Figure 4.5 (a) The custom-built connector attached to an RPi (model B), and (b) a low-cost crimping tool

Figure 4.6 Measuring voltage, current, and resistance

Figure 4.7 The KA7805A/LM7805 voltage regulator and an example regulator circuit

Figure 4.8 Circuit and behavior of a 1N4001 diode with a 5 V AC supply and a 1 kΩ load resistor

Figure 4.9 An LED example and a circuit to drive an LED with appropriate forward current and voltage levels

Figure 4.10 Duty cycles of pulse width modulation (PWM) signals

Figure 4.11 Circuit and behavior of a 1N4001 diode with a 5 V AC supply, 1 kΩ load, and parallel 10 μF capacitor

Figure 4.12 Ceramic (non polarized) and electrolytic (polarized) capacitors and an example decoupling circuit

Figure 4.13 Bipolar junction transistors (BJTs)

Figure 4.14 The BJT as a switch

Figure 4.15 Realization of the transistor as a switch (saturation) and confirmation that all relationships hold true

Figure 4.16 Frequency response of the BJT circuit (frequency is 500 kHz and 1 MHz)

Figure 4.17 The field effect transistor (FET) as a switch

Figure 4.18 Frequency response of the FET circuit as the switching frequency is set at 1 MHz and 5 MHz

Figure 4.19 Optocoupler (617 A) circuit with the captured input and output characteristics

Figure 4.20 Various switches and configurations

Figure 4.21 (a) Switch bouncing with no components other than the switch and 10 kΩ resistor; (b) low-pass filtered output at point B; (c) a Schmitt trigger circuit; and (d) output of the Schmitt trigger circuit at point C, versus the input at point A

Figure 4.22 General logic gates

Figure 4.23 (a) IC package examples (to scale), and (b) the JK flip-flop

Figure 4.24 Gate signal levels on the input and output of logic gates (a) TTL , and (b) CMOS at 5 V

Figure 4.25 An AND gate with the inputs accidentally left floating when the switches are open

Figure 4.26 Pull-down and pull-up resistors, used to ensure that the switches do not create floating inputs

Figure 4.27 Open-drain level-shifting example

Figure 4.28 (a) Sinking current on the output, and (b) TTL fan-out example

Figure 4.29 (a) The ideal op-amp, and (b) an open-loop comparator example

Figure 4.30 Output of the comparator circuit

Figure 4.31 The voltage follower op-amp circuit

Chapter 5: Programming on the Raspberry Pi

Figure 5.1 (a) Driving an LED with a GPIO using a FET, and (b) driving an LED with a GPIO using an NPN transistor

Figure 5.2 Building C/C++ applications on the RPi

Figure 5.3 Memory allocation for variables on the 32-bit RPi

Figure 5.4 Example of pointers in C/C++ on the RPi

Chapter 6: Interfacing to the Raspberry Pi Input/Outputs

Figure 6.1 The RPi GPIO header (RPi 2/3)

Figure 6.2 A 5 V LED circuit (a) using a FET, and (b) using a BJT

Figure 6.3 The voltage and current characteristics of the circuits in Figure 6.2 (a) using a FET, and (b) using a BJT

Figure 6.4 Scope display of the GPIO output caused by the flash.sh script

Figure 6.5 Connecting a pushbutton to the RPi (a) internal pull-down resistor, and (b) internal pull-up resistor

Figure 6.6 Internal pull-down resistor value determination, using a 100 kΩ resistor connected (a) from the GPIO pin to GND, and (b) from the GPIO pin to the 3.3 V supply

Figure 6.7 The optocoupler output circuit

Figure 6.8 The optocoupler input circuit

Figure 6.9 The GPIO C++ class flashing the LED

Figure 6.10 The cyclictest results histogram for 10,000 samples (a) on the RPi 2, and (b) on a Linux desktop VM that is under load with no preemption support

Figure 6.11 The RPi GPIO header

Figure 6.12 Single-core versus multicore threading performance test on the RPi 2 and RPi 3 (measuring real time)

Figure 6.13 Time delay in lighting an LED in response to a button press at ˜0% CPU usage (a) using sys/poll.h, and (b) integrating callback functions and Pthreads

Figure 6.14 Examples of the registers available for memory-mapped GPIO manipulation

Figure 6.15 The output of the memory-mapped example in Listing 6.9

Figure 6.16 Some gpio command options

Figure 6.17 Summary of the wiringPi API

Figure 6.18 Performance of the wiringPi C code (a) the fastToggle example, and (b) the buttonLED example

Figure 6.19 Using a one-wire sensor with the RPi and wiringPi (waveform for the AM2301/2302

)

Figure 6.20 (a) Output of the program in Listing 6.15 (b) A button and PWM LED circuit

Figure 6.21 Controlling a servo motor using PWM, positioning from –90° to +90° using different pulse widths

Figure 6.22 The RPi 2 generating 1.2 MHz and 4.8 MHz clock signals simultaneously (FFT also displayed)

Chapter 7: Cross-Compilation and the Eclipse IDE

Figure 7.1 Creating a new C++ project in Eclipse: (a) the project settings, and (b) the cross-compiler prefix

Figure 7.2 The creation and cross-compilation of a C++ project in Eclipse

Figure 7.3 Eclipse Mars settings for cross-compilation

Figure 7.4 Connecting to the RPi for the first time using RSE

Figure 7.5 The Terminal window, connected to the RPi and executing the cross-compiled RPiTest C++ application

Figure 7.6 Eclipse GitHub integration, displaying the exploringRPi repository

Figure 7.7 Setting the debug configuration

Figure 7.8 Setting up the remote debugger

Figure 7.9 Setting the RPi gdb server port

Figure 7.10 Adding to the “bug” menu

Figure 7.11 The Debug Perspective view

Figure 7.12 Example Doxygen HTML output

Figure 7.13 Doxygen Eclox plug-in running within Eclipse Mars

Figure 7.14 The Kernel Configuration tool for Linux 4.0.9

Figure 7.15 (a) The PREEMPT_RT menuconFigure option (b) The results histogram of the cyclictest under load

Chapter 8: Interfacing to the Raspberry Pi Buses

Figure 8.1 (a) The I

2

C bus configuration, and (b) the built-in pull-up resistors on the I2C1 bus

Figure 8.2 Two I

2

C devices connected to the I2C1 bus

Figure 8.3 The DS3231 registers summary

Figure 8.4 Using

i2cget

to read the number of seconds on the RTC from register 0x00

Figure 8.5 Important ADXL345 registers

Figure 8.6 Capture and timings required for communication with the ADXL345 device

Figure 8.7 (a) Using SPI to connect to one slave device; and (b) testing SPI using a loopback configuration

Figure 8.8 The SPI loopback test

Figure 8.9 The 74HC595 seven-segment display SPI example (supports multiple display modules)

Figure 8.10 The 74HC595 SPI signal and output

Figure 8.11 The ADXL345 SPI communication timing chart (from the ADXL345 datasheet)

Figure 8.12 (a) SPI connection to the ADXL345; and (b) a capture of the communications required to read register 0x00

Figure 8.13 (a) Using two ADXL345 accelerometers on a single SPI bus; and (b) control of more than one slave device using GPIO pins and additional logic

Figure 8.14 UART transmission format for a typical one-byte transfer

Figure 8.15 (a) Loopback testing the UART; and (b) configuring the minicom program settings

Figure 8.16 Logic Analyzer display of the loopback serial transmission of the letter “h”

Figure 8.17 A PuTTY desktop COM terminal that is listening for messages from the Raspberry Pi

Figure 8.18 (a) The LED serial server circuit, and (b) PuTTY on the PC communicating to the RPi LED serial server

Figure 8.19 RPi UART connection to the GPS module

Figure 8.20 The

gpsmon

output display

Figure 8.21 Adafruit four-channel, Adafruit eight-channel, and Watterott four-channel logic-level translators

Figure 8.22 Switching BSS138-based translators from 3.3 V to 5 V logic levels at 50 kHz, 200 kHz, and 1 MHz

Chapter 9: Enhancing the Input/Output Interfaces on the RPi

Figure 9.1 The Gertboard attached to the RPi GPIO header

Figure 9.2 A general SPI ADC configuration for the RPi with an example LDR circuit attached to Channel 0 of the MCP3208 IC

Figure 9.3 Reading data from the 12-bit MCP320x and the 10-bit MCP300x families of SPI ADCs

Figure 9.4 (a) Plot of a data capture of a 500 Hz sinusoidal input signal; (b) example of sample-clock jitter; (c) data capture of a 5 kHz sinusoidal input signal

Figure 9.5 (a) Plot of 2,000 samples captured using the SPI ADC with the BCM2835 C library; (b) plot of 1 million samples using the same library

Figure 9.6 The MCP4725 I

2

C DAC with an optional op-amp circuit that improves the output current range

Figure 9.7 (a) Connecting to the MCP4921 SPI DAC; (b) the SPI message format for the MCP4921/11/01

Figure 9.8 (a) The SPI DAC output signal; (b) the SPI DAC output using the C Library for BCM2835

Figure 9.9 The Adafruit PCA9685 16-channel 12-bit PWM driver

Figure 9.10 Registers for the PCA9685 16-channel 12-bit PWM controller

Figure 9.11 Example PWM output of Channel0 and Channel1 of the PCA9685

Figure 9.12 Output of Listing 9.9

Figure 9.13 Adding GPIOs to the RPi using the: (a) MCP23017 I

2

C GPIO expander, and (b) MCP23S17 SPI GPIO expander

Figure 9.14 The MCP23x17 registers

Figure 9.15 Daisy chaining up to eight MCP23S17s as a single SPI bus device

Figure 9.16 An SPI write request to the MCP23S17 at device address 000 to set the IOCONA register to 0x3A

Figure 9.17 (a) Three low-cost USB-to-TTL converters, and (b) three such devices attached to the RPi

Figure 9.18 (a) The UART device loopback test, and (b) The UART output displaying “Hello” at 115,200 baud

Chapter 10: Interacting with the Physical Environment

Figure 10.1 (a) A 12 V DC motor with an integrated 131¼:1 gearbox ($40), and (b) an integrated counts per revolution (CPR) Hall Effect sensor shaft encoder

Figure 10.2 The output from the shaft encoder in Figure 10.1(b) when rotating: (a) clockwise, and (b) counterclockwise

Figure 10.3 Simplified H-bridge description

Figure 10.4 Driving a DC motor using an example H-bridge driver breakout board

Figure 10.5 (a) The Pololu Simple Motor Controller, and (b) the associated motor configuration tool

Figure 10.6 (a) Stepper motor external and internal structure, and (b) full- and half-step drive signals

Figure 10.7 Driving a stepper motor using the open-hardware EasyDriver board

Figure 10.8 Driving a stepper motor using the RPi and the EasyDriver interface board

Figure 10.9 (a) Controlling a relay using the RPi, and (b) example relay breakout boards

Figure 10.10 The RPi SPI ADC circuit and its connection to the TMP36 analog temperature sensor

Figure 10.11 (a) Sharp infrared distance measurement sensor, and (b) its analog output response

Figure 10.12 (a) An RPi circuit for connecting to the Sharp GP2D12 sensor; (b) the plot of the gnuplot fitted functions

Figure 10.13 (a) A voltage divider with a low-pass filter, and (b) the MCP6002 dual op-amp in a voltage-follower configuration

Figure 10.14 (a) A general op-amp signal conditioning circuit that inverts the input, (b) conditioned output when

V

in

is 0 V to 5 V, (c) conditioned output when

V

in

is –5 V to +5 V, and (d) conditioned and amplified output when the input signal is 1.9 V to 2.1 V

Figure 10.15 The ADXL335 analog accelerometer and its connection to the RPi with further signal conditioning

Figure 10.16 (a) The MAX7219 8-digit 7-segment display module, and (b) a summary register table for the MAX7219

Figure 10.17 The MAX7219 eight-digit seven-segment display counting due to Listing 10.7

Figure 10.18 SPI interfacing to character LCD modules using a 74HC595 8-bit serial shift register

Figure 10.19 Output from Listing 10.9 on a 4 × 20 and a 2 × 16 inverted RGB character display module

Figure 10.20 Connection to two OLED dot-matrix displays using the I

2

C bus

Figure 10.21 An OLED dot-matrix temperature and humidity sensing and display example

Chapter 11: Real-Time Interfacing Using the Arduino

Figure 11.1 Arduino boards (to relative scale): (a) the Arduino UNO, and (b) the Arduino Pro Mini (3.3V or 5V)

Figure 11.2 The Arduino platform “Hello World” example and the Arduino Pro Mini programming configuration

Figure 11.3 UART communication between the RPi and the Arduino UNO/Pro Mini 5V with a PWM LED example

Figure 11.4 Analysis of the UART communication between the RPi and the Arduino Pro Mini: (a) the logic analyzer, and (b) the same letter H on the oscilloscope

Figure 11.5 Sending the command “LED 255\0” to the Arduino and receiving the response string “Set brightness to 255”

Figure 11.6 The Arduino I

2

C slave test circuit with a TMP36 analog temperature sensor

Figure 11.7 Writing to and reading from the 0x04 register that has been created on the Arduino

Figure 11.8 The HC-SR04 ultrasonic distance sensor circuit

Figure 11.9 The signal response of the HC-SR04

Figure 11.10 The Arduino as an SPI slave

Chapter 12: The Internet of Things

Figure 12.1 Different software communication architectures implemented in this chapter

Figure 12.2 (a) A low-cost heatsink, and (b) the temperature plot from a CPU load test with and without a heatsink attached

Figure 12.3 The first web page from the Nginx server

Figure 12.4 A simple CGI script example

Figure 12.5 Weather sensor web page

Figure 12.6 A PHP web-based weather sensor

Figure 12.7 The LED Cgicc form post example

Figure 12.8 Express hello world example

Figure 12.9 A ThingSpeak web sensor example

Figure 12.10 A ThingSpeak MATLAB example

Figure 12.11 The Gmail settings security option

Figure 12.12 Example IFTTT recipe

Figure 12.13 A typical IoT solution architecture

Figure 12.14 IBM Bluemix console window

Figure 12.15 The Bluemix application catalog

Figure 12.16 IBM IoT dashboard window

Figure 12.17 IoT device configuration

Figure 12.18 Connection Log

Figure 12.19 IoT PaaS receiving CPU temperature data samples in JSON format

Figure 12.20 IBM Quickstart receiving CPU temperature data samples in JSON format

Figure 12.21 Client/server example

Figure 12.22 RPi remote monitoring using Linux Dash

Figure 12.23 AdaFruit pseudo-PoE cable

Figure 12.24 True PoE connection for the T-568B wiring scheme

Chapter 13: Wireless Communication and Control

Figure 13.1 Bluetooth-connected RPi

Figure 13.2 An Android mobile phone connecting to the RPi using Bluetooth: (a) device pairing, (b) a Bluetooth terminal application setup, and (c) terminal communication

Figure 13.3 An example App Inventor Android application that uses the Bluetooth code library to communicate to the RPi

Figure 13.4 A selection of Wi-Fi adapters and test results when they are connected to the RPi

Figure 13.5 The bottom and top views of the low-cost NodeMCU (version 2) Wi-Fi slave processor

Figure 13.6 (a) The NodeMCU device profile under Windows, and (b) the NodeMCU firmware programmer

Figure 13.7 NodeMCU Wi-Fi slave test: (a) the test circuit, and (b) the web page output

Figure 13.8 (a) The XBee Pro S2 and XBee S2 devices with wire antennas, and (b) the SparkFun XBee USB Explorer

Figure 13.9 The Digi XCTU software: (a) device discovery using an XBee USB adapter, and (b) the device configuration window

Figure 13.10 (a) XCTU firmware update reset warning, and (b) a reset pushbutton modification for the XBee USB Explorer

Figure 13.12 (a) The XBeeA circuit configuration, and (b) the XBeePi circuit configuration

Figure 13.11 Configuring the Arduino XBee to connect to the RPi XBee Device: (a) the RPi XBee, and (b) Arduino XBee XCTU settings

Figure 13.13 The XCTU Console working mode receiving JSON messages from the Arduino XBee device

Figure 13.14 (a) Configuring XBee1 as a coordinator with PAN ID 1234, and (b) configuring XBee2 as a router with PAN ID 1234

Figure 13.15 (a) The XBee1 RPi coordinator circuit, and (b) the standalone XBee2 router circuit with sample I/O connections

Figure 13.16 (a) The XBee S2 pinout, and (b) the XCTU I/O settings for an XBee S2 module

Figure 13.17 The Adafruit NFC/RFID interface for the RPi along with passive RFID tags

Figure 13.18 (a) Low-cost PN532 NFC breakout boards ($5–$16); (b) RFID cards and key chain tags

Chapter 14: Raspberry Pi with a Rich User Interface

Figure 14.1 (a) Connection to an HDMI and a Bluetooth adapter, and (b) a Bluetooth keyboard/touchpad (to scale with RPi)

Figure 14.2 Screen capture of the RPi monitor display

Figure 14.3 VNC Viewer on Windows

Figure 14.4 The GTKhello application

Figure 14.5 The GTKsensor application

Figure 14.6 Qt “hello world” RPi example executing using VNC

Figure 14.7 QTimer signals and slots example

Figure 14.8 Qt Creator IDE visual design editor running directly on the RPi (via VNC)

Figure 14.9 Qt Creator IDE test application

Figure 14.10 Development of the Qt weather sensor GUI application within Qt Creator

Figure 14.11 The Qt weather sensor GUI application components

Figure 14.12 The UI component signals and associated slots

Figure 14.13 The Qt fat-client GUI weather application client/server architecture

Figure 14.14 The menu and the Server Settings dialog

Figure 14.15 A multithreaded server

Chapter 15: Images, Video, and Audio

Figure 15.1 (a) The RPi NoIR camera; (b) correct attachment of the ribbon cable to the RPi CSI connector

Figure 15.2 Logitech USB HD webcams (a) C270, (b) C310, and (c) C920

Figure 15.3 (a) The fswebcam webcam capture (1280 × 720) displayed using gpicview via VNC, and (b) the Cheese application displaying some available image filters

Figure 15.4 The OpenCV image processing example: (a) edge-detected version of Figure 15.3(a), and (b) face detection on the Lenna image

Figure 15.5 The HiFiBerry audio HAT: (a) for the RPiA/B, and (b) for the RPiA+/B+/2

Figure 15.6 (a) Seven-port USB hub with multiple adapters, (b) the Sound Blaster audio adapter, and (c) the Dynamode USB audio adapter

Chapter 16: Kernel Programming

Figure 16.1 The Linux kernel and user space architecture

Figure 16.2 (a) An LED and pushbutton circuit for testing the GPIO LKM; (b) the LKM performance results (with debouncing disabled)

List of Tables

Chapter 2: Raspberry Pi Software

Table 2.1 Regular RPi Ethernet Advantages and Disadvantages

Table 2.2 Crossover Cable Network Advantages and Disadvantages

Table 2.3 Useful First Commands in Linux

Table 2.4 Basic File System Commands

Table 2.5 Some Time-Saving Terminal Keyboard Shortcuts

Table 2.6 Nano Shortcut Keys: A Quick Reference

Table 2.7 Common Package Management Commands (Using nano as an Example Package)

Chapter 3: Exploring Embedded Linux Systems

Table 3.1 Common systemd Commands

Table 3.2 systemd Targets Aligned with SysV Runlevels

Table 3.3 Commands for Working with Users, Groups, and Permissions

Table 3.4 The Linux Top-Level Directory

Table 3.5 Useful Commands for File Systems

Table 3.6 Useful Pipe Examples

Table 3.7 Useful tar Commands

Table 3.8 Summary of the Main Git Commands

Chapter 4: Interfacing Electronics

Table 4.1 Comparison of Two Commercially Available TTL and CMOS ICs for a 7408 Quadruple Two-input AND gates IC

Chapter 5: Programming on the Raspberry Pi

Table 5.1 Numeric Computation Time for 5,000,000 Iterations of the

n

-Body Algorithm on Raspbian (Jessie Minimal Image)

Table 5.2 Advantages and Disadvantages of Command Scripting on the RPi

Table 5.3 Advantages and Disadvantages of Java on the RPi

Table 5.4 Advantages and Disadvantages of C/C++ on the RPi

Chapter 8: Interfacing to the Raspberry Pi Buses

Table 8.1 I

2

C Buses on the RPi

Table 8.2 Comparison of I

2

C versus SPI on the RPi

Table 8.3 SPI Communication Modes

Table 8.4 Advantages and Disadvantages of UART Communication

Chapter 9: Enhancing the Input/Output Interfaces on the RPi

Table 9.1 Input/Output Pins for the MCP3208

Chapter 10: Interacting with the Physical Environment

Table 10.1 Summary Comparison of Common Motor Types

Table 10.2 Example Analog Sensor Types and Applications

Table 10.3 Comparison of Typical Digital and Analog Sensor Devices

Table 10.4 Mapping of the 74HC595 Data Bits to the Character LCD Module Inputs, as Required for the C++ LCDCharacterDisplay Class

Chapter 12: The Internet of Things

Table 12.1 Characteristics of Server Versus Client Applications

Table 12.2 CronTable Fields

Chapter 13: Wireless Communication and Control

Table 13.1 Summary Comparison of Different Wireless Standards

Table 13.2 Comparison of XBee Models

Chapter 14: Raspberry Pi with a Rich User Interface

Table 14.1 Strengths and Weaknesses of Different RPi UI Architectures

Table 14.2 Summary of the Important Qt Modules

Introduction

The core idea behind the Raspberry Pi (RPi) project was the development of a small and affordable computing platform that could be used to stimulate the interest of children in core information and communications technology (ICT) education. The rapid evolution of low-cost system on a chip (SoC) devices for mobile applications made it possible to widely deliver the affordable RPi platform in early 2012. The impact was immediate; by February 2015, more than five million Raspberry Pi boards were sold. Given the proliferation of smartphones, the idea of holding in one hand computers that are capable of performing billions of instructions per second is easy to take for granted, but the fact that you can modify the hardware and software of such small yet powerful devices and adapt them to suit your own needs and create your own inventions is nothing short of amazing. Even better, you can now purchase a Raspberry Pi Zero for as little as $5 (the price of a large cup of coffee)!

The Raspberry Pi boards on their own are too complex to be used by a general audience; it is the ability of the boards to run embedded Linux in particular that makes the resulting platform accessible, adaptable, and powerful. Together, Linux and embedded systems enable ease of development for devices that can meet future challenges in smart buildings, the Internet of Things (IoT), robotics, smart energy, smart cities, human-computer interaction (HCI), cyber-physical systems, 3D printing, advanced vehicular systems, and many, many more applications.

The integration of high-level Linux software and low-level electronics represents a paradigm shift in embedded systems development. It is revolutionary that you can build a low-level electronics circuit and then install a Linux web server, using only a few short commands, so that the circuit can be controlled over the Internet. You can easily use the Raspberry Pi as a general-purpose Linux computer, but it is vastly more challenging and interesting to get underneath the hood and fully interface it to electronic circuits of your own design—and that is where this book comes in!

This book should have widespread appeal for inventors, makers, students, entrepreneurs, hackers, artists, dreamers—in short, anybody who wants to bring the power of embedded Linux to their products, inventions, creations, or projects and truly understand the RPi platform in detail. This is not a recipe book; with few exceptions, everything demonstrated here is explained at a level that will enable you to design, build, and debug your own extensions of the concepts presented. Nor does this book include any grand design project for which you must purchase a prescribed set of components and peripherals to achieve a very specific outcome. Rather, this book is about providing you with enough background knowledge and “under-the-hood” technical details to enable and motivate your own explorations.

I strongly believe in learning by doing, so I present low-cost, widely available hardware examples so that you can follow along. Using these hands-on examples, I describe what each step means in detail, so that when you substitute your own hardware components, modules, and peripherals you will be able to adapt the content in this book to suit your needs. As for that grand design project, that is up to you and your imagination!

In late 2014, I released a well-received book on the BeagleBone platform titled Exploring BeagleBone: Tools and Techniques for Building with Embedded Linux. Given the focus of this book on embedded Linux and the emphasis on introducing the core principles, there are some similarities between the introductory content in that book and this book. However, this book has been written from first principles purely for the RPi platform, focusing on its strengths and addressing several of its weaknesses. I also took the opportunity to extend the coverage of the material to cover topics such as Linux kernel development, the Arduino as a service processor, Wi-Fi sensor nodes, XBee communication, MQTT messaging, the Internet of Things (IoT), platform as a service (PaaS), and much more. If you have a copy of Exploring BeagleBone, you should visit this book's website (www.exploringrpi.com) to compare the content in both books before you make your purchasing decision.

When writing this book, I had the following aims and objectives:

To explain embedded Linux and its interaction with electronic circuits—taking you through the topics and challenges on the popular RPi platform.

To provide in-depth information and instruction on the Linux, electronics, and programming skills that are required to master a pretty wide and comprehensive variety of topics in this domain.

To create a collection of practical Hello World hardware and software examples on each and every topic in the book, from low-level interfacing, general-purpose input/outputs (GPIOs), buses, bus-attached analog-to-digital converters (ADCs), and universal asynchronous receiver/transmitters (UARTs) to high-level libraries such as OpenCV and the Qt Framework. The book also covers more advanced topics such as low-level register manipulation and Linux loadable kernel module (LKM) development.

To enhance and extend the interfacing capability of the RPi platform by developing frameworks for connecting it to circuits (e.g., SPI-based ADCs), to service processors (e.g., Arduino and NodeMCU), and to cloud-based IoT platforms and services.

To ensure that each circuit and segment of code has a broad pedagogical reach and is specifically designed to work on the Raspberry Pi. Every single circuit and code example in this book was built and tested on the RPi platform (most on multiple board versions).

To use the Hello World examples to build a library of code that you can use and adapt for your own Raspberry Pi projects.

To make all the code available on GitHub in an easy-to-use form.

To support this book with strong digital content, such as the videos on the DerekMolloyDCU YouTube channel, and the

www.exploringrpi.com

custom website that was developed specifically to support this book.

To ensure that by the end of this book you have everything you need to imagine, create, and build

advanced

Raspberry Pi projects.

How This Book Is Structured

There is no doubt that some of the topics in this book are quite complex. After all, Raspberry Pi boards are complex devices! However, everything that you need to master them is present in this book within three major parts:

Part I

: Raspberry Pi Basics

Part II

: Interfacing, Controlling, and Communicating

Part III

: Advanced Interfacing and Interaction

In the first part of the book, I introduce the hardware and software of the RPi platforms in Chapters 1 and 2, and subsequently provide three primer chapters:

Chapter 3

, “Exploring Embedded Linux Systems”

Chapter 4

, “Interfacing Electronics”

Chapter 5

, “Programming on the Raspberry Pi”

If you are a Linux expert, electronics wizard, and/or software guru, feel free to skip these primers. However, for everyone else, I have put in place a concise but detailed set of materials to ensure that you gain all the knowledge required to effectively and safely interface to the Raspberry Pi. The remaining chapters refer to these primers often.

The second part of the book, Chapters 6–11, provides detailed information on interfacing to the Raspberry Pi GPIOs, buses (I2C, SPI), UART devices, and USB peripherals. You learn how to configure a cross-compilation environment so that you can build large-scale software applications for the Raspberry Pi. Part II also describes how to combine hardware and software to provide the Raspberry Pi with the capability to interact effectively with its physical environment. In addition, Chapter 11, “Real-Time Interfacing Using the Arduino,” shows you how to use the Arduino as a slave processor with the Raspberry Pi, which helps you to overcome some of the real-time constraints of working with embedded Linux.

The third and final part of the book, Chapters 12–16, describes how to use the Raspberry Pi for advanced interfacing and interaction applications such as IoT; wireless communication and control, rich user interfaces; images, video, and audio; and Linux kernel programming. Along the way, you encounter many technologies, including TCP/IP, ThingSpeak, IBM Bluemix, MQTT, Cgicc, Power over Ethernet (PoE), Wi-Fi, NodeMCUs, Bluetooth, NFC/RFID, ZigBee, XBee, cron, Nginx, PHP, e-mail, IFTTT, GPS, VNC, GTK+, Qt, XML, JSON, multithreading, client/server programming, V4L2, video streaming, OpenCV, Boost, USB audio, Bluetooth A2DP, text-to-speech, LKMs, kobjects, and kthreads!

Conventions Used in This Book

This book is filled with source code examples and snippets that you can use to build your own applications. Code and commands are shown as follows:

This is what source code looks like.

When presenting work performed in a Linux terminal, it is often necessary to display both input and output in a single example. A bold type is used to distinguish the user input from the output. For example:

pi@erpi ~ $

ping www.raspberrypi.org

PING lb.raspberrypi.org (93.93.128.211) 56(84) bytes of data. 64 bytes from 93.93.128.211: icmp_seq=1 ttl=53 time=23.1 ms 64 bytes from 93.93.128.211: icmp_seq=2 ttl=53 time=22.6 ms …

The $ prompt indicates that a regular Linux user is executing a command, and a # prompt indicates that a Linux superuser is executing a command. The ellipsis symbol (…) is used whenever code or output not vital to understanding a topic has been cut. Editing the output like this enables you to focus on only the most useful information. In addition, an arrow symbol on a line entry indicates that the command spans multiple lines in the book but should be entered on a single line. For example:

pi@erpi /tmp $

echo "this is a long command that spans two lines in the → book but must be entered on a single line" >> test.txt

You are encouraged to repeat the steps in this book yourself, whereupon you will see the full output. In addition, the full source code for all examples is provided along with the book using a GitHub repository.

You'll also find some additional styles in the text. For example:

New terms and important words appear in

italics

when introduced.

Keyboard strokes appear like this: Ctrl+C.

All URLs in the book refer to HTTP/S addresses and appear like this:

www.exploringrpi.com

.

A URL shortening service is used to create aliases for long URLs that are presented in the book. These aliases have the form

tiny.cc/erpi102

(e.g., link two in

Chapter 1

). Should the link address change after this book is published, the alias will be updated.

There are several features used in this book to identify when content is of particular importance or when additional information is available:

WARNING

This type of feature contains important information that can help you avoid damaging your Raspberry Pi board.

NOTE

This type of feature contains useful additional information, such as links to ­digital resources and useful tips, which can make it easier to understand the task at hand.

FEATURE TITLE

This type of feature goes into detail about the current topic or a related topic.

EXAMPLE: EXAMPLE TITLE

This type of feature typically provides an example use case, or an important task that you may need to refer to in the future.

What You'll Need

Ideally, you should have a Raspberry Pi board before you begin reading this book so that you can follow along with the numerous examples. If you have not already purchased a Raspberry Pi board, I recommend the Raspberry Pi 3 Model B. Although it is presently the most expensive board ($35–$40), it is also the most powerful. This board has a 64-bit quad-core processor, a wired network adapter, wireless Ethernet, and onboard Bluetooth; therefore, it has all the features required to run any example in this book. You can purchase a Raspberry Pi board in the United States from online stores such as Adafruit Industries, Digi-Key, SparkFun, and Jameco Electronics. They are available internationally from stores such as Farnell, Radionics, and Watterott.

A full list of recommended and optional accessories for the Raspberry Pi is provided in Chapter 1. If you do not yet have a Raspberry Pi, you should read that chapter before purchasing one. In addition, the first page of each chapter contains a list of the electronics components and modules required if you want to follow along. The book website (www.exploringrpi.com) provides details about how to acquire these components.

I purposefully focus the examples in this book on the lowest-cost and most widely available components, breakout boards, and modules that I could identify that meet the needs of the examples. This should help you follow along with many examples, rather than focusing your budget on a small few. Indicative prices are listed throughout the book to give you a feel for the price of the components before you embark on a project. They are the actual prices for which I purchased the items on websites such as ebay.com, amazon.com, and aliexpress.com.

NOTE

No products, vendors, or manufacturers listed in this book are the result of any type of placement deal. I have chosen and purchased all the products myself based on their price, functionality, and worldwide availability. Listed prices are indicative only and are subject to change. Please do your own research before purchasing any item that is listed in this book to ensure that it truly meets your needs.

Errata

We have worked really hard to ensure that this book is error free; however, it is always possible that some were overlooked. A full list of errata is available on each chapter's web page at the companion website (www.exploringrpi.com). If you find any errors in the text or in the source code examples, I would be grateful if you could please use the companion website to send them to me so that I can update the web page errata list and the source code examples in the code repository.

Digital Content and Source Code

The primary companion site for this book is www.exploringrpi.com. It is maintained by the book's author and contains videos, source code examples, and links to further reading. Each chapter has its own web page. In the unlikely event that the website is unavailable, you can find the code at www.wiley.com/go/exploringrpi.

I have provided all the source code through GitHub, which allows you to download the code to your Raspberry Pi with one command. You can also easily view the code online at tiny.cc/erpi001. Downloading the source code to your Raspberry Pi is as straightforward as typing the following at the Linux shell prompt:

pi@erpi ~ $

git clone https://github.com/derekmolloy/exploringrpi.git

If you have never used Git before, don't worry; it is explained in detail in Chapter 3.

Now, on with even more adventures!

Part IRaspberry Pi Basics

In This Part

Chapter 1

:

Raspberry Pi Hardware

Chapter 2

:

Raspberry Pi Software

Chapter 3

:

Exploring Embedded Linux Systems

Chapter 4

:

Interfacing Electronics

Chapter 5

:

Programming on the Raspberry Pi

Chapter 1Raspberry Pi Hardware

In this chapter, you are introduced to the Raspberry Pi (RPi) platform hardware. The chapter focuses on recently released Raspberry Pi models and describes the various subsystems and physical inputs/outputs of the boards. In addition, the chapter lists accessories that can prove helpful in developing your own Raspberry Pi–based projects. By the end of this chapter, you should have an appreciation of the power and complexity of this physical-computing platform. You should also be aware of the first steps to take to protect your board from physical damage.

Introduction to the Platform

The RPi models are capable general-purpose computing devices, and for that reason they have found favor for introducing learners to general computing and computer programming. The RPi models, some of which are illustrated in Figure 1.1, are also capable physical computing devices that can be used for embedded systems applications—and for Internet-attached embedded applications in particular.

Figure 1.1 Raspberry Pi platform board examples (to relative scale)

Some general characteristics of RPi devices include the following:

They are low cost, available for as little as $5–$35.

They are powerful computing devices. For example, the RPi 3 contains a 1.2 GHz ARM Cortex-A53 processor that can perform more than 700 million Whetstone instructions per second (MWIPS).

1

They are available in a range of models that are suitable for different applications (e.g., the larger-format RPi 3 for prototyping and the tiny-format RPi Zero or Compute Module for deployment).

They support many standard interfaces for electronic devices.

They use little power, running at between approximately 0.5 W (RPi Zero when idle) and approximately 5.5 W (RPi 3 under load).

They are expandable through the use of Hardware Attached on Top (HAT) daughter boards and USB devices.

They are supported by a huge community of innovators and enthusiasts, who generously give of their time to help the RPi Foundation with their educational mission.

The RPi platform can run the Linux operating system, which means that you can use many open source software libraries and applications directly with it. Open source software driver availability also enables you to interface devices such as USB cameras, keyboards, and Wi-Fi adapters with your project, without having to source proprietary alternatives. Therefore, you have access to comprehensive libraries of code that have been built by a talented open source community; however, it is important to remember that the code typically comes without any type of warranty or guarantee. If there are problems, you have to rely on the good nature of the community to resolve them. Of course, you could also fix the problems yourself and make the solutions publicly available.

One impressive feature of recent RPi models is that their functionality can be extended with daughter boards, called HATs (Hardware Attached on Top), that connect to the GPIO header (the 40-pin double-pin connector row on the boards in Figure 1.1). You can design your own HATs and attach them securely to your RPi using this header. In addition, many HATs are available for purchase that can be used to expand the functionality of your RPi platform. Some examples of these are described toward the end of this chapter.

Who Should Use the RPi

Anybody who wants to transform an engineering concept into a real interactive electronics project, prototype, or work of art should consider using the RPi. That said, integrating high-level software and low-level electronics is not an easy task. However, the difficulty involved in an implementation depends on the level of sophistication that the project demands. The RPi community is working hard to ensure that the platform is accessible by everyone who is interested in integrating it into their projects, whether they are students, makers, artists, or hobbyists. For example, the availability of the Scratch visual programming tool on the RPi (tiny.cc/erpi101) is an excellent way to engage children with both computer programming and the RPi.

For more advanced users with electronics or computing knowledge, the RPi platform enables additional development and customization to meet specific project needs. Again, such customization is not trivial: You may be an electronics expert, but high-level software programming and/or the Linux operating system might cause you difficulty. Or you may be a programming guru but you have never wired an LED! This book aims to cater to all types of users who are interested in interfacing with the RPi, providing each type of reader with enough Linux, electronics, and software exposure to ensure that you can be productive, regardless of your previous experience level.

When to Use the RPi

The RPi is perfectly placed for the integration of high-level software and low-level electronics in any type of project. Whether you are planning to build an automated home management system, robot, multimedia display, Internet of Things (IoT) application, vending machine, or Internet-connected work of interactive art, the RPi has the processing power to do whatever you can imagine of an embedded device.

The major advantage the RPi and other embedded Linux devices have over more traditional embedded systems, such as the Arduino, PIC, and AVR microcontrollers, is apparent when you leverage the Linux OS for your projects. For example, if you build a home automation system using the RPi and you then decide that you want to make certain information available on the Internet, you can simply install the Nginx web server. You could then use server-side scripting or your favorite programming language to interface with your home automation system to capture and share information. Alternatively, your project might require secure remote shell access. In that case, you could install a Secure Shell (SSH) server simply by using the Linux command sudo apt install sshd (as covered in Chapter 2). This could potentially save you weeks of development work. In addition, you have the comfort of knowing that the same software is running securely on millions of machines around the world.

Linux also provides you with device driver support for many USB peripherals and adapters, making it possible for you to connect cameras, Wi-Fi adapters, and other low-cost consumer peripherals directly to your platform without the need for complex/expensive software driver development.

The RPi is also an excellent device for playing high-definition video. The RPi has this capability because its Broadcom BCM2835/6/7 processor was designed for multimedia applications, and it has a hardware implementation of H.264/MPG-4 and MPG-2/VC-1 (via additional license) decoders and encoders. The RPi has found popular use for multimedia applications such as running the Kodi home media center2 (www.kodi.tv) for playing full-HD video content.

When to Not Use the RPi

The Linux OS was not designed for real-time or predictable processing. This would be problematic if, for example, you want to sample a sensor precisely every one millionth of a second. If the precise time arises to take a sample and the kernel is busy with a different task, it cannot be easily interrupted. Therefore, in its default state, the RPi is not an ideal platform for real-time systems applications. Real-time versions of Linux are available, but they are currently targeted at very experienced Linux developers, and there are limits to their real-time capabilities. However, the RPi can be combined with real-time service processors, and the RPi can be used as the “central intelligence.” You can interconnect such real-time microcontrollers to the RPi via electrical buses (e.g., I2C, UART) and Ethernet, and have the RPi act as the central processor for a distributed control system. This concept is described in Chapters 11, 12, and 13.

The RPi platform is not ideal for project developments that are likely to be commercialized. The Raspberry Pi platform largely utilizes open source software (there are some closed-source blobs used with the GPU), but it is not open source hardware. Schematics are available for RPi boards (e.g., tiny.cc/erpi102), but there is a lack of documentation on the hardware used. In addition, the Broadcom bootloader license3 explicitly states that its redistribution in binary form is only permitted if it will “… only be used for the purposes of developing for, running or using a Raspberry Pi device.” It is unlikely that such a license would transfer to a product of your own design.

As described earlier in this chapter, the focus of the RPi Foundation is on education, and product commercialization is far from that brief. If you are planning to build an embedded Linux project that is to be commercialized, you should examine the BeagleBone platform, which is entirely open source and is supported by strong Texas Instruments documentation. In addition, you should of course purchase my book Exploring BeagleBone from the same Wiley mini-series.

RPi Documentation

This book integrates my experiences in developing with the RPi platform along with supporting background materials on embedded Linux, software development, and general electronics, to create an in-depth guide to building with this platform. However, it is simply not possible to cover everything in just one book, so I have avoided restating information that is listed in the key documents and websites described in this section. The first starting point for supporting documentation is the following website:

The Raspberry Pi Foundation website:

This provides the main support for the RPi platform, with blogs, software guides, community links, and downloads to support your development. See

www.raspberrypi.org

.

A huge amount of documentation is available on the RPi platform, but the most important documents for this book are as follows:

The Raspberry Pi Documentation:

This is the official documentation for the RPi that is written by the Raspberry Pi Foundation. It includes guides on getting started, configuration, guides to Linux distributions, and more. See

www.raspberrypi.org/documentation/

.

Broadcom