Pages: [1]   Go Down
Author Topic: Echo answer of Serial3 into Serial  (Read 661 times)
0 Members and 1 Guest are viewing this topic.
NZ
Offline Offline
Sr. Member
****
Karma: 0
Posts: 390
Turtle in a hard shell
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

This may be trivial, but whats the easiest way to send the reply received on Serial3 of a 2560, out to Serial (0) so it can be seen on the serial monitor.

I am trying to talk to a Sena ESD110V2 Bluetooth module, and I am just trying to get it to scan what is in range, and I want to see it so I can hard code the info that comes in (just testing).

Is something like this code snippet along the right lines?

Code:
Serial3.print("AT+BTINFO?");
  char echoArray[50];
  byte myByte;
  while(Serial3.available() <= 0)
  {
    myByte = Serial3.read();
    echoArray[i] = myByte;
    i++;
  }
  Serial.print(echoArray);

Thanks
Logged

NZ
Offline Offline
Sr. Member
****
Karma: 0
Posts: 390
Turtle in a hard shell
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops

Code:
Serial3.print("AT+BTINFO?\r");
  char echoArray[10];
  byte myByte;
  while(Serial3.available() > 0)
  {
    myByte = Serial3.read();
    echoArray[i] = myByte;
    i++;
    if(i == 9)
    {
      Serial.println(echoArray);
      i = 0;
    }
  }

Crashed the IDE a few times with what I first wrote...

This seemed to get the response I needed. Awesome.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  while(Serial3.available() <= 0)
  {
    myByte = Serial3.read();
    echoArray[i] = myByte;
    i++;
  }
Serial.available() returns the number of bytes in the serial buffer, waiting to be read. The value can never be less than 0. Your while loop will fire whenever there is nothing to be read, and will read it, storing it in a buffer, with no error checking. You will, of course, in very short order stomp all over memory beyond the bounds of your array (within nanoseconds of applying power to the Arduino, as a matter of fact).
Logged

NZ
Offline Offline
Sr. Member
****
Karma: 0
Posts: 390
Turtle in a hard shell
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep spotted the mistake and that sounds like just what happened

Thanks
Logged

Pages: [1]   Go Up
Jump to: