python - 值错误 : The channel sent is invalid on a Raspberry Pi - Controlling GPIO Pin 2 (BOARD) using Python causes Error

标签 python raspberry-pi raspbian gpio

所以我有一个小风扇连接到引脚 6(接地)和引脚 2。我试图在需要时手动启动和停止风扇,但尝试时出现此错误:

ValueError:发送的 channel 在 Raspberry Pi 上无效

这是我以 root 身份执行的代码。它似乎在其他引脚上工作,但在引脚 2 上不起作用

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

GPIO.setup(2, GPIO.OUT, pull_up_down=GPIO.PUD_UP)

我不确定如何访问此 pin。我做错了什么吗?

最佳答案

这可能是愚蠢的事情,我看起来完全一样。 GPIO 似乎有两种模式。 将 GPIO.setmode(GPIO.BOARD) 更改为

GPIO.setmode(GPIO.BCM) 

它对我干净安装 Raspbian 很有用

关于python - 值错误 : The channel sent is invalid on a Raspberry Pi - Controlling GPIO Pin 2 (BOARD) using Python causes Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24226310/

相关文章:

linux - sudo 关闭后启动 Raspberry Pi?

docker - 由于 "no such file or directory"导致 gitlab CI 失败

python - 如何删除像 July 1, 2019 这样的字符串

python - 合并并创建具有相同 id 的所有记录的新 JSON 数组

python - TensorFlow 中图形集合的目的是什么?

python - 使用 python 和 ElementTree 解析 XML

linux - 使用 "logger"登录到单独的日志文件

python - 由于 g++ 编译器错误,NS-3 构建失败

linux - MPD:使用 Linux bash 脚本接收实际的 mpd-status

camera - 树莓派 3B+ : Camera V1. 3 不工作