You are previewing Raspberry Pi : Making Amazing Projects Right from Scratch!.
O'Reilly logo
Raspberry Pi : Making Amazing Projects Right from Scratch!

Book Description

Explore the powers of Raspberry Pi and build your very own projects right out of the box

About This Book

  • From robotics to gaming, this Learning Path will unlock your creativity!

  • Build your own impressive IoT projects to transform your home

  • Featuring some of Packt’s very best Raspberry Pi content, this Learning Path doesn’t just get you to your destination – it opens up a whole horizon of possibilities!

  • Who This Book Is For

    Want new ideas for your next Raspberry Pi project? Got one lying around gathering dust? This Learning Path gets you straight into the creative dirty work of programming and playing with your pi. Whether your new to Raspberry Pi, or an experienced maker, we think this Learning Path will inspire you and get your creative juices flowing!

    What You Will Learn

  • Discover an aweome range of Raspberry Pi projects

  • Bridge the gap between software and hardware through your Pi and find out how to make an operating system interact with cameras and other hardware

  • Find out how to use your Raspberry Pi for gaming

  • Secure your home with this tiny computer!

  • Make science fiction a reality – build a walking robot

  • In Detail

    Looking for inspiration for your next Raspberry Pi project? Not sure where to begin? This Learning Path is the perfect place to begin, providing you with an accessible yet comprehensive journey through Raspberry Pi. Following three modules, you’ll soon be confident and prepared to get creative with your microcomputer.

    Raspberry Pi by Example is the first module in this Learning Path – and it does exactly what it says. It doesn’t just teach, it shows you how to go and build some awesome Raspberry Pi projects immediately. Build and play your own games with the Pi, build a complete Internet of Things home automation system that controls your house through Twitter… let your imagination run wild!

    In the next module we’ll look in more depth at building a home security system. You’ll be using some of the skills you devoped through the first module, but apply them to something more intricate and impressive. Using a Linux based operating system as the foundations, you’ll gradually build up an entire security infrastructure adding cameras, remote controls, and even intrusion alerts!

    In the final module, we’ll take you into the world of Raspberry Pi robotics. By the end of it, you’ll have built a biped robot that can interact with its environment!

    This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products:

  • Raspberry Pi By Example by Ashwin Pajankar and Arush Kakkar

  • Building a Home Security System with Raspberry Pi by Matthew Pole

  • Raspberry Pi Robotics Essentials by Richard Grimmett

  • Style and approach

    It’s not every day you build a home automation system. It’s not every day you build a walking robot. But with this Learning Path you’ll do just that. So get started and let this tiny computer expand your imagination.

    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 If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Raspberry Pi : Making Amazing Projects Right from Scratch!
      1. Table of Contents
      2. Raspberry Pi : Making Amazing Projects Right from Scratch!
      3. Raspberry Pi : Making Amazing Projects Right from Scratch!
      4. Credits
      5. Preface
        1. What this learning path covers
        2. What you need for this learning path
        3. Who this learning path is for
        4. Reader feedback
        5. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      6. 1. Module 1
        1. 1. Introduction to Raspberry Pi and Python
          1. Single-board computers
          2. Raspberry Pi
            1. Raspberry Pi models
          3. Operating systems
            1. Raspbian
          4. Setting up the Raspberry Pi
            1. Preparing MicroSD card manually
            2. Booting up our Pi for the first time
            3. Shutting down and rebooting Pi safely
            4. Updating the Pi
          5. Getting started with Python
            1. Turtle programming with Python
          6. Summary
        2. 2. Minecraft Pi
          1. Introduction to Minecraft Pi
          2. Playing Minecraft Pi
            1. Movement control in Minecraft Pi
            2. Action control in Minecraft Pi
            3. Other controls in Minecraft Pi
          3. Python programming for Minecraft Pi
          4. Summary
        3. 3. Building Games with PyGame
          1. Introducing PyGame
          2. Installing PyGame
          3. Drawing a binary fractal tree
          4. Building a snake game
          5. Summary
        4. 4. Working with a Webcam and Pi Camera
          1. Working with webcams
            1. Crontab
            2. Creating a timelapse sequence using fswebcam
            3. Webcam video recording and playback
          2. Working with the Pi Camera and NoIR Camera modules
            1. Using raspistill and raspivid
            2. Using picamera in Python with the Pi Camera module
            3. The Pi camera versus the webcam
          3. Summary
        5. 5. Introduction to GPIO Programming
          1. Introducing GPIO pins
          2. Building an LED Blinker
            1. Connecting a button
          3. Installing PiGlow
          4. Using PiGlow
          5. Building a binary clock
          6. Summary
        6. 6. Creating Animated Movies with Raspberry Pi
          1. Introducing stop-motion animation
          2. Setting up the prerequisites
            1. Setting up and testing the camera
            2. Adding the hardware button
          3. Rendering the video
          4. Summary
        7. 7. Introduction to Computer Vision
          1. Introducing Computer Vision
          2. Introducing OpenCV
          3. Setting up Pi for Computer Vision
            1. Testing the OpenCV installation with Python
          4. Introducing NumPy
            1. Array creation
            2. Basic operations on arrays
            3. Linear algebra
          5. Working with images
            1. Using matplotlib
          6. Working with Webcam using OpenCV
            1. Saving a video using OpenCV
            2. Pi Camera and OpenCV
          7. Retrieving image properties
          8. Arithmetic operations on images
          9. Splitting and merging image color channels
            1. Negating an image
          10. Logical operations on images
          11. Colorspaces and conversions
          12. Tracking in real time based on color
          13. Summary
        8. 8. Creating Your Own Motion Detection and Tracking System
          1. Thresholding images
            1. Otsu's method
          2. Noise
            1. Kernels for noise removal
            2. 2D convolution filtering
            3. Low pass filtering
          3. Morphological transformations on images
          4. Motion detection and tracking
          5. Summary
        9. 9. Grove Sensors and the Raspberry Pi
          1. Introducing the GrovePi
          2. Setting up the GrovePi
          3. Displaying the weather
          4. Intruder detection system
          5. Summary
        10. 10. Internet of Things with the Raspberry Pi
          1. Introducing the Internet of Things
          2. Installing the Twitter API for Python
            1. Using Tweepy
          3. Setting up a SQLite database in Python
          4. Building a tweeting weather station
            1. Adding speech capabilities to our weather station
          5. Summary
        11. 11. Build Your Own Supercomputer with Raspberry Pi
          1. Introducing a Pi-based supercomputer
          2. Installing and configuring MPICH2 and MPI4PY
            1. Installing the MPICH library
            2. Installing MPI4PY
          3. Setting up the Raspberry Pi cluster
          4. Setting up SSH access from the host to the client
          5. Running code in parallel
          6. Performance benchmarking of the cluster
          7. Introducing N-Body simulations
          8. Installing and running GalaxSee
          9. Summary
        12. 12. Advanced Networking with Raspberry Pi
          1. Introducing DHCP
          2. A few networking concepts
          3. Configuring a Raspberry Pi to act as a DHCP server
          4. Introducing Domain Naming System (DNS)
          5. Setting up a DNS server on the Pi
          6. Configuring the setup for a web server
          7. Automating node discovery in a network
          8. Summary
        13. 13. Setting Up a Web Server on the Raspberry Pi
          1. Introducing and installing Apache on Raspbian
          2. Installing PHP and MySQL
          3. Installing WordPress
            1. Configuring the WordPress installation
          4. Summary
        14. 14. Network Programming in Python with the Pi
          1. The basics of sockets
          2. The difference between TCP and UDP
            1. The architecture and programming of UDP sockets
              1. Sending and receiving data with UDP
              2. UDP servers and NCAT
              3. An echo server using Python UDP sockets
              4. A UDP client
            2. The architecture of TCP sockets
              1. Creating a TCP socket
              2. Connecting to a server with a TCP socket
              3. Receiving data from the server
            3. Programming socket servers
              1. Binding a socket
              2. Listening for incoming connections
              3. Handling multiple connections
          3. Looking back
          4. A Telnet client in Python
          5. A chat program
            1. The chat server
            2. The chat client
          6. References
          7. Exercise
          8. Summary
        15. 15. Newer Raspberry Pi Models
          1. The Raspberry Pi Zero
          2. The Raspberry Pi 3
      7. 2. Module 2
        1. 1. Setting Up Your Raspberry Pi
          1. Which flavor of Pi?
            1. Raspberry Pi Model A
            2. Raspberry Pi Model B
            3. Raspberry Pi Model B+ and Model 2
            4. Model comparison table
            5. So which one?
          2. Preparing the SD card
            1. Downloading the Raspbian image
            2. Using Microsoft Windows
            3. Using Linux
            4. Booting your Pi
            5. Expanding the file system
              1. Using the raspi-config utility
          3. Setting up your Pi
            1. Getting up to date
            2. Getting the right time
              1. fake-hwclock
              2. ntp
            3. Talking of security–
              1. What is this sudo thing anyway?
            4. Connecting via Wi-Fi
          4. Summary
        2. 2. Connecting Things to Your Pi with GPIO
          1. Prerequisites
          2. Say hello to the GPIO
            1. Digital I/O pins
            2. The I2C bus
            3. The SPI bus
            4. The UART serial bus
            5. USB ports
            6. Power connections
          3. Getting acquainted with the GPIO
            1. Let there be light
              1. Getting flashy–
            2. Adding a switch
              1. Pulling yourself together
              2. The detection script
          4. The most elaborate light switch in the world
            1. The illuminating script
          5. Summary
        3. 3. Extending Your Pi to Connect More Things
          1. Prerequisites
          2. The I2C bus
            1. Just 2 wires
            2. What's your address?
            3. There is a parallel universe
              1. Serial-to-parallel conversion
          3. Give me power
          4. Building an I2C expander
            1. The I2C port expander circuit
              1. Let's walk through the circuit
            2. Building your expansion board
          5. Using ready-made expansion boards
            1. Hobbytronics MCP23017 expander port kit
            2. PiFace Digital I/O expansion board
            3. Gertboard
          6. Summary
        4. 4. Adding a Magnetic Contact Sensor
          1. Prerequisites
          2. The working of magnetic contact sensors
          3. Setting up the I2C port expander
            1. Enabling the I2C Bus
            2. Installing the I2C tools package
            3. Finding our devices
            4. Setting up the port expander
          4. Connecting our magnetic contact sensor
          5. Monitoring the sensor
          6. Anti-tamper circuits
          7. Getting into the zone
          8. Summary
        5. 5. Adding a Passive Infrared Motion Sensor
          1. Prerequisites
          2. Passive infrared sensors explained
            1. Setting up your PIR sensor
          3. Give me power (again)
          4. Connecting our PIR motion sensor
          5. 12V alarm zone circuits
            1. Alarm circuit protection
            2. How it works
          6. Wireless PIR motion sensors
            1. 433-MHz wireless alarm systems
            2. Connecting a 433-MHz receiver
              1. The alternative approach (because we have no choice)
            3. The receiver wiring diagram
          7. Logging detection data
          8. Summary
        6. 6. Adding Cameras to Our Security System
          1. Prerequisites
          2. The Raspberry Pi camera module
            1. Connecting the camera module
            2. Setting up the camera module
              1. Testing the camera module
          3. Be a video star
            1. Caught on camera
          4. You have new mail
            1. Setting up the e-mail sender client
            2. Sending attachments
            3. Where was that taken?
          5. Night vision
            1. An illuminating experience
            2. The Elaborate light switch re-visited
            3. Is that a badger?
          6. Using USB cameras
            1. Installing the webcam
            2. Taking a snap
              1. Snap snap snap
          7. The multicamera setup
            1. The Slave driver
          8. Summary
        7. 7. Building a Web-Based Control Panel
          1. Installing the web server
            1. Testing the PHP5 installation
          2. Being in control
            1. Arming yourself
          3. The master configuration file
          4. Creating the web page
            1. The control panel HTML template
            2. Giving it some style
            3. Making it dynamic
              1. Getting a bit of help first
              2. The main PHP code
              3. I'm someone else
          5. Remote access to our control panel
            1. Setting up a dynamic DNS account
              1. The Raspberry Pi dynamic DNS client
            2. Setting up a static IP on your Raspberry Pi
            3. Port-forwarding
          6. Summary
        8. 8. A Miscellany of Things
          1. Arming and disarming the system
          2. Driving inductive loads
          3. Beyond intrusion
            1. A simple water detector
              1. How it works
            2. A simple temperature sensor
              1. How it works
            3. A carbon monoxide detector
          4. Remote administration for our Raspberry Pi
            1. Getting Webmin
              1. Updating the repository sources
              2. Importing the signing key
              3. Accessing Webmin locally
              4. Remotely accessing Webmin
          5. Summary
        9. 9. Putting It All Together
          1. Alarm system diagram
            1. Overview of the system elements
              1. A +12V power supply
              2. A +3.3V power supply
              3. The opto-isolator input module
              4. The port expander
              5. An arm/disarm switch
              6. Alarm outputs
          2. Designing the control scripts
          3. Building the control script
            1. Exploring the script code
              1. Declarations
              2. Updating config settings
              3. Setting up the GPIO
              4. Setting up the I2C port expander
              5. Decoding the zone inputs status
              6. Initialization
              7. The system monitoring loop
              8. Arming the system
              9. Monitoring the zones
              10. Entry delay
              11. Sounding the main alarm
              12. Disarming and resetting the system
              13. We're done (almost)–
          4. Automatically starting the system
          5. Preserving the SD card
            1. Creating a RAM-based file system
          6. Conclusion
            1. Tips for building systems
          7. Summary
      8. 3. Module 3
        1. 1. Configuring and Programming Raspberry Pi
          1. Configuring Raspberry Pi – the brain of your robot
          2. Installing the operating system
          3. Adding a remote graphical user interface
            1. Establishing wireless access
          4. Programming on Raspberry Pi
            1. Creating and running Python programs on the Raspberry Pi
            2. An introduction to the C/C++ programming language
          5. Summary
        2. 2. Building the Biped
          1. Building robots that can walk
          2. How servo motors work
          3. Building the biped platform
          4. Using a servo controller to control the servos
          5. Communicating with the servo controller with a PC
          6. Connecting the servo controller to the Raspberry Pi
          7. Creating a program to control your biped
          8. Summary
        3. 3. Motion for the Biped
          1. A basic stable pose
          2. A basic walking motion
          3. A basic turn for the robot
          4. Summary
        4. 4. Avoiding Obstacles Using Sensors
          1. Connecting Raspberry Pi to an infrared sensor
          2. Connecting Raspberry Pi to a USB sonar sensor
          3. Summary
        5. 5. Path Planning and Your Biped
          1. Connecting a digital compass to the Raspberry Pi
          2. Accessing the compass programmatically
          3. Dynamic path planning for your robot
            1. Basic path planning
            2. Avoiding obstacles
          4. Summary
        6. 6. Adding Vision to Your Biped
          1. Installing a camera on your biped robot
            1. Installing a USB camera on Raspberry Pi
            2. Installing RaspiCam on Raspberry Pi
          2. Downloading and installing OpenCV – a fully featured vision library
          3. Edge Detection and OpenCv
          4. Color and motion finding
          5. Summary
        7. 7. Accessing Your Biped Remotely
          1. Adding a wireless dongle and creating an access point
          2. Adding a joystick remote control
          3. Adding the capability to see remotely
          4. Summary
      9. A. Bibliography
      10. Index