You are previewing Mastering the Raspberry Pi.
O'Reilly logo
Mastering the Raspberry Pi

Book Description

You probably already know that the Raspberry Pi is an excellent teaching tool. If you want to teach Linux basics or Python programming or basic electronics, it's a great place to start. But what if you are an electronics engineer or a Linux systems administrator or a very experienced maker? You want to know all of the details and inner working of the Raspberry Pi -- how to (figuratively or maybe even literally) make it get up and dance without wading through basics and introductory material.

If you want to get right into the pro-level guts of the Raspberry Pi, complete with schematics, detailed hardware explanations, messing around with runlevels, reporting voltages and temperatures, and recompiling the kernel, then Mastering the Raspberry Pi is just the book you need. Along with all of the thorough explanations of hardware and operating system, you'll also get a variety of project examples and explanations that you can tune for your own project ideas.

You'll find yourself turning to Mastering the Raspberry Pi over and over again for both inspiration and reference. Whether you're an electronics professional, an entrepreneurial maker, or just looking for more detailed information on the Raspberry Pi, this is exactly the book for you.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Chapter 1: Why This Book?
    1. Who Needs This Book?
    2. This Book Is Primarily About
    3. Learning Approach
    4. Organization of This Book
    5. Software in This Book
    6. Final Words
  11. Chapter 2: The Raspberry Pi
    1. Models
    2. Hardware in Common
    3. Which Model?
  12. Chapter 3: Preparation
    1. Static IP Address
    2. Using SSH
    3. VNC
      1. Display Number
      2. Geometry
      3. Depth
      4. Pixel Format
      5. Password Setup
      6. Server Startup
      7. VNC Viewers
      8. Stopping VNC Server
    4. Prototype Station
    5. Adafruit Pi Cobbler
    6. Gertboard
    7. Bare Metal
  13. Chapter 4: Power
    1. Calculating Power
    2. Current Requirement
    3. Peripheral Power
    4. Model B Input Power
    5. Model A Input Power
    6. 3.3 Volt Power
    7. Powered USB Hubs
    8. Power Adapters
      1. An Unsuitable Supply
      2. E-book Adapters
      3. Best Power Source
      4. Voltage Test
    9. Battery Power
      1. Requirements
      2. Headroom
      3. LM7805 Regulation
      4. DC-DC Buck Converter
    10. Signs of Insufficient Power
    11. No Power
  14. Chapter 5: Header Strips, LEDs, and Reset
    1. Status LEDs
      1. OK or ACT LED
      2. PWR LED
      3. FDX LED
      4. LNK LED
      5. 10M or 10/100 LED
    2. Header P1
      1. Safe Mode
      2. Logic Levels
      3. GPIO Configuration at Reset
      4. 1-Wire Driver
    3. Header P5
    4. Reset
  15. Chapter 6: SDRAM
    1. /proc/meminfo
      1. MemTotal
      2. MemFree
      3. Buffers
      4. Cached
      5. SwapCached
      6. Active
      7. Inactive
      8. Active(anon)
      9. Inactive(anon)
      10. Active(file)
      11. Inactive(file)
      12. Unevictable
      13. Mlocked
      14. SwapTotal
      15. SwapFree
      16. Dirty
      17. Writeback
      18. AnonPages
      19. Mapped
      20. Shmem
      21. Slab
      22. SReclaimable
      23. SUnreclaim
      24. KernelStack
      25. PageTables
      26. NFS_Unstable
      27. Bounce
      28. WritebackTmp
      29. CommitLimit
      30. Committed_AS
      31. VmallocTotal
      32. VmallocUsed
      33. VmallocChunk
    2. Physical Memory
    3. Memory Mapping
      1. Address
      2. Length
      3. Protection
      4. Flags
      5. File Descriptor
      6. Offset
      7. Return Value
      8. Volatile
    4. Virtual Memory
    5. Final Thoughts on SDRAM
  16. Chapter 7: CPU
    1. Identification
    2. Overclocking
    3. Execution
    4. Threads
      1. pthread Headers
      2. pthread Error Handling
      3. pthread_create(3)
      4. pthread_attr_t
      5. pthread_join(3)
      6. pthread_detach(3)
      7. pthread_self(3)
      8. pthread_kill(3)
    5. Mutexes
      1. pthread_mutex_create(3)
      2. pthread_mutex_destroy(3)
      3. pthread_mutex_lock(3)
      4. pthread_mutex_unlock(3)
    6. Condition Variables
      1. pthread_cond_init(3)
      2. pthread_cond_destroy(3)
      3. pthread_cond_wait(3)
      4. pthread_cond_signal(3)
      5. pthread_cond_broadcast(3)
  17. Chapter 8: USB
    1. Power
    2. Powered Hubs
    3. USB API Support
      1. libusb
      2. Include Files
  18. Chapter 9: Ethernet
    1. Wired Ethernet
      1. /etc/network/interfaces
      2. Changing to Static IP
      3. Test Static IP Address
      4. USB Adapters
      5. /etc/hosts File
    2. Wireless Ethernet
      1. Configuration
  19. Chapter 10: SD Card Storage
    1. SD Card Media
    2. SD Card Interface
    3. SD Card Basics
    4. Raspbian Block Size
      1. Disk Cache
    5. Capacities and Performance
    6. Transfer Modes
      1. SPI Bus Mode
      2. 1-bit SD Mode
      3. 4-bit SD Mode
    7. Wear Leveling
  20. Chapter 11: UART
    1. RS-232 Converter
      1. DTE or DCE
    2. RS-232
      1. Start Bit
      2. Data Bits
      3. Parity Bit
      4. Stop Bit(s)
      5. Baud Rate
      6. Break
      7. Flow Control
    3. Raspberry Pi UARTs
    4. ARM PL011 UART
      1. RTS/CTS Access
      2. PL011 UART Features
    5. Exclusive Serial Line Use
      1. Procedure
      2. Verification
    6. Serial API
      1. Header Files
      2. open(2)
      3. struct termios
      4. tcgetattr(3)
      5. tcsetattr(3)
      6. tcsendbreak(3)
      7. tcdrain(3)
      8. tcflush(3)
      9. tcflow(3)
      10. cfmakeraw(3)
      11. cfgetispeed(3)
      12. cfgetospeed(3)
      13. cfsetispeed(3)
      14. cfsetospeed(3)
      15. cfsetspeed(3)
      16. read(2)
      17. write(2)
      18. readv(2) and writev(2)
      19. Error EINTR
  21. Chapter 12: GPIO
    1. Pins and Designations
    2. Configuration After Reset
    3. Pull-up Resistors
      1. Configuring Pull-up Resistors
      2. Testing Pull-up State
    4. Logic Levels
    5. Drive Strength
      1. Input Pins
      2. Output Pins
      3. Driving Bi-color LEDs
      4. Testing Drive Strength
    6. GPIO Current Budget
    7. Configuration
      1. Alternate Function Select
      2. Output Pins
      3. Input Pins
      4. Alternate Function
    8. Sysfs GPIO Access
      1. export
      2. unexport
      3. gpioX
      4. Chip Level
    9. GPIO Tester
    10. GPIO Input Test
    11. Floating Potentials
    12. Reading Events
      1. Test Run
    13. Direct Register Access
      1. gpio_init( )
      2. gpio_config( )
      3. gpio_write( )
      4. gpio_read( )
      5. gpio_io.c
    14. GPIO Transistor Driver
      1. Driver Design
      2. Substitution
      3. Inductive Loads
      4. Driver Summary
    15. Utility gpio
      1. Displaying GPIO Settings
      2. Reading GPIO
      3. Writing GPIO
      4. Modify Drive Levels
  22. Chapter 13: 1-Wire Driver
    1. 1-Wire Line and Power
    2. Line Driving
    3. Master and Slave
    4. Protocol
      1. Reset
      2. Data I/O
    5. Slave Support
    6. Reading Temperature
      1. Bus Master
      2. Slave Devices
      3. Reading the Temperature
    7. 1-Wire GPIO Pin
  23. Chapter 14: I2C Bus
    1. I2C Overview
    2. SDA and SCL
    3. Multimaster and Arbitration
    4. Bus Signaling
    5. Data Bits
    6. Message Formats
    7. Which I2C Bus?
    8. I2C Bus Speed
    9. Tools
    10. I2C API
      1. Kernel Module Support
      2. Header Files
      3. open(2)
      4. ioctl(2,I2C_FUNC)
      5. ioctl(2,I2C_RDWR)
  24. Chapter 15: SPI Bus
    1. SPI Basics
    2. SPI Mode
    3. Signaling
    4. Slave Selection
    5. Driver Support
    6. SPI API
      1. Header Files
      2. Open Device
      3. SPI Mode Macros
      4. Bits per Word
      5. Clock Rate
      6. Data I/O
      7. Close
      8. Write
      9. Read
    7. SPI Testing
  25. Chapter 16: Boot
    1. Booting ARM Linux
    2. Boot Sequence
    3. Boot Files
    4. config.txt
      1. Composite Video Settings
      2. High-Definition Video
      3. Overscan Video
      4. Frame Buffer Settings
      5. General Video Options
      6. Licensed Codecs
      7. Testing
      8. Memory
      9. Boot Options
      10. Overclocking
      11. Warranty and Overclocking
      12. Voltage Settings
    5. cmdline.txt
      1. Serial console=
      2. Virtual console=
      3. kgdboc=
      4. root=
      5. rootfstype=
      6. elevator=
      7. rootwait=
      8. nfsroot=
      9. ip=
    6. Emergency Kernel
  26. Chapter 17: Initialization
    1. Run Levels
    2. /etc/inittab
      1. inittab Action initdefault
      2. General Startup Sequence
      3. inittab Action wait
      4. inittab Action once
      5. inittab Action respawn
    3. Changing Run Levels
      1. telinit
      2. Change of Run Level
      3. Single-User Mode
      4. Halt and Reboot
    4. Creating a New Service
  27. Chapter 18: vcgencmd
    1. vcgencmd Commands
    2. Option measure_clock
    3. Option measure_volts
    4. Option measure_temp
    5. Option codec_enabled
    6. Option version
    7. Option get_lcd_info
    8. Option get_config
  28. Chapter 19: Linux Console
    1. Available Consoles
    2. Serial Console
  29. Chapter 20: Cross-Compiling
    1. Terminology
    2. Operating System
    3. Host, Guest, Build, and Target
      1. Platform Limitations
      2. Without VirtualBox (Native)
      3. Using VirtualBox (Ubuntu/Linux)
    4. Planning Your Cross-Development Environment
    5. Building the Cross-Compiler
      1. Download crosstool-NG
      2. Staging Directory
      3. Unpack the Tarball
      4. Create /opt/x-tools
      5. Install Package Dependencies
      6. Configure crosstools-NG
    6. make crosstool-ng
    7. make install
    8. PATH
    9. Cross-Compiler Configuration
      1. Paths and Misc Options
      2. Target Options
      3. Operating System
      4. Binary Utilities
      5. C Compiler
      6. Save Configuration
    10. Build Cross-Compiler
      1. Troubleshooting
  30. Chapter 21: Cross-Compiling the Kernel
    1. Image Tools
    2. Download Kernel
    3. Edit Makefile
    4. make mrproper
    5. Kernel Config
    6. make menuconfig
    7. make
    8. Prepare Kernel Image
    9. Install Kernel Image
      1. Boot Failure
    10. Modules
    11. Firmware
    12. VirtualBox Mount of SD Card
  31. Chapter 22: DHT11 Sensor
    1. Characteristics
    2. Circuit
    3. Protocol
      1. Overall Protocol
      2. Data Bits
      3. Data Format
      4. Software
      5. Chosen Approach
    4. Example Run
    5. Source Code
  32. Chapter 23: MCP23017 GPIO Extender
    1. DC Characteristics
      1. GPIO Output Current
      2. GPIO Inputs
      3. Standby Current
      4. Input Logic Levels
      5. Output Logic Levels
    2. Reset Timing
    3. Circuit
    4. I2C Bus
    5. Wiring and Testing
    6. Software Configuration
      1. General Configuration
    7. Main Program
    8. Module i2c_funcs.c
    9. Module sysgpio.c
    10. Example Run
    11. Response Times
  33. Chapter 24: Nunchuk-Mouse
    1. Project Overview
    2. Nunchuk Features
    3. Connector Pinout
    4. Testing the Connection
    5. Nunchuk I2C Protocol
      1. Encryption
      2. Read Sensor Data
    6. Linux uinput Interface
      1. Working with Header Files
      2. Opening the Device Node
      3. Configuring Events
      4. Creating the Node
      5. Posting EV_KEY Events
      6. Posting EV_REL Events
      7. Posting EV_SYN Events
      8. Closing uinput
    7. X-Window
    8. Input Utilities
    9. Testing the Nunchuk
      1. Testing ./nunchuk
      2. Utility lsinputs
      3. Utility input-events
    10. The Program
  34. Chapter 25: Real-Time Clock
    1. DS1307 Overview
      1. Pins X1 and X2
      2. Pin SQW/OUT
    2. Power
    3. 3-Volt Compatibility
      1. Logic Levels
    4. Tiny RTC Modifications
      1. Checking for Pull-up Resistors
    5. DS1307 Bus Speed
    6. RTC and RAM Address Map
    7. Reading Date and Time
    8. I2C Communication
    9. Wiring
    10. Running the Examples
    11. The Ultimate Test
    12. The Startup Script
  35. Chapter 26: VS1838B IR Receiver
    1. Operating Parameters
      1. Pinout
    2. VS1838B Circuit
      1. The IR Receiver
    3. Software
      1. Signal Components
      2. Code Organization
      3. Command-Line Options
  36. Chapter 27: Stepper Motor
    1. Floppy-Disk Stepper Motor
      1. Your Junk-Box Motor?
    2. Driver Circuit
      1. Darlington Pair
    3. Driving the Driver
      1. Input Levels
      2. Power-on Reset/Boot
    4. Modes of Operation
      1. Wave Drive (Mode 0)
      2. Full-Step Drive (Mode 1)
      3. Half-Step Drive (Mode 2)
    5. Software
      1. Testing
  37. Chapter 28: The H-Bridge Driver
    1. The L298 Driver
      1. Sensing Resistor
      2. Enable A and B
      3. Inputs In1 and In2
      4. Protection Diodes
    2. L298 PCB
    3. Driving from GPIO
      1. The DMM Check
    4. Bipolar Stepper Modes
      1. One-Phase-On Mode
      2. Two-Phase-On Mode
      3. Half-Step Mode
    5. Choosing Driving GPIOs
    6. Project Schematic
      1. Junk-Box Motors
    7. Program Operation
      1. Program Internals
  38. Chapter 29: Remote-Control Panel
    1. Switched Inputs
    2. The CD4013
    3. Testing the Flip-Flop
    4. The LED
    5. ØMQ
      1. Performing Installation
      2. Compiling and Linking
    6. Sensing Station Design
    7. Sensing Station Program
    8. Console Program
      1. Console Commands
    9. Sensor Source Code
    10. Console Source Code
  39. Chapter 30: Pulse-Width Modulation
    1. Introduction to PWM
    2. PWM Parameters
    3. PWM Hardware Peripheral
    4. PWM Software
    5. Meter Circuit
    6. pwm Program
      1. Hardware PWM Set Command
      2. Hardware Based CPU Percent-Busy Display
      3. Software PWM Program
      4. How Many PWMs?
      5. Running the Software PWM Command
      6. Software Based CPU Percent-Busy Display
  40. Appendix A: Glossary
  41. Appendix B: Power Standards
  42. Appendix C: Electronics Reference
    1. Ohm’s Law
    2. Power
    3. Units
  43. Appendix D: Raspbian apt Commands
    1. List Available Packages
    2. List Installed Packages
    3. List Files for Package
    4. Perform Package Search
    5. Install a Package
    6. Remove a Package
    7. Install Updates
    8. Upgrade
    9. Obtain Kernel Sources
  44. Appendix E: ARM Compile Options
  45. Appendix F: Mac OS X Tips
  46. Bibliography
  47. Index