Book Image

Raspberry Pi Robotic Projects - Third Edition

By : Richard Grimmett, Jon Witts
Book Image

Raspberry Pi Robotic Projects - Third Edition

By: Richard Grimmett, Jon Witts

Overview of this book

This book will allow you to take full advantage of Raspberry Pi Zero and Raspberry Pi 3 by building both simple and complex robotic projects. The book takes a mission-critical approach to show you how to build amazing robots and helps you decide which board to use for which type of robot. The book puts a special emphasis on designing mobile (or movable) robots using the Raspberry Pi Zero. The projects will show inexpensive, yet powerful, ways to take full advantage. It will teach you how to program Raspberry Pi, control the movement of your robot, and add features to your robots.
Table of Contents (13 chapters)
Raspberry Pi Robotic Projects - Third Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Controlling R2D2 using the Raspberry Pi in Python


The hardware is ready; now you can access all this functionality from the Raspberry Pi. First, install the library associated with the control board, found at http://www.monkmakes.com/rrb3/. Perform the following steps:

  1. Type cd ~.

  2. Run the command git clone https://github.com/simonmonk/raspirobotboard3.git —this will retrieve the library.

  3. Then type cd raspirobotboard3/python to go to the raspirobotboard3/python directory.

  4. Type sudo python setup.py install—this will install the files.

  5. Now you'll create some Python code that will allow you to access both the DC motor to turn the top and/or light the LED. Here is that code:

#!/usr/bin/python 
import time 
import RPi.GPIO as io 
from rrb3 import * 
 
io.setmode(io.BCM) 
 
forward_pin = 27 
backward_pin = 22 
led1 = 24 
led2 = 23 
 
def forward(): 
    io.output(forward_pin, True) 
    io.output(backward_pin, False) 
 
...