from http://www.cnblogs.com/xiaobo-Linux/p/8969324.html
命令行控制LED灯 
echo 12 > /sys/class/gpio/export  写入输出口

cd /sys/class/gpio/ gpio12/

进入这个端口

主要的2个文件 direction / value

direction 控制输出 echo out > direction /控制输入 echo in > direction

value  控制高低电平 1高电平 ; 0低电平 echo 1 > value点亮 / echo 0 > value 熄灭

读取高低电平 cat value

用Python 点亮一盏灯

$sudo python //启动python;
>>import RPi.GPIO as GPIO;//导入RPi.GPIO模块
>>GPIO.setmode(GPIO.BCM);//设置模块;
>>GPIO.setup(12,GPIO.out)//设置GPIO 12 输出状态;
>>GPIO.output(12,GPIO.HIGH)//高电平点亮
>>GPIO.output(12,GPIO.LOW)//低电平熄灭
>>exit()

让LED闪烁(python)

 
import RPi.GPIO as GPIO //导入模块
import time   //时间
 
 
GPIO.setmode(GPIO.BCM)  //设置
GPIO.setup(12,GPIO.OUT)   //输出口12
while True:    //无线循环
    GPIO.output(12,GPIO.HIGH)  //高电平
    time.sleep(1)    //暂停1S
    GPIO.output(12,GPIO.LOW)  //低电平
    time.sleep(1)    //暂停1s
 
LED闪瞎眼(Python)

import RPi.GPIO as GPIO
import time
import 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)
    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 定义

函数描述
int(x [,base])
 
将x转换为一个整数。基数指定为base,如果x是一个字符串。
 
long(x [,base] )
 
将x转换为一个长整数。基数指定为base,如果x是一个字符串。
 
float(x)
 
将x转换到一个浮点数。
 
complex(real [,imag])
 
创建一个复数。
 
str(x)
 
转换对象x为字符串表示形式。
 
repr(x)
 
对象x转换为一个表达式字符串。
 
eval(str)
 
计算一个字符串,并返回一个对象。
 
tuple(s)
 
把s转换为一个元组。
 
list(s)
 
把s转换为一个列表。
 
set(s)
 
把s转换为一个集合。
 
dict(d)
 
创建一个字典。 d必须的(键,值)元组序列。
 
frozenset(s)
 
把s转换为冻结集。
 
chr(x)
 
整数转换为一个字符。
 
unichr(x)
 
整数转换为一个Unicode字符。
 
ord(x)
 
转换单个字符为整数值。
 
hex(x)
 
将整数转换为十六进制字符串。
 
oct(x)
 
将整数转换为以八进制的字符串。
 
 
1.安装python
$ sudo apt-get install python-dev
复制代码
 
 
2.执行更新
$ sudo easy_install -U distribute
复制代码
 
3.安装python-pip
$ sudo apt-get install python-pip
复制代码
 
4.安装python的GPIO库
$ sudo pip install rpi.gpio
复制代码

树莓GPIO &&python的更多相关文章

  1. 树莓派与 Python —— GPIO

    首先来直观地认识树莓派提供的 40 个引脚(GPIO,general purpose i/o,接收外界输入,并向外界提供运算处理后的输出): 1. 安装 从远程库(repositories)中下载安装 ...

  2. 树莓派Zero W GPIO控制

    作者:陈拓 chentuo@ms.xab.ac.cn 2018.06.09/2018.07.05 0.  概述 本文介绍树莓派 Zero W的GPIO控制,并用LED看效果. 0.1 树莓派GPIO编 ...

  3. 树莓派 Raspberry PI之GPIO

    树莓派 Raspberry PI之GPIO 树莓派各版本硬件原理图:https://www.raspberrypi.org/documentation/hardware/raspberrypi/REA ...

  4. 树莓派B+使用入门&RPI库安装&wringPi库安装

    最近看看试用一下树莓派进行一些开发操作,于是入手一块Raspberry Pi B+的板子来玩.由于没有显示器,没有备用的键盘和鼠标,所以想到用SSH来控制树莓派,刚开始还很担心已经安装好的操作系统到底 ...

  5. 树莓派进阶之路 (006) - 树莓派安装wiringPi

    安装git-core sudo apt-get install git-core 下载winringPi库 git clone git://git.drogon.net/wiringPi 编译和安装库 ...

  6. 为树莓派添加一个强实时性前端[原创cnblogs.com/helesheng]

    树莓派是最近流行嵌入式平台,其自由的开源特性以及低廉的价格,吸引了来 自全球的大量极客和计算机大咖的关注.来自各大树莓派社区的幕后英雄,无私地在这个开源硬件平台上做了大量的工作,将其打造成了世界上通用 ...

  7. node-red 安装

    介绍 Node-RED背景介绍• Node-Red是IBM公司开发的一个可视化的编程工具.它允许程序员通过组合各部件来编写应用程序.这些部件可以是硬件设备(如:Arduino板子).Web API(如 ...

  8. 树莓派高级GPIO库,wiringpi2 for python使用笔记(二)高精度计时、延时函数

    学过单片机的同学应该清楚,我们在编写传感器驱动时,需要用到高精度的定时器.延时等功能,wiringpi提供了一组函数来实现这些功能,这些函数分别是: micros() #返回当前的微秒数,这个数在调用 ...

  9. 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装

    网上的教程,一般Python用RPi.GPIO来控制树莓派的GPIO,而C/C++一般用wringpi库来操作GPIO,RPi.GPIO过于简单,很多高级功能不支持,比如i2c/SPI库等,也缺乏高精 ...

随机推荐

  1. 潭州课堂25班:Ph201805201 redis第四课 (课堂笔记)

    redis支持丰富的数据类型, 是个非关系型数据库.以键值对存储,存在内存里, : string. 字符 list.   列表 set. 集合 zset(sorted set). 有序集合 hash ...

  2. Putty 工具使用

    如何使用Putty远程(SSH)管理Linux VPS Putty是一个免费的.Windows 32平台下的telnet.rlogin和ssh客户端,但是功能丝毫不逊色于商业的telnet类工具.用它 ...

  3. spring源码分析系列 (3) spring拓展接口InstantiationAwareBeanPostProcessor

    更多文章点击--spring源码分析系列 主要分析内容: 一.InstantiationAwareBeanPostProcessor简述与demo示例 二.InstantiationAwareBean ...

  4. 【转载】jdk1.8 LongAdder源码学习

    本文转自https://blog.csdn.net/u011392897/article/details/60480108 LongAdder是jdk8新增的用于并发环境的计数器,目的是为了在高并发情 ...

  5. class-dump 使用

    转:class-dump 使用 class-dump 官网地址:这里 我这里下载的是 class-dump-3.5.dmg 版本的.双击.dmg 文件,将  拉倒 /usr / local / bin ...

  6. 内核同步机制-RCU同步机制

    转自:https://blog.csdn.net/nevil/article/details/7718375 转自http://www.360doc.com/content/09/0805/00/36 ...

  7. Core Animation学习总结

    文件夹: The Layer Beneath The Layer Tree(图层树) The Backing Image(寄宿层) Layer Geometry(图层几何学) Visual Effec ...

  8. Chart-template

    ylbtech-Chart: 1.返回顶部 1-1. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   7.返回顶部   8.返回顶部   9.返回顶部   ...

  9. Tomcat增加虚拟内存(转)

    程序要遍历读取xml并写入数据库,需要占用大量内存 如果数据量大则报错 Exception in thread "Timer-0" java.lang.OutOfMemoryErr ...

  10. 添加script标签、添加事件

    添加script标签 var _hmt = _hmt || [];    (function () {        var hm = document.createElement("scr ...