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 the DC motors


To control the DC motors from the Raspberry Pi, you'll first want to install the libraries. Here are the steps to do so:

  1. cd ~: Go to the home directory.

  2. git clone https://github.com/simonmonk/raspirobotboard3.git : This command will get the library.

  3. cd raspirobotboard3/python: Go to the directory that has the installed files.

  4. sudo python setup.py install: Install the Python library.

Once these are installed, you can write this simple program to make the wheels go forward:

#!/usr/bin/python 
from rrb3 import * 
import time 
rr = RRB3(11, 11) 
rr.set_motors(0.5, 0, 0.5, 0) 
time.sleep(1) 
rr.set_motors(0, 0, 0, 0) 

This should make the wheels go forward at half the speed. You can add a bit of code to check full speed and forward and backward:

#!/usr/bin/python 
from rrb3 import * 
import time 
rr = RRB3(11, 11) 
rr.set_motors(1, 0, 1, 0) 
time.sleep(1) 
rr.set_motors(0.5, 0, 0.5, 0) 
time.sleep(1)...