How can I pause serial transfer and then un-pause it ?
Bezalelohim opened this issue · 7 comments
So I am running a usb (UART) connection from my arduino(using the serialtransfer.h library) to my pc (using the pyserial transfer library).
This how each 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. This is not the case as the sending of packets from Arduino is almost instantaneous even with delay functions
The python code is the standard code on your github with few changes to the parameters of rx.obj function
here 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()
{
Serial.begin(115200);
pinMode(motor1,OUTPUT);
pinMode(motor2,OUTPUT);
myTransfer.begin(Serial);
}
void loop()
{
if(myTransfer.available())
{
// 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);
delay(5000);
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);
delay(5000);
}
myTransfer.sendData(sendSize);
}
}
This is not the case as the sending of packets from Arduino is almost instantaneous even with delay functions
That sounds like the delays aren't being called, which seems more like a sketch issue. Try using debug prints via a second serial port (plus UART to USB converter) and see what exactly is going on.
Also note that you can use sendDatum()
to replace txObj()
and sendData()
if and only if you're transferring a single object in a single packet.
I am using an Arduino Uno and it doesn't have 2 serial ports. So while transferring via usb cable I can't use serial to print.
For delays not working
Its very wired that delays doesn't work as it baked into Arduino IC. To recap My only problem is this : delaying the
myTransfer.sendData(sendSize);
enough so that the program is run sequentially instead it runs as "if its on separate thread" and non sequentially .
So while transferring via usb cable I can't use serial to print.
That's not true, you can use softwareserial.h or another software uart library to communicate with a uart to usb converter.
Its very wired that delays doesn't work as it baked into Arduino IC. To recap My only problem is this : delaying the
myTransfer.sendData(sendSize);
enough so that the program is run sequentially instead it runs as "if its on separate thread" and non sequentially .
If the sendData()
calls are not being delayed, then it is most likely because your sketch is not calling delay()
due to a bug somewhere in the sketch or Python.
You were right the if statement wasn't being executed, there seems to an issue with Arduino processing the received list.
I am sending a list A=[1,2,3,4,5,6,7,8,9] from my pc using python to the Arduino so then in Arduino code the if statement A[5] > A[4] is always true for the list a , but this doesn't seem to be the case.
Also A[4] == 5 returns as false.
Thank You for all the help so far :)
That's not true, you can use softwareserial.h or another software uart library to communicate with a uart to usb converter.
I think you need a usb to ttl converter for that, it would very helpful for debugging but the current corona situation in my country doesn't allow for non-necessity goods to restocked or delivered online.
The reason you might be having issues is that Python normally defaults to ints being 32 bits wide while Arduino Uno ints are 16 bits wide.
Yes It is working Now!!! Changing the initialization int obj_cord[9] to int32_t obj_cord[9] in the arduino code fixed it. Now all statements are working fine Thankyou 👍