I have Arduino library the leverages PyFirmata. This library is called each time a Thread is started, and I need to access the Arduino on the same port. Is it possible to do this? The Arduino sleeps for 60 seconds but another instance is created during this time of the Arduino but a serial exception is raised that com port is busy.
def init(self, logger=None):
self.logger = logger
self.openboards = []
comList = serial.tools.list_ports.comports()
boardsConnected = []
for element in comList:
if 'Arduino Mega' in element.description:
boardsConnected.append(element.description)
for i in range(0, len(boardsConnected)):
connected = str(boardsConnected[i])
port = connected.split(' ')
megaPort = port[3].replace('','')
megaPort = megaPort.strip("()")
try:
self.board = pyfirmata.ArduinoMega(megaPort)
self.openboards.append(self.board)
except serial.serialutil.SerialException:
print('Problem connecting to Arduino. Comm port may already be in use. Checking and trying to fix...')
for i in range(2, 14):
self.board.digital[i].write(1)
for i in range(22, 28):
self.board.digital[i].write(1)