树莓派3 gpio接口规范gpio可不可以控制sdn芯片

[原创]通过Raspberry Pi(树莓派)的GPIO接口控制步进电机/Control ...
[原创]通过Raspberry Pi(树莓派)的GPIO接口控制步进电机/Control ...
是什么?引用维基百科的一句话:
The Raspberry Pi is a credit card sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools.
简单地说,它就是一个基于ARM CPU的、信用卡那么大的迷你计算机。In short, Pi is an ARM-based mini computer which has a credit card size.
在阅读本文之前,请确保你已经阅读过我的另外几篇,因为本文与它们有或多或少的关系。Before reading this article, please make sure that you've read&&of mine on Pi, because this article is more or less based on them.
【1】实验目的&/&Experiment purpose在树莓派上编写一个C程序,通过其GPIO口控制步进电机的转动方向以及速度。Write a C program to control the direction & speed of rotation of a stepper motor through the GPIO on Raspberry Pi.【2】为什么要用树莓派来控制步进电机 / Why doing this在我的概念中,无论是,还是,我都还是在“虚拟世界”中折腾树莓派,因为它没有向外界输出任何动作。而在构建一个稍微复杂的系统时,这种能力可能是很重要的,于是,用树莓派来控制步进电机是我必须要做的事情。In my view, no matter&, or , the Raspberry Pi was in a "virtual" world all the time because it didn't output any&movement to the real world. Having this ability may be very important to build a slightly more complex system, so I decided to use Pi to control a stepper motor.文章来源:【3】实现方案 / The implementation怎样通过Raspberry Pi的GPIO口来控制步进电机?已经有很多人这样做了。How to control a stepper motor through the GPIO on Pi? Lots of people have tried that before.由于步进电机通常需要一块驱动板,而这样的产品已经很容易买到并且极其廉价(肯定比你自己做要便宜),因此,我们没有必要自己去做。我在淘宝上不断地查啊查,终于找到了白菜价的步进电机和配套驱动板,加起来才一共8块多钱。Because we need a driver circuit board to drive the stepper motor, and it's really easy to buy this kind of product with super low price nowadays, so it's no need to make it ourselves. I (the largest e-commerce website&in China) and found a super cheap stepper motor & it's matched driver board, they cost me only about 8 RMB, that is, less than $1.5!
下面来看看我买的步进电机和驱动板的样子:The stepper motor & it's driver board:
文章来源:步进电机和驱动板的接线:Connect the stepper motor with it's driver board:
文章来源:该驱动板配有一个原理图,根据它我们可以知道如何把整个系统连接起来:The driver board has a&schematic diagram and we can learn from it how to connect the whole system together:
可见,驱动板上有4个输入口:IN1~IN4,这4个口用来接树莓派的4个GPIO口。同时,我们需要为驱动板提供5V的供电,这从哪里来?当然是从树莓派引出来。从下面的GPIO口分布图可以得知,“2”口就是+5V,正好就利用它。We can see that there are total 4 input pins: IN1~IN4, these 4 pins will be connected to 4 GPIO pins on Raspberry Pi. And we also need to provide a 5V power supply to the board, so where can we get this? Use the pin "2"(5V) next to pin "1"(3.3V)&on Pi&is the most convenient way. Refer to following GPIO pinouts for details:
文章来源:我将树莓派上的GPIO 17、18、21、22口(用树莓派的命名方式就是0、1、2、3口)分别接到步进电机驱动板上的IN1、IN2、IN3、IN4口,最后接好线的效果如下:I connected GPIO 17, 18, 21, 22(namely GPIO 0, 1, 2, 3 in Raspberry Pi name) on Pi to IN1, IN2, IN3, IN4 on the driver board separately, after it's done, the whole system looks like this:
文章来源:【4】编写程序 / Write the program在参考了这款步进电机配套的51单片机的示例代码后,我知道了依次把驱动板的IN1~IN4置为高电平,就可以驱动步进电机,也就是说,要把树莓派的4个GPIO输出口依次置为高电平。例如,假设用0代表低电平,1代表高电平的话,GPIO 17、18、21、22口的电平第一次被置为1、0、0、0,第二次被置为0、1、0、0,第三次被置为0、0、1、0,第四次被置为0、0、0、1。After checking the code(for MCS51 singlechip) provided by the product dealer I knew that it's possible to drive the motor by set IN1~IN4 high level in turn, namely set the 4 GPIO pins high level in turn. For example, if we use 0 to represent low level and 1 to represent high level, then GPIO 17, 18, 21, 22 on Raspberry Pi will be set to 1,0,0,0 in the 1st round, 0,1,0,0 in the 2nd round, 0,0,1,0 in the 3rd round and 0,0,0,1 in the 4th round.
于是我写出了下面的代码(仍然使用这个库来操作GPIO):So I wrote the follow code(still use
to manipulate the GPIO):
#include &wiringPi.h&
#include &stdio.h&
#include &unistd.h&
#include &stdlib.h&
#define CLOCKWISE 1
#define COUNTER_CLOCKWISE 2
void delayMS(int x);
void rotate(int* pins, int direction);
int main(int argc,char* argv[]) {
&&if (argc & 4) {
&&&&printf("Usage example: ./motor 0 1 2 3 \n");
&&&&return 1;
&&int pinA = atoi(argv[1]);
&&int pinB = atoi(argv[2]);
&&int pinC = atoi(argv[3]);
&&int pinD = atoi(argv[4]);
&&int pins[4] = {pinA, pinB, pinC, pinD};
&&if (-1 == wiringPiSetup()) {
&&&&printf("Setup wiringPi failed!");
&&&&return 1;
&&pinMode(pinA, OUTPUT);
&&pinMode(pinB, OUTPUT);
&&pinMode(pinC, OUTPUT);
&&pinMode(pinD, OUTPUT);
&&delayMS(50);&&&
&&for (int i = 0; i & 500; i++) {
&&&&rotate(pins, CLOCKWISE);
&&return 0;
void delayMS(int x) {
&&usleep(x * 1000);
void rotate(int* pins, int direction) {
&&for (int i = 0; i & 4; i++) {
&&&&if (CLOCKWISE == direction) {
&&&&&&for (int j = 0; j & 4; j++) {
&&&&&&&&if (j == i) {
&&&&&&&&&&digitalWrite(pins[3 - j], 1);
&&&&&&&&} else {
&&&&&&&&&&digitalWrite(pins[3 - j], 0);
&&&&} else if (COUNTER_CLOCKWISE == direction) {
&&&&&&for (int j = 0; j & 4; j++) {
&&&&&&&&if (j == i) {
&&&&&&&&&&digitalWrite(pins[j], 1);
&&&&&&&&} else {
&&&&&&&&&&digitalWrite(pins[j], 0);
&&&&delayMS(4);
文章来源:编译程序:Compile the code:
g++ motor.c -o motor -lwiringPi
运行程序:Run the program:
./motor 0 1 2 3
这里向程序传入了4个参数,它们分别代表要控制的树莓派的GPIO口。切记,由于使用了WiringPi库,所以要参考上面的GPIO分布图的左边那部分来确定这些数字。The four arguments passed to the program are the GPIO pin numbers on Pi. Be sure to keep in mind that because of using WiringPi, we need to refer to the left part of the GPIO pinouts image describe above to identify the numbers.
可以看到步进电机已经转动了(如所示)。如果你发现转动方向(顺/逆时针)反了,你可以把传入的参数顺序调整一下,就可以让它转对方向。Then we'll see the stepper motor start to rotate shown as . If you find that the direction of rotation is wrong, just adjust the order of the arguments passed to the program and it will be able to make the direction right.从前面的代码可见,如果要改变步进电机的转速,只需要改变rotate()函数中每次delay的时间即可。因此,如果我们把delay的时间逐渐由大变小,就会导致步进电机呈加速状态。让步进电机周期性加速的完整代码如下:From the code above we know that we can change the rotation speed of the motor by changing the delay time in function rotate(). So if we reduce the delay time gradually, the motor will be in an accelerating state. The full source code to make the motor speeding up periodically is shown below:
#include &wiringPi.h&
#include &stdio.h&
#include &unistd.h&
#include &stdlib.h&
#define CLOCKWISE 1
#define COUNTER_CLOCKWISE 2
void delayMS(int x);
void rotate(int* pins, int direction, int delay);
void stop(int* pins);
int main(int argc,char* argv[]) {
&&if (argc & 4) {
&&&&printf("Usage example: ./motor 0 1 2 3 \n");
&&&&return 1;
&&int pinA = atoi(argv[1]);
&&int pinB = atoi(argv[2]);
&&int pinC = atoi(argv[3]);
&&int pinD = atoi(argv[4]);
&&int pins[4] = {pinA, pinB, pinC, pinD};
&&if (-1 == wiringPiSetup()) {
&&&&printf("Setup wiringPi failed!");
&&&&return 1;
&&pinMode(pinA, OUTPUT);
&&pinMode(pinB, OUTPUT);
&&pinMode(pinC, OUTPUT);
&&pinMode(pinD, OUTPUT);
&&delayMS(50);&&&
&&int delay = 25;
&&while (true) {
&&&&for (int i = 0; i & 10; i++) {
&&&&&&rotate(pins, CLOCKWISE, delay);
&&&&delay--;
&&&&if (delay & 4) {
&&&&&&delay = 25;
&&&&&&stop(pins);
&&&&&&delayMS(500);
&&return 0;
void delayMS(int x) {
&&usleep(x * 1000);
void rotate(int* pins, int direction, int delay) {
&&for (int i = 0; i & 4; i++) {
&&&&if (CLOCKWISE == direction) {
&&&&&&for (int j = 0; j & 4; j++) {
&&&&&&&&if (j == i) {
&&&&&&&&&&digitalWrite(pins[3 - j], 1);
&&&&&&&&} else {
&&&&&&&&&&digitalWrite(pins[3 - j], 0);
&&&&} else if (COUNTER_CLOCKWISE == direction) {
&&&&&&for (int j = 0; j & 4; j++) {
&&&&&&&&if (j == i) {
&&&&&&&&&&digitalWrite(pins[j], 1);
&&&&&&&&} else {
&&&&&&&&&&digitalWrite(pins[j], 0);
&&&&delayMS(delay);
void stop(int* pins) {
&&for (int i = 0; i & 4; i++) {
&&&&digitalWrite(pins[i], 0);
文章来源:程序运行效果如下面的视频(,)所示:Run the program and then you'll see the speeding up effect, as the video(, ) shown below:至此,本文的主要目的已经达到。如果你还想对树莓派了解更多,请看。So the main&purpose of this article has been reached. If you want to know more about Pi, please read&.
发表评论:
TA的最新馆藏[转]&[转]&只需一步,快速开始
后使用快捷导航没有帐号?
树莓派GPIO入门01-使用GPIO接口控制发光二极管闪烁
11:01| 发布者:
| 查看: 2529
|原作者: mango
对象读者我假设你的树莓派已经连上你家里的路由(有线无线都行)。并且你已经可以在另外一台设备(台式机,笔记本,手机,平板电脑都可以) 上通过SSH软件登陆到你的树莓派了。当然你也可以直接在树莓派上通过HDMI连接显示器,通过USB键盘鼠标直接进行操作。不管怎样,你可以启动树莓派并进入树莓派的linux命令行界面。最终效果控制你的LED发光管按一定时间间隔闪烁硬件树莓派一台。1代B,B+或者2015年刚出的2代都可以。我自己用的是2代,GPIO的管脚编号可能会稍微有些差异,相应的需要注意或修改的地方我会在文中说明。另外,今后教程的硬件部分不再特意提到树莓派了。LED发光管(可以理解成小灯泡)一只,什么颜色都可以,一般卖电子零件的商店肯定有卖。或者去淘宝买。几块钱就可以买到一把。母头杜邦线两条,就是电线,带插头的是公头,带插座的是母头。我们这个实验用两端都是母头的杜邦线。硬件图原理说明LED灯有一长一短两根针脚,如果将较长的一根连上电源正极,较短的一根脸上电源负极造成电位差就可以点亮LED灯。但如果两个针脚同时都是负极(低电平)或者都是正极(高电平)则不会产生电位差也就不会被点亮。将较短的一根连上树莓派的GND(也就是负极)端,较长的一根不要直接连上树莓派的5V或者3.3V(两者都可理解为正极或高电平,以后统称高低电平,不再另行解释),而是连接到一个GPIO针脚上。然后我们可以通过程序控制GPIO口的电位高低状态即可控制LED的亮(GPIO口设置为高电平)或灭(GPIO口设置为低电平)。树莓派GPIO针脚说明(适合1代Mode B+或者2代Mode B)先看一下实物图:实物图右上角有左右两排共40根针脚,并不是所有的针脚都是GPIO针脚。详情参考下图:树莓派GPIO针脚说明注意这两张图的上下左右顺序已经对齐了,实际连线的时候不要看错方向接错针脚。否则有损坏树莓派的可能。硬件连接原理图选择开发语言控制GPIO口有很多方式,比如shell直接控制raspberry-gpio-python库(Python语言)wiringPi库(C语言)BCM2835 C Library(C语言)我们采用易于开发的python脚本语言作为开发语言。安装Python以及GPIO库先安装python-dev,输入以下指令。1sudo apt-get install python-dev安装RPi.GPIO,依次输入以下指令。特别说明,由于RPi.GPIO仍处于不断完善的过程中,推荐去下载最新代码。12345678910# 下载 $ wget http:# 有朋友反映上面这句执行不成功提示连接超时,原因是国内google被墙了# 这里我提供我已经下载好的文件,下载链接在文章最后# 解压缩 $ tar xvzf RPi.GPIO-0.5.3a.tar.gz# 进入解压之后的目录 $ cd RPi.GPIO-0.5.3a # 启动安装 $ sudo python setup.py install写代码代码里有详细的注释,代码很简单。1234567891011121314151617181920212223242526#!/usr/bin/env python# encoding: utf-8import RPi.GPIOimport time# 指定GPIO口的选定模式为GPIO引脚编号模式(而非主板编号模式)RPi.GPIO.setmode(RPi.GPIO.BCM)# 指定GPIO14(就是LED长针连接的GPIO针脚)的模式为输出模式# 如果上面GPIO口的选定模式指定为主板模式的话,这里就应该指定8号而不是14号。RPi.GPIO.setup(14, RPi.GPIO.OUT)# 循环10次for i in range(0, 10): # 让GPIO14输出高电平(LED灯亮) RPi.GPIO.output(14, True) # 持续一段时间 time.sleep(0.5) # 让GPIO14输出低电平(LED灯灭) RPi.GPIO.output(14, False) # 持续一段时间 time.sleep(0.5)# 最后清理GPIO口(不做也可以,建议每次程序结束时清理一下,好习惯)RPi.GPIO.cleanup()源代码下载  点击下载源码
  点击下载RPi.GPIO
没办法,只能发这个板块了希望不要被删
——————————————
插座上一堆乱七八糟的充电器,收纳又很麻烦怎么办?
来做一个漂亮的4口充电器吧,只
本固态特斯拉线圈教程由极客迷螃蟹兄编写,若需要转载,请联系QQ:首先此特
虽说光立方教程早已烂大街了,但是做出来成就感还是不错的,不发帖就太亏了,个人建议
成品镇楼!!
(小米电子时钟,233~~)
————————————————
All Rights Reserved温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
I'm on my way to future,where you are there.
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2705)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'手把手教你远程控制树莓派的GPIO!!!!',
blogAbstract:'之前大家可能看了“手把手教你如何使用树莓派的GPIO控制LED!!!“&&&',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:4,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'I\'m on my way to future,where you are there. ',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}后使用快捷导航没有帐号?
查看: 12451|回复: 14
注册时间最后登录阅读权限70积分21890精华2帖子
翰林, 积分 21890, 距离下一级还需 8110 积分
TA的每日心情奋斗 09:10签到天数: 361 天[LV.8]以坛为家I
本帖最后由 GY@艳 于
17:21 编辑
ukonline2000
一个简单的树莓派GPIO的图形控制程序,这样就方便那些觉得敲命令比较麻烦的童鞋, 分享给大家吧,希望对大家有所帮助!
有了它,大家就可以简单的一开一关控制GPIO,甚至控制电器和小车一类的,当然最好是用扩展板
废话不说了,先上图吧!
13:44 上传
1.使用方法,装好GPIO的库,参考这两个文章
2.下载源程序demo.py,在终端中用root登录(输入su -)
(1.29 KB, 下载次数: 244)
13:48 上传
点击文件名下载附件
3.然后输入
python demo.py
记住需要在图形界面下
程序代码:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Thu Jul 19 15:47:52 2012
# design by ukonline2000 form
# begin wxGlade: extracode
import RPi.GPIO as GPIO
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(7,GPIO.OUT)
# end wxGlade
class MyFrame(wx.Frame):
& & def __init__(self, *args, **kwds):
& && &&&# begin wxGlade: MyFrame.__init__
& && &&&kwds[&style&] = wx.DEFAULT_FRAME_STYLE
& && &&&wx.Frame.__init__(self, *args, **kwds)
& && &&&self.label_2 = wx.StaticText(self, -1, &GPIO0&)
& && &&&self.button_1 = wx.Button(self, -1, &ON&)
& && &&&self.button_5 = wx.Button(self, -1, &OFF&)
& && &&&self.label_3 = wx.StaticText(self, -1, &GPIO1&)
& && &&&self.button_2 = wx.Button(self, -1, &ON&)
& && &&&self.button_6 = wx.Button(self, -1, &OFF&)
& && &&&self.label_4 = wx.StaticText(self, -1, &GPIO2&)
& && &&&self.button_3 = wx.Button(self, -1, &ON&)
& && &&&self.button_7 = wx.Button(self, -1, &OFF&)
& && &&&self.label_5 = wx.StaticText(self, -1, &GPIO3&)
& && &&&self.button_4 = wx.Button(self, -1, &ON&)
& && &&&self.button_8 = wx.Button(self, -1, &OFF&)& && &&&
& && &&&self.label_6 = wx.StaticText(self, -1, &GPIO4&)
& && &&&self.button_9 = wx.Button(self, -1, &ON&)
& && &&&self.button_10 = wx.Button(self, -1, &OFF&)
& && &&&self.label_7 = wx.StaticText(self, -1, &GPIO5&)
& && &&&self.button_11 = wx.Button(self, -1, &ON&)
& && &&&self.button_12 = wx.Button(self, -1, &OFF&)
& && &&&self.label_8 = wx.StaticText(self, -1, &GPIO6&)
& && &&&self.button_13 = wx.Button(self, -1, &ON&)
& && &&&self.button_14 = wx.Button(self, -1, &OFF&)
& && &&&self.label_9 = wx.StaticText(self, -1, &GPIO7&)
& && &&&self.button_15 = wx.Button(self, -1, &ON&)
& && &&&self.button_16 = wx.Button(self, -1, &OFF&)
& && &&&self.__set_properties()
& && &&&self.__do_layout()
& && &&&self.Bind(wx.EVT_BUTTON, self.on0, self.button_1)
& && &&&self.Bind(wx.EVT_BUTTON, self.off0, self.button_5)
& && &&&self.Bind(wx.EVT_BUTTON, self.on1, self.button_2)
& && &&&self.Bind(wx.EVT_BUTTON, self.off1, self.button_6)
& && &&&self.Bind(wx.EVT_BUTTON, self.on2, self.button_3)
& && &&&self.Bind(wx.EVT_BUTTON, self.off2, self.button_7)
& && &&&self.Bind(wx.EVT_BUTTON, self.on3, self.button_4)
& && &&&self.Bind(wx.EVT_BUTTON, self.off3, self.button_8)& && &&&
& && &&&self.Bind(wx.EVT_BUTTON, self.on4, self.button_9)
& && &&&self.Bind(wx.EVT_BUTTON, self.off4, self.button_10)
& && &&&self.Bind(wx.EVT_BUTTON, self.on5, self.button_11)
& && &&&self.Bind(wx.EVT_BUTTON, self.off5, self.button_12)
& && &&&self.Bind(wx.EVT_BUTTON, self.on6, self.button_13)
& && &&&self.Bind(wx.EVT_BUTTON, self.off6, self.button_14)
& && &&&self.Bind(wx.EVT_BUTTON, self.on7, self.button_15)
& && &&&self.Bind(wx.EVT_BUTTON, self.off7, self.button_16)
& && &&&# end wxGlade
& & def __set_properties(self):
& && &&&# begin wxGlade: MyFrame.__set_properties
& && &&&self.SetTitle(&Raspi GPIO Demo&)
& && &&&self.SetSize((246, 330))
& && &&&self.label_2.SetMinSize((80, 40))
& && &&&self.label_2.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_1.SetMinSize((80, 40))
& && &&&self.button_5.SetMinSize((80, 40))
& && &&&self.label_3.SetMinSize((80, 40))
& && &&&self.label_3.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_2.SetMinSize((80, 40))
& && &&&self.button_6.SetMinSize((80, 40))
& && &&&self.label_4.SetMinSize((80, 40))
& && &&&self.label_4.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_3.SetMinSize((80, 40))
& && &&&self.button_7.SetMinSize((80, 40))
& && &&&self.label_5.SetMinSize((80, 40))
& && &&&self.label_5.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_4.SetMinSize((80, 40))
& && &&&self.button_8.SetMinSize((80, 40))
& && &&&self.label_6.SetMinSize((80, 40))
& && &&&self.label_6.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_9.SetMinSize((80, 40))
& && &&&self.button_10.SetMinSize((80, 40))
& && &&&self.label_7.SetMinSize((80, 40))
& && &&&self.label_7.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_11.SetMinSize((80, 40))
& && &&&self.button_12.SetMinSize((80, 40))
& && &&&self.label_8.SetMinSize((80, 40))
& && &&&self.label_8.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_13.SetMinSize((80, 40))
& && &&&self.button_14.SetMinSize((80, 40))
& && &&&self.label_9.SetMinSize((80, 40))
& && &&&self.label_9.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, &&))
& && &&&self.button_15.SetMinSize((80, 40))
& && &&&self.button_16.SetMinSize((80, 40))
& && &&&# end wxGlade
& & def __do_layout(self):
& && &&&# begin wxGlade: MyFrame.__do_layout
& && &&&sizer_1 = wx.BoxSizer(wx.VERTICAL)
& && &&&grid_sizer_1 = wx.GridSizer(8, 3, 0, 0)
& && &&&grid_sizer_1.Add(self.label_2, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_1, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_5, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_3, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_2, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_6, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_4, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_3, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_7, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_5, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_4, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_8, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_6, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_9, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_10, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_7, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_11, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_12, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_8, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_13, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_14, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.label_9, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_15, 0, 0, 0)
& && &&&grid_sizer_1.Add(self.button_16, 0, 0, 0)
& && &&&sizer_1.Add(grid_sizer_1, 1, wx.EXPAND, 0)
& && &&&self.SetSizer(sizer_1)
& && &&&self.Layout()
& && &&&# end wxGlade
& & def on0(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 0 is ON!&
& && &&&GPIO.output(11,True)
& && &&&event.Skip()
& & def off0(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 0 is OFF!&
& && &&&GPIO.output(11,False)
& && &&&event.Skip()
& & def on1(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 1 is ON!&
& && &&&GPIO.output(12,True)
& && &&&event.Skip()
& & def off1(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 1 is OFF!&
& && &&&GPIO.output(12,False)
& && &&&event.Skip()
& & def on2(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 2 is ON!&
& && &&&GPIO.output(13,True)
& && &&&event.Skip()
& & def off2(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 2 is OFF!&
& && &&&GPIO.output(13,False)
& && &&&event.Skip()
& & def on3(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 3 is ON!&
& && &&&GPIO.output(15,True)
& && &&&event.Skip()
& & def off3(self, event): # wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 3 is OFF!&
& && &&&GPIO.output(15,False)
& && &&&event.Skip()
& & def on4(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 4 is ON!&
& && &&&GPIO.output(16,True)
& && &&&event.Skip()
& & def off4(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 4 is OFF!&
& && &&&GPIO.output(16,False)
& && &&&event.Skip()
& & def on5(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 5 is ON!&
& && &&&GPIO.output(18,True)
& && &&&event.Skip()
& & def off5(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 5 is OFF!&
& && &&&GPIO.output(18,False)
& && &&&event.Skip()
& & def on6(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 6 is ON!&
& && &&&GPIO.output(22,True)
& && &&&event.Skip()
& & def off6(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 6 is OFF!&
& && &&&GPIO.output(22,False)
& && &&&event.Skip()
& & def on7(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 7 is ON!&
& && &&&GPIO.output(7,True)
& && &&&event.Skip()
& & def off7(self, event):&&# wxGlade: MyFrame.&event_handler&
& && &&&print &GPIO 7 is OFF!&
& && &&&GPIO.output(7,False)
& && &&&event.Skip()
# end of class MyFrame
if __name__ == &__main__&:
& & app = wx.PySimpleApp(0)
& & wx.InitAllImageHandlers()
& & frame_1 = MyFrame(None, -1, &&)
& & app.SetTopWindow(frame_1)
& & frame_1.Show()
& & app.MainLoop()
爱板&&爱板&&爱板& &&&
注册时间最后登录阅读权限100积分18183精华6帖子
TA的每日心情奋斗 12:42签到天数: 692 天[LV.9]以坛为家II
感谢楼主分享,赞一个!
注册时间最后登录阅读权限20积分54精华0帖子
童生, 积分 54, 距离下一级还需 146 积分
该用户从未签到
提示这个是欠什么? File &demo.py&, line 5, in &module&
& & import wx
ImportError: No module named wx
复制代码
注册时间最后登录阅读权限70积分21890精华2帖子
翰林, 积分 21890, 距离下一级还需 8110 积分
TA的每日心情奋斗 09:10签到天数: 361 天[LV.8]以坛为家I
medreams 发表于
提示这个是欠什么?
感谢你的解答啊
爱板&&爱板&&爱板& &&&
注册时间最后登录阅读权限70积分10217精华1帖子
翰林, 积分 10217, 距离下一级还需 19783 积分
TA的每日心情怒3&天前签到天数: 1110 天[LV.10]以坛为家III
注册时间最后登录阅读权限20积分54精华0帖子
童生, 积分 54, 距离下一级还需 146 积分
该用户从未签到
apt-get install python-wxtools复制代码
注册时间最后登录阅读权限20积分89精华0帖子
童生, 积分 89, 距离下一级还需 111 积分
TA的每日心情慵懒 10:51签到天数: 6 天[LV.2]偶尔看看I
请问您这里设置的GPIO11,12-18,还有GPIO18,22和7是根据revision 1还是revision 2的GPIO呢?因为我在rev 2的图上对应不上某些pin..
注册时间最后登录阅读权限20积分97精华0帖子
童生, 积分 97, 距离下一级还需 103 积分
该用户从未签到
我这个地方在做的时候遇到几个问题。我大概讲一下体会。
开始的时候我用user guide里面的IO控制方法是可以的(详见官方版的user guide),说明硬件没有问题,但是用这个demo是有问题的。
1. 缺少 wx的 load module ,后来自己安装了一个。
2. 关于IO的编号其实有两种mode,一种是BCM,一种是BOARD。需要做setup。如果是BCM,就看是GPIO的编号;如果是BOARD,IO编号就是指位置的编号。
3. 这个demo.py里面没有设置mode,楼主你确定能准确的run起来吗?
另外,有没有群什么的可供交流?谢谢。
注册时间最后登录阅读权限70积分21890精华2帖子
翰林, 积分 21890, 距离下一级还需 8110 积分
TA的每日心情奋斗 09:10签到天数: 361 天[LV.8]以坛为家I
dennystc 发表于
我这个地方在做的时候遇到几个问题。我大概讲一下体会。
开始的时候我用user guide里面的IO控制方法是可以 ...
问题已经收到了,我不太懂,已经帮你找了专业人士解决,请耐心等待。
爱板&&爱板&&爱板& &&&
注册时间最后登录阅读权限100积分4960精华3帖子
TA的每日心情开心 16:50签到天数: 15 天[LV.4]偶尔看看III
dennystc 发表于
我这个地方在做的时候遇到几个问题。我大概讲一下体会。
开始的时候我用user guide里面的IO控制方法是可以 ...
这个demo是去年写的了,但是的GPIO库版本较低,不需要这么多mode配置,现在要使用新版本的RPI.GPIO库的话,需要修改一下demo才行
博客站点:
分区版主职务勋章
爱板网分区版主
爱板会员勋章
注册成为爱板网会员
活跃会员勋章
经常参与各类话题的讨论,发帖内容较有主见
在线达人勋章
在线时间长,且活跃度高
在线之王勋章
在线时间非常长,且活跃度高
论坛版主职务勋章
爱板网论坛版主
论坛骨干勋章
在论坛积极发帖,并积极与坛友交流互动,成为论坛骨干力量
发帖机器勋章
在论坛积极发帖,数量巨大,质量较高
优秀会员勋章
经常在论坛发帖,与论坛互动交流,对论坛贡献很大
原创达人勋章
经常在论坛发表原创帖,且质量较高
突出贡献勋章
长期对论坛的繁荣而不断努力,或多次提出建设性意见
技术高手勋章
拥有多年经验和一流的技术水平
站长推荐 /3
我们从众多的智能硬件中选择 “智能插座”来作为话题的切入点。不管你有没有使用过,但站在用户的角度,你一定有你的想法和发言权。针对智能插座,说出你的想法和观点,你觉得怎样才能算的上一个好的智能插座?查看详情
查看泰克示波器相关视频和技术文档,回答问题,就有机会抽奖赢好礼啦!邀请好友更可额外获得奖励哦!
下载相关技术文档,为自己喜欢的技术文档投票,就有机会获得100元的京东券啦!除了分分钟就搞定的事情,来看看哪些主题方案最受欢迎吧!立即查看
Powered by Discuz!

我要回帖

更多关于 树莓派3 gpio接口规范 的文章

 

随机推荐