Book Image

Raspberry Pi Zero Cookbook

Book Image

Raspberry Pi Zero Cookbook

Overview of this book

The Raspberry Pi Zero, one of the most inexpensive, fully-functional computers available, is a powerful and revolutionary product developed by the Raspberry Pi Foundation. The Raspberry Pi Zero opens up a new world for the makers out there. This book will give you expertise with the Raspberry Pi Zero, providing all the necessary recipes that will get you up and running. In this book, you will learn how to prepare your own circuits rather than buying the expensive add–ons available in the market. We start by showing you how to set up and manage the Pi Zero and then move on to configuring the hardware, running it with Linux, and programming it with Python scripts. Later, we integrate the Raspberry Pi Zero with sensors, motors, and other hardware. You will also get hands-on with interesting projects in media centers, IoT, and more.
Table of Contents (17 chapters)
Raspberry Pi Zero Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Basics of SPI and setting up an SPI module


The SPI, or Serial Peripheral Interface, is similar to the I2C bus, but has a few advantages for a few more wires. Generally, you'd choose I2C or SPI based on the peripheral you are trying to talk to and what protocol it supports. For this recipe, we will look at configuring SPI for upcoming recipes.

Getting ready

Just like setting up I2C in the previous recipe, the easiest way to get going is with raspi-config. Run with sudo, and select Interfacing Options. Select P4 to enable SPI, and reboot.

How to do it...

Once you've enabled SPI and rebooted, you should find your bus on the device list:

Working with the SPI module is a little bit more complex than I2C, but it gives you more flexibility as well as expandability to run multiple peripherals over the same bus. This will be a lot of fun later, but for now, let's look at the pins you will be using. Just like any connection to your Raspberry Pi Zero, the Power and Ground pins will be the same, but...