Beaglebone_black_ Study notes-(8) Key for GPIO input

Source: Internet
Author: User

Today I wrote a gpio as an example of input port on the basis of LED light. In the experiment, I use a key as IO input device, then use Bb_black to collect the current information.

First Step: Hardware introduction

1, Key introduction

Touch the structure of the keys as shown, the keys of the feet, 3,4 feet are connected together, when the button is the 1,3 (or 2,4) pin short connection, loosen the open between two feet.

2. Hardware principle

Note:

(1) In order to prevent misoperation, 3.3V will burn the IO port The author has connected a current limiting resistor (10k) between the key and the 3.3V;

(2) The author of this experiment used the 14-pin of the P8 row seat, which is the gpio_26 pin.

3. Hardware connection

I use the button is removed from the scrap board, welded two lines, two lines of the other end of the direct welding pin, welded parts with heat shrinkable tube to hold, in doing a variety of development when used up very simple and practical.

Step Two: Software code

1, first look at the first part of the code

1#include <stdio.h>2 #defineGpio_dir "/sys/class/gpio/"3 4 intMain ()5 { 6FILE *stream=NULL;7     Chara[Ten]; 8Stream=fopen (Gpio_dir"Export","W");9 TenFwrite" -",sizeof(int),2, stream);  One fclose (stream); A  -  -Stream=fopen (Gpio_dir"gpio26/direction","r+");  theFwrite"inch",sizeof(Char),2, stream);  - fclose (stream); -      while(1)  -     {  +Stream=fopen (Gpio_dir"Gpio26/value","r+");  -FSCANF (Stream,"%s", a);  +printf"%s\n", a);  A fclose (stream); atSleep1);  -     } -  -     return 0;  -}

2. Experimental results:

Beaglebone_black_ Study notes-(8) Key for GPIO input

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.