Book Image

Getting Started with Raspberry Pi Zero

By : Richard Grimmett
Book Image

Getting Started with Raspberry Pi Zero

By: Richard Grimmett

Overview of this book

Raspberry Pi Zero is half the size of Raspberry Pi A, only with twice the utility. At just three centimeters wide, it packs in every utility required for full-fledged computing tasks. This practical tutorial will help you quickly get up and running with Raspberry Pi Zero to control hardware and software and write simple programs and games. You will learn to build creative programs and exciting games with little or no programming experience. We cover all the features of Raspberry Pi Zero as you discover how to configure software and hardware, and control external devices. You will find out how to navigate your way in Raspbian, write simple Python scripts, and create simple DIY programs.
Table of Contents (16 chapters)
Getting Started with Raspberry Pi Zero
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Creating a program on Raspberry Pi Zero so that you can control your hand


You now know that you can talk to your servo motor controller and move your servos. In this section, you'll create a Python program that will let you talk to your servos to move them to specific angles.

Let's start with a simple program that will position your hand so that the servos are set to one end of the range (which should open the hand) and then go the other end of the range (which should close your hand). This program starts with the code you wrote in Chapter 5, Building a Robot That Can Walk. Here is the basic code to control the servos:

Here is an explanation of the code:

  • #! /usr/bin/python: This first line allows you to make this Python file execute from the command line.

  • import serial: This line imports the serial library. You need the serial library to talk to your unit via USB.

  • def setAngle(ser, channel, angle):: This function converts your desired setting of servo and angle into the serial command that...