Pages: [1]   Go Down
Author Topic: serial print to xbee  (Read 607 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!
I have a problem when using xbee between my computer and my arduino.

I have a loop that looks for serial input, and if available it reads it and use the command to give a reply.
If i have this string in the bottom of the loop:
Code:
Serial.println();
everything works fine.
It looks for commands and gives reply.

BUT, if I remove the code in the bottom, so I only get a serial reply when I want to, nothing works.

Anyone here have an idea?
Logged

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

Here is my test code:
Code:
int command = 0;

void setup()
{
  Serial.begin(57600);
}

void loop(){
  if (Serial.available())
  {
    command = Serial.read();
    if (command == 84)
    {
      Serial.println("You pressed T");
    }
    else if (command == 71)
    {
      Serial.println("You pressed G");
    }
  Serial.print("Command: ");
  Serial.println(command);
  }
  Serial.println();           //<----------- Nothing works without this line
  command = 0;
  delay(500);
}
Logged

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

Code:
    if (command == 84)
    {
      Serial.println("You pressed T");
    }
    else if (command == 71)
    {
      Serial.println("You pressed G");
    }
You know, it really isn't necessary to look up the ASCII values of letters. The compiler already knows the values.

Code:
if(command == 'T')
works just as well, and even I can figure out what letter to send to get the response.

Code:
  Serial.println();           //<----------- Nothing works without this line
Then, you need to tell us what is on the other end of the serial port. The Serial Monitor does not require that statement.
Logged

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

My arduino is connected to a xbee breakout board wich have a xbee pro s2. This is configured as a router/end device AT.

This is in a network with a xbee pro s2 that stands in a usb explorer.

I use terminal in x-ctu on a windows pc to communicate with it
Logged

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

Quote
I use terminal in x-ctu on a windows pc to communicate with it
Then, what was the question?
Logged

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

if you read the first post, you can find it
Logged

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

If you open the Serial Monitor, can you dispense with the unnecessary Serial.println()? If so, then the issue is with X-CTU.
Logged

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

What other program can i use to test it?
Logged

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

Quote
What other program can i use to test it?
Why not use the Serial Monitor?
Logged

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

ok. can I use serial monitor with xbee? I didnt know..
will try it.. thanx;)
Logged

Pages: [1]   Go Up
Jump to: