Go Down

Topic: Connect Xbee to Pin 5 and 6 instead of Rx Tx- Solved! (Read 1 time) previous topic - next topic

May 24, 2012, 09:06 pm Last Edit: Jun 24, 2012, 04:19 pm by napok Reason: 1
Hi. I tried already a lot, bought the books (wireless networks, Arduino etc.).
But not much success. Just built some Arduino projects.
I need to use the softserial but I seem to not find any simple forum post that covers it.
I want to hook the Xbees to Pin 5 and 6 because my Lilypad Simple Board has no Rx Tx pins.
http://proto-pic.co.uk/lilypad-arduino-simple-board/?gclid=CL6_2LDMmbACFcshtAodpGq7Wg

I tried to use:
Code: [Select]
const int RXPin = 4;
const int TXPin = 5;
SoftwareSerial xbee  =SoftwareSerial(RXpin, TXpin);

and I get the error message:
sketch_may24h.cpp:4:1: error: 'SoftwareSerial' does not name a type
or
SoftSerial.h: No such file or directory

Can you show me a way (Code) to get my 2 Xbee series 2 to talk to each other?
And if you want to help me further:
The goal of the project is a piece of interactive jewellery for my college project.
If you push a button that's attached to Pin9 the other one's LED on Pin11 lights up.
Also I would like Pin10 to light up if the Arduino-Xbees are in range and not light up when out of range.
Thanks.

Arrch


SoftSerial.h: No such file or directory

Seems to tell you the problem right there.

Thanks.
I have also tried the correct word SoftwareSerial.
This is the Code:
Code: [Select]
void setup() {               
const int RXPin = A5;
const int TXPin = A3;
SoftwareSerial xbee  =SoftwareSerial(RXpin, TXpin);
  Serial.begin(9600);
}

void loop()
{
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

Then the error:
In function 'void setup()':
7:1: error: 'SoftwareSerial' was not declared in this scope
7:16: error: expected ';' before 'xbee'
When I leave it away no error occurs:
Code: [Select]
void setup() {               
const int RXPin = A5;
const int TXPin = A3;
  Serial.begin(9600);
}

void loop()
{
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

but, does it then make the pins A5 and A3 Rx and Tx at all?
I have connected the Xbees with the so-called Lilypad Xbee,
http://www.sparkfun.com/products/8937
but I might need an Xbee Adapter to access the Xbees beforehand, right?
Or could I modify the Lilypad Xbee breakoutboard maybe in conjunction
with the FTDI  Basic from Sparkfun?
http://www.sparkfun.com/products/10275
The Xbees 2 do need pairing first, right?
Thanks so much for your help!

I had to change the pins from 4 and 5 to A5 and A3, because there is no pin 4 on the Lilypad Simple Board...
God, I wish I had just bought the regular Lilypad with its RxTx!

Arrch

Notice the differences in the example code:

Code: [Select]
SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  {
...
}

versus
Code: [Select]
void setup() {               
...
SoftwareSerial xbee  =SoftwareSerial(RXpin, TXpin);
}

I understand.
It has to be declared above. This doesn't produce an error any more.
So would this work now?
In order to check it, I need to read the
serial of the other Xbee now, right?
Code: [Select]
#include <SoftwareSerial.h>

const int RXPin = A5;
const int TXPin = A3;

SoftwareSerial xbee = SoftwareSerial(RXPin, TXPin);

void setup()
{               
  Serial.begin(9600);
  xbee.begin(9600);
}

void loop()
{
  xbee.print('H');
  delay(1000);
  xbee.print('L');
  delay(1000);
}

Arrch

Code: [Select]
SoftwareSerial xbee = SoftwareSerial(RXPin, TXPin);
Can be shortened:
Code: [Select]
SoftwareSerial xbee (RXPin, TXPin);


Hi again.
Now I tried it out -
to read out of my SoftwareSerial via simple wire into another Arduino (both Lilypad Simple) and get the other one to blink Led13.
I have connected Rx on the sender to Tx on the receiver and vice versa.
I have given both a nice Lipo 3.7 W that lights everything properly usually.
It doesn't work.
So, if the other Arduino doesn't get the read via cable, it won't print it into the Xbee when I hook it onto that pair of pins later, right?
What have I done wrong-still?
Code: [Select]
#include <SoftwareSerial.h>

const int RXPin = A5;              // setting the pin to RX
const int TXPin = A3;              // setting the pin to TX

SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name

void setup()
{               
  xbee.begin(9600);
}

void loop()
{
  xbee.print('H');                  // send the letter H out
  delay(1000);                      // wait for one second
  xbee.print('L');                  // send the letter L out
  delay(1000);                      // wait for one second
}

Code: [Select]
#include <SoftwareSerial.h>

const int RXPin = A5;        // change the pin into the RX
const int TXPin = A3;        // change the pin into the TX
int ledPin = 13;

SoftwareSerial xbee (RXPin, TXPin);//naming the new serial

void setup()
{
  pinMode(ledPin, OUTPUT);   //initialize the digital pin as output
  xbee.begin(9600);
}

void loop()
{
  if (xbee.read() == 'H')
  digitalWrite(ledPin, HIGH);// set the LED on
  delay(1000);               // wait for a second
  digitalWrite(ledPin, LOW); // turn the LED off
  delay(1000);               // wait for a second
}

Hi again.
If anyone still wants to help me.
Here are 2 photos how I have wired the two Arduinos Simple Boards.
http://www.flickr.com/photos/57866883@N08/

It´s the Linux Arduino!
Thanks everyone!
I went on a windows pc and it worked perfectly.
Somehow the Linux version Arduino 1.01 that I had no
problems programming other Arduino stuff with, has
a problem with the SoftwareSerial. It doesn't understand: write and available.
It`s now only a minor nuissance but:
Does anyone have an idea how to use a Linux Notebook with SoftwareSerial now?
Otherwise I have to sneak into my son`s room and use his Microsoft Computer...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy