O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Raspberry Pi Computer Architecture Essentials

Book Description

Explore Raspberry Pi's architecture through innovative and fun projects

About This Book

  • Explore Raspberry Pi 2’s hardware through the Assembly, C/C++, and Python programming languages
  • Experiment with connecting electronics up to your Raspberry Pi 2 and interacting with them through software
  • Learn about the Raspberry Pi 2 architecture and Raspbian operating system through innovative projects

Who This Book Is For

Raspberry Pi Computer Architecture Essentials is for those who are new and those who are familiar with the Raspberry Pi. Each topic builds upon earlier ones to provide you with a guide to Raspberry Pi’s architecture. From the novice to the expert, there is something for everyone. A basic knowledge of programming and Linux would be helpful but is not required.

What You Will Learn

  • Set up your Raspberry Pi 2 and learn about its hardware
  • Write basic programs in Assembly Language to learn about the ARM architecture
  • Use C and C++ to interact with electronic components
  • Find out about the Python language and how to use it to build web applications
  • Interact with third-party microcontrollers
  • Experiment with graphics and audio programming
  • Expand Raspberry Pi 2’s storage mechanism by using external devices
  • Discover Raspberry Pi 2’s GPIO pins and how to interact with them

In Detail

With the release of the Raspberry Pi 2, a new series of the popular compact computer is available for you to build cheap, exciting projects and learn about programming.

In this book, we explore Raspberry Pi 2’s hardware through a number of projects in a variety of programming languages. We will start by exploring the various hardware components in detail, which will provide a base for the programming projects and guide you through setting up the tools for Assembler, C/C++, and Python. We will then learn how to write multi-threaded applications and Raspberry Pi 2’s multi-core processor. Moving on, you’ll get hands on by expanding the storage options of the Raspberry Pi beyond the SD card and interacting with the graphics hardware. Furthermore, you will be introduced to the basics of sound programming while expanding upon your knowledge of Python to build a web server. Finally, you will learn to interact with the third-party microcontrollers.

From writing your first Assembly Language application to programming graphics, this title guides you through the essentials.

Style and approach

This book takes a step-by-step approach to exploring Raspberry Pi’s architecture through projects that build upon each other. Each project provides you with new information on how to interact with an aspect of the Raspberry Pi and Raspbian operating system, providing a well-rounded guide.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Raspberry Pi Computer Architecture Essentials
    1. Table of Contents
    2. Raspberry Pi Computer Architecture Essentials
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Introduction to the Raspberry Pi's Architecture and Setup
      1. History and background of the Raspberry Pi
        1. Raspberry Pi hardware specifications
        2. Dimensions
        3. System on Chip
        4. CPU
        5. GPU
        6. SDRAM
        7. 4 USB 2.0 ports and 1 SoC on-board USB
        8. MicroSD card port
        9. Ethernet port
        10. Audio
        11. GPIO pins
        12. Video – analog TV out
        13. Video – HDMI port
      2. Basic hardware needed
      3. The microSD card – the main storage and boot device of the Raspberry Pi 2
        1. Preinstalled microSD card versus creating your own
        2. The NOOBS operating system installation manager
        3. Downloading the latest version of Raspbian
        4. Setting up your microSD card and installing the Raspbian operating system
        5. Raspbian installation wrap-up
        6. Check SSH is running
          1. RSA key generation for SSH
            1. Linux and Mac RSA key generation
            2. Windows RSA key generation
        7. Assign a static IP to your Raspberry Pi 2
      4. Installing Screen and Vim
        1. Vim – an optional handy text editor
      5. Running tests on the OS and configuration changes
        1. Diagnostic tests
        2. Over and underclocking the Raspberry Pi
        3. Going further – testing the GPIO pins
      6. Some handy Linux commands
      7. Troubleshooting
      8. Summary
    9. 2. Programming on Raspbian
      1. Which programming languages?
      2. Assembly language
        1. Assembling and linking
      3. The C and C++ languages
        1. C – a brief introduction
        2. A quick look at C++
        3. Our first C program
          1. Geany – a handy text editor and development environment
          2. Creating a new C program
        4. C libraries – a trove of reusable code
        5. The C (and C++) compiler
        6. Compiling and running our application
      4. The Python language
        1. A simple Python program
        2. Running a Python program from a file
      5. Summary
    10. 3. Low-Level Development with Assembly Language
      1. Back to basics
        1. Multiline comments
        2. Directives
        3. Single line comments
        4. Registers
        5. Branching
        6. The assembler
        7. The linker
        8. Makefiles
      2. Memory and addresses
        1. The .data directive
          1. The .balign directive
          2. Words
          3. Labels
        2. The memory
        3. The addresses
        4. LDR and SUB
        5. Running our program
      3. Adding power to our program – control structures
        1. If else statements
        2. Iteration
        3. Testing our control structures
      4. Summary
    11. 4. Multithreaded Applications with C/C++
      1. What are threads?
        1. Thread types
          1. User level threads
          2. Kernel level threads
          3. Hybrid threads
        2. POSIX threads
        3. Steps involved in implementing threads
          1. Creation and termination
          2. Synchronization
          3. Scheduling
        4. An example in C
        5. Trying out our program
      2. A C++ equivalent
        1. The g++ command
      3. Going further – mutexes and joins
        1. Compile and test
      4. Summary
    12. 5. Expanding on Storage Options
      1. Booting up
      2. Setting up the external HDD
        1. Getting the disk name
        2. Setting up the HDD
        3. Modifying cmdline.txt
      3. Network-attached storage (NAS)
        1. Installing Samba
        2. Testing the NAS
          1. Mac
          2. Linux
          3. Windows
      4. Summary
    13. 6. Low-Level Graphics Programming
      1. VideoCore IV GPU
        1. Sample programs
      2. Accessing the frame buffer
        1. Check the display settings
        2. Testing our C code
      3. Filling the screen with a color
        1. A C program to turn the screen red
        2. Compile and run the C program
      4. Drawing a line
        1. Plotting pixels and drawing lines
        2. Compile and run
        3. Next steps – polygons
      5. Summary
    14. 7. Exploring the Raspberry Pi's GPIO Pins
      1. Introduction to GPIO pins
        1. Standard GPIO
        2. I2C
        3. Serial Rx and Tx
        4. SPI
        5. PWM and PPM
        6. GPIO power voltages
      2. Hardware choices
        1. Prototyping shields and boards
        2. Cooking Hacks Arduino bridge shield
        3. Connecting directly to the GPIO pins
      3. Switching an LED on and off
        1. Setting up the hardware
        2. C blinking LED program
        3. Python blinking LED program
        4. Reading data from the GPIO pins in Python
      4. Summary
    15. 8. Exploring Sound with the Raspberry Pi 2
      1. Introduction to the Raspberry Pi's sound
        1. Configuring the audio output
        2. Setting the audio output
      2. Interacting with audio through GPIO
        1. Installing the audio drivers
        2. Hardware setup
        3. Loading drivers
        4. Getting some drum tracks
        5. Python drum machine
        6. Audio shields for the Raspberry Pi
      3. C and ALSA
        1. ALSA examples
      4. Introducing Sonic Pi
        1. Setup
        2. Experimenting with Sonic Pi
      5. Summary
    16. 9. Building a Web Server
      1. Introduction to web servers
        1. HTTP requests
        2. HTML
      2. Popular web servers available on the Raspberry Pi
        1. Apache
        2. NGINX
      3. Building a Python web server
        1. Python web server code
        2. Adding an index page and a favicon
      4. Adding database support
        1. SQLite
        2. SQL – a quick overview
        3. Python program with SQLite support
        4. Flask – displaying database data via Python
        5. Next steps
      5. Summary
    17. 10. Integrating with Third-Party Microcontrollers
      1. Genuino/Arduino microcontroller
      2. Setting up the Arduino software
        1. Installing the IDE on your Raspberry Pi 2
        2. A quick guide to the Arduino IDE
      3. Integration with Arduino
        1. Serial communication over USB
        2. Communication between the Arduino and Raspberry Pi via GPIO
        3. Communication over I2C
        4. Communication over the Web
      4. Summary
    18. 11. Final Project
      1. Choose your storage mechanism
      2. Building a Flask-based website
        1. Adding a database
        2. A basic website
        3. Web forms
          1. Add
          2. Edit
      3. Adding in an LED
        1. Building the circuit – a recap
        2. Integrating with our Python app
      4. Extending the project further
        1. Replace the LED with a screen
        2. E-mail support
        3. Playing a sound
      5. Summary
    19. Index