本文介绍了使用python 3在树莓派2上运行pyfirmata时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在树莓派2上运行pyfirmata.我在这里安装了它:
I am trying to run pyfirmata on my raspberry pi 2. I have it installed in here:
/home/pi/pyFirmata
但是当我尝试运行以下代码时:
But when I try to run the following code:
from pyfirmata import Arduino, util
import time
board = pyfirmata.Arduino('/dev/ttyACM0')
analog_pin = board.get_pin('a:0:i')
it = pyfirmata.util.Iterator(board)
it.start()
analog_pin.enable_reporting()
while True:
reading = analog_pin.read()
if reading != None:
voltage = reading * 5.0
print("Reading= %f\t Voltage= %f" % (reading, voltage))
time.sleep(1)
我收到以下错误消息:
Traceback (most recent call last):
File "/home/pi/Arduino_Avoltage.py", line 1, in <module>
from pyfirmata import Arduino, util
ImportError: No module named pyfirmata
我已经阅读了与pyfirmata一起安装的"read me"文件,而Arduino上已经安装了标准的firmata.我不知道我做错了什么.我需要将其与python 3配合使用,有什么建议吗?谢谢.
I have read the "read me" file that was installed with the pyfirmata and the Arduino has standard firmata installed on it. I can't figure out what I did wrong. I need this to work with python 3, any suggestions? Thanks.
推荐答案
您应将pyFirmata放入 site-packages :
You should put pyFirmata in site-packages:
/home/pi/Lib/site-packages/pyFirmata
这篇关于使用python 3在树莓派2上运行pyfirmata时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!