Chapter 3. Blinking External LEDs

In the previous chapter we programmed onboard LEDs on BeagleBone using BoneScript APIs. As BeagleBone is an embedded device, it can be used in an environment where a keyboard, mouse and monitor might not be available. Rather, most of the times embedded boards do not have these devices. Typical input and output components of embedded boards are LEDs and push-buttons. LEDs can be used as the output device to represent information, for example the board may turn an LED on when there is high system load and turn it off when the system load is low. So, by looking at LEDs we get information about if the system is under high load or not. That is why it is important to program LEDs on BeagleBone so that we can send information as output via LEDs where the monitor is absent. In this chapter, we will continue to program LEDs. We will connect external LEDs and blink them using our BoneScript program. To achieve this, we need to learn about GPIO on BeagleBone.

Here are the topics that will be covered in this chapter:

  • What is GPIO?
  • BeagleBone GPIO map
  • Blinking external LED circuit setup
  • Program to blink external LED
  • Dancing external LEDs circuit setup
  • Program to dance external LEDs

What is GPIO?

The BeagleBone processor AM335X has several pins to communicate with outside chips and components. Some of these are dedicated pins to communicate with the DDR memory chip on BeagleBone. These pins are permanently connected to a memory chip. You cannot attach other components or chips to these pins. The same holds true for the processor's JTAG pins, USB pins, Power IC connection pins, etc. These pins have a fixed role of communicating with respective components/chips. These types of pins dedicated to communicate with single component/chip are specific purpose pins. Users do not have control over these pins individually. The processor with all its pins as specific purpose pins becomes rigid. It becomes less flexible to attach new components and program them.

To provide flexibility to adopt components outside the board, some of the digital pins on the processor are not given any specific role. Users are given the power to control each one of them via software. These pins with no specific role are called GPIO (General Purpose Input Output). The following features define a digital pin as GPIO:

  • The user can enable or disable it by program. This can be done at run time.
  • The user can set the direction of a pin as input or output according to the type of attached component. Only one direction can be active at a time. Once selected, the pin will operate in that direction only. The user can change direction at run time. We have seen the function PinMode() in the previous chapter, which sets the direction.
  • When the direction is set as output, the GPIO pin can be set as HIGH or LOW. Accordingly, the connected chip/component gets turned on or off. Changing the pin as HIGH and LOW in pattern can send digital data or control signals through the pin. We have seen the function digitalWrite()to write on an output pin in the previous chapter.
  • When set as input, a GPIO pin reads digital signals coming from a connected component/chip. It can be HIGH or LOW. Digital data or control signals can be interpreted based on HIGH and LOW patterns collected over time. Often processor interrupt (irq) is configurable when GPIO work as input. We will learn about GPIO input in the next chapter.

The user can attach various digital components to a GPIO pin like external LEDs, buttons, buzzers, relays, and so on. They allow the connection of components that are not a default part of the board, for example BeagleBone does not come with an infrared sensor. But you can attach an infrared sensor to a GPIO pin and capture infrared signals.

GPIO is a feature provided by a processor. Embedded board manufacturers might use some of the available GPIO pins for specific purposes like showing status via LEDs, monitoring SD card insertion/removal, resetting an external chip, for example the onboard USER3 LED on BeagleBone is actually connected to processor pin GPIO1_24. Drivers to handle GPIO pins are written generically. At the time of booting, the BeagleBone hardware description device tree file informs the kernel that GPIO1_24 is actually an LED. We will learn about the device tree in detail in the Appendix C, Pinmux and the Device Tree. Even after using some GPIO pins for a specific purpose, BeagleBone has plenty of GPIO pins left to be controlled by the user. Let's see how BeagleBone gives us access to GPIO pins and how to program them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.50.222