如何在Raspberry PI 4上运行AWS Greenggrass Core中的RPI.GPIO模块
回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>正在寻找使用RPi.GPIO和Raspberry Pi 4的帮助</p>
<p>我有一个简单的Greengrass Lambda函数,它试图使用RPi.GPIO模块从电阻式土壤湿度传感器收集数据。我的Lambda函数依赖于Python3.7和RPi.GPIO模块的0.7.0版。我已经用一个简化的Python脚本验证了GPIO模块在Greengrass之外的设备上安装并正常工作</p>
<pre><code> import RPi.GPIO as GPIO
import RPIO
import time
channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)
def callback(channel):
if GPIO.input(channel):
print("No water detected")
else:
print("Water detected")
GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)
GPIO.add_event_callback(channel, callback)
while True:
time.sleep(1)
</code></pre>
<p>Greenglass Lambda可通过IoT组中定义的本地资源访问本地/dev/gpiomem文件系统。我使用的是Classic(V1)</p>
<p>但是,当我尝试部署Lambda函数时,会出现以下错误:</p>
<blockquote>
<p>-lambda_runtime.py:382,Failed to initialize Lambda runtime due to exception: This module can only be run on a Raspberry Pi!</p>
</blockquote>
<p>我在我的RPi上安装了两个版本的Python(2.7.16和3.7.3,Greengrass运行时使用3.7),并验证了这两个版本都具有0.7.0版本的RPi.GPIO模块</p>
<p>我的Lambda函数显式导入模块</p>
<pre><code>import logging
import platform
import sys
import RPi.GPIO as GPIO
import time
from threading import Timer
import greengrasssdk
</code></pre>
<p>是否有人遇到过此问题,您会推荐什么解决方案</p>