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.
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 remote.sh
and rbar.sh
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
remote.sh
01 #!/bin/bash 02 # remote.sh 03 EXEPATH=/home/pi/QRMusic 04 AUDIODEV=hw:0 05 VIDEODEV=/dev/video0 06 OPTIONS="--nodisplay -Sdisable -Sqrcode.enable --prescale=320x240 -Sposition=disable" 07 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}/rbar.sh 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
rbar.sh
01 #!/bin/bash 02 # rbar.sh 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
Conclusion
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.
Infos
- C-Berry specifications: http://admatec.de/sites/default/files/downloads/C-Berry_0.pdf
- "Creating a child-friendly audio player with the Raspberry Pi" by Markus Nasarek, Raspberry Pi Geek, no. 5, 2014: http://www.raspberry-pi-geek.com/Archive/2014/05/Creating-a-child-friendly-audio-player-with-the-Raspberry-Pi
- Raspbian: http://www.raspberrypi.org/downloads
- Graphics driver (download): http://www.airspayce.com/mikem/bcm2835/bcm2835-1.36.tar.gz
- Software for the C-Berry LCD module (download): http://admatec.de/sites/default/files/downloads/C-Berry.tar.gz
- Bitmap display and sample bitmaps: https://github.com/rheikvaneyck/CBerryDisplay
- QRMusic Script: https://github.com/rheikvaneyck/QRMusic
« Previous 1 2 3 Next »
Buy this article as PDF
Pages: 6
(incl. VAT)