Beaglebone Black Lessons four innings: simple LED control experiment

Source: Internet
Author: User
Tags echo command

BBB lesson four innings: simple LED control experiment

Learn the BBB board ultimate goal is to do the same with the imagined microcontroller control. But control is not the same idea at all (Linux in essence, the control of hardware devices, read and write under the device related to virtual files), the study of the days of the head is big or no progress. Guest articles. There is no unified statement, it is expected that the BBB board of different years. and the installed version number of the system is different.

Finally, choose an example from the most basic single command control IO interface to start.

Reach target: Output 0 or 1 from GPIOportP8.12 and P8.11 pins

This class uses two commands, Cat and Echo, with a lot of detailed usage online. The simplest understanding: cat is used to view the value of a file (variable), and Echo is used to write a file (variable) value.

The Operation IO Port is a series of read-write operation to the file under the/sys/class/gpio folder, because the Gpio driver is loaded by default, so it does not need to be loaded into device tree, which can be done later.

Simply explained, the/sys folder contains the system kernel and driver-related content, it is a virtual file system, the file system folder structure is essentially the kernel object model tree. We are able to read and write the files here to achieve the operation of the device.

As to what files are in each device. The effect of which files are manipulated or defined by the device driver.

After the system is powered on, the/sys/class/gpio folder has only a few default files folders. BBB board a total of more than 100 available gpioport and not a list, Linux under the control IO port is read and write Io file, so first the corresponding Gpio file to find out, in fact, through the echo command to control the need to set the gpioport to a usable state,/ Sys/class/gpio folder will be able to display the relevant files (simple understanding is that the original port control file stealth. Show it through the echo command)

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhv5zwppztg4odg=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

1. Using P8.12 pin to control LED light

Perform echo > Export under the/sys/class/gpio folder, meaning P8.12 is set to the available state

This "44" number is through the "BBB Pin function speed Check table". Find P8.12 The corresponding gpio.no is 44

Run this command before querying the current folder file. A gpio44 folder will appear:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhv5zwppztg4odg=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Prepare a small LED. Two lines, universal board (no also OK, can connect the light can), I use here is p8.12port,p8.2 negative side.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhv5zwppztg4odg=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Use Dir to list the 7 files under the Gpio44 folder. The "direction" is the set port for input in or output out of the file (parameters), "value" is the port value 0 or 1 (low or high), we directly read and write these two files can be.

Use the cat command to view the current value and then change it to the required value by using the Echo command. Note the command uses formatting. As a result of this simple experiment, the indicator light is illuminated and the lamp operation is done. So "direction" is set to out. Using the command catdirection to view the original value as in, use the command echo out > Direction set to Out.

The diode light can then be lit or switched off by changing the value of the values.

Input: Echo 1 >value light on

Input: Echo 0 >value light off

The process feels very easy, but it is very difficult to understand.

Only can understand the character Terminal Mode command operation, clear the control principle of the ability in C programming in the easy.

2. Using P8.11 pin to control LED light

Perform echo > Export under the/sys/class/gpio folder. It means to set the P8.11 to a usable state.

This "45" number is the same as the "BBB Pin function speed Check table". Find P8.11 The corresponding gpio.no is 45

Run this command before querying the current folder file. A gpio45 folder will appear:

The control process is the same, it is no longer written. Take a few pictures to see the next.


3, through the experiment we must be clear points:

A Controls the Gpioport output of the BBB board by 0 or 1. The value of the value file under the corresponding gpioxxx under the/sys/class/gpio folder is changed.

B Change the Gpioport input and output mode is to change the/sys/class/gpio folder under the corresponding gpioxxx under the direction file value is in or out

C The entire BBB board hardware Device control by reading and writing the corresponding Linux device virtual files, so learning BBB board file Structure system is very important

D Know the correct use of the BBB Pin function quick Check table

E. As in this experiment, the operating Gpioport drive is loaded as the system is default. So there is no need to load the device tree for operation, however, other analogy ADC, UART must be in the relevant loading device tree before the interface is operated. This device tree I am now also very vague concept, after further discussion.

F. Learn to use cat and Echo commands flexibly

Beaglebone Black Lessons four innings: simple LED control experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.