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. Android疑问小结

    1:为什么新建项目继承自ActionBarActivity而不是Activity? 为了版本兼容的,你新建项目时最低版本选择4.0以上,就不会出现appcompat_v7包,AndroidBarAct ...

  2. 20172302《程序设计与数据结构》实验四Android程序设计实验报告

    课程:<程序设计与数据结构> 班级: 1723 姓名: 侯泽洋 学号:20172302 实验教师:王志强老师 实验日期:2018年5月30日 必修/选修: 必修 1.实验内容 (1)And ...

  3. Oozie分布式工作流——Action节点

    前篇讲述了下什么是流控制节点,本篇继续来说一下什么是 Action Nodes操作节点.Action节点有一些比较通用的特性: Action节点是远程的 所有oozie创建的计算和处理任务都是异步的, ...

  4. 标 题: [心得]传统IT转互联网面试经验分享

    发信人: lgonnet (逃之夭夭), 信区: Java标  题: [心得]传统IT转互联网面试经验分享发信站: 水木社区 (Wed Jul  1 10:18:38 2015), 站内 统一回复一下 ...

  5. 用ndk-stack分析应用native程序异常crash掉

    adb logcat | "/home/hxl/bin/android-ndk-r10d/ndk-stack" -sym "/home/hxl/plu/BadGame/p ...

  6. Scala:HelloWorld

    代码 object HelloWorld { def main(args: Array[String]): Unit = { println("Hello world") } } ...

  7. Python中多进程的使用

    进程:程序的一次执行(程序载入内存,系统分配资源运行).每个进程有自己的内存空间,数据栈等,进程之间可以进行通讯,但是不能共享信息. 线程:所有的线程运行在同一个进程中,共享相同的运行环境.每个独立的 ...

  8. 外网IP监测上报程序(使用Poco库的SMTPClientSession发送邮件)

    目录 IPReport 项目介绍 编译说明 安装使用说明 获取外网IP方式 邮件发送关键代码 IPReport 代码地址https://gitee.com/solym/IPReport 项目介绍 外网 ...

  9. ASP.NET MVC 一款可预览、裁剪头像上传组件

    今天介绍一款Web上常用的头像上传组件,常用于头像上传时对用户上传的图片进行裁剪并实时预览,最终效果如下: 源代码结构: Github地址: https://github.com/FrankFan/A ...

  10. 【微信上传素材接口--永久性】微信永久性上传、获取返回的medie_id 和url

    上传图片到微信服务器获得media_id和url (永久性) 其他接口类:https://www.cnblogs.com/gjw-hsf/p/7375261.html 转载地址:https://blo ...