I am righting an app for the Arduino Mega 2560. I want to read parts of the recvData which is char type. How do I do this. I'm new to C.
void blueToothGetData(){
//convert char to string
//char *chr = "this is a char";
//string str = chr;
char recvData =' ';
if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
recvData = blueToothSerial.read();
}
}
Bluetooth works over serial, so keep reading in the chars and store them in a array. You will need a terminating char like a period.
char DATA_Array[20];
int count =0;
In your loop()
if(Serial.available()) {
char DATA = Serial.read();
if(DATA == '.') {
// display data then clear it for new data
// set count back to zero
}
else {
Data_Array[count++] = DATA;
}
}
However I forgot to mention For Sending and Receiving from the bluetooth I am using SoftwareSerial.H Here In lies my problem. It appears that A char variable as in my example above, appears to read the whole of the buffer.
For example a char in this case readData lwhen used with readData = bluetoothSerial.read() returns the entire buffer.
to test this I used the following code with out a loop, just a single call:
For example a char in this case readData lwhen used with readData = bluetoothSerial.read() returns the entire buffer.
Only when there is only one character in the buffer, which is probably most of the time, considering that serial data arrival is orders of magnitude slower than the Arduino can read it.