Hello,
i have an arduino micro connected to bluetooth and to one sensor.
The aim is to get information from sensor through bluetooh console (android mobile)
#include <SoftwareSerial.h>
#define rxPin1 10
#define txPin1 11
#define rxPin2 0
#define txPin2 1
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin1, txPin1);
SoftwareSerial BTSerial = SoftwareSerial(rxPin2, txPin2);
int i;
char CaractR;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin1, INPUT);
pinMode(txPin1, OUTPUT);
pinMode(rxPin2, INPUT);
pinMode(txPin2, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(19200);
BTSerial.begin(9600);
mySerial.flush();
BTSerial.flush();
}
void loop() {
if(mySerial.available()>0){
CaractR = mySerial.read();
Serial.println(CaractR);//print in windows console
//BTSerial.print(CaractR);//print in bluetooth device (android mobile console)
}
}
with that code i am able to get information in windows:
it looks like that in windows console:
1
7
.
5R
1
7
.
5R
1
7
.
5R
this is what is expected! so everything is all right until now
1/
Issue is when i try to get the information throught bluetooth.It does work but only when i manage to get information flow at a lower speed. Issue here is that speed of information from sensor is too fast for bluetooth reception console!
I can make the information slower using delay(200) for example in the loop BUT the information from sensor goes mad after few second (stops or show bad characters).. i guess i cann't use delay to lower the speed because it kind of dezinchronise data from sensor and end in a bug.
How can i proceed to lower coming rate ?
2/ (extra question)
what is the best way to get the 4 character concatenated?
like string data= CaractR (concatenated)= mySerial.readuntil space after two charac +.+ one charact(17.5 for example);...
Cordially
Bastien