gpt4 book ai didi

python - 定义引脚时出现 InvalidPinDefError

转载 作者:行者123 更新时间:2023-12-01 09:22:49 26 4
gpt4 key购买 nike

我正在尝试使用 pyfirmata 在 Arduino Uno R3 和我的 python 程序之间发送和接收数据。在 Arduino 上安装了 StandartFirmata sketch。代码是:

from time import sleep
import serial
import pyfirmata
com_port_number = str(int(input('Введите номер COM-порта ')))
port = 'COM' + com_port_number # COM port number
print('Выбран порт COM ', port)
try:
board = pyfirmata.Arduino(port)
except serial.SerialException:
print('Не удается подключится к выбранному COM-порту')
com_port_number = str(int(input('Введите номер СОМ-порта')))
port = 'COM' + com_port_number
board = pyfirmata.Arduino(port)
sleep(1)
it = pyfirmata.util.Iterator(board)
it.start()
temp_list = []
potentiomentr = board.get_pin('a:0:o')
acid_control = board.get_pin('a:2:o')
stock_control = board.get_pin('a:3:o')
temperature_pin = board.get_pin('d:4:i') # well, this line is worked fine. Temperature sensor works correctly
in_connection_pc = board.get_pin('d:0:o') #but now i have InvalidPinDefError
triac = board.get_pin('d:6:o')
level = board.get_pin('d:8:i')
in_engine = board.get_pin('d:5:o')
in_triac = board.get_pin('d:10:o')
in_pump = board.get_pin('d:11:o')
drive_control = board.get_pin('d:12:o')
pump_control = board.get_pin('d:13:o')
while 1: # бесконечный цикл
a = temperature_pin.read()
b = in_connection_pc.write(1)
print(a)
list.append(a,b)
print(list)
sleep(3)
board.exit()

但是我有一些奇怪的错误:

Traceback (most recent call last):
File "C:/Users/lomil/PycharmProjects/Pyython_and_CSV_love/test_analog.py", line 22, in <module>
in_connection_pc = board.get_pin('d:0:i') #but now i have InvalidPinDefError??
File "C:\Users\lomil\Python_32\lib\site-packages\pyfirmata\pyfirmata.py", line 220, in get_pin
raise InvalidPinDefError('Invalid pin definition: UNAVAILABLE pin {0} at position on {1}'.format(pin_def, self.name))
pyfirmata.pyfirmata.InvalidPinDefError: Invalid pin definition: UNAVAILABLE pin d:0:i at position on COM1

当我评论除了

之外的所有行时
temperature_pin = board.get_pin('d:4:i') 

它有效,但我不明白其他引脚有什么问题。当我向 Arduino 编写测试草图时,它们非常好并且运行良好。

最佳答案

错误消息实际上是在提示:COM1 位置上的引脚 d:0:i 不可用。在 Arduino Uno(和大多数 Arduino)上 digital pins 0 and 1 are dual-use pins and are also used for communications over the serial port, aka COM port .

Firmata 的工作原理是通过串行端口不断进行通信,因此在使用 Firmata 时,您实际上无法将数字引脚 0 和 1 用于其他用途。

因此,无论您在数字引脚 0 上插入 Arduino 的任何电线,都需要移至另一个未使用的数字引脚,例如引脚 3。因此,如果将该电线移至数字引脚 3,那么在代码中您现在需要in_connection_pc = board.get_pin('d:3:o')

关于python - 定义引脚时出现 InvalidPinDefError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50685712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com