Python Experiments

Once the library has installed, we can start up a Python command line and try a few commands to get the motors running. Type the following command to start an Interactive Python session.

Download: file
from rrb2 import *
rr = RRB2()
rr.forward()
If you have a very old revision 1 model B Raspberry Pi then change the second line to: rr = RRB2(revision=1)

To stop the motors again, enter the following line:

Download: file
rr.stop()

To set the motors running forward for 5 seconds, use the command:

Download: file
rr.forward(5)

To set the motors running forward at half speed enter the following command:

Download: file
rr.forward(0, 0.5)

As well as forward try experimenting with the commands reverse, left and right, which work in just the same way as forward.

This guide was first published on Sep 19, 2014. It was last updated on Sep 19, 2014. This page (Python Experiments) was last updated on Sep 19, 2019.