BrickPi3 – 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
Supported Sensors and Motors
The following Sensors and Motors are supported in Python with examples:
- LEGO EV3 Ultrasonic Sensor
- LEGO EV3 Gyro Sensor
- LEGO EV3 Color Sensor
- LEGO EV3 Touch Sensor
- LEGO EV3 Infrared Sensor
- LEGO EV3 Large Motor
- LEGO EV3 Medium Motor
- LEGO NXT Ultrasonic Sensor
- LEGO NXT Color Sensor
- LEGO NXT Light Sensor
- LEGO NXT Touch Sensor
- LEGO NXT Motor
- Analog Sensor (Sound Sensor, for example)
- Dexter Industries dGPS
- Dexter Industries dThermal
- Dexter Industries dPressure
- Dexter Industries dTIR
Contribute!
Developed a driver for a sensor you don’t see up there? Tell us in the forums, or pull request through Github!