Raspberry Gpio &&python

Source: Internet
Author: User

From http://www.cnblogs.com/xiaobo-Linux/p/8969324.html command line control LED light
echo >/sys/class/gpio/export Write output

cd/sys/class/gpio/gpio12/

Enter this port

The main 2 files Direction/value

Direction control output echo out > Direction/control input echo in > direction

Value control high and low level 1, 0 low echo 1 > Value lit/echo 0 > value off

Read high and low level cat value



Use Python to light a lamp.

$sudo python//start python;
>>import Rpi.gpio as gpio;//import Rpi.gpio module
>>gpio.setmode (GPIO). BCM);//Setup module;
>>gpio.setup (12,gpio.out)//Set GPIO 12 output state;
>>gpio.output (12,gpio. HI)//high-level lit
>>gpio.output (12,gpio. Low)//off-level
>>exit ()

Let the LED blink (python)
Import Rpi.gpio as Gpio//Importing module import time//Gpio.setmode (GPIO). BCM)//Set Gpio.setup (12,gpio. Out)//output Port 12while True://Wireless Cycle Gpio.output (12,gpio. High)//Time.sleep (1)//Pause 1S gpio.output (12,gpio. Low)//Time.sleep (1)//pause 1s led flash blind (Python)
Import Rpi.gpio as Gpioimport timeimport math Gpio.setmode (GPIO. BCM) Gpio.setup (18,gpio. Out) Gpio.setup (21,gpio. Out) Gpio.setup (22,gpio. Out) Gpio.setup (16,gpio. Out) Gpio.setup (12,gpio. Out) Gpio.setup (23,gpio. Out) Gpio.setup (7,gpio. Out) Gpio.setup (8,gpio. Out) for I in range (0,1): Gpio.output (18,gpio. High) Time.sleep (0.5) gpio.output (18,gpio. Low) Time.sleep (0.5) gpio.output (21,gpio. High) Time.sleep (0.5) gpio.output (21,gpio. Low) Time.sleep (0.5) gpio.output (22,gpio. High) Time.sleep (0.5) gpio.output (22,gpio. Low) Time.sleep (0.5) gpio.output (23,gpio. High) Time.sleep (0.5) gpio.output (23,gpio. Low) Time.sleep (0.5) gpio.output (12,gpio. High)
 time.sleep (0.5)     Gpio.output (12,gpio. Low)     Time.sleep (0.5)     Gpio.output (16,gpio. High)     Time.sleep (0.5)     Gpio.output (16,gpio. Low)     Time.sleep (0.5)     Gpio.output (7,gpio. High)     Time.sleep (0.5)     Gpio.output (7,gpio. Low)     Time.sleep (0.5)     Gpio.output (8,gpio. High)     Time.sleep (0.5)     Gpio.output (8,gpio. Low)     Time.sleep (0.5)     Gpio.output (8,gpio. High)     Time.sleep (0.5)     Gpio.output (8,gpio. Low)     Time.sleep (0.5)     Gpio.output (7,gpio. High)     Time.sleep (0.5)     Gpio.output (7,gpio. Low)     Time.sleep (0.5)     Gpio.output (16,gpio. High)     Time.sleep (0.5)     Gpio.output (16,gpio. Low)     Time.sleep (0.5)     Gpio.output (12,gpio. High)     Time.sleep (0.5)     Gpio.output (12,gpio. Low) &nbsP   Time.sleep (0.5)     Gpio.output (23,gpio. High)     Time.sleep (0.5)     Gpio.output (23,gpio. Low)     Time.sleep (0.5)     Gpio.output (22,gpio. High)     Time.sleep (0.5)     Gpio.output (22,gpio. Low)     Time.sleep (0.5)     Gpio.output (21,gpio. High)     Time.sleep (0.5)     Gpio.output (21,gpio. Low)     Time.sleep (0.5)     Gpio.output (18,gpio. High)     Time.sleep (0.5)     Gpio.output (18,gpio. Low)     Time.sleep (0.5) while true:    Gpio.output (18,gpio. High)     Time.sleep (0.01)     Gpio.output (18,gpio. Low)     Time.sleep (0.01)     Gpio.output (21,gpio. High)     Time.sleep (0.01)     Gpio.output (21,gpio. Low)     Time.sleep (0.01)     Gpio.output (22,gpio. High)     Time.sleep (0.01)     Gpio.output (22,gpio. Low)     Time.sleep (0.01)     Gpio.output (23,gpio. High)     Time.sleep (0.01)     Gpio.output (23,gpio. Low)     Time.sleep (0.01)     Gpio.output (12,gpio. High)     Time.sleep (0.01)     Gpio.output (12,gpio. Low)     Time.sleep (0.01)     Gpio.output (16,gpio. High)     Time.sleep (0.01)     Gpio.output (16,gpio. Low)     Time.sleep (0.01)     Gpio.output (7,gpio. High)     Time.sleep (0.01)     Gpio.output (7,gpio. Low)     Time.sleep (0.01)     Gpio.output (8,gpio. High)     Time.sleep (0.01)     Gpio.output (8,gpio. Low)     Time.sleep (0.01)     Gpio.output (8,gpio. High)     Time.sleep (0.01)     Gpio.output (8,gpio. Low)     Time.sleep (0.01)     Gpio.output (7,gpio. High)     Time.sleep (0.01)     Gpio.output (7,gpio. Low)     Time.sleep (0.01)     Gpio.output (16,gpio. High)     Time.sleeP (0.01)     Gpio.output (16,gpio. Low)     Time.sleep (0.01)     Gpio.output (12,gpio. High)     Time.sleep (0.01)     Gpio.output (12,gpio. Low)     Time.sleep (0.01)     Gpio.output (23,gpio. High)     Time.sleep (0.1)     Gpio.output (23,gpio. Low)     Time.sleep (0.1)     Gpio.output (22,gpio. High)     Time.sleep (0.01)     Gpio.output (22,gpio. Low)     Time.sleep (0.01)     Gpio.output (21,gpio. High)     Time.sleep (0.01)     Gpio.output (21,gpio. Low)     Time.sleep (0.01)     Gpio.output (18,gpio. High)     Time.sleep (0.01)     Gpio.output (18,gpio. Low)     Time.sleep (0.01)       python definition
The function descriptor int (x [, Base]) converts x to an integer. The cardinality is specified as base, if X is a string. Long (x [, Base]) converts x to a long integer. The cardinality is specified as base, if X is a string. Float (x) converts the x to a floating-point number. Complex (real [, Imag]) creates a complex number. STR (x) Converts the object x to a string representation. Repr (x) object x is converted to an expression string. eval (str) evaluates a string and returns an object. Tuple (s) converts s to a tuple. List (s) converts s to a list. Set (s) converts s to a collection. Dict (d) Create a dictionary. D must be the (key, value) tuple sequence. Frozenset (s) converts s to frozen set. Chr (x) integers are converted to one character. The UNICHR (x) integer is converted to a Unicode character. Ord (x) converts a single character to an integer value. Hex (x) converts an integer to a hexadecimal string. The OCT (x) converts integers to strings that are eight-binary.



1. Install python$ sudo apt-get install python-dev copy Code 2. Execute update $ sudo easy_install-u distribute copy code 3. Installing python-pip$ sudo apt-get Install PYTHON-PIP Copy code 4. Installing Python's Gpio library $ sudo pip install rpi.gpio copy Code

Raspberry Gpio &&python

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.