I am totally beginner but I am trying to finish my project as school work :-( but from the beginning, I am really stuck.
Could anyone help me out?
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
void setup() {
// initialize serial communication at 9600 bits per second:
BTserial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
BTserial.print(sensorValue1);
BTserial.print('|');
BTserial.println(sensorValue2);
delay(50);
}
The received value is here
D/BluetoothConnectionSrv: InputStream: 955|108
D/BluetoothConnectionSrv: InputStream: 9
D/BluetoothConnectionSrv: InputStream: 46|51
D/BluetoothConnectionSrv: InputStream: 9
D/BluetoothConnectionSrv: InputStream: 47|57
I need only values from 2 sensors, it seems to be as D/BluetoothConnectionSrv: InputStream: 955|108 D/BluetoothConnectionSrv: InputStream: 946|51 D/BluetoothConnectionSrv: InputStream: 947|57
I've tried to send "How are you?", then the result in the app was this
D/BF: o
D/BF: u ?Are yo
D/BF: u ?
D/BF: H
D/BF: ow Are you
D/BF: ?
Source code in my app
bluetoothSocket = socket;
InputStream tempIn = null;
OutputStream tempOut = null;
try {
tempIn = bluetoothSocket.getInputStream();
tempOut = bluetoothSocket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
inputStream = tempIn;
outputStream = tempOut;
}
public void run(){
byte[] buffer = new byte[1024];
int bytes;
while(true){
try {
bytes = inputStream.read(buffer);
handler.obtainMessage(STATE_MESSAGE_RECEIVED, bytes, -1, buffer).sendToTarget();
} catch (IOException e) {
e.printStackTrace();
}
}
}
case STATE_MESSAGE_RECEIVED:
byte[] readBuff = (byte[]) msg.obj;
String tempMsg = new String(readBuff, 0, msg.arg1);
tvMessage.setText(tempMsg);
Log.d("BF",tempMsg);
break;
BTserial.println
command toBTserial.print
– jsotola Jan 23 '19 at 5:32println
where it appends a new line character, although CR/LF should be 0x0D/0x0A... – Tom Jan 23 '19 at 12:17