So I am running a USB (UART) connection from my Arduino UNO (using the serialtransfer.h library) to my pc (using the pyserial transfer library). This how the INTENDED cycle of code goes: I receive the list_ packet and save it to a list on the Arduino . Then the elements in the list are checked and used to control parameters of motor a using GPIO pins. Finally a return message is sent to acknowledge each transfer.

I was hoping to make the return message from Arduino as sort of a flag ; whether to wait or move onto the next transfer, this is on the python side of things.

However this is not the case as the sending of packets from Arduino is almost instantaneous even with delay functions and before the Arduino can process the information the transfer is done.

1)Why doesn't delay() work ?

2) Why isn't code sequential ?

This is the Arduino side of things

#include "SerialTransfer.h"

SerialTransfer myTransfer;
int motor1 = 13;
int motor2 = 10;

int obj_cordinates[9];
char reply [16] = {"Packet Recieved"};
void setup()

void loop()
    // use this variable to keep track of how many
    // bytes we've processed from the receive buffer
    uint16_t recSize = 0;
    uint16_t sendSize = 0;

    recSize = myTransfer.rxObj(obj_cordinates, recSize);
    sendSize = myTransfer.txObj(reply, sendSize);
     if( obj_cordinates[4] == 15) 
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);
      digitalWrite(motor1, LOW);
      digitalWrite(motor2, HIGH);


The python side of things

import time
from pySerialTransfer import pySerialTransfer as txfer

def Ser_tran_list (list_):

        link = txfer.SerialTransfer('COM6')  
        time.sleep(2) # allow some time for the Arduino to completely reset

        to_transfer = True
        while to_transfer:
            send_size = 0
            # Send a list
            list_size = link.tx_obj(list_)
            send_size += list_size
            # send a character
            str_ = 'Sending data Packet'
            str_size = link.tx_obj(str_, send_size) - send_size
            send_size += str_size
            while not link.available():
                if link.status < 0:
                    if link.status == txfer.CRC_ERROR:
                        print('ERROR: CRC_ERROR')
                    elif link.status == txfer.PAYLOAD_ERROR:
                        print('ERROR: PAYLOAD_ERROR')
                    elif link.status == txfer.STOP_BYTE_ERROR:
                        print('ERROR: STOP_BYTE_ERROR')
                        print('ERROR: {}'.format(link.status))

            # Parse response string
            rec_str_   = link.rx_obj(obj_type=type(str_),
            # Display the received data
            print('SENT: {} {}'.format(list_,str_))
            print('Recieved: {}'.format(rec_str_))
            to_transfer = False

  • 1
    1) Probably because obj_cordinates[4] != 15 You can't use delay() for something that needs eventually some unpausing ... Commented Jun 10, 2021 at 14:29

1 Answer 1


The delay() function uses the milliseconds interrupt. Inside an interrupt handler, all other interrupts are suspended so the millis() counter doesn't count and delay() never ends. delayMicroseconds() will work in the interrupt routine because it just sits in a busy loop. Rewrite the code to eliminate the delay function, you can use millis if you want. This is telling you while in the delay function just about everything stops until it is finished.

  • There are several protocols that will do what you want. There is hardware handshaking and serial handshaking. This link explains a lot about both and how flow control works. stackoverflow.com/questions/7578812/…
    – Gil
    Commented Jul 13, 2021 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.