Go Down

Topic: transmitting data through Xbee's (Read 415 times) previous topic - next topic

victorfb

I am trying to make two arduino to communicate using Xbee's but when I send numbers the arduino converts them to ascii characters, for example if I type 42 on the serial monitor it transmits *, how can I change that? This is the code that I am using.
Code: [Select]
#include <SoftwareSerial.h>

#define Rx    0                     // DOUT to pin 6
#define Tx    1                     // DIN to pin 7
SoftwareSerial Xbee (Rx, Tx);

void setup() {
  Serial.begin(57600);               // Set to No line ending;
  Xbee.begin(57600);                //   type a char, then hit enter
  delay(100);
}

void loop() {
  if(Serial.available()) {          // Is serial data available?
    char outgoing = Serial.read();  // Read character, send to XBee
    Xbee.print(outgoing);
  }

  if(Xbee.available()) {            // Is data available from XBee?
    char incoming = Xbee.read();    // Read character,
    Serial.println(incoming);       //   send to Serial Monitor
  }

  delay(50);
 

PaulS

Code: [Select]
#define Rx    0                     // DOUT to pin 6
#define Tx    1                     // DIN to pin 7
SoftwareSerial Xbee (Rx, Tx);

Boy do I get tired of pointing this out. You can't use the hardware serial pins for software serial.


PaulS

Quote
Ok then, so what do I use?

Some other pins.

victorfb

This is my first time using xbee's, dont I have to use pins 0 and 1 to transmit and receive? this was an example that I found on the internet and I was trying to understand it

PaulS

You can NOT effectively use the hardware serial pins to talk to the XBee and the PC. If you don't mind crosstalk, then just use Serial to talk to both. Doing so will get very confusing.

Which shield are you using?

victorfb

So to make this work I have to take off this part?
Code: [Select]
SoftwareSerial Xbee (Rx, Tx); or just use other pins different than 0 and 1?
I am using this kit http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/ProductID/785/List/0/Default.aspx?SortField=ProductName,ProductName

PaulS

Quote
So to make this work I have to take off this part?
or just use other pins different than 0 and 1?

Yes. If the hardware supports it, SoftwareSerial on other pins is better.

Since you are not using a shield, the hardware does support using other than the hardware serial pins.

victorfb

well I figure it out already, I found another code and works pretty well. Thank you though

Go Up