提问人:Hassaan Khan 提问时间:8/26/2023 最后编辑:Hassaan Khan 更新时间:8/29/2023 访问量:130
python vscde 上的 Arduino Id 实例错误
Arduino Id Instance error on python vscde
问:
每当我尝试运行一个应该使用 Sonar HC-SR04 模块传输信号的代码,然后接收该信号以输出距离时。 但是一旦我运行代码,它就会立即停止并弹出此错误:
Opening all potential serial ports... COM3
Waiting 4 seconds(arduino_wait) for Arduino devices to reset...
Searching for an Arduino configured with an arduino_instance = 1
Traceback (most recent call last):
File "d:\Hassaan\MarvinPythonTest.py", line 4, in <module>
board = pymata4.Pymata4()
^^^^^^^^^^^^^^^^^
File "C:\Users\kk198\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymata4\pymata4.py", line 235, in __init__
self._find_arduino()
File "C:\Users\kk198\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymata4\pymata4.py", line 404, in _find_arduino
raise RuntimeError(f'arduino_instance_id does not match '
RuntimeError: arduino_instance_id does not match a value on the boards.
我试过放回端口、重置 Arduino、修复代码(尽管代码适用于 Arduino ide)、更新库、重新安装、重新启动我的笔记本电脑以及更改引脚,但没有任何效果。pymata4
from pymata4 import pymata4
import time
board = pymata4.Pymata4()
# Define the pins
trig_pin = 8
echo_pin = 9
# Configure the pins
board.set_pin_mode(trig_pin, board.OUTPUT)
board.set_pin_mode(echo_pin, board.INPUT)
while True:
# Set the trigger pin HIGH
board.digital_write(trig_pin, 1)
# Wait for 10 microseconds
time.sleep(0.00001)
# Set the trigger pin LOW
board.digital_write(trig_pin, 0)
# Wait for the echo_pin to go HIGH
while board.digital_read(echo_pin) == 0:
start_time = time.time()
# Wait for the echo_pin to go LOW
while board.digital_read(echo_pin) == 1:
end_time = time.time()
# Calculate duration and distance
duration = end_time - start_time
distance = duration * 34300 / 2 # Using 34300 cm/s as the speed of sound
print(f"Distance: {distance:.2f} cm")
# Wait for 1 second before the next loop
time.sleep(1)
答:
0赞
Hassaan Khan
8/29/2023
#1
只需重新上传firmataezpress,它就会起作用
评论