Go Down

Topic: serial print to xbee (Read 682 times) previous topic - next topic

h_vestbo

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: [Select]
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?

h_vestbo

Here is my test code:
Code: [Select]
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);
}

PaulS

Code: [Select]
    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: [Select]
if(command == 'T')
works just as well, and even I can figure out what letter to send to get the response.

Code: [Select]
  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.

h_vestbo

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

PaulS

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

Then, what was the question?

h_vestbo

if you read the first post, you can find it

PaulS

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

h_vestbo

What other program can i use to test it?

PaulS

Quote
What other program can i use to test it?

Why not use the Serial Monitor?

h_vestbo

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

Go Up