This is the chapter web page to support the content in Chapter 6 of the book: Exploring BeagleBone – Tools and Techniques for Building with Embedded Linux. The summary introduction to the chapter is as follows:

This chapter integrates the Linux, programming, and electronics groundwork from earlier chapters to show you how to build circuits and write programs that interface to the BeagleBone’s single-wire inputs and outputs. In this chapter, you will see practical examples that explain how to use a general-purpose input/output (GPIO) to output a binary signal to switch on an LED, or to read in a binary input from a push button. Also included are the steps required to read in an analog input and to send out a pulse-width modulated (PWM) output. Interfacing to GPIOs is a reasonably complex topic due to a recent change incorporated into the Linux kernel. However, the BBB has cape management features, and code is made available throughout this chapter that you can use to make interfacing reasonably straightforward.

Learning Outcomes

After completing this chapter, you should be able to do the following:

  • Use a BBB GPIO to output a binary signal to a digital circuit, or read in a binary input from a digital circuit.
  • Write shell scripts and C++ code in order to control a BBB GPIO.
  • Describe the use of internal pull-up and pull-down resistors.
  • Write a Linux device tree overlay that can configure the BBB’s P8 and P9 header pins to suit your application needs.
  • Use a BBB PWM pin to output an analog voltage or as a control signal for motors and certain types of servos.
  • Use a BBB analog input to read in a value from an analog circuit, using an op-amp to protect the BBB from damage and/or invalid measurement.
  • Write C++ code, which utilizes advanced functionality, to efficiently read in a digital input using a custom GPIO
  • Use a GPIO-KEYS device tree overlay to create a Linux virtual keyboard device using GPIO inputs.
  • Use an advanced Linux configuration that allows for user-level control of the sysfs GPIO entries.

Updates for Debian (2015-03-01 Release)

The first minor change relates to the discussion on pg. 223. As a result of this update, the PINS environment variable can only be set as superuser. Regardless, you can set the environment variable and use sudo cat $PINS to get the output that is described on pg. 224.

As described on the Chapter 3 web page, the location of uEnv.txt has moved in this release to /boot on the main Linux partition. Therefore, to disable the HDMI overlay as described on pg. 225 you must use:

In addition to allow for ease of upgrade of kernel, the dtb files have been relocated from /boot/uboot/dtbs (as described on pg. 221) to /boot/dtbs/3.8.13-bone70.

The default overlays are no longer available in the /lib/firmware directory but they still function correctly as described in the book. For example (under 3.8.13-bone70):

Digital Media Resources

Here the digital resources referred to in the chapter web page. There are high-resolution versions of some of the key figures and links to important videos that are described in the chapter.
BeagleBone P8 Headers

The BBB P8 Header

BeagleBone P9 Headers

The BBB P9 Header

BeagleBone Black Header Charts

Figure 6-6 and Figure 6-7 from Chapter 6 are available for download as a high-resolution PNG raster format and a high-resolution PDF vector-mapped format using the following links:

These are high-resolution images that can be displayed and/or printed in color. The PDF version can be scaled to a format that suits your needs.

Figure color key:

  • RED — pins are already allocated (e.g., to HDMI or eMMC). See Chapter 6 for information on how to re-allocate these pins. Do not use these pins without re-allocating them.
  • GREEN — pin mode is for enhanced GPIOs for the PRU-ICSS (see Chapter 13)
  • BLUE — pin mode is for UART functionality on the PRU-ICSS

There is a note on page 226 about loading custom overlays on boot. There is now a script workaround to this issue by editing the /etc/default/capemgr file and adding a line such as: CAPE=EBB-GPIO-Example

The BealeBone GPIOs – Using Device Tree Overlays

In this video I demonstrate how to use the BeagleBone’s GPIOs for both input and output applications. I wire simple input and output circuits that are attached to two GPIOs — one that lights an LED and the other that receives a button input. This video covers the Linux device tree for ARM embedded systems and explain how you can create custom Device Tree Overlays (DTOs) to configure the GPIOs for your applications at run time from within Linux userspace.

Additional PWM Example

There is a full description of PWM on the BeagleBone, but only a code segment is provided to describe how you can use the PWM class that has been added to the library. To rectify this I have added another PWM example to the GitHub repository in the directory exploringBB/chp06/pwm. The code example is:

To use this example you must perform the following steps:

  • You must load the overlay for the PWM overlay
  • You must load the am33xx_pwm overlay
  • You must edit the code example above to have the exact name that appears on your board. You can see below that this is pwm_test_P9_42.12.

So, for example, the steps are:

Source Code

The full source code listing for this chapter is available in the GitHub repository directory exploringBB/chp06. There are the important source code listings for this chapter, which describe how you can interact with a GPIO using a custom class and how you can interact with the GPIOs using a Bone-Keys device:


  • Page 246. At the top of the page “P9_15(GPIO49)” should be “P9_15(GPIO48)”. It is correct in all other locations.
  • Page 247(Loc 7296). There are three ‘-‘ characters when there should be two ‘-‘ characters in three locations, in front of ‘path’, ‘attribute’, and ‘action’ on the command calls to udevadm.