The previous chapter showed that the BeagleBone Black board is designed to accept hardware add-ons called capes and how they ease the setup of projects. We can apply the same philosophy to the software part, thanks to the different tools that help developers. Now, in this chapter, we will go further with our hands-on approach by creating our applications.
You'll then have an overall view of how you can realize your own ideas without many difficulties. Thus the main purpose of this chapter could be resumed as:
Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime
I hope that you'll be more eager to develop projects by yourself afterwards.
In this chapter, we will cover the following topics:
This project aims to connect a matrix to the BeagleBone board so that it can be remotely accessed through a network connection. For this purpose, you will program the following parts:
This project allows you to approach the following technologies:
git
command. As you have already used Git in the previous chapters, you know that with a simple command you are sure to work with the last changes (corrections, improvements, fixes, and so on) from the author. The dedicated site can be found at http://dlewin.github.io/BeagleboneBlack-Server-Book, as shown in the following screenshot:git
from the command line of your board:git clone https://github.com/dlewin/BeagleboneBlack-Server-Book.git
Now that you know what you are going to play with, we'll mix these technologies in three flavors, elaborating in a progressive manner. Obviously, this implies that you need some additional knowledge but rest assured that it will be explained sufficiently. Having said that, you need to be at ease with the example and its concepts before you go to the next step.
The graphical representation of this project will be a matrix of LEDs that Adafruit has arranged in a very handy product, and there is no need to for additional components such as resistors, power circuits, and so on: the box contains all that is required to start quickly.
You can get more details from their website at http://www.adafruit.com/products/902.
When you receive it, you just need to solder some pins as indicated in the Adafruit documentation and it's ready to be used. As shown in the presentation, the messages between the matrix and the BeagleBone Black board use a form of the I2C protocol. Let's look how it works.
Whichever board you use in your projects—Arduino, Raspberry, Mini2440—most of the time, you need to deal with sensors, components, or devices that "talk" I2C or SPI. These data buses simplify our coder's life. Indeed, our matrix just need to be managed with only two signals, SCL and DAT, to execute all the operations.
Instead of a wire for each function, a communication is specified by Philips on the two wires with the protocol part of the I2C. Fortunately, this happens behind the scenes, thanks to the I2C Linux driver.
Are you interested in getting more details about the I2C bus? Check out http://support.saleae.com/hc/en-us/articles/200730905-Learn-I2C-Inter-Integrated-Circuit for an interesting explanation.
Using the driver means that, even though you use the I2C protocol, you never have to deal with the bus message frames, CRC, and all the detail of the protocol, so you can focus on the data to be sent from BeagleBone to the matrix.
After this short introduction to the I2C protocol, we can now set up the connection between the two devices, as shown here:
This image is not a drawing. You can obtain the source file from the GitHub website as a design file in order to use it with Fritzing (http://fritzing.org/home/), an open source electronic design software.
Assuming that the matrix is now built, we can wire the matrix according to the following schema:
The synoptic is easy to understand: just wire the four pins to the board. However after this, if you want to access the complete header's reference, check the header documentation provided by the BeagleBone Wiki at http://elinux.org/Beagleboard:Cape_Expansion_Headers.
For our experiments, we use the I2C-2 because the device's tree file defines that the I2C-1 is already used.
Usually, you should ensure that the function pin you intend to use is free.
This subject is outside the scope of this book and requires you to understand the device tree mechanism. A complete explanation can be found in the Free Electron presentation at http://free-electrons.com/pub/conferences/2013/elce/petazzoni-device-tree-dummies/petazzoni-device-tree-dummies.pdf.
As BeagleBone Black was the first to follow the recommended guidelines, our board is used as an example along with the explanation, which is handy.