Sending a byte stream over from an Arduino which includes some int16_t values (little endian) but struggling to recombine them. This is as close as I can get, but I loose the sign.
int1 = (inBuffer<<8) | inBuffer&0xff;
int2 = (inBuffer<<8) | inBuffer&0xff;
int3 = (inBuffer<<8) | inBuffer&0xff;
int4 = (inBuffer<<8) | inBuffer&0xff;
Thanks but I can’t see an answer to my question there.
I need to use a byte stream for speed.
Sending ASCII and dealing with strings and tokens is way too slow for my requirements.
Java’s corresponding datatype is
I’ve got this example sketch which uses a FloatBuffer:
But you can easily adapt it to use a ShortBuffer instead:
However I think you’re gonna need to switch your Arduino code to send bytes as big endian, which is the default protocol for transmission AFAIK.
Did you try:
int1 = ( (0xff & inBuffer) << 8) | ( (0xff & inBuffer) << 8)
I think that should work.
oops, thanks for the correction =)