[Raspberry Pi Q&A, Help & Troubleshooting] superchuckles:
ok, here's my situation -- my bedroom door is a powered pocket door, that the motor speed controller, relay board, & open/close button pushes are all handled by an arduino uno. the problem with the uno was/is, after going thru a cycle or two, it would randomly & mysteriously reset, usually with the door open (thus not closing the door, & the uno thinking the door was closed). anyway, long story just a little bit longer, my solution was/is to use a raspberry pi 3 b, connected via usb. now, when the uno receives a button push, it sends an "O" thru the usb to the pi. upon receiving the "O" from the uno, the pi responds with an "o" to the uno, waits for a period, then sends a "c" to the uno, waits a couple of seconds, then resets the uno by closing & reopening the serial port on the usb. in this configuration, everything has ran perfectly & smoothly for months now..... then i just had to add remote control. first i tried directly adding an ir remote to the pi using lirc, & though i could program in my remote just fine, i could never get the code to work properly. then i just thought, "add another arduino!" i have half a dozen laying around, so i added one. the new arduino has only one function (with 3 buttons - left, right, & button push -- which is essentially the same as the wired button push in its operation). i added the 2nd arduino by connecting it to another usb port, & modified my python code to accommodate the extra button pushes. thing is, the extra python code has added serious lag to operation -- now, whether you push a button on the remote, or the wired button, it can take anywhere from 2 to 5 seconds for the system to respond, whereas without the remote, it was virtually instantaneous. any help as to why, or how i could simplify the code would be greatly appreciated.

import os
import serial
import time

port1 = serial.Serial("/dev/ttyUSB1", baudrate=115200, timeout=2.0) #door controller arduino
port2 = serial.Serial("/dev/ttyUSB0", baudrate=115200, timeout=2.0) #IR remote arduino

if (port1.isOpen() == False):
port1.open()

if (port2.isOpen() == False):
port2.open()

while True:
a=0
def countdwn(y):
while y >= 1:
y -=1
if (port1.isOpen() == False):
port1.open()
rcv=port1.read(1) #this sequence is started by pushing a button on the wall to open the door. the arduino
if rcv != "" : # sends an "O" thru the usb to the raspberry pi & then waits for reply
if rcv != "\n":
if rcv != "\r":
if rcv != "s":
print rcv
if rcv == "O": # recieve open command from arduino that controls door
port1.write("o") # send open command to same arduino
port1.write("\n")
os.system('aplay -q /home/pi/holodoor2.wav') #play star trek holodeck door sound
time.sleep(2)
port1.close()#this line & the following line are added to reset the door controller arduino
port1.open()
time.sleep(2) #delay to walk thru door - actually takes about 3.5 seconds - if shortened,
# the arduino will be in the middle of the reset when the close command comes
port1.write("c") # send door close command to door controlling arduino
port1.write("\n")
os.system('aplay -q /home/pi/holodoor2.wav')
time.sleep(2)
port1.close() #same as before -- to reset arduino
port1.open()
time.sleep(1)
#beginning of IR section follows
if (port1.isOpen() == False):
port1.open()
if (port2.isOpen() == False):
port2.open()
rcv2=port2.read(1)
if rcv2 != "" :
if rcv2 != "\n":
if rcv2 != "\r":
print rcv2
if rcv2 == "P": #essentially the same routine as the above button push sequence
port1.write("o")
port1.write("\n")
os.system('aplay -q /home/pi/holodoor2.wav')
time.sleep(2)
port1.close()
port1.open()
time.sleep(2)

port1.write("c")
port1.write("\n")
os.system('aplay -q /home/pi/holodoor2.wav')
time.sleep(2)
port1.close()
port1.open()
time.sleep(1)
y = 30

if rcv2 == "R": #simple open & leave door open by pushing the right arrow key on IR remote
port1.write("o")
port1.write("\n")
os.system('aplay -q /home/pi/holodoor2.wav')
time.sleep(2)
port1.close()
port1.open()
#time.sleep(2)

if rcv2 == "L": #same as above but close door
port1.write("c")
port1.write("\n")
os.system('aplay -q /home/pi/holodoor2.wav')
time.sleep(2)
port1.close()
port1.open()

countdwn(30)

port1.close()
port2.close()

time.sleep(1)
y = 30