19
Getting Started with the BrickPi a learn.sparkfun.com tutorial Available online at: http://sfe.io/t199 Contents Introduction Configure SD Card BrickPi Assembly Powering the BrickPi Configure the Raspberry Pi Programming Resources and Going Further Introduction If you're familiar with Lego 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 . Page 1 of 19

Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

Getting Started with the BrickPi alearn.sparkfun.com tutorial

Available online at: http://sfe.io/t199

Contents

IntroductionConfigure SD CardBrickPi AssemblyPowering the BrickPiConfigure the Raspberry PiProgrammingResources and Going Further

Introduction

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

Page 1 of 19

Page 2: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

BrickPi

DEV-12732RetiredFavorited Favorite 1Wish List

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

Page 2 of 19

Page 3: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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 connectthe BrickPi to a Raspberry Pi, attach Legos, connect motors/sensors, and write a simple Pythonscript to control the motors/sensors.

Required Materials

BrickPiRaspberry PiSD CardMonitor of some sortHDMI Cable or Composite cableWall Adapter Power Supply - 9VDCDC Barrel Jack Adapter - Female9V Snap ConnectorKeyboard and mouseLego Mindstorms Servo MotorLego Mindstroms Touch Sensor

NOTE: The servo motor and touch sensor can also be found within the Lego Mindstorms NXT set.Page 3 of 19

Page 4: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

Suggested Reading

Setting up Raspbian

Configure SD Card

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

Required Downloads

Download Dexter Industries' Raspbian buildDownload Win32DiskImager7-Zip to unzip the .rar Raspbian image

Flash the SD Card

1. Insert the SD Card into your computer2. Install Win32DiskImager3. Unzip Dexter Industries' Raspbian build (use 7-Zip if the image is in .rar form)4. Run Win32DiskImager with administrative privileges5. Select the unzipped Dexter Industries' Raspbian build as the Image File6. Select the location of the SD Card7. Click "Write"

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

Build the Case

Page 4 of 19

Page 5: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

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

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

Page 5 of 19

Page 6: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

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

Page 6 of 19

Page 7: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

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

Page 7 of 19

Page 8: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

8) Insert the SD card.

Attach Legos

Lego beams can be attached to the top and bottom pieces of acrylic in order to secure the BrickPi

Page 8 of 19

Page 9: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

and Raspberry Pi to your Lego creation.

Attach Lego pegs to the holes in the acrylic

Attach Lego beams to the pegs

Page 9 of 19

Page 10: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

![BrickPi Lego motor port locations](https://cdn.sparkfun.com/r/600-600/assets/f/d/4/b/e/Sensor_Port_Layout_Yellow.png =302x210)

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](https://cdn.sparkfun.com/r/600-600/assets/2/1/c/4/c/Motor_Ports_Blue.png =302x210)

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.

Connect Peripherals

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

Page 10 of 19

Page 11: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

Powering the BrickPi

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

Page 11 of 19

Page 12: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

Page 12 of 19

Page 13: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

3) Plug the connector into the BrickPi.

Page 13 of 19

Page 14: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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 orunplugging the power adapter.

Page 14 of 19

Page 15: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

7) Your Raspberry Pi should come to life!

Configure the Raspberry Pi

Once the Raspberry Pi has booted, you should be presented with the Dexter Industries desktop. IfPage 15 of 19

Page 16: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

you are ever asked for a username or password, the defaults are:

Username: pi Password: raspberry

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

and enter the following command:

sudo raspi-config

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

Page 16 of 19

Page 17: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

Programming

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

leafpad motor_sensor.py

Enter the following code into the text editor:

language:pythonfrom BrickPi import *

BrickPiSetup()

BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCHBrickPi.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)

Page 17 of 19

Page 18: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

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

python motor_sensor.py

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

Press ctrl+c to end the program.

Resources and Going Further

Page 18 of 19

Page 19: Getting Started with the BrickPi - learn.sparkfunUsername: pi Password: raspberry If you would like to configure the Raspberry Pi, open up a terminal: and enter the following command:

The BrickPi opens up many opportunities to expand on the Lego Mindstorms kit. To learn moreabout 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 interestingprojects: http://www.dexterindustries.com/BrickPi/projects/

Resources

BrickPi hardware GitHub repository: https://github.com/DexterInd/BrickPiBrickPi Python GitHub repository: https://github.com/DexterInd/BrickPi_PythonBrickPi C GitHub repository: https://github.com/DexterInd/BrickPi_CBrickPi Scratch repository: https://github.com/DexterInd/BrickPi_Scratch

learn.sparkfun.com | CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado

Page 19 of 19