Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By : Nixon
Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By: Nixon

Overview of this book

The Raspberry Pi is one of the smallest and most affordable single board computers that has taken over the world of hobby electronics and programming, and the Python programming language makes this the perfect platform to start coding with. The book will start with a brief introduction to Raspberry Pi and Python. We will direct you to the official documentation that helps you set up your Raspberry Pi with the necessary equipment such as the monitor, keyboard, mouse, power supply, and so on. It will then dive right into the basics of Python programming. Later, it will focus on other Python tasks, for instance, interfacing with hardware, GUI programming, and more. Once you get well versed with the basic programming, the book will then teach you to develop Python/Raspberry Pi applications. By the end of this book, you will be able to develop Raspberry Pi applications with Python and will have good understanding of Python programming for Raspberry Pi.
Table of Contents (13 chapters)
12
Index

The GPIO library


The RPi.GPIO module provides a simple interface to the basic digital logic functionality of the GPIO header as well as software synthesized PWM, which allows the Pi to output an analog like signal.

Before starting to use the GPIO pins, it is important to know what each pin can do and what it is connected to. The following diagram shows the pinouts for each version and revision of the Raspberry Pi:

Note

Note that the Raspberry Pi 2 has the same pinout as the Raspberry Pi B+.

Typically, when using the GPIO pins, you should avoid using the GPIOs 14 and 15 as they are by default used for a serial terminal which provides access to the shell running on the Pi. GPIOs 0, 1, 2, and 3 should also be avoided as they are used for the I2C interface, which requires a pull-up resistor to be used on the pins that is fitted by default and can cause issues with some devices.

Single LED output

To demonstrate the basic use of the GPIO library, we will create a simple script that will flash an LED...