Pages: [1]   Go Down
Author Topic: transmitting data through Xbee's  (Read 351 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
 
Logged

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

Code:
#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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok then, so what do I use?
Logged

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

Quote
Ok then, so what do I use?
Some other pins.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So to make this work I have to take off this part?
Code:
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
Logged

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

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: