An interactive Advent calendar


To play music, I'll use the ogg123 command-line tool from the vorbis-tools package. The tool can be installed with the command:

$ sudo apt-get install vorbis-tools

OGG is the only audio file format this player uses, so you need to convert the file format of the music you want to use with your advent calendar to .ogg. After converting the files, put them in a sub-folder with a name like calender/music/. Number each music title contained in the subfolder starting with  1 and continuing through  24 so that each piece is played in the order and on the date specified (i.e., December 1-24).

For this project, I used inexpensive, standard box speakers attached to the Rasp Pi jack. If for some reason the Rasp Pi does not play the music, you can try to set the music audio output by entering the

amixer cset numid=3



Thirty-two blue LED chaser lights ring and illuminate the small opening used to deliver the daily gift, which far surpasses the number of I/O ports on the Rasp Pi.

The I2C bus makes it possible to connect additional I/O components (see the "I2C Bus" box). The WiringPi tools are also relevant here because they include the necessary drivers.

I2C Bus

The serial data bus is suitable for short-distance communication on boards or within devices. The data transmission occurs synchronously via two wires. One is the data wire SDA, and the other is the clock line SCL. Both wires draw pull-up resistance to a positive pole. The bus master initiates communication.

The I2C bus has a 7-bit address range and can therefore serve 128 subscribers, minus the 16 addresses that are already reserved. Typically, it is only possible to choose among the lower 3  bits of the addresses on the client. The upper bits are generally wired tight. The datasheet accompanying the component identifies the possible addresses.

The bus transmits data in bytes. The transmission speed amounts to between 100Kbps bidirectional, or standard mode, and 5Mbps unidirectional, or ultrafast mode. Options for increasing the coverage of the I2C buses range from reducing the pull-up resistors to tunneling through CAN bus drivers.

The PCF8574 microchips I used for this project behave in interesting ways. They deliver a maximum of 0.1mAh per output. This is insufficient to light even one LED. Fortunately, the chip is not so stingy in drawing power and as a result can tolerate 20mAh per output.

For the project described here, this means you should connect the LEDs and their pre-resistor to the positive supply voltage. The LEDs will light up as soon as the I/O ports switch to a logical zero – exactly the opposite of what normally occurs. Technically speaking, this does not cause any problems other than that you will need to program the ports accordingly.

The PCF8574 microchip has three address inputs with which to communicate with the serial bus. The wiring diagram (Lauflicht.sch) shows the four boards occupying the addresses from 0x00 to 0x03. The eight I/O ports of the PCF8574 are connected directly to the LEDs.

Installing i2c-tools helps make sure using the I2C bus on the Rasp Pi is reasonably straightforward; then, you can load the driver for the I2C interface:

$ sudo apt-get install i2c-tools
gpio load i2c

After you have put the four PCF8574 I2Cs together and wired them according to the wiring diagram, you should use the gpio i2cd command to determine whether the connection to the bus has been made (Listing  2). The microchips use addresses 0x20 to 0x23. Entering the commands

Listing 2

Checking the PCF8574

$ gpio i2cd
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 21 22 23 -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
i2cset -y 1 0x20 0xff
i2cset -y 1 0x20 0x00

allows you to control the boards. The parameter 0xff shuts everything off.

In the subfolder calender/led/, you should set up a Perl script for each day; that is, you should set up script files with names extending from to Additionally, you should create a file named where you can deposit the circuit sequence options for the LEDs. The file contains the settings.

The examples provided online can be modified and adapted by the user. The files for the days contain only the invocations for the LED lighting patterns and the appropriate parameters.

To start a script that invokes all of the subroutines (Listing  3), you need to store two symbolic links in the calender/ folder, as well:

$ ln -s ./led/
$ ln -s ./led/

Then, invoke scripts from the folder with


to make sure everything runs correctly.

Listing 3

#!/usr/bin/perl -w
require "./";

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content