Pages: [1]   Go Down
Author Topic: Divide blueToothSerial Response  (Read 284 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please help.

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();
  }
}

Thanks in advance guys.

Phil
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/forum/index.php/topic,149014.0.html
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3778
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
   }
}
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Guys for your responses.

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:

    readData = blueToothSerial.read();
    Serialprint(readData+"\r\n");

Printed in the Monitor was an entire string.

So how can I strip readData apart.

Thanks for all your efforts in replying I appreciate it.

Phil
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's about time to post your whole program, don't you think ?

For instance, what data type is readData in your latest example and how/where is bluetoothSerial defined ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50841
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Pages: [1]   Go Up
Jump to: