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

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日

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算