Book Image

Raspberry Pi Robotics Projects - Second Edition

By : Dr. Richard Grimmett
Book Image

Raspberry Pi Robotics Projects - Second Edition

By: Dr. Richard Grimmett

Overview of this book

<p>This book starts with the essentials of turning on the basic hardware. It provides the capability to interpret your commands and have your robot initiate actions. In this second edition, you will learn more specifics on how to use the Raspberry Pi’s GPIO pins to communicate with and control a wide range of additional hardware.</p> <p>Teaching you to use the Raspberry Pi from scratch, this book will discuss a wide range of capabilities that can be achieved with it. These capabilities include voice recognition, human-like speech simulation, computer vision, motor control, GPS location, and wireless control. You will then learn how to combine these capabilities to create your own robotics projects. By the end of the book, you will be able to employ the Raspberry Pi to build some intricate and enthralling robotics projects with ease.</p>
Table of Contents (18 chapters)
Raspberry Pi Robotics Projects Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using the keyboard to control your project


Now that the keyboard is connected, let's figure out how to accept commands on Raspberry Pi. Now that you can enter commands wirelessly, the next step is to create a program that can take these commands and then have your project execute them. There are a couple of options here; you'll see examples of both. The first is to simply include the command interface in your program. Let's take an example of the dcmotor.py program you wrote to move your wheeled robot. If you want, you can copy that program by using the cp dcmotor.py remote.py command.

In order to add user control, you need two new programming constructs, the while loop and the if statement. Let's add them to the program, and then, we will learn what they do. The following is a listing of the area of code you are going to change:

You will edit your program by making some changes. Add the code in the preceding screenshot just below the ser = serial.Serial('/dev/ttyUBS0', 19200, timeout = 1...