巫山雨_fz 2021-11-22 19:23 采纳率: 74.1%
浏览 74
已结题

win10系统usb转gpio模块在Python中import pygpio报错

img

img


网购的usb转gpio模块

import sys
from sys import argv,exit
from pygpio import BaseGPIO as GPIO

IN1 = 1
def setup_gpio():
GPIO.setup(IN1, OUT)

if name == 'main':
app = QApplication(sys.argv)
setup_gpio()
sys.exit(app.exec_())
出现如下报错
File "D:\lpcj\Qt-Camera\lpcj3.py", line 166, in setup_gpio
GPIO.setup(IN1, OUT)

NameError: name 'OUT' is not defined

打开gpio.py文件,有内容如下

Copyright (c) 2014 Adafruit Industries

Author: Tony DiCola

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in

all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

THE SOFTWARE.

import Adafruit_GPIO.Platform as Platform

OUT = 0
IN = 1
HIGH = True
LOW = False

RISING = 1
FALLING = 2
BOTH = 3

PUD_OFF = 0
PUD_DOWN = 1
PUD_UP = 2
class BaseGPIO(object):
"""Base class for implementing simple digital IO for a platform.
Implementors are expected to subclass from this and provide an implementation
of the setup, output, and input functions."""

def setup(self, pin, mode, pull_up_down=PUD_OFF):
    """Set the input or output mode for a specified pin.  Mode should be
    either OUT or IN."""
    raise NotImplementedError
  • 写回答

3条回答 默认 最新

  • soar3033 2021-11-22 20:38
    关注

    GPIO.setup(IN1, GPIO.OUT)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 12月2日
  • 已采纳回答 11月24日
  • 创建了问题 11月22日