PicoBorg Reverse - Advanced motor control for your Raspberry Pi

Installation

Mounting

Two basic mounting options are provided:
The First option is to mount the board on top of a Rev 2 Raspberry Pi using the central mounting hole by positioning the board over the Raspberry Pi's mounting hole (the one closest to the HDMI connector), the board can be oriented however you choose.
The Second option is to mount the board using any combination of the three available mounting holes to part of the robot you are building, we recommend using all three if possible.
If stacking multiple boards using the mounting hole you will need to ensure the posts used provide enough clearance between boards so they cannot touch, if they are too close it may cause problems.

Connections

The first thing to do is connect the six-pin header used for talking with the Raspberry Pi to the Raspberry Pi GPIO header as shown below.
The outlines show an individual 3x1 pin cable (two supplied), the coloured boxes show the colour of the wire (grey is used instead of black in the diagram).

As you can see you may connect multiple boards at once, read further down for instructions on configuring the software correctly to run with multiple boards attached.

DC (normal) motors

You will need to add the motors (or only one if you desire) and the battery / power supply to the board as shown below:

You may also connect a normally closed switch where the jumper is normally connected as a safety switch (emergency power off, EPO), allowing a switch press to prevent the motors running until re-enabled by a special command, PBR.ResetEpo().

Stepper motors

You will need to add the motor to both motor outputs, and the battery / power supply to the board as shown below:

The shown stepper connection colours are based on the following internal wiring for the stepper:

Note that on 5 / 6 wire steppers the remaining connections should be the center-taps (labelled white and grey above), these must not be connected to anything, we recommend putting some electrical tape over the end of these wires to ensure they do not contact any other connections.
You may also connect a normally closed switch where the jumper is normally connected as a safety switch (emergency power off, EPO), allowing a switch press to prevent the motors running until re-enabled by a special command, PBR.ResetEpo().

DC (normal) motors with feedback

The software provided will accept a taco input signal as an indication of either number of rotations or distance travelled by wheels.
The input signal is a single wire for each motor attached, and may be any of the following:
  • A one per rev pulse / index mark
  • A taco signal (such as those used on a computer fan)
  • One of the signals from an encoder (quadrature), either A or B
You will need to add the motors (or only one if you desire) and the battery / power supply to the board the same way as for the standard DC motor setup.
The taco / encoder signal should be connected to the correct pin for the attached motor, the 3v3 and Ground on the same five-pin header may be used to power the taco / encoder if needed.

You may also connect a normally closed switch where the jumper is normally connected as a safety switch (emergency power off, EPO), allowing a switch press to prevent the motors running until re-enabled by a special command, PBR.ResetEpo().

Software

Please note that this installation expects you to be connected to the internet, it will download i2c-tools and python-smbus for using I²C from Python, as well as pygame for the joystick examples.

You may need to enable I2C first, to do this:
  1. Enter the following command in a terminal: sudo raspi-config
  2. Move down to option 8 Advanced Options and press ENTER
  3. Move down to option A7 I2C and press ENTER
  4. Make sure Yes is highlighted and press ENTER
  5. When the dialog says I2C is enabled press ENTER
  6. Make sure Yes is highlighted again and press ENTER
  7. When the dialog says I2C will be loaded by default press ENTER
  8. Move right until Finish is highlighted, then press ENTER
If the I2C option is not available simply proceed to the next step.

To run through the automatic installer just use this one line in a terminal:
bash <(curl https://www.piborg.org/install-picoborgrev.txt)
If you would prefer to manually run through the steps use the commands below:
mkdir ~/picoborgrev
cd ~/picoborgrev
wget http://www.piborg.org/downloads/picoborgrev/examples.zip
unzip examples.zip
chmod +x install.sh
./install.sh
Manual download: http://www.piborg.org/downloads/picoborgrev/examples.zip
At the end of the install a desktop icon will appear for the example GUI, you should now be ready to go.
If you are intending to use Python 3 there are a couple more bits to do, see Python 3 and PicoBorg Reverse

Multiple Boards

In order to setup multiple boards there is an additional step, we need to give each board a unique address.
The allowable addresses are 3 (0x03) to 119 (0x77), the numbers in parenthesis are in hexadecimal.
The first task is to pick a unique number for each board, for this example we will have three boards which we will number 10, 11, and 12.
Start the Raspberry Pi with the first board
Open a terminal and start a Python prompt as follows:
cd ~/picoborgrev
python
Load the library
import PicoBorgRev
Set the address of the attached board, the function should tell you if this is successful or not
PicoBorgRev.SetNewAddress(10)
Disconnect the attached board and connect the next board, you can do this with the Raspberry Pi still running if careful, if you are worried shut the Raspberry Pi down first, then repeat the steps up to and including loading the library.
Set the address of the attached board, repeat the last two steps for each board.
PicoBorgRev.SetNewAddress(11)
PicoBorgRev.SetNewAddress(12)
Finally attach all of the boards at once, then run the following to see what addresses were found:
print PicoBorgRev.ScanForPicoBorgReverse()
If everything went well the last line should show the numbers you set, e.g.
[10 11 12]
You can now use them all in a script like so
# Setup the library ready for use
import PicoBorgRev
# Board #1, address 10
PBR1 = PicoBorgRev.PicoBorgRev()
PBR1.i2cAddress = 10
PBR1.Init()
PBR1.ResetEpo()
# Board #2, address 11
PBR2 = PicoBorgRev.PicoBorgRev()
PBR2.i2cAddress = 11
PBR2.Init()
PBR2.ResetEpo()
# Board #3, address 12
PBR3 = PicoBorgRev.PicoBorgRev()
PBR3.i2cAddress = 12
PBR3.Init()
PBR3.ResetEpo()
Simply use PBR1, PBR2, or PBR3 anywhere you would have used PBR in a single board example.
You can use as many boards as there are free address numbers, over a hundred in all ^_^
For more detailed instructions or help see Setting up multiple PicoBorg Reverses on the forum.

General Usage

Example GUI

All very simple, drag the sliders up from zero to increase the speed in a forwards direction, down from zero to increase the speed in a reverse direction.
The All Off button stops both motors from moving
This can be run from the desktop shortcut, or from the PicoBorg Reverse install folder (cd ~/picoborgrev) using:
./pbrGui.py

Other Examples

The following scripts may be run from the PicoBorg Reverse install folder (cd ~/picoborgrev): ./pbrSequence.py - Runs both motors through a pattern of speeds.
./runPbrJoy.sh - Uses a joystick to control both motors like a car (may require setup).
./pbrStepper.py - Controls a single stepper motor, asks user for commands.
./pbrStepperSeq.py - Controls a single stepper motor, runs a looping pattern.
For more information or setup help see the full example details here.

Python Library

The example scripts make use of our Python library, PicoBorgRev.py, to command the board.
The library exposes all of the features of the board with the following functions:
# Setup the library ready for use
import PicoBorgRev                      # Load the library
PBR = PicoBorgRev.PicoBorgRev()         # Create a board object
PBR.Init()                              # Setup the board
PBR.ResetEpo()                          # Reset the safety latch (optional switch)

# Setting motor speeds
PBR.SetMotor1(power)                    # Set motor 1 speed
PBR.SetMotor2(power)                    # Set motor 2 speed
PBR.SetMotors(power)                    # Set speed of both motors
PBR.MotorsOff()                         # Stop both motors

# Reading motor speeds
PBR.GetMotor1()                         # Read motor 1 speed
PBR.GetMotor2()                         # Read motor 2 speed

# Controlling the safety latch (EPO)
PBR.ResetEpo()                          # Reset the safety latch
PBR.SetEpoIgnore(state)                 # Set the safety latch to be enabled / disabled
PBR.GetEpoIgnore()                      # Read if the safety latch is enabled / disabled

# Controlling the LED
PBR.SetLed(state)                       # Turn the LED on/off
PBR.GetLed()                            # Read the LED as on/off

# Testing for faults
PBR.GetEpo()                            # Read the state of the safety latch
PBR.GetDriveFault()                     # See if there is a fault reported

# Setting up feedback (encoder) mode
PBR.SetEncoderMoveMode(enabled)			# Enable / disable feedback following mode
PBR.GetEncoderMoveMode()				# Check if we are in feedback following mode
PBR.SetEncoderSpeed(power)				# Set the speed of both motors in feedback following mode
PBR.GetEncoderSpeed()					# Read the speed of both motors in feedback following mode

# Using feedback (encoder) mode
PBR.EncoderMoveMotor1(counts)			# Move motor 1 a number of counts in a direction
PBR.EncoderMoveMotor2(counts)			# Move motor 2 a number of counts in a direction
PBR.EncoderMoveMotors(counts)			# Move both motors a number of counts in a direction
PBR.IsEncoderMoving()					# Check if we are still performing an encoder move
PBR.WaitWhileEncoderMoving(timeout)		# Wait until the encoder move is completed or has timed-out
PBR.MotorsOff()                         # Stop both motors / abort the last encoder move

# Setting parameters (before Init)
PBR.i2cAddress = address                # Set the address of the board to use
PBR.printFunction = function            # Re-route / disable diagnostic messages

# Reading parameters (after Init)
print PBR.busNumber                     # Shows which I²C bus the board is connected on
print PBR.foundChip                     # See if the board is found / not found

# Other functions
PicoBorgRev.ScanForPicoBorgReverse()    # Sweep the I²C bus for available boards
PicoBorgRev.SetNewAddress(address)      # Configure the attached board with a new address
PBR.Help()                              # Get help on the available functions
For more complete details see the PicoBorg Reverse library reference.
To see the source code for the library or any of the examples see the code listings here.
Subscribe to Comments for &quot;PicoBorg Reverse - Advanced motor control for your Raspberry Pi &quot;