I have been banging my head against the wall for the past two days trying to figure this out.
I'm trying to send a array of integers, from python using pyserialtransfer package and receive it on the arduino mega with serialtranfer.h.
The packages have no commenting or documentation, which is a bit annoying.
I think what i'm failing to completely understand is how the line
"recSize = myTransfer.rxObj(arr, recSize);" is working, How does this actually assign the received bytes?
I've read the guide on advanced serial communication by the author of the package Power_Broker and also the basic communication tutorial by Robin2. I understood it all ( I Thought!) which makes this more annoying.
I'm getting a successful transfer, kind of, but every second data point is coming out as a 0 .
It seems to me that the arduino thinks it's receiving a different data type than it is?
or do the 0s represent a delimiter or a stop byte? I thought from reading power_brokers threads this package doesnt use delimiters? and, shouldn't the package automatically deal with start stop COBS and CRC bytes?
Here is my python code:
from time import sleep
from pySerialTransfer import pySerialTransfer as txfer
port = "/dev/ttyACM0"
arr = [9,7,3]
if __name__ == '__main__':
try:
link = txfer.SerialTransfer(port)
link.open()
sleep(5)
while True:
sendSize = 0
sendSize = link.tx_obj(arr, start_pos=sendSize)
link.send(sendSize)
except KeyboardInterrupt:
link.close()
And here is my arduino code:
#include "SerialTransfer.h"
#include "FastLED.h"
SerialTransfer myTransfer;
int arr[6];
void setup()
{
Serial.begin(115200);
myTransfer.begin(Serial);
}
void loop()
{
check_serial();
for (int i = 0; i < 6; i++) {
Serial.print(arr[i]);
}recSize = myTransfer.rxObj(arr, recSize);
Serial.println();
Serial.println("-----");
}
void check_serial() {
if(myTransfer.available())
{
// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint8_t recSize = 0;
recSize = myTransfer.rxObj(arr, recSize);
}
}
Obviously if I open the serial monitor to view the prints, it blocks the python code. But If I run the python code and then open serial monitor after, it has received the data, but it looks like this:
"907030"
So theres an extra 0 being inserted there, and I'm not sure why.
My final use case is to send an array of 60 8-bit integers (will never be > 255) to the arduino several times per second ( data points from a pose estimation algorithm).
So to speed things up, i'd appreciate advice on how make this more efficient and send just 8bit ints.