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. [HDU5968]异或密码

    [HDU5968]异或密码 题目大意: 数据共\(T(T\le100)\)组.每组给定一个长度为\(n(n\le100)\)的非负整数序列\(A(A_i\le1024)\),\(m(m\le100)\ ...

  2. 我的git笔记

    转眼间加入git的阵营已经快两年了,结识git,缘起github,2年前在寻找代码托管网站,当时还是用svn,起初使用google code,可是google的服务虽好,在天朝你懂得,后来发现了git ...

  3. git 删除分支 远程 && 本地

    //查看远程分支 git branch -a //删除远程分支 git branch -r -d origin/branch-name git push origin :branch-name// 或 ...

  4. css 类选择器结合元素选择器和多类选择器

    1.结合元素选择器 <p class="important">css</p> p.important {color: red} 匹配class属性包含imp ...

  5. android:碎片的生命周期

    和活动一样,碎片也有自己的生命周期,并且它和活动的生命周期实在是太像了,我相 信你很快就能学会,下面我们马上就来看一下. 4.3.1    碎片的状态和回调 还记得每个活动在其生命周期内可能会有哪几种 ...

  6. WebMagic编译时提示Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.18的解决方法

    问题描述:    从http://git.oschina.net/flashsword20/webmagic 下载最新代码,按照http://webmagic.io/docs/zh/posts/ch3 ...

  7. RHEL磁盘修复

    0. 1.基础工具:e2label /device/xxx [new label name]   显示/设定设备的label名称 2.e2fsck 修复工具,用-b 指定备用的superblock位置 ...

  8. PL/SQL学习笔记之数据类型中的标量、LOB

    一:标量 标量 即 基本数据类型,主要有4种:数值.字符.布尔类型.日期时间. 1:数值类型 数据类型 描述 PLS_INTEGER 通过2,147,483,647到-2147483648范围内有符号 ...

  9. 基于CentOS搭建VNC远程桌面服务

    系统要求:CentOS 7.2 64 位操作系统 安装.启动 VNC VNC 远程桌面原理 名词解释: Xorg:在 Linux 用户中非常流行,已经成为图形用户程序的必备条件,所以大部分发行版都提供 ...

  10. SSD卡对mongodb的影响

    结论 1:SSD卡显著改善磁盘IO,io占用在50%以下 2:SSD卡使mongodb性能稳定.在200并发,数据量是内存5倍的情况下仍然保证每秒1500次插入和4500次查询.     数据如下: ...