Getting Started with the BrickPi

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Pages
Contributors: Shawn Hymel
Favorited Favorite 0

Introduction

If you're familiar with Mindstorms ®, then you are probably aware of all the cool projects that you can make and the educational value of such an easy-to-use robotics platform. Enter the BrickPi.

BrickPi

DEV-12732
Retired

The BrickPi is a RasbperryPi add-on that lets you control Mindstorm parts. The BrickPi stacks on top of the Raspberry Pi and accepts Mindstorms motors and sensors.

BrickPi on a Raspberry Pi

BrickPi on top of a Raspberry Pi

The BrickPi allows you to control Mindstorms parts using any number of languages including C, Python, and Scratch.

Covered in This Tutorial

In this tutorial, we will cover how to get started with the BrickPi. We will show you how to connect the BrickPi to a Raspberry Pi, attach building blocks, connect motors/sensors, and write a simple Python script to control the motors/sensors.

Required Materials

NOTE: The servo motor and touch sensor can also be found within the Mindstorms NXT set.

Suggested Reading

Configure SD Card

IMPORTANT: You need to use Dexter Industries' custom Raspbian build to get the BrickPi to work.

Required Downloads

Flash the SD Card

  1. Insert the SD Card into your computer
  2. Install Win32DiskImager
  3. Unzip Dexter Industries' Raspbian build (use 7-Zip if the image is in .rar form)
  4. Run Win32DiskImager with administrative privileges
  5. Select the unzipped Dexter Industries' Raspbian build as the Image File
  6. Select the location of the SD Card
  7. Click "Write"

Win32DiskImager flashing Dexter Industries' Raspbian build

Don't forget to Run as Administrator!

BrickPi Assembly

You will need to build the hardware around the BrickPi in order to connect it to the Raspberry Pi and your building blocks.

Build the Case

1) Unpack the BrickPi hardware and remove the protective paper from the case.

BrickPi parts

2) Screw the two small standoffs into the holes in the bottom piece of acrylic.

BrickPi assembly

3) Screw a Raspberry Pi onto the two bottom standoffs.

Raspberry Pi in BrickPi case

4) Screw the four long standoffs into corner slots of the bottom piece of acrylic.

BrickPi assembly process

5) Attach the BrickPi to the Raspberry Pi by mating the BrickPi's header to the Raspberry Pi's GPIO header.

BrickPi mounted on Raspberry Pi

6) (Optional) Now is a good time to label the motor and sensor ports on the BrickPi. I recommend S1, S2, and so on for the sensor ports and MA, MB, and so on for the motor ports.

BrickPi with labels

7) Attach the top piece of acrylic to the four posts using the remaining screws.

Fully assembled BrickPi with Raspberry Pi

8) Insert the SD card.

SD Card in Raspberry Pi inside BrickPi case

Attaching the Building Blocks

Beams can be attached to the top and bottom pieces of acrylic in order to secure the BrickPi and Raspberry Pi to your building block creation.

Lego pegs in BrickPi case

Attach pegs to the holes in the acrylic

Lego beam on BrickPi case

Attach beams to the pegs

Any of the Mindstorms sensors can be attached to the ports labeled with an "S" followed by a number. You will need to remember the port number that you plugged your sensor into.

BrickPi Lego motor port locations

Sensor port locations (Image courtesy of dexterindustries.com)

Motors can be attached to the ports labeled with an "M" followed by a letter.

BrickPi Lego sensor port locations

Motor port locations (Image courtesy of dexterindustries.com)

For this example, connect a single touch sensor to S1 and a single servo motor to MA.

Sensor and motor connected to the BrickPi

Connect Peripherals

Similar to the setting up the Raspberry Pi tutorial, we need to connect a keyboard, mouse, and monitor. Plug a keyboard and mouse into the USB ports, and connect a monitor using an HDMI cable.

BrickPi and Raspberry Pi with connected peripherals

Powering the BrickPi

Dexter Industries recommends a few different ways to provide power to your robot.

Powering the BrickPi

Dexter Industries' guide to powering the BrickPi (Image courtesy of dexterindustries.com)

However, we will do things differently. In order to get unlimited run time and the ability to power a couple of motors, we will hack a wall power supply to attach to the BrickPi.

1) Cut the 9V battery connector off of the 9V Snap Connector and strip the ends.

Hacked BrickPi 9V connector

2) Attach the red wire to the positive (+) and the black wire to the negative (-) screw terminals of the DC Barrel Jack Adapter.

Attach 9V connector ends to DC Barrel Jack Adapter

3) Plug the connector into the BrickPi.

Hacked 9V adapter on BrickPi

4) Plug the 9V wall adapter into the other end of the DC Barrel Jack Adapter.

5) IMPORTANT: Make sure your monitor is connected to the Raspberry Pi and turned on!

6) Plug the wall adapter power supply into a wall outlet.

WARNING: The large power regulator (TO-220 Package) gets hot! Be careful when plugging or unplugging the power adapter.

Highlighted regulator on BrickPi

7) Your Raspberry Pi should come to life!

Dexter Industries' custom Raspbian build

Configure the Raspberry Pi

Once the Raspberry Pi has booted, you should be presented with the Dexter Industries desktop. If you are ever asked for a username or password, the defaults are:

Username: pi
Password: raspberry

BrickPi Desktop

If you would like to configure the Raspberry Pi, open up a terminal:

Raspberry Pi Terminal

and enter the following command:

sudo raspi-config

You will be presented with the Raspberry Pi configuration screen. It is recommended that you expand the filesystem. Have a look at the other options (descriptions for the various options can be found here).

Raspberry Pi configuration

Programming

Open a terminal (if you do not already have one open) and create a new file for our motor and sensor test. Open that file with Leadpad (Raspbian's default text editor).

leafpad motor_sensor.py

Enter the following code into the text editor:

language:python
from BrickPi import *

BrickPiSetup()

BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH
BrickPi.MotorEnable[PORT_A] = 1

BrickPiSetupSensors()

while True:
        result = BrickPiUpdateValues()
        if not result:
                if BrickPi.Sensor[PORT_1]:
                        BrickPi.MotorSpeed[PORT_A] = 200
                else:
                        BrickPi.MotorSpeed[PORT_A] = 0
        time.sleep(0.01)

Raspberry Pi Leafpad with BrickPi Python code

Save and exit out of Leafpad. In the console, enter the following:

python motor_sensor.py

Now, whenever you press the Touch Sensor, the Servo Motor should move!

BrickPi Python example working

Press ctrl+c to end the program.

Resources and Going Further

The BrickPi opens up many opportunities to expand on the Mindstorms kits. To learn more about Dexter Industries and the BrickPi, check out their website: http://www.dexterindustries.com/BrickPi/.

If you are looking for some ideas, Dexter Industries updates their BrickPi site with interesting projects: http://www.dexterindustries.com/BrickPi/projects/

Resources