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. WPF应用Access数据库

    WPF应用Access数据库 现在Access数据库中有表GuestTable,其中的字段如下图所示,现在需要应用WPF技术为此表制作一个数据库管理窗口,实现对此数据库中的数据进行数据的增.删.改和查 ...

  2. Android跨进程通信:图文详解 Binder机制 原理

    binder原理讲的很详细 https://blog.csdn.net/carson_ho/article/details/73560642

  3. Reveal:分析iOS UI的利器

    转:http://security.ios-wiki.com/issue-3-4/ Reveal简介 Reveal是分析iOS应用UI的利器: Reveal能够在运行时调试和修改iOS应用程序.它能连 ...

  4. mysql yum安装

    # 下载yum源的rpm包wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm# 安装rpm包rpm - ...

  5. C++ 并发编程,std::unique_lock与std::lock_guard区别示例

    背景 平时看代码时,也会使用到std::lock_guard,但是std::unique_lock用的比较少.在看并发编程,这里总结一下.方便后续使用. std::unique_lock也可以提供自动 ...

  6. UVA 10303 - How Many Trees?(数论 卡特兰数 高精度)

    Problem D How Many Trees? Input: standard input Output: standard output Memory Limit: 32 MB A binary ...

  7. centos清除dns cache.

    # /etc/init.d/nscd restart # service nscd restart # service nscd reload # nscd -i hosts https://www. ...

  8. .NET 用 Unity 依赖注入——概述注册和解析类型(1)

    本文内容 Unity 概述 环境 一个真实的例子 类型注册(Type Registrations) 解析类型(Resolving Types) 跳槽,新公司使用了 Unity,初步看了一下,公司的使用 ...

  9. SQLSERVER 设置默认值

    DECLARE @test intSET @test=nullselect isnull(@test,0)

  10. windows多线程同步互斥--总结

    我的windows多线程系列文章: windows多线程--原子操作 windows多线程同步--事件 windows多线程同步--互斥量 windows多线程同步--临界区 windows多线程同步 ...