Where to Buy
- BUY in the USA from amazon.com.
- BUY in the USA from Adafruit.
- BUY in the USA from eduporium.com.
- BUY in the UK from Amazon.co.uk.
- BUY Worldwide from SeeedStudio.
The RasPiRobot Board V3 is an expansion board designed to turn your Raspberry Pi into a robot controller! This board comes fully assembled and includes a switched-mode power supply so you can supply your Raspberry Pi from a variety of battery packs.
The board fits right on top of your Pi’s GPIO socket and allows for bi-directional control of both motors with an H-Bridge motor driver chip. It also allows for control of both motor’s speed independently. The board can also supply the Raspberry Pi with power using a cool and efficient switch mode power supply, allowing you to run a fully-loaded Pi and the robot from 6xAA batteries (not included!)
The main features of version 3 are listed below.
- Compatible with Raspberry Pi models 3, 2, 1, Zero, A, A+, B and B+
- Extensive Open Source Python library with examples – download from Github
- Supplied fully assembled – no soldering
- Bi-directional control of two motors
- Variable (PWM) power control. This allows you to both control the speed of the motors independently and the use of lower voltage motors than the battery pack.
- Supplies the Raspberry Pi with power – run a fully loaded Pi and the Robot from 6 x AA batteries
- Rangefinder header socket directly compatible with cheap HC-SR-04 ultrasonic range finders. Just plug them in
- 5V I2C header, pin compatible with Adafruit displays
- Two buffered open collector outputs capable of 2A each
- Two LEDs
- Two switch inputs
- Screw terminals for motors and battery
- Through headers allowing access to all GPIO pins (although the RRB3 uses many of them)
Version 3 of the RaspiRobot Board (RRB3) has learnt by the feedback from version 2 and it is a great improvement.
The main change is the switch to the more efficient TB6612FNG motor driver and an update to the library that allows you to specify a battery supply voltage (9 to 12V) and a motor voltage (1V up to the battery supply voltage).
How it Works
The diagram below shows how an RRB2 board is used. The RRB2 is powered from a battery pack that needs to be between 6 and 12V DC. Although using 4 x AA batteries can in theory provide 6V, actually the battery voltage will usually quickly fall below that, so it it better to use at least 6 x AA batteries, either rechargeable or regular heavy duty batteries. A 7.2V LiPo battery pack will also work just fine.
Note that you don’t need a separate power supply for the Raspberry Pi. The RRB3 will provide enough power with ease to the Raspberry Pi. However, it is perfectly OK to power your Pi over USB even while the batteries to the RRB3 are connected.
The RRB3 provides power to the motors direct from the battery pack.
Installing the Python Libraries
On your Raspberry Pi, issue the following commands in a Terminal window:
$ cd ~ $ git clone https://github.com/simonmonk/raspirobotboard3.git $ cd raspirobotboard3/python $ sudo python setup.py install
Attach the RRB3 to your Raspberry Pi. You do not need to attach batteries, motors or anything else to the RRB3 just yet. For now you can just power it through the Pi’s normal USB power connector.
Lets run some tests from the Python Console now that everything is installed. We can experiment with the RRB3, even without any motors
Open a Python console (Python2 not 3) by typing the following into a Terminal window:
$ sudo python
Then, within the python console, type the following, one line at a time:
from rrb3 import * rr = RRB3(9, 6) rr.set_led1(1) rr.set_led1(0) rr.set_led2(1) rr.set_led2(0) rr.sw1_closed()
The last step should display the answer “False” because no switch is attached.
If you prefer, you can use True and False in place of 1 and 0 in the examples above.
Connect a Battery and Motors
The quickest way to use the RRB3 as a roving robot is to buy a
The library implements a class called RRB3. This is only available for Python 2 and any Python programs that you write that use the library must be run as a super user.
To import the library and create an instance of the class, put this at the top of your Python program.
from rrb3 import * rr = RRB3(9, 6)
The first parameter ‘9’ is the battery voltage (6 x 1.5V AA batteries). The second parameter (‘6’) is the motor voltage (6V for most low cost robot chassis motors). It is important to set these values correctly, as the library will manage the voltage supplied to the motors, to prevent them burning out or running too fast.
The rest is pretty straightforward, there are just a load of useful methods on the class that you can use.
There are two LEDs built-in to the RaspiRobotBoard, called LED1 and LED2. Both of these can be turned on and off using the following methods:
To turn LED1 on just do:
To turn it off again do:
To control LED2 just do the same thing but using set_led2.
The sw1_closed() and sw2_closed() functions return true if the contacts for that switch are closed. By default, the switches are open. You can test out closing the switch by shorting the two contacts with a screwdriver.
The following test program will show you the state of each of the switch contacts.
from rrb3 import * rr = RRB3() while True: print("SW1=" + str(rr.sw1_closed()) + " SW2=" + str(rr.sw2_closed())) raw_input("check again")
The RRB3 has two high-power open collector outputs. These can each provide up to 2A and so are suitable for driving loads at the battery voltage, such as high power LEDS, IR senders, alarm bells, relays etc.
Each OC output has a pair of screw terminals. Once screw terminal is marked + and this is connected to the positive power input from the batteries. The other connection is the open collector output.
This means that you can just connect your load (say a 12V siren) across the two screw terminals and then control it as described below. If the load you are using has a positive terminal then this needs to be connected to the screw terminal marked +.
To turn the Open Collector OC1 output on just do:
To turn it off again do:
To control OC2, substitute set_oc2 in place of set_oc1 in the examples above
There are two levels of command for controlling the motors. There is a high level interface that assumes that the motors are connected to wheels on a rover. These commands are forward, reverse, left, right and stop.
… will start both motors running in the same direction to move the robot rover forwards. They will continue in this direction until another command is issued.
If you want to move forward for a certain amount of time, you can specify a number of seconds as an optional first argument. If you supply a second parameter between 0 and 1 this will control the speed of the motor. This is set to 0.5 as a defaut. If you want the motors to run indefinately, but also want to control the speed, then use 0 as the first patrameter.
rr.forward() # forward half speed indefinately rr.forward(5) # forward for 5 seconds at half speed rr.forward(5, 1) # forward for 5 seconds at full speed
The commands left, right and reverse all work in the same way.
The stop command stops all the motors.
There RRB3 can be used to drive a single bipolar stepper motor with one coil connected to the L motor driver and the other to the R terminals.
Two commands are available to make the motor step in one direction or the other:
rr.step_forward(5, 200) # step in one direction for 200 steps with a 5ms delay between each phase change rr.set_reverse(5, 200) # other direction
The low level interface is intended for control of the motors directly. It allows you to control the speed of each motor and its direction independently.
The method for this (set_motors) takes four arguments: the left speed, left motor direction, right spped and direction.
So to set both motors going forward at full speed, you would just use the following:
rr.set_motors(1, 0, 1, 0)
.. and half speed would be:
rr.set_motors(0.5, 0, 0.5, 0)
to send the motors both at half speed in opposite directions is:
rr.set_motors(0.5, 1, 0.5, 0)
If you fit the RRB3 with an SR-04 ultrasonic rangefinder, then you can use the following call to measure the distance to the enarest obstacle in cm.
You can find the schematic design file in the “hardware” section of this repo.
Input Voltage: 6-12V (9 recommended when driving motors) Motor Current total average: 1.2A Motor Current total peak: 3.2A (built-in thermal shutdown) OC1 and OC2 output ccurrents: 2A at battery voltage (unprotected) Max current supplied to Pi (excluding motor current): 1.5A
The I2C socket is pin compatible with these Adafruit displays:
To use these you will need to download Adafruit’s Python library for the Pi from here.
Make sure that you plug the display in the right way around. The socket pins are labelled on the RRB3, make sure they match up with the labels on the display. You can use male to female jumper wires if you wish to put the display further away or its too big.
Have a look in the “examples” folder of this library for some examples using the RRB3.
If one of the motor channels doesn’t work.
* Try swapping the polarity of the motor leads over on the same L or R channel. Is it now the forward command that works?
* Try the motor connected directly to a a battery. Does it rotate in both directions when you swap the polarity of the leads.
* Does the Pi reset when you do ‘forward’? This could indicate a power source that’s too weak.
* Do you have a multimeter to test the outputs?
* Make sure that NONE of the motor leads are connected to GND.
* Make sure that no other software is using the GPIO pins. If this isn’t a ‘fresh from the box’ pi there is every likelihood that something else is using one of the GPIO pins you need so if you re-install Raspbian it should clear this up.