Examples and drivers for controlling the BrickPi with C can be found here:  https://github.com/DexterInd/BrickPi/tree/master/Software/BrickPi_C

We assume that you know a little bit about gcc and the compiler to use the C version.  If you’re just starting out, we highly recommend working in Python.


Two drivers are necessary and in the “Drivers” folder:  BrickPi.h and tick.h.

BrickPi.h contains information on controlling motors, reading encoders, reading and setting analog sensors, and reading and setting digital sensors.

The function BrickPiSetup() is called to initialize the BrickPi.


Compiling is recommended in gcc.  This usually comes standard with a Raspberry Pi installation.  An example command line for compiling the “LEGO – Ultrasonic Sensor test.c” is

gcc -o program "Test BrickPi lib.c" -lrt -lm -L/usr/local/lib -lwiringPi

After compiling the program can be run with the command



The github repository for C has examples for all LEGO sensors, as well as Dexter Industries sensors.  There is an example in the repository for using the LEDs on the BrickPi board.

The following LEGO sensors currently have example programs:

  • Color Sensor
  • Encoder
  • Motors
  • Touch Sensor
  • Ultrasonic Sensor
  • Analog Sensors (Includes sound sensor)

The following Dexter Industries sensors currently have example programs:


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