BeagleBone Media Center (2015)
Chapter 5. Building Your Media Player
As shown in the previous chapters, the BeagleBone Black board can do much more than provide media and services. It can be adapted to a wide range of projects you have in mind. Moreover, we'll see how this board differs from others with respect to design. You'll be introduced to the concept of add-ons, so you will know how to choose a functional brick that can be used in one of your projects. At the end of this chapter, you'll see how to get your project up and running. This is the chapter where we can have some fun, so let's get our brain on fire!
In this chapter, we will cover the following topics:
· Introducing BeagleBone capes
· Your own media player in your hands
· Installing a system for the expansion board
· Using the expansion board with Android
Introducing BeagleBone capes
In the first chapter, we said that the richness of a system relies mainly on its ecosystem. For example, the OS of a computer, such as Windows, Mac OS, or Linux, can be used not only for the graphical interface but also for the wide range of applications that you can install. This is quite similar to the embedded world, where a large choice of boards might confuse you quickly; you need to choose a CPU, OS, supported applications, programming languages that can be used on it, documentations, and so on. The list can be quite long depending on your final project.
A good criterion to look out for in a board is its expansion capability: the feature where one can add some more functionality to a board, such as plugins to software. In this sense, our board has a lot of features to propose. In the BeagleBone world, these add-ons are called capes.
Here's a definition of capes according to the creators of BeagleBone:
Adding cape plug-in boards to the popular BeagleBone computer allows hobbyists, makers and developers to quickly and easily augment BeagleBone's capabilities with LCD screens, motor control and battery power as well as the ability to create their own circuits
This hardware openness lets you add functional boards, as you'd do from the application markets (the Apple store, Google Play, and so on) and thus enables you to add any functionality for your projects. You just have to plug your cape onto the two expansion connectors so that it is directly powered and recognized by the system. For a good overview, take a look at the capes' wiki page, available at http://elinux.org/Beagleboard:BeagleBone_Capes.
Here, you will find documentations and presentations from professionals and hobbyists who have designed capes.
Exploring capes' categories
At the beginning of BeagleBone Black, the Wiki was composed of 20 capes that weren't compatible with the Black series. At the time of writing this book, this list has grown to 77 capes with 51 capes for BeagleBone Black; this gives us an idea of the community's effort behind this market. Here's an extract:
It's not possible to group all the capes in distinct categories, as some of them are conceptual. Anyway, to give you an idea, these capes mostly propose the following features:
· Power (PowerBar and the Power Supply cape are useful for autonomous projects)
· Displays (mini displays, LCD3, LCD4, and LCD7)
· An extension board with a display (4D capes)
For the others/miscellaneous category:
· Crypto cape: A very interesting cape that you can use to add serious security measures to your server or your applications. According to the author:
This cape will offload the CPU for cryptographic operations (usefully for a networked device that makes heavy use of VPN/TLS/SSL). It can also be used to enhance the security of an existing project with hardware RSA, ECC, SHA-2, a RTC, additional EEPROM
· Prototyping (breadboards, protoboard).
· "All in one," which includes different functionalities, sensors or actuator drivers such as the GVS cape (GVS stands for Ground, Voltage, and Signal).
· Robotic and I/O (Robocape, industrial I/O cape).
· ADC, PWM, Analog, dual relays, smart relays.
· Interfacing capes (for Arduino shield, mikroBUS).
No matter what you choose, before considering a cape you must look for the BB Black Compatible logo, as shown here:
This guarantees that the cape you buy will work with your board.
Considering a personal Palm Media player
This part of the chapter deals with how you can build a media player for yourself using the concept of capes, which you've just been introduced to. From the long list of available capes, we'll use the BeagleBone Black Expansion board from Chipsee.
From the two versions of this expansion board—resistive and capacitive—we will use the capacitive version, which has a five-point multitouch.
If you take a look at the functionalities that this expansion board proposes, it will give you an idea of why this is more than a display:
· A 7-inch screen with a resolution of 1024 x 600 pixels
· Capable of 5-point detection
· One audio out and one mic in
· Two RS232 ports
· One RS485 port
· Two analog channels
· 1 CAN port
· 1 integrated buzzer
· Five user keys
· Two user LEDs (green and blue)
· One embedded 3-axis accelerometer
On the reverse side of the board, you can see the following components (also shown in the following screenshot):
1. A multifunction connector with communication, acquisition, and power connections. You'll find the same signals from COM1 (Tx, Rx) and an additional COM port UART2 that is shared with RS485 #1, an additional port RS482 #2, and finally a Control Area Network (CAN), which is a network designed to be used in industrial conditions.
2. The COM1 serial port, which has been changed from its original implementation. The provided systems are configured to debug to UART1 instead of UART0 on the BeagleBone, including a hardware driver. This implies that you can directly connect a serial terminal to the DB9 connector.
3. Power and reset buttons (coming from BeagleBone for accessibility).
5. JTAG connector.
6. P8 header.
7. P9 header.
8. Audio output/microphone input (blue- and rose-colored, respectively).
9. The boot switch, which allows you to choose between the SD card (up) or eMMC boot (down).
10. Power: 5V/2A DC input is used for BeagleBone as for all the expansion board's needs. You don't need any additional adapters.
On the front side (from up to down), the board consists of the following:
· 5 programmable user's keys: With Android, they are associated with the home screen and the back, menu, volume up, and volume down buttons
· Blue LED: This denotes CPU activity in the Android OS
· Green LED: This denotes power in the Android OS
Installing a system for the expansion board
Chipsee provides different operating systems that you can install to start and manage the display. Having a look at these different OSes will help you to choose the one that will fit your project best.
Looking at the available operating systems
Chipsee proposes a wide range of operating systems, which are provided in the following table:
This is versatile and ergonomic and has a large market to offer
This is unsuitable for embedded boards' customization
This offers rich apps and is documented and open source
The provided version is more desktop- or server-oriented
TI Linux EZSDK
This is vastly documented, good for exploration and learning, and designed for embedded apps
This is not for beginners and has a non-negligible learning curve
We will now look at how to install Android, Debian, and EZSDK and finally see how Android can be used for some multimedia experiences.
Retrieving the latest files, images, documentation, or software
Even if you are provided with two CD-ROMs that include the documentation, user manual, and software, it's better to download the latest versions delivered by the manufacturer at http://chipsee.eu/index.php?option=com_jdownloads&Itemid=204&view=viewcategory&catid=18.
You can install Android USB drivers for the Windows platform. These drivers are located at YourRoot:\Chipsee\Android4.2\Android4.2\SoftWare\Tools\usb_driver.
The installation is straightforward for any driver. You will end up with a new Android phone device. This way, you are able to use it as a disk.
Prerequisites for installing any system
Before going into the OS installation, we have to check some things, such as the SD card naming, and we have to set the local language.
Considering a virtual machine
All the following explanations are for installation from Linux as a native operating system. You can install directly on your computer or you can use a virtual machine as well. If you want to make some developments or try some different projects, a VM is the best solution. Similar to a Python virtual environment, which we have seen in Chapter 4, Getting Your Own Video and Feeds, virtual machines give you the freedom to experiment with everything you want without losing your system.
There are many free virtualization managers that you can install; these are the most famous ones:
· VirtualBox (https://www.virtualbox.org/): This is easy and fast to configure.
· VMware (player) (http://www.vmware.com): This is as easy as VirtualBox but has some limitations in the free version.
· QEMU (www.qemu.org): This is harder to configure than the two previous ones, but the only one that comes close to hardware emulation. This solution is recommended when you don't have your ARM board with you but still need to use it.
In addition, VirtualBox and QEMU are open source applications, so you will have additional tools proposed by their respective communities.
Finding your SD card device
All the scripts provided are simple enough to require a single parameter: the SD card device's name. Let's see two ways to check the SD card device's name.
You won't see the device until the SD card is effectively inserted, and not just the USB reader.
Listing devices with lsblk
For example, after inserting an 8-GB SD card, we can use lsblk, a useful tool that is provided with our Linux distributions (http://linux.die.net/man/8/lsblk). The name stands for list block devices, so you have a tree of all the block devices that Linux is able to manage.
Just start lsblk from the command line, as shown here:
Depending on the size we are looking for and the device type, we can deduce that our SD card is currently sdf.
Using the dmesg utility
Remember in Chapter 4, Getting Your Own Video and Feeds, we looked into the system messages to find how our USB webcam was named. Here, we use the same recipe:
dmesg | grep 'sd.'
While being verbose, dmesg ensures that you format the correct device.
Checking your investigation
In all cases, ensure that you are using the correct device to partition:
fdisk –l /dev/sdf
With a new card, this command should return the following line of code:
/dev/sdf empty table partition
Adapting foreign systems for the installer script
If you execute the provided installation scripts from a non-English speaking system, you will end up with a nonbootable BeagleBone. This is because the installation scripts rely on text searches and matches. For example, in French, instead of the term "disk" and "cylinders," the results will be "disque" and "cylindres," respectively. These are results that the script doesn't understand, and in the end no system will be properly installed.
A simple workaround for Debian systems is to edit your locale file, as follows:
If, however, you'd like to keep the original language, then comment it with # at the beginning, use the script, and uncomment it thereafter.
Save the file and reboot to have the settings applied.
Installing your system
Now, it's time to prepare the expansion board and to install an operating system. We'll go through the three main OSes; the processes for each one are similar. However, for beginners, we will describe which file to install.
Installing and using Android
After you have downloaded the compressed Android file on your, you need to copy it to a dedicated directory. This is can be handy, so you can install all the three OSes beside each other in a separate space. So, if you are not really happy with Android, you can try Debian and get back to Android by a simple installation command.
Here's the procedure to do this, which is quite simple:
tar vzxf prebuilt-jb42-bbb-exp-20140321.tar.gz
sudo fdisk -l /dev/sdf
sudo ./mksdcard.sh --device /dev/sdf
The 3rd part is just a check for you to be sure that you don't format your computer.
When installing Android, you need to validate the installation by pressing the Y key so that the installation process starts:
Wait for the Done message, which notifies the end of the installation process. Plug your SD card into the BeagleBone board and power it on.
Remember to press the user button to tell the board to start using SD not eMMC. This button is located on the other side of the SD card slot.
You will have to wait for a while for the boot to be achieved, which is particularly long for Android compared with the others. However, our comfort comes at this price, doesn't it?
If you want, go directly to a walkthrough with Android; skip the next parts until the Using the expansion board with Android section.
Installing and using Debian
As we did for Android, you can define your boot disk with some easy steps (please remember that sdf is an example; you need to check your own SD card device's name):
tar vzxf prebuilt-debian-bbb-exp-20140322.tar.gz
sudo fdisk -l /dev/sdf
sudo ./mksdcard.sh --device /dev/sdf
As for Android, when installing Debian, you are asked to validate your choice before you start the installation process, as shown in the following screenshot:
This will take a while; wait until the Done message appears.
The connection and usage is pretty straightforward; we find the system that we had in the previous chapters with MediaDrop. With Debian, you will have fewer things to learn and you can install it finally. When you think about which system to install, this is something for you to consider.
All in all, a good idea can be to install MediaDrop and servers to the Debian OS with the Chipsee display, so you can have all the servers and a media player as well.
From SSH, the credentials to connect to the Debian OS are as follows:
· User: debian
· Password: chipsee
Installing and using TI EZSDK
Texas Instruments is the manufacturer of the BeagleBone Black controller. Actually, they did a great job of giving exhaustive documentation and even their own version of Linux dedicated to this board. TI's version is for those who want to learn the hardware parts. Execute the following commands:
tar vzxf prebuilt-chipsee-bbb-exp-ezsdk-20131210.tar.gz
sudo fdisk -l /dev/sdf
sudo ./mksdcard.sh --device /dev/sdf
After the board is powered on with the user button, a nice Linux and TI's logo will make you wait for a bit to load the special environment called a matrix.
Here's a compilation of the main application spaces you will find in Matrix:
Taking a look at TI's linux unique tools
After starting, you'll find the app launcher, a kind of desktop that centralizes all the available applications:
· Profiling (up left): Examples for process, reports, and kernel profiling.
· Benchmarking (up right): NBench (from the Byte magazine), linpack (single precision tests), Dhrystone, DDR, pipe communication's bandwidth, memory latency, Whetstone, latencies (fork, signals, TCP servicing, and so on).
· Qt4/QML (down left): Qt Quick Playground which is great for the QML developers. In this group are many examples to test in this script language.
· Qt4: There are 3 demos Animated Tiles, Thermostat Demo (down right), and Deform.
· Cryptos: Examples for everything concerning cryptography from secure, server, to AES, SHA1, and OpenSSL benchmarking.
· Multimedia: Audio, MPEG4, and H264 decoding applications.
· Power: Set your CPU frequencies: 275 to 720 MHz, suspend/resume.
· There are more applications to explore, paying particular attention to settings/system Shutdown, which is handy to power off the system.
For the complete documentation and explanations about the SDK and information on the AM335x microcontroller, a good source will be http://software-dl.ti.com/sitara_linux/esd/AM335xSDK/latest/index_FDS.html.
I think http://processors.wiki.ti.com/index.php/Sitara_AM335x_Portal will be a good place to visit if you need to do the following:
· Get into the controllers' details
· Develop applications, as follows:
· Bare metal look for the composer studio, which is a complete development environment
· Training lab materials
· Training slides
Developing with Qt
TI' SDK is provided with a good amount of Qt sources and documentations.
If you take a look at the Qt archive, you'll see three documents, as shown here:
· Start with the user program: This is, in fact, a bash script that is worth taking a look at for GPIO usage
· User Guide For Embedded Qt: This shows you how to prepare, install, cross-compile, and get your application in the Matrix environment
· Recalibrate the resistive touch: This is the whole procedure for screen calibration
Aside is the Example-applications.zip file, which includes all the application sources you found in Matrix. These examples are for developers who already have a good technical background:
The examples.tar.gz file includes demos and examples that you find with all Qt installations, so they are all well-documented.
For more details about coding, these sources are strongly recommended.
Using the expansion board with Android
With the installation completed, we will now use the expansion board as if it were a customized tablet.
Using files from a computer
You have many options that you can use to exchange files, as follows:
· USB devices: Using the expansion board as a device, like a disk (see the Installing drivers section earlier in this chapter).
· USB keys: These can be used to get files from/to a computer and BeagleBone. The best way to have these recognized is to use the FAT32 filesystem. When the stick is plugged in, a styled Android logo appears, telling you that this new media is under analysis.
You can install applications to the expansion board in many ways; here are a few examples:
· By manually copying the APK file to the SD card in the data directory and installing it from the provided Qt file explorer. Of course, this must be done offline.
· By downloading the APK file on the USB stick and installing it from the provided Qt file explorer.
· By browsing to the application's market website. This is the most handy way to have your application installed; however, this implies that you have Wi-Fi through a USB dongle and you have referenced your Google account in the settings panel.
For example, here is a screenshot that you would see during the SSHDroid SSH server installation:
This little software is handy if you want to use the same SSH connection you had when communicating with Debian previously.
Of course, the Chipsee expansion board can also be used as a game console, thanks to the included accelerometer.
The prebuilt image includes many games you can play such as NFS Shift, A tilt 3D labyrinth, Angry birds, Fruit slice, and more. Here's a compilation:
What is cool about this board is that the 3-axis accelerometer can be used for the games. However, before you do that, you need to configure it by performing the following steps:
1. Start Chipsee Touch to calibrate the screen.
2. Start Chipsee sensor tool to define the axis properly, as shown in the following screenshot:
That way, the sensor will react properly with the board.
Watching and listening to media
On the prebuilt image, you can find some demo videos. Notice that even if there is no hardware decoder, the board is totally able to render different video formats.
To watch to a video, click on the application's group icon and then select Mobo Player.
This application is a movie player and a picture viewer as well.
You can also enter into the SD card directory—Qt file manager/Storage/sdcard1/Video—so you can play the samples provided with the prebuilt image, as shown in the following screenshot:
You can even play a video while doing something else. For this, while playing the video, select the resize icon for the video's window to be resized to a smaller dimension, as shown here:
We addressed a topic that will be very useful for most of the media projects that you'll want to implement. The Chipsee expansion board lets you create an interactive object to watch videos, play some games, program in different languages, establish network and industrial communications, and many more.
What is important to note here is that this is a good platform for creative minds. It means that you can use these hardware capabilities for your own software, such as house management, media, server, and so on. In addition, I hope that you have now understood that the time you've spent to learn the command line and the Linux system from the previous chapters have been useful here. This knowledge can be reused for your next projects, embedded or not. This is the most important thing: to learn once and then deploy multiple times.
From the BeagleBone market place, the Chipsee expansion board is just one item among many capes; you should regularly visit the capes store for new boards. These choices let you have many different combinations to be experimented with. Imagine that we were playing with a single BeagleBone and now this configuration can be a part of a network of multiple BeagleBones, each one equipped with a different cape using sensors/actuators, thus allowing you to have wider projects.
We will now abandon the hardware part of this book and continue on our journey of creativity by taking a look at the software side of the journey in the same spirit. In the end, you can have your own software.