Hi, need some help with converting variables into byte arrays for serial transmission on Arduino in each direction. I need to convert int, long, long long and float to byte arrays for transmission then back to those variables when received.
I am new to C/C++ but not programming in general and when I started searching I found a lot of conflicting approaches, arguments along with concerns about Endienness. I realize the importance of that, but as everything stays within the Arduino family, would Endienness be an issue?
This got me to thinking that I can't be the first ever to need these functions, so thought I would ask here about a libraries (free - I am retired) that might be available to cover this issue.
In other languages I program, I would just copy the actual byte values using Pointers to the variables, but cannot find any good examples like that in C/C++ - yet.
But a library set of all these functions in one place would sure be handy.
Normally this processor "prints" C-strings via the serial port. To convert numeric value to a C-string you should be able to use the sprintf() function. To convert a C-string back to a number you should be able to use sscanf().
Seriously sprintf() and sscanf() ?
Did you read what I was trying to do? Passing data arrays between devices via serial.
Yes, I was serious. You didn't define what you meant by byte array and since the Arduino normally "prints" and "receives" character strings, not "byte arrays", sprintf() and sscanf() are viable ways of converting "numbers" to and from strings.