BrickPi3 Getting Started – Program in Python

BrickPi3 Getting Started – Program in Python

python-and-the-brickpi3BrickPi3 – Program in Python

Python is the most widely used language with the BrickPi3.  Below are instructions for getting started with the BrickPi and Python.  If you’re using Raspbian for Robots, you can skip the installation, as the Python drivers and examples come fully installed.

Installation

If you are using Raspbian For Robots, BrickPi3 software is already be installed.  You can download and install Raspbian for Robots for free on your own SD Card using these directions.

To install BrickPi3 on Raspbian, connect the Raspberry Pi to the internet and enter the following command:

curl -kL dexterindustries.com/update_brickpi3 | bash

 

Reboot the Raspberry Pi to finish the installation:

sudo reboot

Running example programs

The Python example programs for using sensors, motors, and BrickPi3 LED are installed in this directory:

~/Dexter/BrickPi3/Software/Python/Examples

To run an example program such as the example for the EV3 Color Sensor, open the command line, and change the directory to where the examples are installed:

cd ~/Dexter/BrickPi3/Software/Python/Examples

And then run the example with the following command:

python EV3-Color_Sensor_Color.py

Drivers

The drivers and examples were written for Python 3, but are Python 2.7 compatible. The driver file is located in the directory

~/Dexter/BrickPi3/Software/Python

and is named “brickpi3.py”.  This file contains all of the necessary routines for commanding the motors and sensors, and collecting information from the BrickPi3. To use the module in your own Python scripts, just import it:

import brickpi3

BrickPi+ Assembled TankSupported Sensors and Motors

The following Sensors and Motors are supported in Python with examples:

Contribute!

Developed a driver for a sensor you don’t see up there?  Tell us in the forums, or pull request through Github!

Next: Troubleshoot Common Issues With the BrickPi3.

Learn to Program with Scratch

Go Back to Build your robot: Attach LEGO MINDSTORMS (NXT/EV3) sensors, motors & TECHNIC parts

Back to BrickPi3 Tutorials & Documentation