Using the C-Berry screen for graphics output

Extending the Player

The music player project, as described previously [2], created a process for selecting audio files that used QR codes and a remote control. In that project, the player was designed to function without a display screen. However, that meant it could not provide any information about its current operating status.

The program for loading bitmaps in Listing  1 assumes the task of creating output that reports the operating status of the player. The program simply shows the file corresponding to the stage of operation. Figure 4 provides an overview of the four possible status indicators.

Figure 4: An overview of the four status indicators for the QR code player.

The updated scripts for the QR code player are available in the GitHub repository [7]. You will need to adapt the EXEPATH variable so that the software can find the scripts.

To set up control over the screen, copy the compiled program from Listing 1 to the script directory and then modify the and scripts as shown in Listings 5 and 6. The Splash.bmp, Error.bmp, ScannQRCode.bmp, and CurrentTitle.bmp image files should also reside in this directory.

Listing 5

01 #!/bin/bash
02 #
03 EXEPATH=/home/pi/QRMusic
04 AUDIODEV=hw:0
05 VIDEODEV=/dev/video0
06 OPTIONS="--nodisplay -Sdisable -Sqrcode.enable --prescale=320x240 -Sposition=disable"
08 arg="$1"
09 case $arg in
10 "power")
11   sudo ${EXEPATH}/loadbmp ${EXEPATH}/Splash.bmp
12   sleep 2
13   sudo ${EXEPATH}/loadbmp ${EXEPATH}/ScannQRCode.bmp
14   zbarcam ${OPTIONS} ${VIDEODEV} | ${EXEPATH}/
15   ;;
16 "next")
17   echo "Next Song"
18   xmms2 next
19   ;;
20 "prev")
21   echo "Previous Song"
22   xmms2 prev
23   ;;
24 "volup")
25   echo "volume 5 up"
26   xmms2 server volume +5
27   ;;
28 "voldown")
29   echo "volume 5 down"
30   xmms2 server volume -5
31   ;;
32 "play")
33   echo "toggle playback"
34   xmms2 toggle
35   status=`xmms2 current`
36   if [[ "$status" =~ ^Paused ]]; then
37   aplay -q ${EXEPATH}/no.wav
38   fi
39   ;;
39 esac

Once the modifications are made, the player will indicate on the screen what it is currently doing. It will involve more work to display the corresponding bitmap for the current album.

You can download the album covers from an online provider. Then, some diligence is required to create and name bitmap files for each of the covers. Replace line 32 from Listing 6 with the line

${EXEPATH}/loadbmp "${EXEPATH}/${album}.bmp"

once you have a bitmap for each album cover.

Listing 6

01 #!/bin/bash
02 #
03 EXEPATH=/home/pi/QRMusic
04 AUDIODEV=hw:0
05 while true
06 do
07   read qr
08   read qr2
09   if [[ "$qr" =~ ^QR ]]; then
10     artist=`echo $qr | cut -d':' -f 3`
11     echo "artist: $artist"
12     album=`echo $qr2 | cut -d':' -f 2-`
13     echo "album: $album"
14     if [[ "$album" =~ ^http ]]; then
15       killall zbarcam
16       xmms2 stop
17       xmms2 clear
18       xmms2 add $album
19       aplay -q ${EXEPATH}/ok.wav
20       xmms2 play
21       exit
22       s=""
23     else
24       s=`xmms2 search album:"$album" | egrep -e "$album"`
25     fi
26     if [[ -n "$s" ]]; then
27       killall zbarcam
28       xmms2 stop
29       xmms2 clear
30       xmms2 add album:"$album" -o "tracknr"
31       aplay -q ok.wav
32       sudo ${EXEPATH}/loadbmp ${EXEPATH}/CurrentTitle.bmp
33       xmms2 play
34       exit
35     else
36       xmms2 stop
37       aplay -q ${EXEPATH}/no.wav
38       sudo ${EXEPATH}/loadbmp ${EXEPATH}/Error.bmp
39     fi
40     sleep 5
41   fi
42 done


The examples illustrated here only begin to scratch the surface of the multitude of possibilities that exist once a screen is present. Many more functions become available, ranging from color output all the way to complex diagrams. The programming necessary to achieve this is not difficult. However, the precise placement of each pixel of the text and graphics on the screen does call for some diligence.

On the other hand, loading the bitmap files is very easy and getting output in the form of status indicators through the use of simple bitmaps makes for an appealing addition to a program like the QR code player.


  1. C-Berry specifications:
  2. "Creating a child-friendly audio player with the Raspberry Pi" by Markus Nasarek, Raspberry Pi Geek, no. 5, 2014:
  3. Raspbian:
  4. Graphics driver (download):
  5. Software for the C-Berry LCD module (download):
  6. Bitmap display and sample bitmaps:
  7. QRMusic Script:

The Author

Marcus Nasarek has been loyal to Linux for a long time, and he is very enthusiastic about scripting, Ruby and projects involving the Raspberry Pi.

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