Page 110 - Programming the Raspberry Pi Getting Started with Python
P. 110

Figure 11-4    The RaspiRobotBoard
             Note  that  these  instructions  are  for  Version  1  of  the  board. The  position  of  the  connectors  may
          change  in  later  versions. See the book's website (www.raspberrypibook.com) for more information.
          All the connections we are interested in are on the right side of Figure 11-4. At the top is the power
          socket, and beneath that are the screw terminals for the left and right motors.

          Step 3: Install the Software on the Raspberry Pi
          To control the robot, we are going to write a program in Python that detects key presses and use them
          to  control  the  power  to  the  robot’s  motors  on  the  robot. To  do  this,  we  will  use  pygame,  which
          provides a useful way of finding out whether or not keys are pressed.
             It  will  be  much  easier  to  set  the  program  up  before  we  attach  the  Raspberry  Pi  to  the  chassis.
          Therefore,  attach  the  RaspiRobotBoard  to  the  Raspberry  Pi,  but  leave  the  motors  and  battery
          disconnected and power up the Pi from your normal USB power supply.
             The RaspiRobotBoard has its own Python library, but also relies on some other libraries that must
          be installed. First of all, it requires the RPi.GPIO library that you first met in Chapter 5 and then again
          in Chapter 10. If you have not already done so, install the RPi.GPIO  library. You will also need to
          install  the PySerial  library. See the instructions for this in the Arduino section toward the end of
          Chapter 9.
             The      RaspiRobotBoard          library     can     be     installed     from      the    following       website:
          http://code.google.com/p/raspirobotboard/downloads/list
             Installation is the same as for any other Python package. Because we are using Python 2 in this
          project, the library should be installed using the command on the following page.






             The  actual  Python  program  for  this  version  of  the  robot  is  contained  in  the  file
          11_01_rover_basic.py, which must be run as super user.  Therefore, just to try things out (still with the
          motors disconnected), run the program by changing to the “code” directory and entering the following
          in the terminal:


             A blank pygame window should appear and the two LEDs go out. We can test the program without
          the motors because the program sets the LEDs as well as controls the motors. Thus, if you press the UP
          ARROW key, both LEDs should light once more. Press the SPACEBAR to turn them off again. Then try the
   105   106   107   108   109   110   111   112   113   114   115