Hello everybody,
I'm Fabio, hardware developer from Italy. As this is my first message here I will present me as a novice C programmer (let's say that I can fill completely an ATMEGA328P without bootloader but still not so good when dealing with the dynamic part of the memory). I'm also a quite modest designer in the electronics, especially in the audio field and with mechanics.
So I'm asking your precious advices as I would give my contribute for the working environment of Mr. Bill Porter's EasyTransfer Library - being not so prompt to disturb him directly for this purpose.
These days I'm feeling particularly comfortable with this library for a project of mine involving (obviously) many ATMEGA328P linked in serial communication and sharing, one after the other, the same array of bytes - each MCU just receives the array, collect the data of its interest and foldback the same array for the next board. In order to achieve the fastest speed with many bytes on the tiny buffer memory of this MCU, I preferred EasyTransfer as this adopts a protocol of reasonable length.
As stated by Mr. Porter, the protocol is as follows:
Header(0x06,0x85), SizeofPayload, Payload, Checksum
I can say that everything works perfectly on the Arduino-to-Arduino side, but I'm finding the proper difficulty dealing with Phyton, as this is for me the first day of messing around with it.
Despite of SerialTransfer, which was developed also for communication with Phyton, EasyTransfer has no support on this side, so I'm sure that solving this point can be useful to many, and probably not only newbies like me in the matter.
The major issue I'm trying to work around can be found on the .cpp file of the library.
Mostly, the data to be sent, in the form seen above, is generated thru the following piece of code:
//Sends out struct in binary, with header, length info and checksum
void EasyTransfer::sendData(){
uint8_t CS = size;
_stream->write(0x06);
_stream->write(0x85);
_stream->write(size);
for(int i = 0; i<size; i++){
CS^=*(address+i);
_stream->write(*(address+i));
}
_stream->write(CS);
}
In the specific example of my purpose:
my array of bytes has 8 elements and should something like:
[1,51,255,0,0,0,0,0] where the early four digits are the most important ones, the latters could be also discarded from transmission.
It's pretty clear that the header must be sent as 6 and 133 (in hex, 0x06 and 0x85), then I can see a 0x08 that should be the payload size (8), then some data that I can't distinguish, and a terminating checksum continuously changing.
In order to understand better what I'm receiving, some examples of the complete transmission are
x06\x85\x08\x013\x07\x00\x00\x00\x00\x00=\
or
x06\x85\x08\x013\x14\x00\x00\x00\x00\x00.\
or
x06\x85\x08\x013$\x00\x00\x00\x00\x00\x1e\
What can be the best way to generate, in the Python environment, a suitable array to be transmitted that can be read properly by the Arduino side of the EasyTransfer Library?
I'm still aware that getting back to SerialTransfer library is still a choice, but I've found it too much bulky (being casted for 16 bit elements and structs) and also a bit lacking in instructions: the data must be as light, fast and solid as possible and as yet said I feel that EasyTransfer fits perfectly for the job.
Thank you in advance for your contributions
EDIT: just forgot to say that the third value in my array is constantly changing between 0 and 255. Strangely, when I retrieve the readline from Python, I'm missing a value in that between:
x06\x85\x08\x013"\x00\x00\x00\x00\x00\x18
x06\x85\x08\x013#\x00\x00\x00\x00\x00\x19
x06\x85\x08\x013$\x00\x00\x00\x00\x00\x1e
x06\x85\x08\x013%\x00\x00\x00\x00\x00\x1f
x06\x85\x08\x013&\x00\x00\x00\x00\x00\x1c\
but it seems to be received pretty good from Arduino.
Is it supposed that the x013 (plus something) value is a sort of sum of at least two elements, if not three?