Introduction: Template for Programming the Pimoroni Pibrella in C

The Pibrella is a good board for a beginner learning to program the GPIO on a RaspberryPi.

They have libraries on their site for programming it in python or scratch, but nothing for C.

This instructable is a template for programming it in C using the wiringPi library.

The wiringPi library lets you program the RaspberryPi in C in a style similar to an Arduino.

Many thanks to Gordon Henderson for his excellent work writing the wiringPi libraries.

Step 1: Install WiringPi

Gordon Henderson

WiringPi is a set of libraries for programming the RaspberryPi in C.

Instructions for download, install and use are located at

To install wiringPi follow the instructions on this page:

Also see:

And check out his Pibrella page here:

Step 2: The Pibrella

The Pibrella has three LEDs, a push button switch, and a piezo buzzer onboard.

There are also four inputs and four output pins available.

All the pinouts are defined for you individually.

The inputs, outputs, and LEDs are also defined in arrays, and the

proper pin modes are set in the setup() function.

Step 3: And Now for the Code

 * Template for programming the Pibrella from PiMoRoNi in C.
 * Dependencies: The wiringPi C libraries must be installed.  
 * Instructions for download, install and use 
 * are located at
 * Compile with:  gcc -o [FILENAME] [FILENAME].c -lwiringPi
 * Some of the more advanced features require additional #include 
 * statements and Linking additional libraries.
 * Run with:  sudo ./[FILENAME]
#include <wiringPi.h>
 * LEDs
int ledR = 2; // Red
int ledY = 0; // Yellow
int ledG = 7; // Green
int led[] = {2,0,7}; // Red, Yellow, Green - Array of LEDs.

 * Outputs - There are four output pins marked E, F, G and H.
 * There are two female connectors for each output.
 * The connector closest to the red button is the pin (positive).
 * The other connection is the ground
 * Each output pin has a status led which lights when the pin is high.
int outE = 3;  
int outF = 4; 
int outG = 5;
int outH = 6;
int out[] = {3,4,5,6}; // E, F, G, H - Array of outputs.
 * Inputs - There are four input pins marked A, B, C and D.
 * There are two female connectors for each input.
 * The pin closest to the Red button is the digital input
 * and the other is + 3.3 volts.
 * There is an onboard pull down resistor on each input.
 * Using a switch to short directly to +3.3 volts is okay.
 * A resistive sensor (photocell) will switch the pin to high when 
 * when the resistance is less than approximentally 30k.
 * Each input pin has a status led which lights when the pin is high.
int inA = 13;
int inB = 11;
int inC = 10;
int inD = 12;
int in[] = {13,11,10,12}; // A, B, C, D - Array of Inputs.

// Onboard button
int BUTTON = 14; //Button has an onboard pull down resistor. 

// Onboard buzzer
int BUZZER = 1;
 * setup() function, sets all the pinModes for the Pibrella
void setup(void)
  int i; // Index for for loops.

  wiringPiSetup();    // Some WiringPi functions require sudo access. 
                      // Use wiringPiSetup().
  for(i=0;i<3;i++) pinMode(led[i], OUTPUT);
  for(i=0;i<4;i++) pinMode(out[i], OUTPUT);
  for(i=0;i<4;i++) pinMode(in[i], INPUT);
  pinMode(BUTTON, INPUT);
  pinMode(BUZZER, OUTPUT);
 * loop() function, runs in continuous loop when setup finishes.
void loop(void)
// This is sample code, you can delete it 
// and write your own loop()function here.

// In this example the red LED will light 
// if input A is shorted to +3.3 volts,
  if(digitalRead(inA)==HIGH) digitalWrite(ledR, HIGH);
  else digitalWrite(ledR, LOW);

// and the green LED will light if the button is pressed.
  if(digitalRead(BUTTON)==HIGH) digitalWrite(ledG, HIGH);
  else digitalWrite(ledG, LOW);
 * main() function, required in all programs.
int main(void)
  while(1) // Do this forever.
  return 0;

Step 4: Setup and Use

Download the file pibrella.c and place it in your home directory.

Turn off your RaspberryPi, plug int the Pibrella.

Plug the power supply into the Pibrella, then re-boot it.

Edit the pibrella.c file. For a lot of programs all you need to write is the loop() function, everything is already done.

Save your source under a different name.

Compile and run it using the commands documented in the comments.


JRV31 (author)2015-11-04

A thank you goes out to whoever posted a link to this instructable at

About This Instructable




Bio: Most of my instructables will be tutorials for Atmel microcontrollers, Arduino, or Raspberrypi. I try to show concepts that you can use in your own ... More »
More by JRV31:Non-slip SoxMoonLight7400 Quad Nand Gate Simulation
Add instructable to: