问题标签 [gpiozero]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2652 浏览

raspberry-pi - 无法导入 gpiozero

我刚刚安装了完整且最新的(2017 年 11 月)raspbian 来试用 gpiozero。我尝试运行的简单 python3 脚本是这样的:

python3 测试.py

但它给了我

所以它只是无法看到库。到目前为止,我已经检查了 apt-get 并且还尝试了 2.7 的 pip 和 python 3 的 pip3 但它只是没有找到?一定超级简单……

0 投票
1 回答
1217 浏览

python-3.x - 即使有异常处理,python也会挂起

我有一个覆盆子 PI 连接到 MCP3008 ADC,它正在测量热敏电阻上的模拟电压。我正在使用gpiozeropython 库在 PI 和 ADC 之间进行通信。我下面的代码运行了几分钟,然后吐出一个错误,然后挂在 function 上get_temp_percent。该函数返回来自 ADC 的五次测量的平均值。我Signal过去常常在等待 1 秒后抛出异常以尝试通过挂起,但它只是抛出一个错误并挂起。看起来我的except声明中没有任何内容被阅读。为什么我不逃避代码挂起?

函数get_temp_percent导致以下问题

0 投票
1 回答
1255 浏览

python - Raspberry pi gpio 引脚卡在“in”和“high”模式

我在 Raspberry Pi 2 上运行 Raspbian Stretch。我试图构建一个基本的避障漫游车,但遇到了电机问题。示意图在这里找到:

我没有 DC-DC 转换器,我有一个连接到引脚 17 的带有 330 欧姆电阻的 LED。

我正在使用此代码来运行它:

我运行了代码,我的 LED 闪烁了两次,第一个电机 (motora) 前后移动,但第二个电机 (motorb) 根本没有移动。我运行了终端命令“gpio readall”,发现我的第二个电机正在运行的引脚(BCM 5、6)设置为“IN”,并且都设置为“1”。

gpio readall 的终端输出

我尝试使用 GPIO.setup 命令将引脚 5 和 6 更改为输出引脚,但它仍然保持不变。我还尝试使用终端命令将引脚的输出从高更改为低,但没有任何反应。GPIO 引脚似乎卡在此模式下。

有什么办法可以修复这些卡住的 GPIO 引脚?在这种情况下,我做对了吗?

任何帮助将不胜感激!!

0 投票
0 回答
85 浏览

python-3.x - 这个时间戳是从哪里来的?(LED优先信号)

我有这段代码,它运行两次正常,而在第三次调用时我得到一个错误,就好像我会通过时间戳一样。我只通过元组或无。

输出如下

背景

程序的各个部分使用该函数来表示任何类型的错误,但如果高优先级的红色短闪结束,则较低优先级的绿色应继续。如果没有低优先级 - None,则 led 将被关闭(这是except用于的语句)

最低索引是最高优先级。

0 投票
1 回答
511 浏览

python - MicroPython - 它与 gpiozero ?RPi.GPIO 兼容吗?

我正在为家庭自动化制作一个物联网项目,包括使用Strech-Lite操作系统的十几个 Rpi Zero-W,以控制和报告其传感器和/或继电器的状态。

我相信 ESP32 Ebay 链接会更可靠,因为它是一个运行代码的控制器,而不是作为我当前解决方案的整个操作系统(顺便说一下,micro:bit 不符合条件,因为它缺少 wifi)。

我的问题是 - 我可以使用gpiozero图书馆吗?因为我的代码是基于它的

0 投票
2 回答
7378 浏览

python - Python 3.7 导入 gpiozero ModuleNotFoundError 在树莓派零上没有名为“gpiozero”的模块

在我的 Raspberry pi 零上构建 Python 3.7 以尝试从 Python 3.5.3 升级构建成功,遇到了找不到 smbus 的模块并将其切换到 smbus2,现在当我导入 gpiozero 时,我得到模块未找到。我的 DungeonCube.py 程序在 Python 3.5.3 下运行良好,但现在 Python 3.7 似乎无法找到 gpiozero

这就是我所做的测试:

有人知道如何让 python 3.7 看到 gpiozero 模块吗?

0 投票
0 回答
345 浏览

raspberry-pi - 如何排除 GPIO 零故障?

我正在尝试使用 Raspberry Pi Zero 做一个非常基本的“获取 LED”闪烁教程。遵循本指南:

闪烁:使树莓派上的 LED 闪烁

我可以使用 gpio 命令行实用程序打开和关闭 LED,使用 RPi.GPIO 的示例代码也可以正常工作,但我无法让 GPIO 零示例工作。

代码执行没有错误,但 LED 不闪烁。我可以尝试解决哪些可能的问题?

由于命令行和 RPi.GPIO 示例有效,我确定 LED 和电阻器连接正确,所以我不确定接下来要尝试什么。

0 投票
1 回答
1180 浏览

raspberry-pi - 如何获得树莓派引脚的状态?

我需要为树莓派 3 编写两个程序。在程序 1 中,我将一些引脚定义为输出并在其上设置一个值,然后我想在程序 2 中获取这些引脚的状态(值),换句话说,我想设置一个值在我想要的时候固定在一个进程中并读取另一个进程中的值 - 我使用 raspbian

0 投票
2 回答
1132 浏览

python - Using `gpiozero` on `raspberry pi` to control pins, but output pins are reset upon script exit, even though state is remembered between runs

I am using gpiozero to control devices on the Raspberry Pi. When I create a reference to (for example) an LED device, there is a parameter for creating the object without effecting it's current state: initial_state=None. (The default is initial_state=False, which automatically turns the value off upon reference object creation) The problem is it always seems to reset the hardware pin on script exit (though oddly enough not the internal "state"). What's worse, when I run the script again, it knows the state I left it in, and puts the physical pin back to that state!

Here's my jumpers on/off program, it now has a pausing input, during which the state stays unchanged, but when the program exits, the pins reset. (Though as I mention above, the state is "remembered")

Does anyone know a way to tell gpiozero to leave the hardware alone after exit? This question details a similar problem, though a different module.

(Edit: it turns out the gpiozero module changes the pin direction to input but doesn't change the output latch, which is how it gets the old state back when the pin direction is changed back to output.)

0 投票
1 回答
197 浏览

python - Python - Raspberry pi GPIO 到 SQlite3 - 带时间戳的高/Lov

现在我有一个简单的 python 解决方案,它运行完美。它正在制作一个 log.txt 文件并在每次打开/关闭 GPIO 12 时进行更新。

但是文件越来越长了,是时候升级到一个小数据库(SQlite3)了,让网页更容易阅读和排序。

自从我上次接触 SQL 以来已经有好几年了,所以我需要一些帮助才能让它工作。

这是我要更新以使用 SQlite 的 Python 日志文件脚本