Available in the USA on Amazon.com here.


** Works with the Raspberry Pi2 **

The RasPiRobot Board V2 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 L293D 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 up to 2 amps of power using a switch mode power supply, allowing you to run a fully-loaded Pi and the robot from 6xAA batteries (not included!)

Where to Buy

The RasPiRobot Board is sold in the USA by Adafruit at a price of $29.95

It is also available in the UK and world-wide from Seedstudio for around £15 depending on exchange rates

You can also buy it on Amazon.co.uk for £17.50


The main features of version 2 are listed below.

  • Compatible with Raspberry Pi models A, A+, B and B+
  • Open Source Hardware
  • Extensive Open Source Python library with examples – download from Gitbub http://raspirobot.com
  • 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 upto 2A using a switch mode power supply – 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 directly
  • 5V I2C header, pin compatible with Adafruit displays
  • Two buffered open collector outputs
  • Two LEDs
  • Two switch inputs
  • Screw terminals for motors and battery
  • Through headers allowing access to all GPIO pins


Version 2 of the RaspiRobot Board (RRB2) has learnt by the feedback from version 1 and it is a great improvement.


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 RRB2 will provide 5V at 2A with ease to the Raspberry Pi, and motors.

Note that 6V motor will usually work just fine at 5V.

Installing the Python Libraries

On your Raspberry Pi, issue the following commands in a Terminal window:

$ wget https://github.com/simonmonk/raspirobotboard2/raw/master/python/dist/rrb2-1.1.tar.gz
$ tar -xzf rrb2-1.1.tar.gz
$ cd rrb2-1.1
$ sudo python setup.py install

Attach the RRB2 to your Raspberry Pi. You do not need to attach batteries, motors or anything else to the RRB2 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 RaspiRobot Board v2, 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 rrb2 import *
rr = RRB2()

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 RRB2 as a roving robot is to buy a robot chassis such as the Magician Chassis (available from many sources) or similar low-cost robot chassis kits from eBay. These kits come as a laser cut body, a pair of gearmotors, often a battery box and nuts and bolts to fix it all together.

Here is one such chassis. The first step is to bolt this all together. Note that these are usually supplied with a 4 x AA battery box. You will need to swap this for a similar 6 x AA battery box or a 7.2V LiPo battery pack. Rechargeable batteries are a good idea when driving motors.


Once the chassis is built, use some of the bolts suppled to fix the Raspberry Pi on the chassis and then attach the RRB2 onto the GPIO connector. Make sure its the right way arround, and that all the pins meet up with the socket.

The leads from the motors will thread up through the chassis and each pair of leads should go to one of the two screw terminals labelled L and R for (left and right). If you put the leads in the wrong way around, the direction of the motor will be opposite to that expected, so just swap them over if this happens.

Motor wiring

Next, make sure that your Raspberry Pi’s USB power lead is unplugged. From now on we are going to power it from batteries.

WARNING: Never power the Raspberry Pi from both batteries and the USB power connector. One or other, but NOT both.

It is a good idea to leave the wheels off the robot chassis for now so that it does not unexpectedly drive itself off your table. One or both of the motors may spin as the Raspberry Pi starts up.

Wire the battery pack into the third pair of screw terminals. +V towards the outside of the board. The Raspberry Pi’s power light should light up and it will start to boot. LED1 and LED2 on the RRB2 will also light up.

Having your Pi set up for WiFi will allow you to connect to it wirelessly over SSH. So, you may want to plug in a USB WiFi dongle.

API Reference


The library implements a class called RRB2. This is only available for Python 2 and any Python programs that you write that use the libaray must be run as a super user. I.e.

`sudo python myProgram.py’

To import the library and create an instance of the class, put this at the top of your Python program.

from rrb2 import *
rr = RRB2()

If you have an older revision 1 Raspberry Pi, then you need to do this instead:

from rrb2 import *
rr = RRB2(revision=1)

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 setLED2.

Switch Inputs

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 rrb2 import *

rr = RRB2()

while True:
    print("SW1=" + str(rr.sw1_closed()) + " SW2=" + str(rr.sw2_closed()))
    raw_input("check again")

Open Collector Outputs

The RaspiRobotBoard has two low-power open collector outputs. These can each source up to 25mA and so are suitable for driving LEDs with series resistors. They can also be used to drive transistors and other external electronics. They are buffered and therefore protect the Raspberry Pi’ s processor.

To turn the Open Collector OC1 output on just do:


To turn it off again do:


To control OC2, substitute oc2 in place of oc1 in the examples above

Motor (High Level Interface)

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.

Some examples:

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.

Motor (Low Level Interface)

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)

Range Finder

If you fit the RRB2 with an SR-04 ultrasonic rangefinder, then you can use the following call to measure the distance to the enarest obstacle in cm.



The RRB2 uses the following pins:

SW1_PIN = 11
SW2_PIN = 9
LED1_PIN = 7
LED2_PIN = 8
OC1_PIN = 22
OC2_PIN = 27
OC2_PIN_R1 = 21 (rev 1) or 27 rev 2

The LEDs and OC outputs are buffered. The switch inputs are not.

You can find the EAGLE design files in the “hardware” section of tis repo.

Using I2C Displays

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 RRB2, 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.

Example Projects

Have a look in the “examples” folder of this library for some examples using the RRB2.

18 thoughts on “RaspiRobot Board V2

  1. Robert Davey

    Hi Simon. I was delighted to find this article. It’s opened a whole new vista for me, as hitherto I’ve concentrated on using Arduino boards.


    Robert Davey

  2. Valerie

    Hi Simon! I found the RaspiRobot Board V2 in researching how best to go about controlling a stepper motor. I am working on a project for my graduate degree, and have found myself in need of controlling 2 stepper motors. Is the board “stackable”, such that I would be able to control 2 motors, each by way of their own board?

    Thanks so much for your feedback!

  3. admin Post author

    In theory it should work anyway but we will be testing it out later today!

  4. admin Post author

    Sorry for the delay (communications problems our end!!) but yes, it works!!

  5. chris

    very interesting project !

    is it possible to power the Raspberry and the RaspiRobot Board with two different battery (1 for rasp and 1 for motors) and bypass the 5V provided by the card ?
    just to have more time of power…

    With one battrey one many hours works the raspberry with 2 motors ?


  6. admin Post author

    Hi Chris. One rather drastic way to do this is to snip off the 5V pins that go from the RRB2 to the Pi. Then you can use separate batteries, say a 5V USB battery pack for the Pi and an AA battery pack for the motors, although the motors will still use the regulated 5V from the RRB2.

    Assuming you leave the RRB as it is, a set of AA batteries holds about 2000mAh. If you say a Pi 2 uses an average of 300mA then thats about 6 hours worth. If the motors are on all the time, each using 300mA, then you will only get maybe 2 hours.

    Using a 7.4V LiPo battery pack of the type used for RC vehicles, will give you longer battery life. The key figure when looking at batteries is mAh (Milliamps for an hour)


  7. Randal Riedinger

    Where can I get a schematic for this and the “PhoBot – Robotics Shield for Photon” Schematic of which I own both?

  8. admin Post author

    If you go to GitHub/simonmonk, look in repositories you will find both boards & the schematics will be listed under the Hardware section.

  9. Gabriel

    Hi, excellent board, specially for beginners like me!
    Now I would like to now if it would be possible to add some python code to read data from wheel encoders.
    This would be in order allow to drive the robot in straight line.
    Currently I am using pwm to balance speed of motors in manually way, but it is not very precise.
    I have seen your robot kit comes with encoders, although I have a similar kit without encoders but with sproket disks and I bought this encoder, supposedly designed for that:
    I have this chassis: https://www.sparkfun.com/products/retired/12866
    Any help will be much appreciated.
    Thank you!

  10. admin Post author

    Hi, that’s not something I have ever tried, but yes it should work. You will need to connect the two digital outputs from the encoders to digital inputs on the GPIO connector. As most of these are used by the RRB, you will probably need to use a Pi with 40 pin GPIO connector to find some free GPIO pins.

    As far as the code goes, to move forward straight, you will need to count pulses from both sides and if on count starts to get bigger than the other, reduce the speed of the motor that’s going too fast.

    Hope this helps.


  11. Steve Shufelt

    Is there any way to make this work with python 3? I have a pi B with python 3 installed. If not, is there an easy way to install python 2 alongside 3 ?

  12. admin Post author

    If you install using

    $sudo python3 setup.py install

    It will install the library for Python3.

  13. Steve

    Thanks so much! I’ve had some other unrelated issues I need to work through first. But I will let you know how it goes as soon as I can. Thanks again!

  14. Khairul

    Hi Simon. Is There any datasheet for all the component that were used in the schematic board?

Leave a Reply

Your email address will not be published. Required fields are marked *