pymata arduino with hc-sr04 TypeError: 'module' object is not callable

pymata arduino with hc-sr04 TypeError: 'module' object is not callable

我正在使用带有超声波传感器和 pyhon(pymata) 的 arduino uno。我在 manjaro 虽然这可能不是 usefull.I 我试图让它检测距离,但是当我 运行 它出现以下错误 TypeError: 'module' object is not callable。 我使用的代码是:

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()

这些行是错误的:

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)