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

Monitoring the physical health of the RPZ hardware


We took a look earlier on in the look at some of the measurements. In this recipe, we will dive a little bit deeper and use our new knowledge of outputs to regulate and alert on changes in the Raspberry Pi's health.

Getting ready

For this recipe, we will need the buzzer from the previous recipe, an RGB 4-lead LED, and three 330-Ohm resistors. If you don't have an RGB LED, you can alternatively make the same circuit using individual LEDs.

How to do it...

  1. Configure the following circuit:

  2. The following Python code will monitor the Raspberry Pi's health and change the values if there is a problem. Create a file named rpz_alert.py and enter the following code:

        #!/bin/env python 
        # Chapter 7 Hardware Control 
        # RPZ Health Monitoring and Alerting 
        import time 
        import os 
        import RPi.GPIO as GPIO 
        GPIO.setmode(GPIO.BCM) 
        redpin=18 
        greenpin=17 
        bluepin=27 
        buzzerpin=22 
        GPIO.setup(redpin, GPIO.OUT) 
      ...