Pibrella board for Raspberry Pi

Lead Image © Ralf KRaft, 123RF.com

Under My Pibrella

Pibrella eliminates the need for a separate breadboard, jumper wires, and basic electronic components. This makes it a perfect board for prototyping and building both simple and advanced Raspberry Pi-based projects.

Usually, working even on a simple Raspberry Pi-based hardware project involves a breadboard, jumper wires, LEDs, buttons, and other components. Wiring electronics on a breadboard can be tedious, and the final result looks messy and unwieldy. Enter Pibrella  [1], a Raspberry Pi board that comes with all essential components neatly arranged and ready for use.

Pibrella Hardware

Pibrella is a relatively small 4x5.5cm board. Despite its diminutive size, however, it packs an impressive amount of components. It has three LEDs (green, amber, and red), a push-button, a buzzer, and four input and four output ports. Each port has a dedicated surface-mounted LED, which lights up when the port receives or sends a signal. Each input and output port consists of two (plus and minus) female connectors, which greatly simplifies wiring. Pibrella also features a dedicated micro-USB port for connecting an external power supply, which can be useful for connecting power-hungry components such as motors and solenoids.

Adding the board to Raspberry Pi couldn't be easier: Simply snap Pibrella onto Raspberry Pi's GPIO port, and the board is ready to go (Figure 1). To control Pibrella via Python, you need to install the Pibrella library by running the following commands in the terminal:

Figure 1: Pibrella board mounted on Raspberry Pi.
sudo apt-get update
sudo apt-get install python-pip
sudo pip install pibrella

Alternatively, you can install the library from the project's GitHub repository [2]. First, install Git on your Raspberry Pi using the sudo apt-get install git command. Then, run the following commands to install the library:

git clone http://github.com/pimoroni/pibrella
cd pibrella
sudo python setup.py install

Now you can put Pibrella to some practical use.

Getting Started with Pibrella

To learn the ropes, you might want to start with something really simple like controlling the LEDs. Run the sudo python -i command to start the Python interactive shell, then import the Pibrella library using the import pibrella command. The library provides several functions for controlling LEDs. The pibrella.light.red.on() function, for example, turns the red LED on, and pibrella.light.red.off() turns it off. You can control all three LEDs using the functions pibrella.light.on() and pibrella.light.off().

The library also contains libraries for blinking, pulsating, and fading LEDs. The blink function takes two values: time on and time off specified in seconds. For example, the pibrella.light.amber.blink(1, 3) function turns the amber LED on for one second every three seconds. In addition to time on and off, the pulse function takes the fade in and fade out time values – for example, pibrella.light.green.pulse(3, 3, 1, 1), where the first two values are fade in and fade out times. Finally, the fade function is used to fade from one brightness level to another. The pibrella.light.red.fade(0, 100, 10) command, for example, fades the red LED from 0 to 100% in 10 seconds.

Using the described functions, you can build a simple tea timer that provides visual feedback via the LEDs. To do this, you need to write a simple Python script that uses a combination of the sleep and LED control functions to turn the appropriate LEDs on and off at specific times. On Raspberry Pi, create a new text file and enter the code shown in Listing 1.

Listing 1

tea_timer.py

01 #!/usr/bin/env python
02 from time import sleep
03 import pibrella
04 pibrella.light.red.on()
05 sleep(120)
06 pibrella.light.red.off()
07 pibrella.light.amber.fade(100, 0, 60)
08 sleep(60)
09 pibrella.light.green.pulse(1, 1, 1, 1)
10 sleep(15)

Save the file under the tea_timer.py name and make the script executable using the chmod +x tea_timer.py command. Before you run the script, I'll explain what it actually does. The timer is set to three minutes, and as soon as you launch the script, the red LED turns on and stays on for 120 seconds. Then, it turns off, and the amber LED fades out in 60 seconds, after which the green LED pulsates for 15 seconds, indicating that your tea is ready. Now, run the script using the sudo ./tea_timer.py command and behold your fancy tea timer in action.

The script is hardwired for three minutes, but as any experienced tea drinker knows, different tea types require different steeping times. So, you might want to tweak the script to make it more flexible. You can, for example, add code that prompts the user to enter the desired time value and then performs a couple of simple calculations (see Listing 2).

Listing 2

Adding Flexibility

01 #!/usr/bin/env python
02 from time import sleep
03 import pibrella
04 time_min = raw_input("Enter time in minutes (must be >1): ")
05 time_sec = int(time_min)*60
06 pibrella.light.red.on()
07 sleep(time_sec-60)
08 pibrella.light.red.off()
09 pibrella.light.amber.fade(100, 0, 60)
10 sleep(60)
11 pibrella.light.green.pulse(1, 1, 1, 1)
12 sleep(15)

Because Pibrella also has a buzzer, you can add audio feedback to the tea timer.

The Pibrella library features four buzzer-related functions: pibrella.buzzer.buzz() for buzzing at a specified frequency, pibrella.buzzer.note() for playing a note, pibrella.buzzer.fail() for playing a fail sound, and pibrella.buzzer.success() for playing a success sound. You can use any of these functions to add an audio notification to the tea timer. For example, the last three lines of the tea_timer.py script might look something like this:

pibrella.buzzer.success()
pibrella.light.green.pulse(1, 1, 1, 1)
sleep(15)

Instead of starting the tea timer manually by launching the script, you trigger it by pressing the hardware button on the board. To do this, you can use the pibrella.button.read() function for reading the button's state wrapped into an infinite while loop (Listing 3).

Listing 3

On Switch

01 #!/usr/bin/env python
02 from time import sleep
03 import pibrella
04 while True:
05         if pibrella.button.read() == 1:
06             pibrella.light.red.on()
07             sleep(120)
08             pibrella.light.red.off()
09             pibrella.light.amber.fade(100, 0, 60)
10             sleep(60)
11             pibrella.light.green.pulse(1, 1, 1, 1)
12             sleep(15)

Of course, you can put the button to other clever uses, too. The lack of a hardware shutdown button makes it a bit tricky to turn off the Raspberry Pi. Sure, you can simply disconnect the power cord, but that's not an ideal solution. Using a simple Python script, you can turn the Pibrella button into a dedicated off switch for your Raspberry Pi (Listing 4).

Listing 4

Off Switch

01 #!/usr/bin/env python
02 import pibrella, os
03 from time import sleep
04 pibrella.light.green.on()
05 while True:
06         if pibrella.button.read() == 1:
07             pibrella.light.green.off()
08             pibrella.light.red.blink(1, 1)
09             sleep(5)
10             os.system("halt")

As you can see, the script itself is not particularly complicated. It turns the green LED on to indicate that the script is ready, and then it waits for a button press. When the button is pressed, the script blinks for five seconds and then issues the halt command.

Now, you still need to run the script manually, which defeats its purpose (after all, you can simply issue the halt command). To solve this problem, you might want to configure the system to run the script automatically on boot. To do this, run the sudo nano /etc/inittab command to open the inittab file for editing. Locate the 1:2345:respawn:/sbin/getty --noclear 38400 tty1 line and edit it as follows:

1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 tty1

Open then the ~/.bash_profile file in a text editor and append the sudo ./halt.py line to the file. Save the changes and reboot Raspberry Pi.

This simple script can be repurposed easily for other uses. For example, you can use it to play your favorite Internet radio station at a press of the button (Listing 5).

Listing 5

Play Internet Radio

01 #!/usr/bin/env python
02 import pibrella, os
03 pibrella.light.green.on()
04 while True:
05     if pibrella.button.read() == 1:
06         pibrella.light.amber.on()
07         os.system("mplayer -playlist http://ramfm.org/ram.pls")

Besides the LEDs, the buzzer, and the button, Pibrella also features output and input ports that can be controlled using dedicated functions in the Pibrella library. The pibrella.output.e.write(1) function, for example, turns output port E on, whereas pibrella.output.e.write(0) turns it off. This functionality allows you to use Pibrella for controlling external hardware devices and circuits, like the simple transistor switch described in Issue 03 [3].

Better still, you can add Pibrella's button to the mix, thus turning your Raspberry Pi into a proper remote shutter trigger for a camera. Simply connect the transistor switch to the Pibrella board as shown in Figure 2 and create a Python script with the code shown in Listing 6.

Figure 2: Transistor switch connected to the Pibrella board.

Listing 6

Shutter Trigger

01 #!/usr/bin/env python
02 from time import sleep
03 import pibrella
04 while True:
05         if pibrella.button.read() == 1:
06                 pibrella.output.e.write(1)
07                 sleep(0.5)
08                 pibrella.output.e.write(0)

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Backing up images with the Raspberry Pi

    Users who like to take pictures while on the go also need a mobile back up medium in order to free up space on their digital camera's memory once its capacity is full. A Raspberry Pi is the perfect device to use as an image tank for backing up pictures.