tino / pyFirmata

Python interface for the Firmata (http://firmata.org/) protocol. It is compliant with Firmata 2.1. Any help with updating to 2.2 is welcome. The Capability Query is implemented, but the Pin State Query feature not yet.
MIT License
578 stars 191 forks source link

InvalidPinDefError at the moment of definition the pins #69

Open Lomilpda opened 6 years ago

Lomilpda commented 6 years ago

I`m trying to use pyfirmata to send and receive data between Arduino Uno R3 and my python program. At Arduino installed 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()

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`t understand what wrong with other pins. They are totally good and worked fine when I writed test sketch to Arduino.

saura125 commented 3 years ago

I am also facing the same issue! led = board.get_pin('d:31:o') led.write(1)