You want to know how to use a RaspiRobot board.
Figure 8-14 shows the RaspiRobot board (version 1). The board has a dual-motor controller that can be used for two DC motors or a single stepper motor. It is also capable of supplying 5V power to the Raspberry Pi using its built-in voltage regulator. The board also has two switch inputs and two low-power outputs, and provides easy connections to the I2C and serial interfaces of the Raspberrry Pi.
After assembling the RaspiRobot board using the instructions supplied, you will need to install the libraries it requires by entering the following commands into a Terminal session on your Raspberry Pi:
$ sudo apt-get install python-rpi.gpio $ sudo apt-get install python-serial |
To install the accompanying library, issue the following commands in a Terminal window:
$ wget https://github.com/simonmonk/raspirobotboard/archive/master.zip $ unzip master.zip $ cd raspirobotboard-master $ sudo python setup.py install |
Discussion
Fit your RaspiRobot board onto your Raspberry Pi and then power up the Raspberry Pi. You can try out a few commands with the RaspiRobot board using just the Python console without attaching external power or motors to the RaspiRobot board. Since the RaspiRobot board library uses the GPIO port, you will need to start Python as a superuser using this command:
$ sudo python |
When you first power up, you should find that both LEDs on the RaspiRobot board will be lit. Now enter the following commands, and both LEDs should turn off as the library is initialized:
>>> from raspirobotboard import * >>> rr = RaspiRobot() |
Try turning one of the LEDs on and off using these commands:
>>> rr.set_led1(1) >>> rr.set_led1(0) |
The RaspiRobot board has two pairs of pins, each designed to be connected to a switch. These are labeled SW1 and SW2 on the board. You can test whether SW1 is closed using the command:
>>> print(rr.sw1_closed()) False |
Shorting the two pins of SW1 together with a screwdriver and issuing the command again will return True.
Other commands are available to set the two open collector outputs (set_oc1 and set_oc2) as well as motor control commands (forward, reverse, left, right, and stop). See http://www.raspirobot.com for the full command reference.
Of course, you can use the RaspiRobot Board interface with just the RPi.GPIO library. The GPIO pins used by the RaspiRobot Board are listed in Table 8-1.
See Also
You can find out more about the RaspiRobot board and other projects that use it at the RaspiRobot website.
For a recipe that uses this board to make a roving robot, see Recipe 10.8.
To use the RaspiRobot board to control a bipolar stepper motor, see Recipe 10.7.
Table 8-1. RaspiRobot board GPIO pin usage | |
Motor 1A | 17 |
Motor 1B | 4 |
Motor 2A | 10 |
Motor 2B | 25 |
SW1 | 11 |
SW2 | 9 |
OC1 | 22 |
OC2 | 27 |