Hello,
I am pretty new to the world of microcontrollers and and binary data and I have a problem with sending and recieving single integers of data by bluetooth. I have ADXL 345 accelerometer wired to arduino and I read data from all of three axes. I send it by Arduino Serial port. I am using code from this sparkfun tutorial: ADXL345 Hookup Guide - SparkFun Learn. If I do this with this code and send data to Serial port monitor on my laptop everything is working fine.
x = ((int)values[1]<<8)|(int)values[0];
y = ((int)values[3]<<8)|(int)values[2];
z = ((int)values[5]<<8)|(int)values[4];
//Print the results to the terminal.
Serial.print('x');
Serial.print(x, DEC);
Serial.print('y');
Serial.print(y, DEC);
Serial.print('z');
Serial.print(z, DEC);
Every sample is stored in two bytes of data, I am collecting them in I am combining them and result is as I expect -String of results with name of axis before every result. Like this:
x-7y-10z106x-6y-9z105x-5y-9z107x-5y-9z105x-4y-9z106x-5y-9z106x-5y-9z105x-5y-9z106x-6y-9z106x-6y-10z105x-7y-10z106x-6y-10z106x-7y-10z105x-6y-10z105x-5y-9z106x-5y-9z106x-5y-9z106x-6y-9z105x-5y-9z106x-5y-9z106x-5y-9z106x-5y-9z105x-6y-10z106x-6y-9z105x-6y-10z106x-7y-10z106x-7y-10z106
But my goal is to send data by bluetooth. I am using BTM 222 breakout board and I am sending data with this code and recieving on Android end inside my Threads run() method with this code:
axis = (char) mmInStream.read();
value =(mmInStream.read() << 8) | mmInStream.read();
stringBuilder.append(axis);
stringBuilder.append(value);
And I recieve something like this:
x11573y11569031281013944-13945-12592z12592530765531021112410112342x11573y11577z12592630765631021931281013688-13689-12592z12592630765631021931281014200-13945-12592z12592730765531021112410112342x11574y11569031281013944-13945-12592z12592630765531021112410112342x11574y11569031281013944-13945-14714112342x11574y11577z12592730765531021931281013944-13689-14714112341