InvalidPinDefError at the moment of definition the pins

1.1k Views Asked by At

I'm trying to use pyfirmata to send and receive data between Arduino Uno R3 and my python program. At Arduino installed StandartFirmata sketch. Code is:

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

But i have some strange mistake:

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

When I commented all lines except

temperature_pin = board.get_pin('d:4:i') 

It worked, but I can not understand what's wrong with other pins. They are totally good and worked fine when I wrote test sketch to Arduino.

1

There are 1 best solutions below

0
On

The error message is actually complaining: UNAVAILABLE pin d:0:i at position on COM1. On the Arduino Uno (and most Arduinos) digital pins 0 and 1 are dual-use pins and are also used for communications over the serial port, aka COM port.

Firmata works by constantly communicating over the serial port so you can't actually use digital pins 0 and 1 for anything else while using Firmata.

So whatever wire you have plugged into your Arduino on digital pin 0, you need to move to another unused digital pin, like pin 3. So, if you move that wire to digital pin 3, then in code you would now need in_connection_pc = board.get_pin('d:3:o').