WiringPi出错

时间:2015-03-22 18:41:27

标签: python raspberry-pi twisted

我试图在这种模式下通过扭曲设置我的树莓果的输出

from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor

import smbus
import sys
import getopt
import time
import os
import signal

bus = smbus.SMBus(0)
import wiringpi2 as wiringpi
from time import sleep

class Raspi(Protocol):
  def connectionMade(self):  
     print("A client connected")
  def dataReceived(self, data):

if data == "s1":

 pin_base = 65       
 i2c_addr = 0x20     
 wiringpi.wiringPiSetup()                    
 wiringpi.mcp23017Setup(pin_base,i2c_addr)   
 wiringpi.pinMode(65, 1)           
 sleep (0.3) 
 #

elif data == "s2”:

  pin_base = 65       
  i2c_addr = 0x20     
  wiringpi.wiringPiSetup()                    
  wiringpi.mcp23017Setup(pin_base,i2c_addr)   
  wiringpi.pinMode(65, 0)         
  sleep (0.3)
  #
  else:
  stop()

  # Init and start server
  factory = Factory()
  factory.protocol = MovingRaspi
  reactor.listenTCP(8000, factory, 50, '192.168.0.3')
  reactor.run()

但是如果我设置s1然后s2我在WiringPi中有这个错误

wiringPiNewNode:引脚65与现有定义重叠

1 个答案:

答案 0 :(得分:0)

  • 也许wiringpiSetup()方法只能在每次运行时调用一次?
  • 也许您可以尝试在输出模式后“清理”端口:在调用wiringPiSetup()mcp23017Setup()之前将其设置为输入。

来源:How to use WiringPi2 for Python on the Raspberry Pi in Raspbian part 1 #Clean up after yourself