Pages: [1]   Go Down
Author Topic: Arduino XBee Shield/Fio - Serial RX -Decode - Xbee TX  (Read 2513 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

What i'm trying to do is use an Arduino Fio with an XBee to parse some serial data from the RX pin and then send it to the XBee to transmit to another Arduino.

Code:
void setup() {
// Start the hardware serial.
Serial.begin(9600);
}

void loop() {
              //Do exciting things with the data here
  Serial.println("information I want to send out here");
}
}

The Xbee's are both at the default configuration and i've tested that under normal conditions they work.


So my other device sends data into the Fio via the RX pin and then I'm just using Serial.println which should output through the TX pin and therefore the XBee.

Sadly, this doesn't happen, when I don't have an XBee attached the board outputs the received and parsed data via USB as expected.

But once I plug in the XBee, it doesn't seem to receive serial data or transmit it anymore. Is there something I'm missing?

Thanks for your help I hope this will be an easy to solve problem!


Logged

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

Quote
So my other device sends data into the Fio via the RX pin and then I'm just using Serial.println which should output through the TX pin and therefore the XBee.
What other device is that? How is it connected to the Fio?

Anything that appears on the TX pin, the XBee should broadcast over the air. Anything that the XBee receives over-the-air, it should put on the RX pin.

Quote
The Xbee's are both at the default configuration and i've tested that under normal conditions they work.
What kind of XBees are they? What does "the default configuration" mean? Exactly as they left the digi factory? Despite digi's claims, out of the box XBees won't talk to each other.
Logged

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

It is a mindflex headset on the GND and RX pins of the FIO. The Xbees are on the same PAN and firmware updated series 1 modules and I pressed restore for each on X-CTU. I tested they worked on an explorer board and the fio with a simple serial.println("hello world");

Basically the flow of it should be - serial output of headset to arduino fio > parse on the fio > tell Xbee to output the result.

I think having a wire on the RX pin is causing this issu, is there a way I can stop the Xbee conflicting with my boards RX and then work only when I transmit?
Logged

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

Quote
I think having a wire on the RX pin is causing this issu, is there a way I can stop the Xbee conflicting with my boards RX and then work only when I transmit?
Why is the headset connected to the RX pin? Connect it to another pin, and use NewSoftSerial to read that pin.
Logged

italy
Offline Offline
Full Member
***
Karma: 2
Posts: 215
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pay attention about jumpers setting if you're using an xbee shield.

With the jumpers in the Xbee position (i.e. on the two pins towards the interior of the board), the DOUT pin of the Xbee module is connected to the RX pin of the microcontroller; and DIN is connected to TX. Note that the RX and TX pins of the microcontroller are still connected to the TX and RX pins (respectively) of the FTDI chip - data sent from the microcontroller will be transmitted to the computer via USB as well as being sent wirelessly by the Xbee module. The microcontroller, however, will only be able to receive data from the Xbee module, not over USB from the computer.

With the jumpers in the USB position (i.e. on the two pins nearest the edge of the board), the DOUT pin the Xbee module is connected to the RX pin of the FTDI chip, and DIN on the Xbee module is connected to the TX pin of the FTDI chip. This means that the Xbee module can communicate directly with the computer - however, this only works if the microcontroller has been removed from the Arduino board. If the microcontroller is left in the Arduino board, it will be able to talk to the computer normally via USB, but neither the computer nor the microcontroller will be able to talk to the Xbee module.
Logged

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

Thanks for your replies, I'm using the sparkfun xbee shield which has the switch from bline to uart.

I believe the trick is to make my Serial RX pin actually pin2 using NewSoftSerial as you recommended... I've tried following multiple tutorials but I just can't seem to figure out how to assign pin2 to basically act as though its the hardware serial rx pin and then pass to the actual hardware tx pin so the xbee can output. I need to do it this way as the Brain library i'm using requires to use the hardware serial. (I think - refer to the attached code)

sorry for being such a noob

here is the code:
Code:
// Arduino Brain Library
// Serial out example, grabs the brain data and sends CSV out over the hardware serial.
// Eric Mika, 2010

#include <Brain.h>

// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);

void setup() {
// Start the hardware serial.
Serial.begin(9600);
}

void loop() {
// Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
if (brain.update()) {
  Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
}
}


This is a snippet of something which I don't understand from the Brain.h
Code:
// More info on passing Serial objects: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264179436
Brain(HardwareSerial &_brainSerial);
Logged

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

Quote
I believe the trick is to make my Serial RX pin actually pin2 using NewSoftSerial as you recommended.
The Serial instance can not use pin 2. It is hardwired to pin 0. You could connect the headset to pin 2, and use NewSoftSerial, which is NOT a hardware serial class, to read the data.

Code:
NewSoftSerial headset(2, 255); // No write capabilities...

void lood()
{
   if(headset.available() > 0)
   {
      char val = headset.read();
      Serial.print(val); // Send out the hardware serial port, for the XBee to transmit...
   }
}

Quote
I just can't seem to figure out how to assign pin2 to basically act as though its the hardware serial rx pin and then pass to the actual hardware tx pin so the xbee can output.
Then pass what to the actual hardware TX pin?

Quote
This is a snippet of something which I don't understand from the Brain.h
The Serial object is an instance of the HardwareSerial class. The Brain constructor needs a reference to an instance of the HardwareSerial class (Serial, Serial1, Serial2, etc.).

What does the Brain library have to do with reading data from a headset?
Logged

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

Paul you are a genius!! smiley-grin at the moment we're soo close to being able to achieve what I need.

Code:
#include <Brain.h>
#include <NewSoftSerial.h>

// Set up the brain parser, pass it the hardware serial object you want to listen on.

NewSoftSerial Headset(2, 255);
Brain brain(Serial);

void setup() {
// Start the hardware serial.
Headset.begin(9600);
        Serial.begin(9600);

}

void loop() {
// Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"

if(Headset.available() > 0)
   {
      char val = Headset.read();
      Serial.println(val); // Send out the hardware serial port, for the XBee to transmit...
   }
}

This has the Xbee transmitting the data. However i've come to realise and after viewing the Brain library why it needs to use the brain.update() and the brain.readCSV() functions. The brain.update() includes the serial.available function plus a ton of other things to get a proper output - as at the moment its just jumble that is being outputted.

What would be amazing to do is get the brain library applied on the NewSoftSerial (Headset).
Quote
Brain brain(Serial);
but when I try and change the Serial it hates it as inside the library it has
Quote
Brain(HardwareSerial &_brainSerial);   

is there a way I can change the HardwareSerial directly in the libraries and use my softserial instead?

* ArduinoBrainLibrary.zip (3.51 KB - downloaded 8 times.)
Logged

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

Quote
is there a way I can change the HardwareSerial directly in the libraries and use my softserial instead?
You would need to change the HardwareSerial type to NewSoftSerial. Making the library support either hardware or software serial instances is a bigger job.
Logged

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

I changed the 3 instances to NewSoftSerial and now its not working haha - any better ideas? The library interestingly enough has this:
Code:
// TK Support for soft serials. A more generic "Serial" type to inherit from would be great.
// More info on passing Serial objects: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264179436
Brain(NewSoftSerial &_brainSerial);


This is what I found on that website - i'm not sure if it can help.

Code:
#include <NewSoftSerial.h>


class MyLibrary {
  public:
    //pass a reference to a Print object
    MyLibrary( NewSoftSerial &print ) {
printer = &print; //operate on the adress of print
    }
    void test() {
printer->println("Hello library with serial connectivity!");
    }
  private:
    NewSoftSerial * printer;
};

NewSoftSerial NSS(9,8);
MyLibrary myLibrary(NSS);

void setup() {
  NSS.begin(9600); //initialize Serial here
  myLibrary.test();
}


void loop() {
}

Logged

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

I'm confused about what you are trying to do. Start with an explanation of what the Brain class is, and the relationship between it, the headset, the XBee and the hardware and software serial ports.

Where is data coming in from? Where is it going to? What is the other XBee doing?

Quote
I changed the 3 instances to NewSoftSerial and now its not working haha - any better ideas?
It, in that sentence, is a pronoun with no referent. That is, I have no clue what "it" is. How do you know "it" isn't working?

Logged

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

Quote
I'm confused about what you are trying to do. Start with an explanation of what the Brain class is, and the relationship between it, the headset, the XBee and the hardware and software serial ports.

Where is data coming in from? Where is it going to? What is the other XBee doing?

The headset is a Neurosky Mindflex EEG headset. The headset's output is EEG data from the wearer. It has a ground and a serial output. The serial output is a jumble of information unless it is decoded properly by using the brain class.The brain class monitors the hardware serial and then decodes the information to display a line of values and remove any of the unneeded values or errors.

The Xbee will be used to retransmit the data to another arduino board with an Xbee, it will then decode the information is a similar fashion.


Originally this works perfectly using the hardware serial on the first board, but when the Xbee is plugged in, it stops working. Hence the need for the NewSoftSerial.


Quote
It, in that sentence, is a pronoun with no referent. That is, I have no clue what "it" is. How do you know "it" isn't working?

I apologise, it is very easy to think everyone knows what i'm trying to do, this is the error I receive when I input this Brain brain(NewSoftSerial); instead of Brain brain(Serial);

Code:
In file included from BrainSoftSerialOut.cpp:5:
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:18: error: expected `)' before '&' token
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:45: error: ISO C++ forbids declaration of 'NewSoftSerial' with no type
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:45: error: expected ';' before '*' token

I attached the libraries if it doesn't make sense.


 
Logged

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

Quote
The serial output is a jumble of information unless it is decoded properly by using the brain class.
OK. So you want to decode the data from the headset on the Arduino the headset is attached to?

Quote
The Xbee will be used to retransmit the data to another arduino board with an Xbee, it will then decode the information is a similar fashion.
This implies that no, you want the Arduino with the headset attached to just transmit the raw data, and the remote Arduino will decode it.

Quote
this is the error I receive when I input this Brain brain(NewSoftSerial); instead of Brain brain(Serial);
Serial is an instance of the HardwareSerial class. NewSoftSerial is a class name. Not the same things at all.
Logged

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

You are extraordinarily knowledgeable Paul, is there any references you'd recommend so I may learn some of these fundamentals you speak of, I feel like I'm wasting your time, but I think we are very close.

Quote
OK. So you want to decode the data from the headset on the Arduino the headset is attached to?
Yes

Quote
This implies that no, you want the Arduino with the headset attached to just transmit the raw data, and the remote Arduino will decode it.
Yes again, The Arduino on the headset will decode the information and the remote Arduino can decode it too. As they'll both require the information.

Quote
Serial is an instance of the HardwareSerial class. NewSoftSerial is a class name. Not the same things at all.
If I am reading this correctly, so now that I have replaced the instances in the library from HardwareSerial to NewSoftSerial, I should be using my newly defined 'Headset' in Brain brain(NewSoftSerial); ?


This is the output I get when I try this:
Code:
Brain brain(Headset);

Code:
In file included from BrainSoftSerialOut.cpp:5:
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:18: error: expected `)' before '&' token
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:45: error: ISO C++ forbids declaration of 'NewSoftSerial' with no type
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:45: error: expected ';' before '*' token
BrainSoftSerialOut:10: error: no matching function for call to 'Brain::Brain(NewSoftSerial&)'
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:14: note: candidates are: Brain::Brain()
C:\Users\Rj\Documents\Arduino\libraries\ArduinoBrainLibrary/Brain.h:14: note:                 Brain::Brain(const Brain&)

So what I did was add the #include NewSoftSerial on the libraries and guess what!! It seems to have worked!!

The headset is functioning properly and as expected! Thanks for your help Paul!

I'm wondering if i should branch the wiring of the new softserial input on pin 2 into two and have the other go to the TX pin of the Fio so that it is automatically transmitted over-the-air by the Xbee, would that work? Would I need to have any code or should it just happen automatically?

Thanks again for your help!

Logged

Pages: [1]   Go Up
Jump to: