没有合适的资源?快使用搜索试试~ 我知道了~
首页Raspberry Pi 2实战:C++探索创新项目指南
"《探索Raspberry Pi 2与C++:实践中的技术行动》(Apress,2015)是一本专为Raspberry Pi 2用户量身打造的指南,由Warren Gay撰写。本书旨在帮助读者充分利用这款微型计算机的潜力,通过实践项目来挖掘其功能。作者首先引导读者将Pi 2打造成一个能进行实际工作的工作站,然后深入探讨如何安装自定义内核,制作计时器,学习GPIO接口的工作原理,并在此过程中习得实用的C++编程技能。 对于有一定电子学基础的爱好者,Pi的粉丝,以及教师、学生、制造商和任何想要深度了解和利用Raspberry Pi的人来说,这本书是一份宝贵的资源。书中详细讲解了如何操作硬件,如GPIO引脚的使用,这对于开发各种创意项目至关重要。同时,C++编程语言的选择也确保了内容对那些寻求高效编程方法的专业人士具有吸引力。 版权方面,作者明确指出,所有内容受版权保护,除非在特定情况下,如学术评论或为了在计算机系统上执行而临时复制,否则复制或使用全书或部分内容都必须遵循出版商所在地现行的版权法,并获得许可。这体现了作者对于知识产权的尊重,同时也保障了读者的合法阅读体验。 《探索Raspberry Pi 2 with C++》不仅是一本技术教程,更是一个动手实践的平台,它鼓励读者通过编写代码和构建项目,提升自己的技能,实现从理论到实践的飞跃,真正让Raspberry Pi 2发挥出其无限可能。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/9371229/bg10.jpg)
xvii
About the Author
Warren W. Gay started out in electronics at an early age, dragging
discarded TVs and radios home from public school. In high school he
developed a fascination for programming the IBM 1130 computer, which
resulted in a career plan change to software development. After attending
Ryerson Polytechnical Institute, he has enjoyed a software developer
career for more than 30 years, programming mainly in C/C++. Warren has
been programming Linux since 1994 as an open source contributor and
professionally on various Unix platforms since 1987.
Before attending Ryerson, Warren built an Intel 8008 system from
scratch before there were CP/M systems and before computers got
personal. In later years, Warren earned an advanced amateur radio license
(call sign VE3WWG) and worked the amateur radio satellites. A high point
of his ham radio hobby was making digital contact with the Mir space
station (U2MIR) in 1991.
Warren works at Datablocks.net, an enterprise-class ad-serving
software services company. There he programs C++ server solutions on
Linux back-end systems.
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9371229/bg11.jpg)
xix
Acknowledgments
I’d like to express my thanks to the good folks at Apress for their ideas, support and patience. Special thanks
to Michelle Lowman for running with the project and Mark Powers for leading the orchestra. Last, but not
least, thanks to the orchestra itself, where the concert begins.
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9371229/bg12.jpg)
1
Chapter 1
Introduction
The introduction of the Raspberry Pi 2 has ushered in exciting new opportunities. No longer is the software
limited to one CPU core, but now executes on four. Memory has been doubled to 1 GB, providing a larger
disk cache and resulting in better SD card performance. This also leaves room for larger applications. Having
four built-in USB ports is also helpful in avoiding the need for a USB hub.
Some things have changed underneath the hood as well, like the physical address for peripherals. The
address BCM2708_PERI_BASE has changed from 0x20000000 to 0x3F000000 for the Raspberry Pi 2. This
means that a lot of software written for the earlier Raspberry Pi models will not work on the new Pi 2 without
changes. With device tree (DT) support built into Raspbian Linux, it is now a simple matter to automatically
detect this. Consequently, the included librpi2 GPIO class detects this automatically.
The main purpose in this book is to exploit the Raspberry Pi 2. To that end, this book comes with
software libraries and tools to make doing things on your Pi easier. The provided C++ libraries will make it
possible to access the GPIO and other peripherals with only a few lines of code. Command line tools like
the gp command will give you simple and ready access to list your GPIO state and to make changes. A useful
feature of gp includes the ability to “blink” a pin, so that you can verify wiring with an LED attached. The gp
command also allows a pin to be “monitored” for changes, making testing inputs easier. All installed tools
include their own self-help display (command option -h).
A Raspberry Pi designer is handicapped without a logic analyzer for tracing events on GPIO pins. For
this reason, I felt strongly that the reader should have one to use. This book provides you with a software-
based logic analyzer for free (it requires no extra hardware). The PiSpy logic analyzer is able to see all GPIO
inputs and outputs and record events to a file. The GtkWave utility is used to display the captured events
graphically.
The C++ programming language was chosen for this book to make your life easier. The C programmer
need not fear this because I’ve kept to the basics without using hairy language elements. Many Arduino
students use C++ every day without knowing it. The C++ standardization efforts of the last decade have had a
very positive effect on g++ and glibc. This and the availability of the Standard Template Library (STL) in glibc
make it a very productive environment in which to program.
I’ve used a hybrid approach to the C++ code presented. I continue to use the well-understood standard
I/O (stdio) routines like printf() so that the code is easy to read and familiar. I know that C++ purists will “tsk
tsk” about this, but this is a practical book rather than a computer science text.
Of particular interest, are the included software utilities and the C++ library librpi2. Tools and libraries
are most useful when you have the documentation in your hands.
Overview
Chapter 2 presents a simple Raspberry Pi 2 workstation construction project. Using a short plank of wood,
you can mount your Raspberry Pi 2 and a breadboard on it. I find that being organized this way helps
considerably.
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9371229/bg13.jpg)
Chapter 1 ■ IntroduCtIon
2
Chapter 3 presents “The Matrix” construction project. It uses an LED matrix to produce a display that
can provide instant display of CPU utilization for each of its cores. It also displays bar graphs for memory and
disk I/O utilization. If you don’t want to construct this project, you can install the htop utility instead.
Chapters 4 and 9 cover an exciting tool that is also included in the book’s software, the PiSpy logic
analyzer tool. This provides a simple-to-use logic analyzer for your Pi, requiring no additional hardware. It
allows you to inspect and capture GPIO signal events, whether the GPIO is an input or output. Through the
use of the direct memory access (DMA) peripheral, PiSpy can capture signal changes up to about 1–2 MHz.
The GtkWave command is then optionally invoked automatically to display the captured data.
Chapter 5 is dedicated to the GPIO gp command. All utilities provided with this book use proper
command line option processing as used by the standard Unix commands. The chapter begins with a brief
discussion of what Unix command line conventions are and then works through the gp command use cases
with explanations.
Chapter 6 introduces the piclk utility, which can display or alter the configuration of the general
purpose clock (or PWM clock). Experiments with the clock are included.
Chapter 7 expands on the clock concept by examining the Pulse Width Modulation (PWM) peripheral.
The pipwm utility and its options are explored in combination with PiSpy. PiSpy illustrates the effect of
different configuration settings.
Chapter 8 takes a light look at what GPIO is and the Complementary MOS (CMOS) technology that it is
made from. Electronics students will find the examination helpful in explaining what CMOS is and avoiding
some pitfalls in interfacing. Additionally CMOS inputs are examined with a brief discussion of chip static
protection schemes.
Chapter 9 provides a detailed look at the PiSpy logic analyzer and describes the various features of
its application.
Chapter 10 looks at GPIO input processing, focusing particularly on the problem of debouncing input
signals from buttons and switches.
Chapter 11 is a software-focused chapter. It provides a fast track to using C++ and the STL in a very easy
and pragmatic way. The STL provides the programmer great benefits in programming time and reliability. In
this chapter we look at the most popular containers and example code fragments are provided throughout.
Chapter 12 is the multithreaded software designed to take advantage of all four CPU cores within an
efficient web server. The server is based on the libevent library behind the scenes, but C++ classes are used
to provide a very simple interface. This allows you to build and customize your own web server with very
little mainline code. The provided piweb project can be used and extended.
Appendixes A through C document the librpi2 C++ classes for programming GPIO. With the provided
library, it is a simple matter to directly control GPIO from your own code. The appendixes provide you with
easy-to-follow documentation and examples for the various class methods supported.
Appendixes D and E describe some other C++ classes that might be useful for people wanting to work
with Matrix or 7-segment displays. Appendix F describes classes that have to do with gathering system
performance metrics as used by the mtop utility.
Appendix G provides some additional information about some of the remaining advanced classes
found in librpi2.
Software for This Book
You will want to download the open source software written for this book. It is available from two sources:
• www.apress.com/9781484217382
• https://github.com/ve3wwg/raspberry_pi2.git
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9371229/bg14.jpg)
Chapter 1 ■ IntroduCtIon
3
The open source software is important because:
1. It provides you with several utilties: gp, piclk, pipwm, mtop, and PiSpy.
2. It includes the piweb C++ web server project.
3. It provides library librpi2, which can be used in your own C++ projects.
If you are using git to download the source code use the command
$ git clone https://github.com/ve3wwg/raspberry_pi2.git ./pi2
The second argument tells git to install the source code into the new pi2 subdirectory.
The gp command provides you with a first-class Unix utility to display and control the GPIO resources.
This utility also includes some useful options to blink a GPIO pin, which is great for checking wiring to LEDs.
Another option allows you to monitor an input to the terminal session, so you can check input wiring and
so on.
The piclk utility allows you display and control the general purpose clock (and PWM clock). The piclk
command and PiSpy are used together for some experiments.
The pipwm utility allows you to display and control the PWM peripherals. The pipwm command and the
PiSpy utility are also used together to allow you to explore the PWM peripherals.
The PiSpy utility gives you a GPIO logic analyzer. Using a Linux driver for DMA and the PiSpy user land
utility, GPIO data can be captured at nearly 2 MHz or less. This utility automatically assigns and releases the
DMA resources it needs for ease of use and system integrity.
If you choose to build the Matrix in Chapter 3, you will be able to visualize the system utilization in real
time using the provided mtop command.
Because the Raspberry Pi 2 has four CPU cores, the piweb project demonstrates a high-performance
C++ web server using libevent. This thin server will put all four CPU cores to work with sufficient web traffic.
Yet, due to its C++ design, it is simple to program and enhance to meet your own needs.
Software Installation
After downloading your source code and unpacking it to a directory (directory ~/pi2 is suggested), then the
process of building and installing can be started. In these directions, I assume that the software directory is
in subdirectory ~/pi2.
1. Quickly check Chapter 11 to see if you need to download a new GNU compiler. It
is my hope that support for C++11 will be already included by the time you read
this. If not, it is a simple matter to download and install a newer GNU compiler
that do es include C++11 support.
2. $ sudo apt-get install make
3. $ sudo apt-get install libevent-dev (needed for the piweb project)
4. $ sudo apt-get install gtkwave (needed for the PiSpy utility)
5. $ sudo apt-get install htop (recommended)
6. $ cd ~/pi2
7. Optional: When rebuilding do: $ make clobber
8. $ make
9. $ sudo make install
www.it-ebooks.info
剩余197页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/a85f9b5ddf8441b8b4d02a19e1ce0d8e_vanridin.jpg!1)
vanridin
- 粉丝: 108
- 资源: 1188
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 计算机人脸表情动画技术发展综述
- 关系数据库的关键字搜索技术综述:模型、架构与未来趋势
- 迭代自适应逆滤波在语音情感识别中的应用
- 概念知识树在旅游领域智能分析中的应用
- 构建is-a层次与OWL本体集成:理论与算法
- 基于语义元的相似度计算方法研究:改进与有效性验证
- 网格梯度多密度聚类算法:去噪与高效聚类
- 网格服务工作流动态调度算法PGSWA研究
- 突发事件连锁反应网络模型与应急预警分析
- BA网络上的病毒营销与网站推广仿真研究
- 离散HSMM故障预测模型:有效提升系统状态预测
- 煤矿安全评价:信息融合与可拓理论的应用
- 多维度Petri网工作流模型MD_WFN:统一建模与应用研究
- 面向过程追踪的知识安全描述方法
- 基于收益的软件过程资源调度优化策略
- 多核环境下基于数据流Java的Web服务器优化实现提升性能
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)