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. C++ 动态存储空间的分配和释放 new与malloc的区别

    使用new申请空间: 特点: 1.没有名字,只能通过指针间接访问它们. 2.从堆中申请空间 分类: 变量: 语法:指针变量 = new 类型名; Delete 指针变量 举例:int *p; p=ne ...

  2. 移动端tap与click的区别 && 点透事件

    移动端的问题 移动端的主要问题是click会有300ms的延迟,主要原因是苹果手机在设计时,考虑到用户在浏览网页时需要放大,所以,在用户点击的300ms之后,才触发click,如果300ms之内还有c ...

  3. 关于Mysql安装启动的若干问题解决

    Mysql由于其免费,高效的特点一直是大学,培训班的主力数据库管理软件.但是对于初学者而言可能没有那么友好,一是没有windows软件通用的那套可视化操作,基本上初期在不搭配navicat的状态下只能 ...

  4. 第一章 flex单词计数程序

    学习Flex&Bison目标, 读懂SQLite中SQL解析部分代码 Flex&Bison简介Flex做词法分析Bison做语法分析 第一个Flex程序, wc.fl, 单词计数程序 ...

  5. Python 库/模块/工具收集

    1 算法 1.1 字符串处理 re 正则表达式的标准库. StringIO / cStringIO 以读写文件的方式来操作字符串(有点类似于内存文件). cStringIO 是 C 语言实现的,提供高 ...

  6. 了解 JavaScript (3)- 马上开始

    之前演示了一个 Hello World 程序,而后讲解了一些基础概念,下面开始一些基础工作. 将脚本放在哪里 脚本可以放置在两个位置 <head></head>之间,头脚本(h ...

  7. 打通MySQL架构和业务的任督二脉

    目前,在很多OLTP场景中,MySQL数据库都有着广泛的应用,也有很多不同的使用方式.从数据库的业务需求.架构设计.运营维护.再到扩容迁移,不同的MySQL架构有不同的特点,适应一定的业务场景,或者解 ...

  8. jquery ajax IE

    在ie上会出现,get/post 只调用一次的现象 解决方法: cache:false http://stackoverflow.com/questions/8841425/how-to-set-ca ...

  9. 预防 app crash 之 unrecognized selector

    处理unrecognized selector异常原因 假如封装一个方法,在其他模块调用该方法时,传入参数不匹配则crash.比如下面的方法:本应该传入的参数类型为NSMutableArray,如果传 ...

  10. TLS/HTTPS 证书生成与验证

    最近在研究基于ssl的传输加密,涉及到了key和证书相关的话题,走了不少弯路,现在总结一下做个备忘 科普:TLS.SSL.HTTPS以及证书 不少人可能听过其中的超过3个名词,但它们究竟有什么关联呢? ...