I'm running into a problem that's a bit deeper than I know how to go. I'm working with the Nano 33 BLE, and passing IMU data over bluetooth. Bluetooth requires that data be passed as a bytes, and so far I have code that passes an array of floats as a byte array, as shown below:
The code currently passes the floats. The ints are where I'm stuck. The rub in all of this is that bluetooth will only let me pass 20 bytes at a time, and to not worry about latency / packet loss I'd like to pass all 18 bytes (3 floats and 3 ints) at once with setValue. Also, gx, gy, and gz are floats. I'm converting them to ints to keep the whole things under 20 bytes
What I don't know how to do is combine the float array and int array into one array / byte array and pass over bluetooth. I have code on the other end in Python to handle conversion back to floats / ints. I'm reading up on pointers more, but any guidance in the meantime would be welcome.
Quick post on my lunch break - I got some time to try out @blh64 code and it works well, except the struct keeps interpreting the ints as 4-byte instead of two. Why is this? The sizeof(dataPacket) is 24 bytes, but I would think it should be 18 (3 4-byte floats and 3 2-byte ints). sizeof dataPacket.gx is 4 however. Any ideas?
Are you sure an int is 2 bytes on that processor? You can tell the compiler that you want things packed as tight as possible, even if it means slower access to the elements of the struct. Probably also a good idea from @gfvalvo to explicitly make the 16 bit ints