我正在使用带有超音速传感器的arduino uno和manjaro上的pyhon(pymata).I am,这可能没有用。我试图让它检测距离,但当我运行它时,出现了以下错误:“模块”对象不可调用。我使用的代码是:
from random import triangular
from tkinter import OFF, ON
import speech_recognition as sr
from pyfirmata import Arduino
from pymata4 import pymata4
import time
#used to check if the arduino port selected is the right one
#board = Arduino('/dev/ttyACM0')
#print(board.get_firmata_version())
#led = board.get_pin('d:10:o')
#red = 9
#blue = 8
#yellow = 5
trig = 10
eco = 11
board = pymata4.Pymata4()
board = pymata4(com_port='/dev/ttyACM0')
board = pymata4(arduino_wait=10)
def the_callback(data):
print("Distance is: ", data[2])
board.set_pin_mode_sonar(trig, eco, the_callback)
while True:
try:
time.sleep(1)
board.sonar_read(trig)
except Exception:
board.shutdown()发布于 2022-05-29 21:17:01
这些线条是错误的:
board = pymata4.Pymata4()
board = pymata4(com_port='/dev/ttyACM0')
board = pymata4(arduino_wait=10)pymata4是一个模块,因此出现了错误。
初始化board时,请使用以下语法:
board = pymata4.Pymata4( com_port='/dev/ttyACM0', arduino_wait=10)https://stackoverflow.com/questions/72426673
复制相似问题